-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added model switcher in sidebar for easy access
- Loading branch information
1 parent
04e649f
commit ace1efb
Showing
12 changed files
with
112 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { AvailableModels } from '../../../config/settings' | ||
import { useChatModels } from '../../../hooks/useChatModels' | ||
import { capitalizeText } from '../../../lib/capitalizeText' | ||
|
||
const ChangeChatModel = () => { | ||
const { availableModels, activeChatModel, setActiveChatModel } = | ||
useChatModels() | ||
return ( | ||
<div> | ||
<select | ||
value={activeChatModel} | ||
className="input cdx-w-44" | ||
onChange={(e) => { | ||
setActiveChatModel(e.target.value as AvailableModels) | ||
}} | ||
> | ||
{availableModels.map(([modal, value]) => ( | ||
<option key={modal} value={value}> | ||
{capitalizeText( | ||
modal | ||
.toLowerCase() | ||
.replace('gpt', 'GPT') | ||
.replace('3_5', '3.5') | ||
.replaceAll('_', ' '), | ||
)} | ||
</option> | ||
))} | ||
</select> | ||
</div> | ||
) | ||
} | ||
|
||
export default ChangeChatModel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { useCallback, useEffect, useState } from 'react' | ||
import { useSettings } from './useSettings' | ||
import axios from 'axios' | ||
import { AvailableModels } from '../config/settings' | ||
|
||
export const useChatModels = () => { | ||
const [settings, setSettings] = useSettings() | ||
const [dynamicModels, setDynamicModels] = useState<string[]>([]) | ||
const chatSettings = settings.chat | ||
const activeChatModel = chatSettings.modal | ||
|
||
const fetchLocalModels = useCallback(async () => { | ||
if (chatSettings.showLocalModels) { | ||
const { | ||
data: { models }, | ||
} = await axios<{ models: { name: string }[] }>( | ||
'http://localhost:11434/api/tags', | ||
) | ||
if (models) { | ||
setDynamicModels(models.map((m) => m.name)) | ||
} | ||
} else { | ||
setDynamicModels([]) | ||
} | ||
}, [chatSettings.showLocalModels]) | ||
|
||
useEffect(() => { | ||
fetchLocalModels() | ||
}, [fetchLocalModels]) | ||
|
||
const availableModels = [ | ||
...Object.entries(AvailableModels), | ||
...dynamicModels.map((m) => [m, m]), | ||
] | ||
|
||
const setActiveChatModel = (model: AvailableModels) => { | ||
setSettings({ | ||
...settings, | ||
chat: { | ||
...chatSettings, | ||
modal: model, | ||
}, | ||
}) | ||
} | ||
|
||
return { | ||
availableModels, | ||
activeChatModel, | ||
setActiveChatModel, | ||
fetchLocalModels, | ||
} | ||
} |