mirror of
https://github.com/open-compass/opencompass.git
synced 2025-05-30 16:03:24 +08:00
[Enhancement] Optimize OpenAI models (#128)
* [Feature] Enhance OpenAI API, add example config for GPT evaluation
This commit is contained in:
parent
d17a5b94fa
commit
bbdedc6c95
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user