Skip to content

Commit

Permalink
feat: retries for openai (#4911)
Browse files Browse the repository at this point in the history
* feat: retries for openai

* fix: formatting

* fix: change max timeout

GitOrigin-RevId: e4ddfadb28e1da7c4c739d75e59ffa3172677cd7
  • Loading branch information
berkecanrizai authored and Manul from Pathway committed Nov 3, 2023
1 parent 854c6d6 commit 9f993b6
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions llm_app/model_wrappers/api_clients/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from abc import ABC, abstractmethod

import requests
from tenacity import retry, stop_after_attempt, wait_random_exponential

logfun = logging.debug

Expand All @@ -22,6 +23,7 @@ def __init__(
):
import openai

openai.api_requestor.TIMEOUT_SECS = 90
openai.api_key = api_key
if api_type:
openai.api_type = api_type
Expand All @@ -34,6 +36,7 @@ def __init__(


class OpenAIChatCompletionClient(OpenAIClient):
@retry(wait=wait_random_exponential(min=1, max=60), stop=stop_after_attempt(6))
def make_request(self, **kwargs):
logfun("Calling OpenAI chat completion service %s", str(kwargs)[:100])
return self.api.ChatCompletion.create(**kwargs)
Expand Down

0 comments on commit 9f993b6

Please sign in to comment.