From 7233e0d4a85438972ff8dde0381faf640d2aa73a Mon Sep 17 00:00:00 2001 From: an-lee Date: Mon, 25 Mar 2024 11:09:10 +0800 Subject: [PATCH] setup max retries for AI request --- enjoy/src/commands/analyze.command.ts | 1 + enjoy/src/commands/extract-story.command.ts | 1 + enjoy/src/commands/ipa.command.ts | 1 + enjoy/src/commands/lookup.command.ts | 1 + enjoy/src/commands/translate.command.ts | 1 + enjoy/src/renderer/hooks/use-conversation.tsx | 5 ++++- 6 files changed, 9 insertions(+), 1 deletion(-) diff --git a/enjoy/src/commands/analyze.command.ts b/enjoy/src/commands/analyze.command.ts index b36d879f..9e5d7ead 100644 --- a/enjoy/src/commands/analyze.command.ts +++ b/enjoy/src/commands/analyze.command.ts @@ -22,6 +22,7 @@ export const analyzeCommand = async ( }, cache: false, verbose: true, + maxRetries: 2, }); const prompt = ChatPromptTemplate.fromMessages([ diff --git a/enjoy/src/commands/extract-story.command.ts b/enjoy/src/commands/extract-story.command.ts index 66500fc7..d5f66070 100644 --- a/enjoy/src/commands/extract-story.command.ts +++ b/enjoy/src/commands/extract-story.command.ts @@ -39,6 +39,7 @@ export const extractStoryCommand = async ( }, cache: true, verbose: true, + maxRetries: 2, }).bind({ tools: [ { diff --git a/enjoy/src/commands/ipa.command.ts b/enjoy/src/commands/ipa.command.ts index 88987b9c..c0ce3df1 100644 --- a/enjoy/src/commands/ipa.command.ts +++ b/enjoy/src/commands/ipa.command.ts @@ -59,6 +59,7 @@ export const ipaCommand = async ( }, cache: true, verbose: true, + maxRetries: 2, }); const prompt = ChatPromptTemplate.fromMessages([ diff --git a/enjoy/src/commands/lookup.command.ts b/enjoy/src/commands/lookup.command.ts index 2e21a864..7ab7b6bd 100644 --- a/enjoy/src/commands/lookup.command.ts +++ b/enjoy/src/commands/lookup.command.ts @@ -71,6 +71,7 @@ export const lookupCommand = async ( }, cache: true, verbose: true, + maxRetries: 2, }); const prompt = ChatPromptTemplate.fromMessages([ diff --git a/enjoy/src/commands/translate.command.ts b/enjoy/src/commands/translate.command.ts index ab248493..32c6eeb9 100644 --- a/enjoy/src/commands/translate.command.ts +++ b/enjoy/src/commands/translate.command.ts @@ -22,6 +22,7 @@ export const translateCommand = async ( }, cache: false, verbose: true, + maxRetries: 2, }); const prompt = ChatPromptTemplate.fromMessages([ diff --git a/enjoy/src/renderer/hooks/use-conversation.tsx b/enjoy/src/renderer/hooks/use-conversation.tsx index 09d25268..99594d54 100644 --- a/enjoy/src/renderer/hooks/use-conversation.tsx +++ b/enjoy/src/renderer/hooks/use-conversation.tsx @@ -39,7 +39,7 @@ export const useConversation = () => { configuration: { baseURL: `${apiUrl}/api/ai`, }, - maxRetries: 3, + maxRetries: 2, modelName: model, temperature, maxTokens, @@ -55,6 +55,7 @@ export const useConversation = () => { configuration: { baseURL: baseUrl || openai.baseUrl, }, + maxRetries: 2, modelName: model, temperature, maxTokens, @@ -69,6 +70,7 @@ export const useConversation = () => { temperature, frequencyPenalty, presencePenalty, + maxRetries: 2, }); } else if (conversation.engine === "googleGenerativeAi") { if (!googleGenerativeAi) throw new Error("Google Generative AI API key is required"); @@ -78,6 +80,7 @@ export const useConversation = () => { modelName: model, temperature: temperature, maxOutputTokens: maxTokens, + maxRetries: 2, }); } };