From 6ced8e73a75cd49ab38f7d7f799fb5e650ec0aa6 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 8 May 2024 13:13:38 -0700 Subject: [PATCH] Update index.test.ts --- apps/test-suite/index.test.ts | 39 +++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/apps/test-suite/index.test.ts b/apps/test-suite/index.test.ts index 2ae525e..1de2bf5 100644 --- a/apps/test-suite/index.test.ts +++ b/apps/test-suite/index.test.ts @@ -81,22 +81,35 @@ describe("Scraping/Crawling Checkup (E2E)", () => { }); const prompt = `Based on this markdown extracted from a website html page, ${websiteData.prompt} Just say 'yes' or 'no' to the question.\nWebsite markdown: ${scrapedContent.body.data.markdown}\n`; - - const msg = await openai.chat.completions.create({ - model: "gpt-4-turbo", - max_tokens: 100, - temperature: 0, - messages: [ - { - role: "user", - content: prompt - }, - ], - }); + let msg = null; + const maxRetries = 3; + let attempts = 0; + while (!msg && attempts < maxRetries) { + try { + msg = await openai.chat.completions.create({ + model: "gpt-4-turbo", + max_tokens: 100, + temperature: 0, + messages: [ + { + role: "user", + content: prompt + }, + ], + }); + } catch (error) { + console.error(`Attempt ${attempts + 1}: Failed to prompt for ${websiteData.website}, error: ${error}`); + attempts++; + if (attempts < maxRetries) { + console.log(`Retrying... Attempt ${attempts + 1}`); + await new Promise(resolve => setTimeout(resolve, 2000)); // Wait for 2 seconds before retrying + } + } + } if (!msg) { - console.error(`Failed to prompt for ${websiteData.website}`); + console.error(`Failed to prompt for ${websiteData.website} after ${maxRetries} attempts`); errorLog.push({ website: websiteData.website, prompt: websiteData.prompt,