From 6f5e4a76eae1ebb51497f3ef10681c0a5bc282bd Mon Sep 17 00:00:00 2001 From: Johannes Date: Fri, 20 Dec 2024 23:06:31 +0100 Subject: [PATCH] Update index.ts --- supabase/functions/generateChildren/index.ts | 41 +++++++++++--------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/supabase/functions/generateChildren/index.ts b/supabase/functions/generateChildren/index.ts index 5b110a5..9b07652 100644 --- a/supabase/functions/generateChildren/index.ts +++ b/supabase/functions/generateChildren/index.ts @@ -17,25 +17,30 @@ const SYSTEMPROMPT = const OPENAI_MODEL = "gpt-4o-2024-08-06"; // Generate new scenario function -async function generateScenario(messages) { - try { - const response = await axios.post( - 'https://api.openai.com/v1/chat/completions', - { - model: OPENAI_MODEL, - messages: [ - { role: 'system', content: SYSTEMPROMPT }, - ...messages, - ], - }, - { headers: { 'Authorization': `Bearer ${OPENAI_API_KEY}` } } - ); - return response.data.choices[0].message.content; // Adjust according to OpenAI response format - } catch (error) { - console.error("Error generating scenario:", error); - throw new Error('Error generating scenario'); +type Message = { + role: string; + content: string; + }; + + async function generateScenario(messages: Message[]): Promise { // Line 20: Now messages has a defined type + try { + const response = await axios.post( + 'https://api.openai.com/v1/chat/completions', + { + model: OPENAI_MODEL, + messages: [ + { role: 'system', content: SYSTEMPROMPT }, + ...messages, + ], + }, + { headers: { 'Authorization': `Bearer ${OPENAI_API_KEY}` } } + ); + return response.data.choices[0].message.content; + } catch (error) { + console.error("Error generating scenario", error); + throw error; + } } -} // Fetch previous scenarios from Supabase async function getPreviousScenarios(startId) {