Skip to content
This repository was archived by the owner on Mar 7, 2026. It is now read-only.

Commit b1f4697

Browse files
authored
Merge pull request #446 from Bhavyajain21/feat/btn-to-add-llm
Add btn to add and refresh llm
2 parents 783302d + 819c805 commit b1f4697

File tree

4 files changed

+100
-23
lines changed

4 files changed

+100
-23
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/Chat/StartChat.tsx

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { PiPaperPlaneRight } from 'react-icons/pi'
33
import { FiSettings } from 'react-icons/fi'
44
import { LLMConfig } from 'electron/main/electron-store/storeConfig'
55
import { AgentConfig, ToolDefinition, DatabaseSearchFilters } from '../../lib/llm/types'
6-
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
76
import { Button } from '@/components/ui/button'
87
import DbSearchFilters from './ChatConfigComponents/DBSearchFilters'
98
import PromptEditor from './ChatConfigComponents/PromptEditor'
@@ -24,6 +23,7 @@ import exampleAgents from './ChatConfigComponents/exampleAgents'
2423
import { allAvailableToolDefinitions } from '@/lib/llm/tools/tool-definitions'
2524
import ToolSelector from './ChatConfigComponents/ToolSelector'
2625
import SuggestionCard from '../ui/suggestion-card'
26+
import LLMSelectOrButton from '../Settings/LLMSettings/LLMSelectOrButton'
2727

