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"],