import { Fragment, useCallback, useEffect } from 'react' import { Tooltip, Switch, Input } from '@janhq/joi' import { useAtom, useAtomValue } from 'jotai' import { InfoIcon } from 'lucide-react' import { useCreateNewThread } from '@/hooks/useCreateNewThread' import useRecommendedModel from '@/hooks/useRecommendedModel' import AssistantSetting from '@/screens/Thread/ThreadCenterPanel/AssistantSetting' import { getConfigurationsData } from '@/utils/componentSettings' import { experimentalFeatureEnabledAtom } from '@/helpers/atoms/AppConfig.atom' import { selectedModelAtom } from '@/helpers/atoms/Model.atom' import { activeThreadAtom } from '@/helpers/atoms/Thread.atom' const Tools = () => { const experimentalFeature = useAtomValue(experimentalFeatureEnabledAtom) const activeThread = useAtomValue(activeThreadAtom) const [selectedModel, setSelectedModel] = useAtom(selectedModelAtom) const { updateThreadMetadata } = useCreateNewThread() const { recommendedModel, downloadedModels } = useRecommendedModel() const componentDataAssistantSetting = getConfigurationsData( (activeThread?.assistants[0]?.tools && activeThread?.assistants[0]?.tools[0]?.settings) ?? {} ) useEffect(() => { if (!activeThread) return let model = downloadedModels.find( (model) => model.id === activeThread.assistants[0].model.id ) if (!model) { model = recommendedModel } setSelectedModel(model) }, [recommendedModel, activeThread, downloadedModels, setSelectedModel]) const onRetrievalSwitchUpdate = useCallback( (enabled: boolean) => { if (!activeThread) return updateThreadMetadata({ ...activeThread, assistants: [ { ...activeThread.assistants[0], tools: [ { type: 'retrieval', enabled: enabled, settings: (activeThread.assistants[0].tools && activeThread.assistants[0].tools[0]?.settings) ?? {}, }, ], }, ], }) }, [activeThread, updateThreadMetadata] ) if (!experimentalFeature) return null return ( {activeThread?.assistants[0]?.tools && componentDataAssistantSetting.length > 0 && (
onRetrievalSwitchUpdate(e.target.checked)} />
{activeThread?.assistants[0]?.tools[0].enabled && (
} content="Embedding model is crucial for understanding and processing the input text effectively by converting text to numerical representations. Align the model choice with your task, evaluate its performance, and consider factors like resource availability. Experiment to find the best fit for your specific use case." />
} content="Vector Database is crucial for efficient storage and retrieval of embeddings. Consider your specific task, available resources, and language requirements. Experiment to find the best fit for your specific use case." />
)}
)}
) } export default Tools