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 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):
|
|||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user