adapt two types of APIs

This commit is contained in:
钱忱 2023-11-10 20:20:05 +08:00
parent 48a528aa37
commit a32733fa27

View File

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