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] ) const onTimeWeightedRetrieverSwitchUpdate = useCallback( (enabled: boolean) => { if (!activeThread) return updateThreadMetadata({ ...activeThread, assistants: [ { ...activeThread.assistants[0], tools: [ { type: 'retrieval', enabled: true, useTimeWeightedRetriever: 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="Time-Weighted Retriever looks at how similar they are and how new they are. It compares documents based on their meaning like usual, but also considers when they were added to give newer ones more importance." />
onTimeWeightedRetrieverSwitchUpdate(e.target.checked) } />
)}
)}
) } export default Tools