From 73eca44dd372fd437544582b0d078511357ae1b3 Mon Sep 17 00:00:00 2001 From: BlinkMonk Date: Wed, 22 May 2024 14:01:28 +0800 Subject: [PATCH] Update openai.ts Fixed GPT request access and authorization key issues --- sources/modules/openai.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sources/modules/openai.ts b/sources/modules/openai.ts index 42debf4..e122671 100644 --- a/sources/modules/openai.ts +++ b/sources/modules/openai.ts @@ -72,6 +72,10 @@ export async function describeImage(imagePath: string) { } export async function gptRequest(systemPrompt: string, userPrompt: string) { + const headers = { + 'Authorization': `Bearer ${keys.openai}`, + 'Content-Type': 'application/json' + }; try { const response = await axios.post("https://api.openai.com/v1/chat/completions", { model: "gpt-4o", @@ -79,8 +83,8 @@ export async function gptRequest(systemPrompt: string, userPrompt: string) { { role: "system", content: systemPrompt }, { role: "user", content: userPrompt }, ], - }); - return response.data; + },{headers}); + return response.data.choices[0].message.content; } catch (error) { console.error("Error in gptRequest:", error); return null; // or handle error differently @@ -106,4 +110,4 @@ console.info(gptRequest( , 'where is the person?' -)) \ No newline at end of file +))