2023-03-31 16:35:30 +08:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
|
import { useRecoilValue } from 'recoil';
|
2023-04-04 01:12:14 +08:00
|
|
|
import EndpointOptionsDialog from '../Endpoints/EndpointOptionsDialog';
|
2023-04-05 14:05:54 -04:00
|
|
|
import { cn } from '~/utils/';
|
2023-03-31 16:35:30 +08:00
|
|
|
|
|
|
|
|
import store from '~/store';
|
|
|
|
|
|
|
|
|
|
const MessageHeader = ({ isSearchView = false }) => {
|
2023-04-04 01:12:14 +08:00
|
|
|
const [saveAsDialogShow, setSaveAsDialogShow] = useState(false);
|
2023-03-31 16:35:30 +08:00
|
|
|
const conversation = useRecoilValue(store.conversation);
|
|
|
|
|
const searchQuery = useRecoilValue(store.searchQuery);
|
|
|
|
|
const { endpoint } = conversation;
|
|
|
|
|
|
|
|
|
|
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}`;
|
2023-05-13 16:29:06 -04:00
|
|
|
} else if (endpoint === 'google') {
|
|
|
|
|
_title = 'PaLM';
|
|
|
|
|
const { modelLabel, model } = conversation;
|
|
|
|
|
if (model) _title += `: ${model}`;
|
|
|
|
|
if (modelLabel) _title += ` as ${modelLabel}`;
|
2023-03-31 16:35:30 +08:00
|
|
|
} 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 (
|
2023-04-04 01:12:14 +08:00
|
|
|
<>
|
|
|
|
|
<div
|
2023-04-05 14:05:54 -04:00
|
|
|
className={cn(
|
2023-05-19 16:02:41 -04:00
|
|
|
'dark:text-gray-450 w-full gap-1 border-b border-black/10 bg-gray-50 text-sm text-gray-500 transition-all hover:bg-gray-100 hover:bg-opacity-30 dark:border-gray-900/50 dark:bg-gray-700 dark:hover:bg-gray-600 dark:hover:bg-opacity-100 dark:text-gray-500',
|
2023-04-05 14:05:54 -04:00
|
|
|
endpoint === 'chatGPTBrowser' ? '' : 'cursor-pointer '
|
|
|
|
|
)}
|
|
|
|
|
onClick={() => (endpoint === 'chatGPTBrowser' ? null : setSaveAsDialogShow(true))}
|
2023-04-04 01:12:14 +08:00
|
|
|
>
|
2023-05-18 11:09:31 -07:00
|
|
|
<div className="d-block flex w-full items-center justify-center p-3">
|
|
|
|
|
{getConversationTitle()}
|
|
|
|
|
</div>
|
2023-04-04 01:12:14 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<EndpointOptionsDialog
|
|
|
|
|
open={saveAsDialogShow}
|
|
|
|
|
onOpenChange={setSaveAsDialogShow}
|
|
|
|
|
preset={conversation}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
2023-03-31 16:35:30 +08:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default MessageHeader;
|