import React, { useState } from 'react'; import { useRecoilValue } from 'recoil'; import store from '~/store'; const clipPromptPrefix = str => { if (typeof str !== 'string') { return null; } else if (str.length > 10) { return str.slice(0, 10) + '...'; } else { return str; } }; const MessageHeader = ({ isSearchView = false }) => { const [extended, setExtended] = useState(false); const conversation = useRecoilValue(store.conversation); const searchQuery = useRecoilValue(store.searchQuery); const { endpoint } = conversation; let options = []; if (endpoint === 'azureOpenAI' || endpoint === 'openAI') { options.push(['model', conversation?.model]); options.push(['chatGptLabel', conversation?.chatGptLabel]); options.push(['promptPrefix', clipPromptPrefix(conversation?.promptPrefix)]); options.push(['temperature', conversation?.temperature]); options.push(['top_p', conversation?.top_p]); options.push(['presence_penalty', conversation?.presence_penalty]); } else if (endpoint === 'bingAI') { options.push(['jailbreak', !!conversation?.jailbreak]); options.push(['toneStyle', conversation?.toneStyle]); } else if (endpoint === 'chatGPTBrowser') { options.push(['model', conversation?.model]); } const triggerExtend = () => { setExtended(prevState => !prevState); }; const getConversationTitle = () => { if (isSearchView) return `Search: ${searchQuery}`; else { let _title = `${endpoint}`; if (endpoint === 'azureOpenAI' || endpoint === 'openAI') { const { chatGptLabel, model } = conversation; if (model) _title += `: ${model}`; if (chatGptLabel) _title += ` as ${chatGptLabel}`; } else if (endpoint === 'bingAI') { const { jailbreak, toneStyle } = conversation; if (toneStyle) _title += `: ${toneStyle}`; if (jailbreak) _title += ` as Sydney`; } else if (endpoint === 'chatGPTBrowser') { const { model } = conversation; if (model) _title += `: ${model}`; } else if (endpoint === null) { null; } else { null; } return _title; } }; return (