Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
opencompass
Commits
bbdedc6c
Unverified
Commit
bbdedc6c
authored
Aug 03, 2023
by
Tong Gao
Committed by
GitHub
Aug 03, 2023
Browse files
[Enhancement] Optimize OpenAI models (#128)
* [Feature] Enhance OpenAI API, add example config for GPT evaluation
parent
d17a5b94
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
0 deletions
+5
-0
opencompass/models/openai_api.py
opencompass/models/openai_api.py
+5
-0
No files found.
opencompass/models/openai_api.py
View file @
bbdedc6c
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment