From e05ff315b58a81ca055d115ad7c9b0ca55e629e4 Mon Sep 17 00:00:00 2001 From: lublagg Date: Thu, 19 Dec 2024 19:52:52 -0500 Subject: [PATCH] checkpoint: user can select assistant id when in dev mode. --- src/app-config.json | 6 --- src/components/App.tsx | 13 +++-- src/components/developer-options.tsx | 44 +++++++++++++-- src/constants.ts | 2 + src/{ => contexts}/app-config-context.ts | 2 +- src/{ => contexts}/app-config-provider.tsx | 14 +++-- src/contexts/open-ai-connection-provider.tsx | 23 ++++++++ src/hooks/use-app-config-context.ts | 2 +- src/hooks/use-assistant-store.ts | 15 ++---- src/hooks/use-open-ai-context.ts | 11 ++++ src/index.tsx | 7 ++- src/models/app-config-model.ts | 21 ++------ src/models/assistant-model.ts | 56 ++++++++++---------- src/test-utils/app-config-provider.tsx | 2 +- src/types.ts | 6 --- src/utils/llm-utils.ts | 9 ---- src/utils/openai-utils.ts | 12 +---- 17 files changed, 137 insertions(+), 108 deletions(-) rename src/{ => contexts}/app-config-context.ts (66%) rename src/{ => contexts}/app-config-provider.tsx (65%) create mode 100644 src/contexts/open-ai-connection-provider.tsx create mode 100644 src/hooks/use-open-ai-context.ts delete mode 100644 src/utils/llm-utils.ts diff --git a/src/app-config.json b/src/app-config.json index 2c22176..2141966 100644 --- a/src/app-config.json +++ b/src/app-config.json @@ -2,12 +2,6 @@ "accessibility": { "keyboardShortcut": "ctrl+?" }, - "assistant": { - "assistantId": "asst_xmAX5oxByssXrkBymMbcsVEm", - "instructions": "You are DAVAI, a Data Analysis through Voice and Artificial Intelligence partner. You are an intermediary for a user who is blind who wants to interact with data tables in a data analysis app named CODAP.", - "modelName": "gpt-4o-mini", - "useExisting": true - }, "dimensions": { "height": 680, "width": 380 diff --git a/src/components/App.tsx b/src/components/App.tsx index e35f2d6..89d8189 100755 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -3,11 +3,12 @@ import { observer } from "mobx-react-lite"; import { initializePlugin, selectSelf } from "@concord-consortium/codap-plugin-api"; import { useAppConfigContext } from "../hooks/use-app-config-context"; import { useAssistantStore } from "../hooks/use-assistant-store"; +import { useOpenAIContext } from "../hooks/use-open-ai-context"; import { ChatInputComponent } from "./chat-input"; import { ChatTranscriptComponent } from "./chat-transcript"; import { ReadAloudMenu } from "./readaloud-menu"; import { KeyboardShortcutControls } from "./keyboard-shortcut-controls"; -import { DAVAI_SPEAKER, GREETING, USER_SPEAKER } from "../constants"; +import { DAVAI_SPEAKER, defaultAssistantId, GREETING, USER_SPEAKER } from "../constants"; import { DeveloperOptionsComponent } from "./developer-options"; import { getUrlParam } from "../utils/utils"; @@ -34,7 +35,9 @@ export const App = observer(() => { useEffect(() => { initializePlugin({pluginName: kPluginName, version: kVersion, dimensions}); selectSelf(); - assistantStore.initialize(); + if (!isDevMode) { + assistantStore.initializeAssistant(defaultAssistantId); + } // eslint-disable-next-line react-hooks/exhaustive-deps }, []); @@ -104,10 +107,6 @@ export const App = observer(() => { } }; - if (!assistantStore.assistant) { - return
Loading...
; - } - return (
@@ -142,7 +141,7 @@ export const App = observer(() => {
} (); + + useEffect(() => { + const fetchAssistants = async () => { + try { + const res = await apiConnection.beta.assistants.list(); + const assistantIds = res.data.map(asst => asst.id); + setAssistantOptioms(assistantIds); + } catch (err) { + console.error(err); + } + }; + + fetchAssistants(); + }, [apiConnection.beta.assistants]); + + const handleSetSelectedAssistant = (e: React.ChangeEvent) => { + const id = e.target.value; + assistantStore.initializeAssistant(id); + }; + return (