diff --git a/electron/main/llm/ipcHandlers.ts b/electron/main/llm/ipcHandlers.ts index 17c8f342..f44d2844 100644 --- a/electron/main/llm/ipcHandlers.ts +++ b/electron/main/llm/ipcHandlers.ts @@ -12,6 +12,7 @@ export const ollamaService = new OllamaService() export const registerLLMSessionHandlers = (store: Store) => { ipcMain.handle('set-default-llm', (event, modelName: string) => { store.set(StoreKeys.DefaultLLM, modelName) + event.sender.send('llm-configs-changed') }) ipcMain.handle('get-default-llm-name', () => store.get(StoreKeys.DefaultLLM)) @@ -22,14 +23,17 @@ export const registerLLMSessionHandlers = (store: Store) => { ipcMain.handle('add-or-update-llm-config', async (event, llmConfig: LLMConfig) => { await addOrUpdateLLMInStore(store, llmConfig) + event.sender.send('llm-configs-changed') }) ipcMain.handle('add-or-update-llm-api-config', async (event, llmAPIConfig: LLMAPIConfig) => { await addOrUpdateLLMAPIInStore(store, llmAPIConfig) + event.sender.send('llm-configs-changed') }) ipcMain.handle('remove-llm', async (event, modelNameToDelete: string) => { await removeLLM(store, ollamaService, modelNameToDelete) + event.sender.send('llm-configs-changed') }) ipcMain.handle('pull-ollama-model', async (event, modelName: string) => { @@ -37,9 +41,11 @@ export const registerLLMSessionHandlers = (store: Store) => { event.sender.send('ollamaDownloadProgress', modelName, progress) } await ollamaService.pullModel(modelName, handleProgress) + event.sender.send('llm-configs-changed') }) ipcMain.handle('delete-llm', async (event, modelName: string) => { await ollamaService.deleteModel(modelName) + event.sender.send('llm-configs-changed') }) } diff --git a/src/components/Chat/ChatInput.tsx b/src/components/Chat/ChatInput.tsx index 1d639b84..f064cfde 100644 --- a/src/components/Chat/ChatInput.tsx +++ b/src/components/Chat/ChatInput.tsx @@ -1,11 +1,13 @@ import React from 'react' import { PiPaperPlaneRight } from 'react-icons/pi' -import { LoadingState } from '../../lib/llm/types' +import { AgentConfig, LoadingState } from '../../lib/llm/types' import { Button } from '../ui/button' import LLMSelectOrButton from '../Settings/LLMSettings/LLMSelectOrButton' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select' import { allAvailableToolDefinitions } from '@/lib/llm/tools/tool-definitions' +import { Switch } from '@/components/ui/switch' +import { Label } from '@/components/ui/label' interface ChatInputProps { userTextFieldInput: string @@ -14,6 +16,8 @@ interface ChatInputProps { loadingState: LoadingState selectedLLM: string | undefined setSelectedLLM: (value: string | undefined) => void + agentConfig: AgentConfig | undefined + setAgentConfig: React.Dispatch> } const ChatInput: React.FC = ({ @@ -23,7 +27,28 @@ const ChatInput: React.FC = ({ loadingState, selectedLLM, setSelectedLLM, + agentConfig, + setAgentConfig, }) => { + // const [useStream, setUseStream] = React.useState(true) + + const handleDbSearchToggle = (checked: boolean) => { + setAgentConfig((prevConfig) => { + if (!prevConfig) throw new Error('Agent config must be initialized before setting db search filters') + return { + ...prevConfig, + dbSearchFilters: checked + ? { + limit: 22, + minDate: undefined, + maxDate: undefined, + passFullNoteIntoContext: true, + } + : undefined, + } + }) + } + return (
@@ -65,8 +90,20 @@ const ChatInput: React.FC = ({
+
+ + +
+
diff --git a/src/components/Settings/LLMSettings/LLMSelectOrButton.tsx b/src/components/Settings/LLMSettings/LLMSelectOrButton.tsx index 578cda28..7a2e4053 100644 --- a/src/components/Settings/LLMSettings/LLMSelectOrButton.tsx +++ b/src/components/Settings/LLMSettings/LLMSelectOrButton.tsx @@ -1,5 +1,4 @@ import React, { useState } from 'react' -import { FiRefreshCw } from 'react-icons/fi' import { Button } from '@/components/ui/button' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import SettingsModal, { SettingsTab } from '../Settings' @@ -11,7 +10,7 @@ interface LLMSelectOrButtonProps { } const LLMSelectOrButton: React.FC = ({ selectedLLM, setSelectedLLM }) => { - const { llmConfigs, fetchAndUpdateModelConfigs } = useLLMConfigs() + const { llmConfigs } = useLLMConfigs() const handleLLMChange = (value: string) => { setSelectedLLM(value) } @@ -57,7 +56,6 @@ const LLMSelectOrButton: React.FC = ({ selectedLLM, setS )} - diff --git a/src/lib/hooks/use-agent-configs.ts b/src/lib/hooks/use-agent-configs.ts index b8bad653..ed996675 100644 --- a/src/lib/hooks/use-agent-configs.ts +++ b/src/lib/hooks/use-agent-configs.ts @@ -4,7 +4,7 @@ import exampleAgents from '@/components/Chat/ChatConfigComponents/exampleAgents' interface UseAgentConfigReturn { agentConfig: AgentConfig | undefined - setAgentConfig: (config: AgentConfig | ((prev: AgentConfig | undefined) => AgentConfig)) => void + setAgentConfig: React.Dispatch> } function useAgentConfig(): UseAgentConfigReturn { diff --git a/src/lib/hooks/use-llm-configs.ts b/src/lib/hooks/use-llm-configs.ts index b2f5a85f..65d1f41e 100644 --- a/src/lib/hooks/use-llm-configs.ts +++ b/src/lib/hooks/use-llm-configs.ts @@ -1,4 +1,4 @@ -import { useState, useEffect } from 'react' +import { useState, useEffect, useCallback } from 'react' import { LLMConfig } from 'electron/main/electron-store/storeConfig' @@ -6,7 +6,7 @@ const useLLMConfigs = () => { const [llmConfigs, setLLMConfigs] = useState([]) const [defaultLLM, setDefaultLocalLLM] = useState('') - const fetchAndUpdateModelConfigs = async () => { + const fetchAndUpdateModelConfigs = useCallback(async () => { const fetchedLLMConfigs = await window.llm.getLLMConfigs() setLLMConfigs(fetchedLLMConfigs) const storedDefaultLLM = await window.llm.getDefaultLLMName() @@ -16,7 +16,11 @@ const useLLMConfigs = () => { } else { setDefaultLocalLLM(storedDefaultLLM) } - } + }, []) + + useEffect(() => { + window.ipcRenderer.on('llm-configs-changed', fetchAndUpdateModelConfigs) + }, [fetchAndUpdateModelConfigs]) const setDefaultLLM = async (modelName: string) => { await window.llm.setDefaultLLM(modelName) @@ -25,7 +29,7 @@ const useLLMConfigs = () => { useEffect(() => { fetchAndUpdateModelConfigs() - }, []) + }, [fetchAndUpdateModelConfigs]) return { llmConfigs,