From c2136f83ab8186c1820fde3186c0617d29f2131f Mon Sep 17 00:00:00 2001 From: Knar Date: Fri, 20 Oct 2023 13:21:47 -0400 Subject: [PATCH] added BACKOFF_RETRY_LIMIT env variable --- packages/config/src/config.ts | 4 ++++ .../openai/server/src/functions/makeChatCompletion.ts | 8 ++++++-- .../openai/server/src/functions/makeTextCompletion.ts | 8 ++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/config/src/config.ts b/packages/config/src/config.ts index 92331c6b31..8c0ea19186 100644 --- a/packages/config/src/config.ts +++ b/packages/config/src/config.ts @@ -119,6 +119,10 @@ export const AGENT_RESPONSE_TIMEOUT_MSEC = export const CLOUD_AGENT_KEY = getVarForEnvironment('CLOUD_AGENT_KEY') || v4() +export const BACKOFF_RETRY_LIMIT = Number( + getVarForEnvironment('BACKOFF_RETRY_LIMIT') || 0 +) + export const AWS_ACCESS_KEY = getVarForEnvironment('AWS_ACCESS_KEY') || '' export const AWS_SECRET_KEY = getVarForEnvironment('AWS_SECRET_KEY') || '' export const AWS_REGION = getVarForEnvironment('AWS_REGION') || '' diff --git a/packages/plugins/openai/server/src/functions/makeChatCompletion.ts b/packages/plugins/openai/server/src/functions/makeChatCompletion.ts index 736ad740ef..46dc8e0c6d 100644 --- a/packages/plugins/openai/server/src/functions/makeChatCompletion.ts +++ b/packages/plugins/openai/server/src/functions/makeChatCompletion.ts @@ -6,7 +6,11 @@ import { } from '@magickml/core' import axios from 'axios' import { OPENAI_ENDPOINT } from '../constants' -import { DEFAULT_OPENAI_KEY, PRODUCTION } from '@magickml/config' +import { + DEFAULT_OPENAI_KEY, + PRODUCTION, + BACKOFF_RETRY_LIMIT, +} from '@magickml/config' import { GPT4_MODELS } from '@magickml/plugin-openai-shared' import { trackOpenAIUsage } from '@magickml/server-core' import axiosRetry from 'axios-retry' @@ -112,7 +116,7 @@ export async function makeChatCompletion( try { // Exponential back-off retry delay between requests axiosRetry(axios, { - retries: 5, + retries: BACKOFF_RETRY_LIMIT, retryDelay: axiosRetry.exponentialDelay, shouldResetTimeout: true, retryCondition: error => { diff --git a/packages/plugins/openai/server/src/functions/makeTextCompletion.ts b/packages/plugins/openai/server/src/functions/makeTextCompletion.ts index 9b25a80d40..83f9577a1e 100644 --- a/packages/plugins/openai/server/src/functions/makeTextCompletion.ts +++ b/packages/plugins/openai/server/src/functions/makeTextCompletion.ts @@ -2,7 +2,11 @@ import { CompletionHandlerInputData, saveRequest } from '@magickml/core' import axios from 'axios' import { OPENAI_ENDPOINT } from '../constants' -import { DEFAULT_OPENAI_KEY, PRODUCTION } from '@magickml/config' +import { + DEFAULT_OPENAI_KEY, + PRODUCTION, + BACKOFF_RETRY_LIMIT, +} from '@magickml/config' import { GPT4_MODELS } from '@magickml/plugin-openai-shared' import { trackOpenAIUsage } from '@magickml/server-core' import axiosRetry from 'axios-retry' @@ -75,7 +79,7 @@ export async function makeTextCompletion( try { // Exponential back-off retry delay between requests axiosRetry(axios, { - retries: 5, + retries: BACKOFF_RETRY_LIMIT, retryDelay: axiosRetry.exponentialDelay, shouldResetTimeout: true, retryCondition: error => {