Skip to content

Commit

Permalink
Listing assistants on the website - FIXED
Browse files Browse the repository at this point in the history
  • Loading branch information
mccarrascog committed May 27, 2024
1 parent 093d04c commit 656c18b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
28 changes: 14 additions & 14 deletions server/web/src/components/Pages/Assistants/Assistants.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -77,7 +79,6 @@ const emptyAssistant: AssistantObject = {
};

export function Assistants() {
const auth = useAuth();
const [loading, setLoading] = useContext(LoadingContext);
const [assistants, setAssistants] = useState<AssistantObject[]>([]);
const [showAlert, setShowAlert] = useState<string>('');
Expand Down Expand Up @@ -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);
Expand All @@ -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 (
<Box className={styles.container}>
Expand Down
4 changes: 2 additions & 2 deletions server/web/src/utils/api/assistants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {

const assistantApiBaseOptions: ApiOptions = {
endpointServer: defaultApiServer,
endpointPath: EndpointsEnum.assistant,
endpointPath: EndpointsEnum.assistants,
endpointValue: '',
requestOptions: {
headers: baseHeaders,
Expand All @@ -64,7 +64,7 @@ import {
headers: {
...assistantApiBaseOptions.requestOptions.headers,
Authorization: `Bearer ${authToken}`,
"OpenAI-Beta": "assistants=v1"
"OpenAI-Beta": "assistants=v2"
},
},
};
Expand Down
1 change: 1 addition & 0 deletions server/web/src/utils/api/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export enum EndpointsEnum {
register = 'register',
organization = 'v1/settings/org',
Projects = 'v1/settings/projects',
assistants = 'v1/settings/assistants',
}

export type EndpointsTypes = {
Expand Down

0 comments on commit 656c18b

Please sign in to comment.