2828
interface StartChatProps {
2929
defaultModelName: string
@@ -71,10 +71,6 @@ const StartChat: React.FC<StartChatProps> = ({ defaultModelName, handleNewChatMe
7171
handleNewChatMessage(userTextFieldInput, { ...agentConfig })
7272
}
7373

74-
const handleLLMChange = (value: string) => {
75-
setSelectedLLM(value)
76-
}
77-
7874
const handleToolsChange = (tools: ToolDefinition[]) => {
7975
setAgentConfig((prevConfig) => {
8076
if (!prevConfig) throw new Error('Agent config must be initialized before setting tools')
@@ -145,18 +141,12 @@ const StartChat: React.FC<StartChatProps> = ({ defaultModelName, handleNewChatMe
145141
<div className="mx-auto h-px w-[96%] bg-background/20" />
146142
<div className="flex h-10 flex-col items-center justify-between gap-2 py-2 md:flex-row md:gap-4">
147143
<div className="flex flex-col items-center justify-between rounded-md border-0 py-2 md:flex-row">
148-
<Select value={selectedLLM} onValueChange={handleLLMChange}>
149-
<SelectTrigger className="m-2 w-32 border border-solid border-muted-foreground bg-transparent">
150-
<SelectValue placeholder="Select LLM" />
151-
</SelectTrigger>
152-
<SelectContent>
153-
{llmConfigs.map((llm) => (
154-
<SelectItem key={llm.modelName} value={llm.modelName}>
155-
{llm.modelName}
156-
</SelectItem>
157-
))}
158-
</SelectContent>
159-
</Select>
144+
<LLMSelectOrButton
145+
llmConfigs={llmConfigs}
146+
selectedLLM={selectedLLM}
147+
setSelectedLLM={setSelectedLLM}
148+
setLLMConfigs={setLLMConfigs}
149+
/>
160150
</div>
161151
<div className="flex items-center">
162152
<Button
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import React, { useState } from 'react'
2+
import { FiRefreshCw } from 'react-icons/fi'
3+
import { LLMConfig } from 'electron/main/electron-store/storeConfig'
4+
import { Button } from '@/components/ui/button'
5+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
6+
import SettingsModal, { SettingsTab } from '../Settings'
7+
8+
interface LLMSelectOrButtonProps {
9+
llmConfigs: Array<{ modelName: string }>
10+
selectedLLM: string
11+
setSelectedLLM: (value: string) => void
12+
setLLMConfigs: React.Dispatch<React.SetStateAction<LLMConfig[]>>
13+
}
14+
15+
const LLMSelectOrButton: React.FC<LLMSelectOrButtonProps> = ({
16+
llmConfigs,
17+
selectedLLM,
18+
setSelectedLLM,
19+
setLLMConfigs,
20+
}) => {
21+
const handleLLMChange = (value: string) => {
22+
setSelectedLLM(value)
23+
}
24+
25+
const [isSettingsModalOpen, setSettingsModalOpen] = useState(false)
26+
const [activeTab, setActiveTab] = useState<SettingsTab>(SettingsTab.GeneralSettingsTab)
27+
28+
const openModalWithTab = (tab: SettingsTab) => {
29+
setActiveTab(tab)
30+
setSettingsModalOpen(true)
31+
}
32+
33+
const closeModal = () => {
34+
setSettingsModalOpen(false)
35+
}
36+
37+
const openLLMSettings = () => {
38+
openModalWithTab(SettingsTab.LLMSettingsTab)
39+
}
40+
41+
const refreshLLMConfigs = async () => {
42+
try {
43+
const LLMConfigs = await window.llm.getLLMConfigs()
44+
setLLMConfigs(LLMConfigs)
45+
} catch (error) {
46+
console.error('Failed to refresh LLM configs:', error)
47+
}
48+
}
49+
50+
return (
51+
<div className="text-left">
52+
<div className="flex items-center">
53+
{llmConfigs.length === 0 ? (
54+
<Button className="bg-transparent text-primary hover:bg-slate-700" onClick={openLLMSettings}>
55+
Attach LLM
56+
</Button>
57+
) : (
58+
<Select value={selectedLLM} onValueChange={(value) => handleLLMChange(value)}>
59+
<SelectTrigger className="w-32 border border-solid border-muted-foreground">
60+
<SelectValue placeholder="Select LLM" />
61+
</SelectTrigger>
62+
<SelectContent>
63+
{llmConfigs.map((llm) => (
64+
<SelectItem key={llm.modelName} value={llm.modelName}>
65+
{llm.modelName}
66+
</SelectItem>
67+
))}
68+
</SelectContent>
69+
</Select>
70+
)}
71+
<FiRefreshCw onClick={refreshLLMConfigs} className="ml-1 cursor-pointer text-xs text-gray-400" />
72+
<SettingsModal isOpen={isSettingsModalOpen} onClose={closeModal} initialTab={activeTab} />
73+
</div>
74+
</div>
75+
)
76+
}
77+
78+
export default LLMSelectOrButton

src/components/Settings/Settings.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react'
1+
import React, { useEffect, useState } from 'react'
22

33
import ReorModal from '../Common/Modal'
44

@@ -11,19 +11,28 @@ import TextGenerationSettings from './TextGenerationSettings'
1111
interface ModalProps {
1212
isOpen: boolean
1313
onClose: () => void
14+
initialTab?: SettingsTab
1415
}
1516

16-
enum SettingsTab {
17+
export enum SettingsTab {
1718
GeneralSettingsTab = 'generalSettings',
1819
LLMSettingsTab = 'llmSettings',
1920
EmbeddingModelTab = 'embeddingModel',
2021
TextGenerationTab = 'textGeneration',
2122
AnalyticsTab = 'analytics',
2223
}
2324

24-
const SettingsModal: React.FC<ModalProps> = ({ isOpen, onClose: onCloseFromParent }) => {
25+
const SettingsModal: React.FC<ModalProps> = ({
26+
isOpen,
27+
onClose: onCloseFromParent,
28+
initialTab = SettingsTab.GeneralSettingsTab,
29+
}) => {
2530
const [willNeedToReIndex, setWillNeedToReIndex] = useState(false)
26-
const [activeTab, setActiveTab] = useState(SettingsTab.GeneralSettingsTab)
31+
const [activeTab, setActiveTab] = useState<SettingsTab>(initialTab)
32+
33+
useEffect(() => {
34+
setActiveTab(initialTab)
35+
}, [initialTab])
2736

2837
const handleSave = () => {
2938
if (willNeedToReIndex) {

0 commit comments

Comments
 (0)