-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Per workspace model selection (#582)
* WIP model selection per workspace (migrations and openai saves properly * revert OpenAiOption * add support for models per workspace for anthropic, localAi, ollama, openAi, and togetherAi * remove unneeded comments * update logic for when LLMProvider is reset, reset Ai provider files with master * remove frontend/api reset of workspace chat and move logic to updateENV add postUpdate callbacks to envs * set preferred model for chat on class instantiation * remove extra param * linting * remove unused var * refactor chat model selection on workspace * linting * add fallback for base path to localai models --------- Co-authored-by: timothycarambat <[email protected]>
- Loading branch information
1 parent
bf503ee
commit 90df375
Showing
24 changed files
with
263 additions
and
53 deletions.
There are no files selected for viewing
120 changes: 120 additions & 0 deletions
120
frontend/src/components/Modals/MangeWorkspace/Settings/ChatModelPreference/index.jsx
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,120 @@ | ||
import useGetProviderModels, { | ||
DISABLED_PROVIDERS, | ||
} from "./useGetProviderModels"; | ||
|
||
export default function ChatModelSelection({ | ||
settings, | ||
workspace, | ||
setHasChanges, | ||
}) { | ||
const { defaultModels, customModels, loading } = useGetProviderModels( | ||
settings?.LLMProvider | ||
); | ||
if (DISABLED_PROVIDERS.includes(settings?.LLMProvider)) return null; | ||
|
||
if (loading) { | ||
return ( | ||
<div> | ||
<div className="flex flex-col"> | ||
<label | ||
htmlFor="name" | ||
className="block text-sm font-medium text-white" | ||
> | ||
Chat model | ||
</label> | ||
<p className="text-white text-opacity-60 text-xs font-medium py-1.5"> | ||
The specific chat model that will be used for this workspace. If | ||
empty, will use the system LLM preference. | ||
</p> | ||
</div> | ||
<select | ||
name="chatModel" | ||
required={true} | ||
disabled={true} | ||
className="bg-zinc-900 text-white text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" | ||
> | ||
<option disabled={true} selected={true}> | ||
-- waiting for models -- | ||
</option> | ||
</select> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div> | ||
<div className="flex flex-col"> | ||
<label htmlFor="name" className="block text-sm font-medium text-white"> | ||
Chat model{" "} | ||
<span className="font-normal">({settings?.LLMProvider})</span> | ||
</label> | ||
<p className="text-white text-opacity-60 text-xs font-medium py-1.5"> | ||
The specific chat model that will be used for this workspace. If | ||
empty, will use the system LLM preference. | ||
</p> | ||
</div> | ||
|
||
<select | ||
name="chatModel" | ||
required={true} | ||
onChange={() => { | ||
setHasChanges(true); | ||
}} | ||
className="bg-zinc-900 text-white text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" | ||
> | ||
<option disabled={true} selected={workspace?.chatModel === null}> | ||
System default | ||
</option> | ||
{defaultModels.length > 0 && ( | ||
<optgroup label="General models"> | ||
{defaultModels.map((model) => { | ||
return ( | ||
<option | ||
key={model} | ||
value={model} | ||
selected={workspace?.chatModel === model} | ||
> | ||
{model} | ||
</option> | ||
); | ||
})} | ||
</optgroup> | ||
)} | ||
{Array.isArray(customModels) && customModels.length > 0 && ( | ||
<optgroup label="Custom models"> | ||
{customModels.map((model) => { | ||
return ( | ||
<option | ||
key={model.id} | ||
value={model.id} | ||
selected={workspace?.chatModel === model.id} | ||
> | ||
{model.id} | ||
</option> | ||
); | ||
})} | ||
</optgroup> | ||
)} | ||
{/* For providers like TogetherAi where we partition model by creator entity. */} | ||
{!Array.isArray(customModels) && | ||
Object.keys(customModels).length > 0 && ( | ||
<> | ||
{Object.entries(customModels).map(([organization, models]) => ( | ||
<optgroup key={organization} label={organization}> | ||
{models.map((model) => ( | ||
<option | ||
key={model.id} | ||
value={model.id} | ||
selected={workspace?.chatModel === model.id} | ||
> | ||
{model.name} | ||
</option> | ||
))} | ||
</optgroup> | ||
))} | ||
</> | ||
)} | ||
</select> | ||
</div> | ||
); | ||
} |
49 changes: 49 additions & 0 deletions
49
...src/components/Modals/MangeWorkspace/Settings/ChatModelPreference/useGetProviderModels.js
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,49 @@ | ||
import System from "@/models/system"; | ||
import { useEffect, useState } from "react"; | ||
|
||
// Providers which cannot use this feature for workspace<>model selection | ||
export const DISABLED_PROVIDERS = ["azure", "lmstudio"]; | ||
const PROVIDER_DEFAULT_MODELS = { | ||
openai: ["gpt-3.5-turbo", "gpt-4", "gpt-4-1106-preview", "gpt-4-32k"], | ||
gemini: ["gemini-pro"], | ||
anthropic: ["claude-2", "claude-instant-1"], | ||
azure: [], | ||
lmstudio: [], | ||
localai: [], | ||
ollama: [], | ||
togetherai: [], | ||
native: [], | ||
}; | ||
|
||
// For togetherAi, which has a large model list - we subgroup the options | ||
// by their creator organization (eg: Meta, Mistral, etc) | ||
// which makes selection easier to read. | ||
function groupModels(models) { | ||
return models.reduce((acc, model) => { | ||
acc[model.organization] = acc[model.organization] || []; | ||
acc[model.organization].push(model); | ||
return acc; | ||
}, {}); | ||
} | ||
|
||
export default function useGetProviderModels(provider = null) { | ||
const [defaultModels, setDefaultModels] = useState([]); | ||
const [customModels, setCustomModels] = useState([]); | ||
const [loading, setLoading] = useState(true); | ||
|
||
useEffect(() => { | ||
async function fetchProviderModels() { | ||
if (!provider) return; | ||
const { models = [] } = await System.customModels(provider); | ||
if (PROVIDER_DEFAULT_MODELS.hasOwnProperty(provider)) | ||
setDefaultModels(PROVIDER_DEFAULT_MODELS[provider]); | ||
provider === "togetherai" | ||
? setCustomModels(groupModels(models)) | ||
: setCustomModels(models); | ||
setLoading(false); | ||
} | ||
fetchProviderModels(); | ||
}, [provider]); | ||
|
||
return { defaultModels, customModels, loading }; | ||
} |
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,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "workspaces" ADD COLUMN "chatModel" TEXT; |
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
Oops, something went wrong.