From 31573390ccfd9b137777ca3a3ff97670541f769e Mon Sep 17 00:00:00 2001 From: David Ng Date: Tue, 17 Oct 2023 12:41:47 +0200 Subject: [PATCH 1/2] Feat: Allow Azure ChatGPT usage Adds variable "OPENAI_API_ENGINE", which is needed for the Azure API --- camel/model_backend.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/camel/model_backend.py b/camel/model_backend.py index e6be3a12e..199eb490d 100644 --- a/camel/model_backend.py +++ b/camel/model_backend.py @@ -13,6 +13,7 @@ # =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. =========== from abc import ABC, abstractmethod from typing import Any, Dict +import os import openai import tiktoken @@ -71,6 +72,7 @@ def run(self, *args, **kwargs) -> Dict[str, Any]: self.model_config_dict['max_tokens'] = num_max_completion_tokens response = openai.ChatCompletion.create(*args, **kwargs, model=self.model_type.value, + engine=os.getenv("OPENAI_API_ENGINE"), **self.model_config_dict) cost = prompt_cost( self.model_type.value, From 266c0fc98646765550b7f635128e151fce502f53 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 18 Oct 2023 16:56:16 +0200 Subject: [PATCH 2/2] feat: add delay to stop hammering OpenAI/Azure --- camel/model_backend.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/camel/model_backend.py b/camel/model_backend.py index 199eb490d..c9f42472d 100644 --- a/camel/model_backend.py +++ b/camel/model_backend.py @@ -14,6 +14,7 @@ from abc import ABC, abstractmethod from typing import Any, Dict import os +import time import openai import tiktoken @@ -70,6 +71,7 @@ def run(self, *args, **kwargs) -> Dict[str, Any]: num_max_token = num_max_token_map[self.model_type.value] num_max_completion_tokens = num_max_token - num_prompt_tokens self.model_config_dict['max_tokens'] = num_max_completion_tokens + time.sleep(0.1) response = openai.ChatCompletion.create(*args, **kwargs, model=self.model_type.value, engine=os.getenv("OPENAI_API_ENGINE"),