From bdabe2530d983e1414a774ac77ede4c581f7fb5e Mon Sep 17 00:00:00 2001 From: David Finch Date: Sat, 7 Oct 2023 09:05:11 -0400 Subject: [PATCH] Added retry from pipi and impmented it on Running the OpenAI Model Backend --- camel/model_backend.py | 4 +++- requirements.txt | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/camel/model_backend.py b/camel/model_backend.py index 5d895b4..ac8ba4b 100644 --- a/camel/model_backend.py +++ b/camel/model_backend.py @@ -16,6 +16,7 @@ from typing import Any, Dict import openai import tiktoken +from retry import retry from camel.typing import ModelType from chatdev.utils import log_and_print_online @@ -46,7 +47,8 @@ class OpenAIModel(ModelBackend): super().__init__() self.model_type = model_type self.model_config_dict = model_config_dict - + + @retry(tries=-1, delay=0, max_delay=None, backoff=1, jitter=0) def run(self, *args, **kwargs) -> Dict[str, Any]: string = "\n".join([message["content"] for message in kwargs["messages"]]) encoding = tiktoken.encoding_for_model(self.model_type.value) diff --git a/requirements.txt b/requirements.txt index 3f53d12..4bfee1d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -77,3 +77,4 @@ wrapt==1.15.0 yapf==0.32.0 yarl==1.9.2 zipp==3.16.2 +retry==0.9.2