From b325dc91751c9119cf30ef241640e18db55a68aa Mon Sep 17 00:00:00 2001 From: william Date: Mon, 18 Nov 2024 14:11:25 -0600 Subject: [PATCH] Add consistent-ish retrying for all SUTs. --- plugins/anthropic/modelgauge/suts/anthropic_api.py | 2 +- plugins/huggingface/modelgauge/suts/huggingface_api.py | 2 +- plugins/openai/modelgauge/suts/openai_client.py | 2 +- src/modelgauge/suts/together_client.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/anthropic/modelgauge/suts/anthropic_api.py b/plugins/anthropic/modelgauge/suts/anthropic_api.py index 5c886a65..65791a90 100644 --- a/plugins/anthropic/modelgauge/suts/anthropic_api.py +++ b/plugins/anthropic/modelgauge/suts/anthropic_api.py @@ -48,7 +48,7 @@ def __init__(self, uid: str, model: str, api_key: AnthropicApiKey): def _load_client(self) -> Anthropic: return Anthropic( api_key=self.api_key, - max_retries=10, + max_retries=7, ) def translate_text_prompt(self, prompt: TextPrompt) -> AnthropicRequest: diff --git a/plugins/huggingface/modelgauge/suts/huggingface_api.py b/plugins/huggingface/modelgauge/suts/huggingface_api.py index ac2eefd5..186353f2 100644 --- a/plugins/huggingface/modelgauge/suts/huggingface_api.py +++ b/plugins/huggingface/modelgauge/suts/huggingface_api.py @@ -46,7 +46,7 @@ def translate_text_prompt(self, prompt: TextPrompt) -> HuggingFaceChatRequest: ), ) - @tenacity.retry(stop=stop_after_attempt(10), wait=wait_random_exponential()) + @tenacity.retry(stop=stop_after_attempt(7), wait=wait_random_exponential()) def evaluate(self, request: HuggingFaceChatRequest) -> HuggingFaceResponse: headers = { "Accept": "application/json", diff --git a/plugins/openai/modelgauge/suts/openai_client.py b/plugins/openai/modelgauge/suts/openai_client.py index 48baf508..ac591416 100644 --- a/plugins/openai/modelgauge/suts/openai_client.py +++ b/plugins/openai/modelgauge/suts/openai_client.py @@ -109,7 +109,7 @@ def __init__(self, uid: str, model: str, api_key: OpenAIApiKey, org_id: OpenAIOr self.org_id = org_id.value def _load_client(self) -> OpenAI: - return OpenAI(api_key=self.api_key, organization=self.org_id, max_retries=10) + return OpenAI(api_key=self.api_key, organization=self.org_id, max_retries=7) def translate_text_prompt(self, prompt: TextPrompt) -> OpenAIChatRequest: messages = [OpenAIChatMessage(content=prompt.text, role=_USER_ROLE)] diff --git a/src/modelgauge/suts/together_client.py b/src/modelgauge/suts/together_client.py index f2dfd5d9..e1a5956a 100644 --- a/src/modelgauge/suts/together_client.py +++ b/src/modelgauge/suts/together_client.py @@ -32,7 +32,7 @@ def _retrying_post(url, headers, json_payload): """HTTP Post with retry behavior.""" session = requests.Session() retries = Retry( - total=10, + total=7, backoff_factor=2, status_forcelist=[ 408, # Request Timeout