From 656c18b2b4647d8b70dfcf214d0252b8940ec624 Mon Sep 17 00:00:00 2001 From: mccarrascog Date: Mon, 27 May 2024 16:20:14 +0200 Subject: [PATCH] Listing assistants on the website - FIXED --- .../Pages/Assistants/Assistants.tsx | 28 +++++++++---------- server/web/src/utils/api/assistants.ts | 4 +-- server/web/src/utils/api/config.ts | 1 + 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/server/web/src/components/Pages/Assistants/Assistants.tsx b/server/web/src/components/Pages/Assistants/Assistants.tsx index 1215bda9b..7e8817a0a 100644 --- a/server/web/src/components/Pages/Assistants/Assistants.tsx +++ b/server/web/src/components/Pages/Assistants/Assistants.tsx @@ -1,8 +1,10 @@ import { useContext, useEffect, useState, ChangeEvent } from "react"; -import { useAuth } from "@/state/Auth"; import { LoadingContext } from "@/state/Loading"; import styles from './Assistants.module.css'; import { getAssistants } from '@/utils/api/assistants'; + +import { SettingsContext } from '@/state/Settings'; + import { Alert, Box, @@ -77,7 +79,6 @@ const emptyAssistant: AssistantObject = { }; export function Assistants() { - const auth = useAuth(); const [loading, setLoading] = useContext(LoadingContext); const [assistants, setAssistants] = useState([]); const [showAlert, setShowAlert] = useState(''); @@ -217,20 +218,24 @@ export function Assistants() { textAlign: 'left', }; + const [settings] = useContext(SettingsContext); + + console.log(settings.apiKey); + async function loadAssistants() { setLoading(true); try { - if (auth.token) { - console.log('auth.token:', auth.token); // Log auth.token - const response = await getAssistants(auth.token); - console.log('Full API response:', response); // Log full API response + if (settings.apiKey) { + console.log('openai token:', settings.apiKey); + const response = await getAssistants(settings.apiKey); + console.log('Full API response:', response); if (response.data) { setAssistants(response.data); } else { console.error('No data in API response'); } } else { - console.error('auth.token is undefined'); + console.error('openai token is undefined'); } } catch (error) { console.error(error); @@ -240,15 +245,10 @@ async function loadAssistants() { } useEffect(() => { - if (auth.token) { + if (settings.apiKey) { loadAssistants(); } -}, [auth.token]); - -//only to see the state of assistants, then im going to delete it -useEffect(() => { - console.log('assistants:', assistants); -}, [assistants]); +}, [settings.apiKey]); return ( diff --git a/server/web/src/utils/api/assistants.ts b/server/web/src/utils/api/assistants.ts index e762c028f..098c2a9d0 100644 --- a/server/web/src/utils/api/assistants.ts +++ b/server/web/src/utils/api/assistants.ts @@ -46,7 +46,7 @@ import { const assistantApiBaseOptions: ApiOptions = { endpointServer: defaultApiServer, - endpointPath: EndpointsEnum.assistant, + endpointPath: EndpointsEnum.assistants, endpointValue: '', requestOptions: { headers: baseHeaders, @@ -64,7 +64,7 @@ import { headers: { ...assistantApiBaseOptions.requestOptions.headers, Authorization: `Bearer ${authToken}`, - "OpenAI-Beta": "assistants=v1" + "OpenAI-Beta": "assistants=v2" }, }, }; diff --git a/server/web/src/utils/api/config.ts b/server/web/src/utils/api/config.ts index 6979a9e2a..d41dea4a3 100644 --- a/server/web/src/utils/api/config.ts +++ b/server/web/src/utils/api/config.ts @@ -27,6 +27,7 @@ export enum EndpointsEnum { register = 'register', organization = 'v1/settings/org', Projects = 'v1/settings/projects', + assistants = 'v1/settings/assistants', } export type EndpointsTypes = {