[Enhancement] Optimize OpenAI models (#128)

* [Feature] Enhance OpenAI API, add example config for GPT evaluation
This commit is contained in:
Tong Gao 2023-08-03 14:55:16 +08:00 committed by GitHub
parent d17a5b94fa
commit bbdedc6c95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,6 @@
import json
import os
import time
from concurrent.futures import ThreadPoolExecutor
from threading import Lock
from typing import Dict, List, Optional, Union
@ -188,10 +189,14 @@ class OpenAI(BaseAPIModel):
except requests.JSONDecodeError:
self.logger.error('JsonDecode error, got',
str(raw_response.content))
continue
try:
return response['choices'][0]['message']['content'].strip()
except KeyError:
if 'error' in response:
if response['error']['code'] == 'rate_limit_exceeded':
time.sleep(1)
continue
self.logger.error('Find error message in response: ',
str(response['error']))
max_num_retries += 1