Unverified Commit bbdedc6c authored by Tong Gao's avatar Tong Gao Committed by GitHub
Browse files

[Enhancement] Optimize OpenAI models (#128)

* [Feature] Enhance OpenAI API, add example config for GPT evaluation
parent d17a5b94
import json import json
import os import os
import time
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from threading import Lock from threading import Lock
from typing import Dict, List, Optional, Union from typing import Dict, List, Optional, Union
...@@ -188,10 +189,14 @@ class OpenAI(BaseAPIModel): ...@@ -188,10 +189,14 @@ class OpenAI(BaseAPIModel):
except requests.JSONDecodeError: except requests.JSONDecodeError:
self.logger.error('JsonDecode error, got', self.logger.error('JsonDecode error, got',
str(raw_response.content)) str(raw_response.content))
continue
try: try:
return response['choices'][0]['message']['content'].strip() return response['choices'][0]['message']['content'].strip()
except KeyError: except KeyError:
if 'error' in response: if 'error' in response:
if response['error']['code'] == 'rate_limit_exceeded':
time.sleep(1)
continue
self.logger.error('Find error message in response: ', self.logger.error('Find error message in response: ',
str(response['error'])) str(response['error']))
max_num_retries += 1 max_num_retries += 1
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment