Skip to content

Commit

Permalink
rm refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
samlhuillier committed Nov 3, 2024
1 parent c53c371 commit 3781ea6
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 11 deletions.
6 changes: 6 additions & 0 deletions electron/main/llm/ipcHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const ollamaService = new OllamaService()
export const registerLLMSessionHandlers = (store: Store<StoreSchema>) => {
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))
Expand All @@ -22,24 +23,29 @@ export const registerLLMSessionHandlers = (store: Store<StoreSchema>) => {

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) => {
const handleProgress = (progress: ProgressResponse) => {
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')
})
}
41 changes: 39 additions & 2 deletions src/components/Chat/ChatInput.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,6 +16,8 @@ interface ChatInputProps {
loadingState: LoadingState
selectedLLM: string | undefined
setSelectedLLM: (value: string | undefined) => void
agentConfig: AgentConfig | undefined
setAgentConfig: React.Dispatch<React.SetStateAction<AgentConfig | undefined>>
}

const ChatInput: React.FC<ChatInputProps> = ({
Expand All @@ -23,7 +27,28 @@ const ChatInput: React.FC<ChatInputProps> = ({
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 (
<div className="flex w-full">
<div className="z-50 flex w-full flex-col overflow-hidden rounded border-2 border-solid border-border bg-background focus-within:ring-1 focus-within:ring-ring">
Expand Down Expand Up @@ -65,8 +90,20 @@ const ChatInput: React.FC<ChatInputProps> = ({
</div>

<div className="flex items-center">
<div className="mr-[-8px] flex flex-col">
<Switch
id="stream-mode"
checked={!!agentConfig?.dbSearchFilters}
onCheckedChange={handleDbSearchToggle}
className="scale-[0.6]"
/>
<Label htmlFor="stream-mode" className="mt-0 text-[8px] text-muted-foreground">
Search notes
</Label>
</div>

<Button
className="flex items-center justify-between gap-2 bg-transparent text-[10px] text-primary hover:bg-transparent hover:text-accent-foreground"
className="flex items-center justify-between bg-transparent text-[10px] text-primary hover:bg-transparent hover:text-accent-foreground"
onClick={handleSubmitNewMessage}
disabled={loadingState !== 'idle'}
>
Expand Down
4 changes: 3 additions & 1 deletion src/components/Chat/ChatMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const ChatMessages: React.FC<ChatMessagesProps> = ({
handleNewChatMessage,
loadingState,
}) => {
const { agentConfig } = useAgentConfig()
const { agentConfig, setAgentConfig } = useAgentConfig()
const [userTextFieldInput, setUserTextFieldInput] = useState<string | undefined>()
const { defaultLLM, setDefaultLLM } = useLLMConfigs()
const [selectedLLM, setSelectedLLM] = useState<string>()
Expand Down Expand Up @@ -143,6 +143,8 @@ const ChatMessages: React.FC<ChatMessagesProps> = ({
loadingState={loadingState}
selectedLLM={selectedLLM}
setSelectedLLM={setSelectedLLM}
agentConfig={agentConfig}
setAgentConfig={setAgentConfig}
/>
</div>
</div>
Expand Down
4 changes: 1 addition & 3 deletions src/components/Settings/LLMSettings/LLMSelectOrButton.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -11,7 +10,7 @@ interface LLMSelectOrButtonProps {
}

const LLMSelectOrButton: React.FC<LLMSelectOrButtonProps> = ({ selectedLLM, setSelectedLLM }) => {
const { llmConfigs, fetchAndUpdateModelConfigs } = useLLMConfigs()
const { llmConfigs } = useLLMConfigs()
const handleLLMChange = (value: string) => {
setSelectedLLM(value)
}
Expand Down Expand Up @@ -57,7 +56,6 @@ const LLMSelectOrButton: React.FC<LLMSelectOrButtonProps> = ({ selectedLLM, setS
</SelectContent>
</Select>
)}
<FiRefreshCw onClick={fetchAndUpdateModelConfigs} className="ml-0 cursor-pointer text-xs text-gray-400" />
<SettingsModal isOpen={isSettingsModalOpen} onClose={closeModal} initialTab={activeTab} />
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/hooks/use-agent-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<React.SetStateAction<AgentConfig | undefined>>
}

function useAgentConfig(): UseAgentConfigReturn {
Expand Down
12 changes: 8 additions & 4 deletions src/lib/hooks/use-llm-configs.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { useState, useEffect } from 'react'
import { useState, useEffect, useCallback } from 'react'

import { LLMConfig } from 'electron/main/electron-store/storeConfig'

const useLLMConfigs = () => {
const [llmConfigs, setLLMConfigs] = useState<LLMConfig[]>([])
const [defaultLLM, setDefaultLocalLLM] = useState<string>('')

const fetchAndUpdateModelConfigs = async () => {
const fetchAndUpdateModelConfigs = useCallback(async () => {
const fetchedLLMConfigs = await window.llm.getLLMConfigs()
setLLMConfigs(fetchedLLMConfigs)
const storedDefaultLLM = await window.llm.getDefaultLLMName()
Expand All @@ -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)
Expand All @@ -25,7 +29,7 @@ const useLLMConfigs = () => {

useEffect(() => {
fetchAndUpdateModelConfigs()
}, [])
}, [fetchAndUpdateModelConfigs])

return {
llmConfigs,
Expand Down

0 comments on commit 3781ea6

Please sign in to comment.