@@ -5,7 +5,7 @@ import { isLoggedInOAPAtom, OAPLevelAtom } from "./oapState"
55import { OAP_PROXY_URL } from "../../shared/oap"
66import { ModelGroupSetting , ModelProvider , ModelVerifyStatus } from "../../types/model"
77import { modelSettingsAtom } from "./modelState"
8- import { defaultBaseModel , defaultModelGroup , intoRawModelConfig , intoRawModelConfigWithQuery , reverseQueryGroup } from "../helper/model"
8+ import { defaultBaseModel , defaultModelGroup , GroupTerm , intoRawModelConfig , intoRawModelConfigWithQuery , ModelTerm , queryGroup , queryModel , reverseQueryGroup } from "../helper/model"
99import { getVerifyKeyFromModelConfig } from "../helper/verify"
1010import { oapGetToken } from "../ipc"
1111import { fetchModels } from "../ipc/llm"
@@ -385,6 +385,26 @@ export const writeOapConfigAtom = atom(
385385 }
386386)
387387
388+ export const selectModelAtom = atom (
389+ null ,
390+ async ( get , set , value : { group : GroupTerm , model : ModelTerm } ) => {
391+ const settings = get ( modelSettingsAtom )
392+ const group = queryGroup ( value . group , settings . groups )
393+ if ( group . length === 0 ) {
394+ throw new Error ( "Group not found" )
395+ }
396+
397+ const model = queryModel ( value . model , group [ 0 ] )
398+ if ( model . length === 0 ) {
399+ throw new Error ( "Model not found" )
400+ }
401+
402+ const data = await set ( writeRawConfigAtom , intoRawModelConfig ( settings , group [ 0 ] , model [ 0 ] ) ! )
403+ localStorage . setItem ( "selectedModel" , JSON . stringify ( value ) )
404+ return data
405+ }
406+ )
407+
388408export const reloadOapConfigAtom = atom (
389409 null ,
390410 async ( get , set ) => {
0 commit comments