Skip to content

Commit

Permalink
Merge pull request #458 from Bhavyajain21/feat/delete-ollama-models
Browse files Browse the repository at this point in the history
feat:delete ollama models
  • Loading branch information
joseplayero authored Oct 18, 2024
2 parents 9e0ce43 + 78756b6 commit 393805d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
4 changes: 4 additions & 0 deletions electron/main/llm/ipcHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ export const registerLLMSessionHandlers = (store: Store<StoreSchema>) => {
}
await ollamaService.pullModel(modelName, handleProgress)
})

ipcMain.handle('delete-llm', async (event, modelName: string) => {
await ollamaService.deleteModel(modelName)
})
}
1 change: 1 addition & 0 deletions electron/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const llm = {
setDefaultLLM: createIPCHandler<(modelName: string) => Promise<void>>('set-default-llm'),
getDefaultLLMName: createIPCHandler<() => Promise<string>>('get-default-llm-name'),
pullOllamaModel: createIPCHandler<(modelName: string) => Promise<void>>('pull-ollama-model'),
deleteLLM: createIPCHandler<(modelNameToDelete: string) => Promise<void>>('delete-llm'),
}

// Expose to renderer process
Expand Down
43 changes: 33 additions & 10 deletions src/components/Settings/LLMSettings/DefaultLLMSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState, useEffect } from 'react'
import { LLMConfig } from 'electron/main/electron-store/storeConfig'
import posthog from 'posthog-js'
import { FiTrash2 } from 'react-icons/fi'
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'

interface DefaultLLMSelectorProps {
Expand All @@ -16,12 +17,24 @@ const DefaultLLMSelector: React.FC<DefaultLLMSelectorProps> = ({ llmConfigs, def
setSelectedLLM(defaultLLM)
}, [defaultLLM])

const handleDefaultModelChange = (selectedModel: string) => {
setSelectedLLM(selectedModel)
setDefaultLLM(selectedModel)
window.llm.setDefaultLLM(selectedModel)
const handleDefaultModelChange = (modelName: string) => {
setSelectedLLM(modelName)
setDefaultLLM(modelName)
window.llm.setDefaultLLM(modelName)

posthog.capture('change_default_llm', {
defaultLLM: selectedModel,
defaultLLM: modelName,
})
}

const handleDeleteLLM = async (modelName: string) => {
const confirmDelete = window.confirm(`Are you sure you want to delete the model ${modelName}?`)

Check warning on line 31 in src/components/Settings/LLMSettings/DefaultLLMSelector.tsx

View workflow job for this annotation

GitHub Actions / build_and_package (macos-13)

Unexpected confirm

Check warning on line 31 in src/components/Settings/LLMSettings/DefaultLLMSelector.tsx

View workflow job for this annotation

GitHub Actions / build_and_package (macos-latest)

Unexpected confirm

Check warning on line 31 in src/components/Settings/LLMSettings/DefaultLLMSelector.tsx

View workflow job for this annotation

GitHub Actions / build_and_package (windows-latest)

Unexpected confirm

Check warning on line 31 in src/components/Settings/LLMSettings/DefaultLLMSelector.tsx

View workflow job for this annotation

GitHub Actions / build_and_package (ubuntu-latest, x64)

Unexpected confirm
if (!confirmDelete) return

await window.llm.deleteLLM(modelName)

posthog.capture('delete_llm', {
modelName,
})
}

Expand All @@ -31,11 +44,21 @@ const DefaultLLMSelector: React.FC<DefaultLLMSelectorProps> = ({ llmConfigs, def
<SelectValue placeholder="Select default LLM" />
</SelectTrigger>
<SelectContent>
{llmConfigs.map((config) => (
<SelectItem key={config.modelName} value={config.modelName}>
{config.modelName}
</SelectItem>
))}
{llmConfigs.map((config) => {
const { modelName } = config
return (
<div key={modelName} className="flex w-full items-center justify-between">
<SelectItem className="cursor-pointer" value={modelName}>
{modelName}
</SelectItem>
{config.apiName === 'Ollama' && (
<div className="cursor-pointer text-red-500">
<FiTrash2 onClick={() => handleDeleteLLM(modelName)} />
</div>
)}
</div>
)
})}
</SelectContent>
</Select>
)
Expand Down

0 comments on commit 393805d

Please sign in to comment.