-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a5e18a1
commit e31d69a
Showing
12 changed files
with
282 additions
and
130 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import SelectGroup, { SelectItemProps } from "../SelectGroup.tsx"; | ||
import { supportModels } from "../../conf.ts"; | ||
import { selectModel, setModel } from "../../store/chat.ts"; | ||
import { useTranslation } from "react-i18next"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { selectAuthenticated } from "../../store/auth.ts"; | ||
import { useToast } from "../ui/use-toast.ts"; | ||
import { useEffect } from "react"; | ||
import { Model } from "../../conversation/types.ts"; | ||
|
||
function GetModel(name: string): Model { | ||
return supportModels.find((model) => model.id === name) as Model; | ||
} | ||
|
||
function ModelSelector() { | ||
const { t } = useTranslation(); | ||
const dispatch = useDispatch(); | ||
const { toast } = useToast(); | ||
|
||
const model = useSelector(selectModel); | ||
const auth = useSelector(selectAuthenticated); | ||
|
||
useEffect(() => { | ||
if (auth && model === "GPT-3.5") dispatch(setModel("GPT-3.5-16k")); | ||
}, [auth]); | ||
|
||
const list = supportModels.map( | ||
(model: Model): SelectItemProps => ({ | ||
name: model.id, | ||
value: model.name, | ||
badge: model.free ? "free" : undefined, | ||
}), | ||
); | ||
|
||
return ( | ||
<SelectGroup | ||
current={list.find((item) => item.name === model) as SelectItemProps} | ||
list={list} | ||
maxElements={6} | ||
onChange={(value: string) => { | ||
const model = GetModel(value); | ||
console.debug(`[model] select model: ${model.name} (id: ${model.id})`); | ||
|
||
if (!auth && model.auth) { | ||
toast({ | ||
title: t("login-require"), | ||
}); | ||
return; | ||
} | ||
dispatch(setModel(value)); | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
export default ModelSelector; |
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.