2023-04-10 00:41:34 +08:00
|
|
|
import React, { useState } from 'react';
|
2023-03-31 04:22:16 +08:00
|
|
|
import { DropdownMenuRadioItem } from '../../ui/DropdownMenu.tsx';
|
2023-04-10 00:41:34 +08:00
|
|
|
import { Settings } from 'lucide-react';
|
2023-03-31 04:22:16 +08:00
|
|
|
import getIcon from '~/utils/getIcon';
|
2023-04-10 00:41:34 +08:00
|
|
|
import { useRecoilValue } from 'recoil';
|
|
|
|
|
import SetTokenDialog from '../SetTokenDialog';
|
|
|
|
|
|
|
|
|
|
import store from '../../../store';
|
2023-03-31 04:22:16 +08:00
|
|
|
|
2023-05-13 16:29:06 -04:00
|
|
|
const alternateName = {
|
|
|
|
|
openAI: 'OpenAI',
|
|
|
|
|
azureOpenAI: 'Azure OpenAI',
|
|
|
|
|
bingAI: 'Bing',
|
|
|
|
|
chatGPTBrowser: 'ChatGPT',
|
|
|
|
|
google: 'PaLM',
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-31 04:22:16 +08:00
|
|
|
export default function ModelItem({ endpoint, value, onSelect }) {
|
2023-04-10 00:41:34 +08:00
|
|
|
const [setTokenDialogOpen, setSetTokenDialogOpen] = useState(false);
|
|
|
|
|
const endpointsConfig = useRecoilValue(store.endpointsConfig);
|
|
|
|
|
|
2023-03-31 04:22:16 +08:00
|
|
|
const icon = getIcon({
|
|
|
|
|
size: 20,
|
|
|
|
|
endpoint,
|
|
|
|
|
error: false,
|
|
|
|
|
className: 'mr-2'
|
|
|
|
|
});
|
|
|
|
|
|
2023-05-18 04:51:30 +05:30
|
|
|
const isUserProvided = endpointsConfig?.[endpoint]?.userProvide;
|
2023-04-10 00:41:34 +08:00
|
|
|
|
2023-03-31 04:22:16 +08:00
|
|
|
// regular model
|
|
|
|
|
return (
|
2023-04-10 00:41:34 +08:00
|
|
|
<>
|
|
|
|
|
<DropdownMenuRadioItem
|
|
|
|
|
value={value}
|
|
|
|
|
className="group dark:font-semibold dark:text-gray-100 dark:hover:bg-gray-800"
|
|
|
|
|
>
|
|
|
|
|
{icon}
|
2023-05-13 16:29:06 -04:00
|
|
|
{alternateName[endpoint] || endpoint}
|
2023-04-10 00:41:34 +08:00
|
|
|
{!!['azureOpenAI', 'openAI'].find(e => e === endpoint) && <sup>$</sup>}
|
|
|
|
|
<div className="flex w-4 flex-1" />
|
2023-05-18 04:51:30 +05:30
|
|
|
{isUserProvided ? (
|
2023-04-10 00:41:34 +08:00
|
|
|
<button
|
|
|
|
|
className="invisible m-0 mr-1 flex-initial rounded-md p-0 text-xs font-medium text-gray-400 hover:text-gray-700 group-hover:visible dark:font-normal dark:text-gray-400 dark:hover:text-gray-200"
|
|
|
|
|
onClick={e => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
setSetTokenDialogOpen(true);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Settings className="mr-1 inline-block w-[16px] items-center stroke-1" />
|
|
|
|
|
Config Token
|
|
|
|
|
</button>
|
|
|
|
|
) : null}
|
|
|
|
|
</DropdownMenuRadioItem>
|
|
|
|
|
<SetTokenDialog
|
|
|
|
|
open={setTokenDialogOpen}
|
|
|
|
|
onOpenChange={setSetTokenDialogOpen}
|
|
|
|
|
endpoint={endpoint}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
2023-03-31 04:22:16 +08:00
|
|
|
);
|
|
|
|
|
}
|