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
gaoqiong
lm-evaluation-harness
Commits
82b4747b
Commit
82b4747b
authored
Feb 05, 2025
by
Baber
Browse files
nit
parent
1efafe22
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
20 deletions
+20
-20
lm_eval/tasks/mathvista/utils.py
lm_eval/tasks/mathvista/utils.py
+20
-20
No files found.
lm_eval/tasks/mathvista/utils.py
View file @
82b4747b
...
@@ -7,6 +7,8 @@ import requests
...
@@ -7,6 +7,8 @@ import requests
# from api_model import make_concurrent_requests
# from api_model import make_concurrent_requests
from
Levenshtein
import
distance
from
Levenshtein
import
distance
from
lm_eval.models.utils
import
retry_on_specific_exceptions
API_KEY
=
os
.
getenv
(
"OPENAI_API_KEY"
)
API_KEY
=
os
.
getenv
(
"OPENAI_API_KEY"
)
assert
API_KEY
is
not
None
,
(
assert
API_KEY
is
not
None
,
(
...
@@ -58,8 +60,10 @@ Extracted answer: B
...
@@ -58,8 +60,10 @@ Extracted answer: B
# Function to send a single request to the OpenAI API
# Function to send a single request to the OpenAI API
@
retry_on_specific_exceptions
(
on_exceptions
=
[
requests
.
exceptions
.
RequestException
],
max_retries
=
5
)
def
send_request
(
prompt
:
str
):
def
send_request
(
prompt
:
str
):
try
:
headers
=
{
headers
=
{
"Authorization"
:
f
"Bearer
{
API_KEY
}
"
,
"Authorization"
:
f
"Bearer
{
API_KEY
}
"
,
"Content-Type"
:
"application/json"
,
"Content-Type"
:
"application/json"
,
...
@@ -76,10 +80,6 @@ def send_request(prompt: str):
...
@@ -76,10 +80,6 @@ def send_request(prompt: str):
result
=
response
.
json
()
result
=
response
.
json
()
return
result
[
"choices"
][
0
][
"message"
][
"content"
]
return
result
[
"choices"
][
0
][
"message"
][
"content"
]
except
Exception
as
e
:
print
(
f
"An error occurred while requesting:
{
e
}
"
)
return
None
def
create_test_prompt
(
demo_prompt
,
query
,
response
):
def
create_test_prompt
(
demo_prompt
,
query
,
response
):
demo_prompt
=
demo_prompt
.
strip
()
demo_prompt
=
demo_prompt
.
strip
()
...
...
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