import React from 'react'; import { useTranslation } from 'react-i18next'; import { useSelector } from 'react-redux'; import userService from '../api/services/userService'; import Dropdown from '../components/Dropdown'; import Input from '../components/Input'; import { CreateAPIKeyModalProps, Doc } from '../models/misc'; import { selectSourceDocs, selectToken } from '../preferences/preferenceSlice'; import WrapperModal from './WrapperModal'; const embeddingsName = import.meta.env.VITE_EMBEDDINGS_NAME || 'huggingface_sentence-transformers/all-mpnet-base-v2'; export default function CreateAPIKeyModal({ close, createAPIKey, }: CreateAPIKeyModalProps) { const { t } = useTranslation(); const token = useSelector(selectToken); const docs = useSelector(selectSourceDocs); const [APIKeyName, setAPIKeyName] = React.useState(''); const [sourcePath, setSourcePath] = React.useState<{ name: string; id: string; type: string; } | null>(null); const [prompt, setPrompt] = React.useState<{ name: string; id: string; type: string; } | null>(null); const [activePrompts, setActivePrompts] = React.useState< { name: string; id: string; type: string }[] >([]); const [chunk, setChunk] = React.useState('2'); const chunkOptions = ['0', '2', '4', '6', '8', '10']; const extractDocPaths = () => docs ? docs .filter((doc) => doc.model === embeddingsName) .map((doc: Doc) => { if ('id' in doc) { return { name: doc.name, id: doc.id as string, type: 'local', }; } return { name: doc.name, id: doc.id ?? 'default', type: doc.type ?? 'default', }; }) : []; React.useEffect(() => { const handleFetchPrompts = async () => { try { const response = await userService.getPrompts(token); if (!response.ok) { throw new Error('Failed to fetch prompts'); } const promptsData = await response.json(); setActivePrompts(promptsData); } catch (error) { console.error(error); } }; handleFetchPrompts(); }, []); return (
{t('modals.createAPIKey.label')}
setAPIKeyName(e.target.value)} borderVariant="thin" labelBgClassName="bg-white dark:bg-charleston-green-2" >
{ setSourcePath(selection); }} options={extractDocPaths()} size="w-full" rounded="xl" border="border" />
setPrompt(value) } size="w-full" border="border" />

{t('modals.createAPIKey.chunks')}

setChunk(value)} size="w-full" border="border" />
); }