From a32733fa279c647367cd19d58957630e170e0a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=B1=E5=BF=B1?= Date: Fri, 10 Nov 2023 20:20:05 +0800 Subject: [PATCH] adapt two types of APIs --- camel/model_backend.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/camel/model_backend.py b/camel/model_backend.py index d54eea4..496120b 100644 --- a/camel/model_backend.py +++ b/camel/model_backend.py @@ -67,9 +67,12 @@ class OpenAIModel(ModelBackend): 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 - response = openai.ChatCompletion.create(*args, **kwargs, - model=self.model_type.value, - **self.model_config_dict) + + try: + response = openai.ChatCompletion.create(*args, **kwargs, model=self.model_type.value, **self.model_config_dict) + except AttributeError: + response = openai.chat.completions.create(*args, **kwargs, model=self.model_type.value, **self.model_config_dict) + cost = prompt_cost( self.model_type.value, num_prompt_tokens=response["usage"]["prompt_tokens"],