diff --git a/apps/shinkai-app/src/pages/AddAgent.tsx b/apps/shinkai-app/src/pages/AddAgent.tsx index d27a4982e..192e26188 100644 --- a/apps/shinkai-app/src/pages/AddAgent.tsx +++ b/apps/shinkai-app/src/pages/AddAgent.tsx @@ -57,7 +57,6 @@ const AddAgent: React.FC = () => { const onSubmit = (data: z.infer) => { const modelMapping: Record = { OpenAI: { model_type: modelType }, - SleepAPI: { model_type: modelType }, }; if (!auth) return; @@ -208,9 +207,6 @@ const AddAgent: React.FC = () => { OpenAI - - SleepAPI - ; @@ -45,33 +43,46 @@ type FormSchemaType = z.infer; export const AddAgent = () => { const history = useHistory(); const auth = useAuth((state) => state.auth); - const uiContainer = useUIContainer((state) => state.uiContainer); const form = useForm({ resolver: zodResolver(formSchema), defaultValues: { - agentName: 'gpt', - externalUrl: 'https://api.openai.com', + agentName: '', + externalUrl: modelsConfig[Models.OpenAI].apiUrl, apiKey: '', model: Models.OpenAI, + modelType: '', }, }); const intl = useIntl(); + const currentModel = useWatch({ + control: form.control, + name: 'model', + }); const { mutateAsync: createAgent, isLoading } = useCreateAgent({ - onSuccess: (data) => { + onSuccess: () => { history.replace({ pathname: '/inboxes/create-job' }); }, }); - const modelOptions: { value: Models; label: string }[] = [ { value: Models.OpenAI, label: intl.formatMessage({ id: 'openai' }), }, { - value: Models.SleepApi, - label: intl.formatMessage({ id: 'sleep-api' }), + value: Models.TogetherComputer, + label: intl.formatMessage({ id: 'togethercomputer' }), }, ]; + const getModelObject = (model: Models, modelType: string) => { + switch (model) { + case Models.OpenAI: + return { OpenAI: { model_type: modelType } }; + case Models.TogetherComputer: + return { GenericAPI: { model_type: modelType } }; + default: + throw new Error('unknown model'); + } + }; const submit = (values: FormSchemaType) => { if (!auth) return; createAgent({ @@ -86,10 +97,7 @@ export const AddAgent = () => { perform_locally: false, storage_bucket_permissions: [], toolkit_permissions: [], - model: - values.model === Models.OpenAI - ? { OpenAI: { model_type: 'gpt-3.5-turbo' } } - : { SleepAPI: {} }, + model: getModelObject(values.model, values.modelType), }, setupDetailsState: { my_device_encryption_sk: auth.my_device_encryption_sk, @@ -100,6 +108,26 @@ export const AddAgent = () => { }, }); }; + const [modelTypeOptions, setModelTypeOptions] = useState< + { label: string; value: string }[] + >([]); + useEffect(() => { + const modelConfig = modelsConfig[currentModel as Models]; + form.setValue('externalUrl', modelConfig.apiUrl); + setModelTypeOptions( + modelsConfig[currentModel as Models].modelTypes.map((modelType) => ({ + label: modelType.name, + value: modelType.value, + })) + ); + }, [currentModel, form]); + useEffect(() => { + if (!modelTypeOptions?.length) { + return; + } + form.setValue('modelType', modelTypeOptions[0].value); + }, [modelTypeOptions, form]); + return (
{ + + + + + + + + {modelTypeOptions.map((modelType) => ( + + {modelType.label} + + ))} + + + + + + )} + />
- + diff --git a/apps/shinkai-visor/src/lang/en.json b/apps/shinkai-visor/src/lang/en.json index e5d7dbe1c..e054690a4 100644 --- a/apps/shinkai-visor/src/lang/en.json +++ b/apps/shinkai-visor/src/lang/en.json @@ -39,7 +39,6 @@ "model.one": "Model", "model.other": "Models", "openai": "OpenAI", - "sleep-api": "Sleep API", "tmwtd": "Tell me what to do", "create-job": "Create job", "menu": "Menu", @@ -84,5 +83,7 @@ "file.other": "Files", "save": "Save", "name.one": "Name", - "edit": "Edit" + "edit": "Edit", + "togethercomputer": "Together AI", + "alphanumeric_with_underscore": "It just accepts alphanumeric characters and underscores" } diff --git a/apps/shinkai-visor/src/lang/es.json b/apps/shinkai-visor/src/lang/es.json index ffdb1a2ef..95a3d11d4 100644 --- a/apps/shinkai-visor/src/lang/es.json +++ b/apps/shinkai-visor/src/lang/es.json @@ -39,7 +39,6 @@ "model.one": "Modelo", "model.other": "Modelos", "openai": "OpenAI", - "sleep-api": "Sleep API", "tmwtd": "Dime qué hacer", "create-job": "Crear job", "menu": "Menu", @@ -84,5 +83,7 @@ "file.other": "Archivos", "save": "Guardar", "name.one": "Nombre", - "edit": "Editar" + "edit": "Editar", + "togethercomputer": "Together AI", + "alphanumeric_with_underscore": "Solo se permiten caracteres alfanuméricos y guiones bajos" } diff --git a/apps/shinkai-visor/src/store/ui-container/ui-container.ts b/apps/shinkai-visor/src/store/ui-container/ui-container.ts deleted file mode 100644 index 66fbc0083..000000000 --- a/apps/shinkai-visor/src/store/ui-container/ui-container.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { create } from "zustand"; -import { devtools } from "zustand/middleware"; - -export type UIContainerData = { - shadowRoot: ShadowRoot; - rootElement: HTMLElement; -}; - -type UIContainerStore = { - uiContainer: UIContainerData | null; - setUIContainer: (uiContainer: UIContainerData) => void; -}; - -export const useUIContainer = create()( - devtools( - (set) => ({ - uiContainer: null, - setUIContainer: (uiContainer: UIContainerData) => set({ uiContainer }), - }), - { - name: "ui-container", - } - ) -); diff --git a/libs/shinkai-message-ts/src/models/SchemaTypes.ts b/libs/shinkai-message-ts/src/models/SchemaTypes.ts index 3e52e1f6e..7fc968ae4 100644 --- a/libs/shinkai-message-ts/src/models/SchemaTypes.ts +++ b/libs/shinkai-message-ts/src/models/SchemaTypes.ts @@ -74,15 +74,16 @@ export interface SerializedAgent { } export interface AgentAPIModel { OpenAI?: OpenAI; - SleepAPI?: SleepAPI; + GenericAPI?: GenericAPI; } export interface OpenAI { model_type: string; } -// eslint-disable-next-line @typescript-eslint/no-empty-interface -export interface SleepAPI {} +export interface GenericAPI { + model_type: string; +} export interface APIAddAgentRequest { agent: SerializedAgent; diff --git a/libs/shinkai-message-ts/src/wasm/SerializedAgentWrapper.ts b/libs/shinkai-message-ts/src/wasm/SerializedAgentWrapper.ts index 0e4a86194..7db63043d 100644 --- a/libs/shinkai-message-ts/src/wasm/SerializedAgentWrapper.ts +++ b/libs/shinkai-message-ts/src/wasm/SerializedAgentWrapper.ts @@ -24,8 +24,8 @@ export class SerializedAgentWrapper { let modelStr = ""; if (agent.model && agent.model.OpenAI && agent.model.OpenAI.model_type) { modelStr = "openai:" + agent.model.OpenAI.model_type; - } else if (agent.model && agent.model.SleepAPI) { - modelStr = "sleep"; + } else if (agent.model && agent.model.GenericAPI && agent.model.GenericAPI.model_type) { + modelStr = "genericapi:" + agent.model.GenericAPI.model_type; } else { throw new Error("Invalid model: " + JSON.stringify(agent.model)); }