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
Hide 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
# from api_model import make_concurrent_requests
from
Levenshtein
import
distance
from
lm_eval.models.utils
import
retry_on_specific_exceptions
API_KEY
=
os
.
getenv
(
"OPENAI_API_KEY"
)
assert
API_KEY
is
not
None
,
(
...
...
@@ -58,27 +60,25 @@ Extracted answer: B
# 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
):
try
:
headers
=
{
"Authorization"
:
f
"Bearer
{
API_KEY
}
"
,
"Content-Type"
:
"application/json"
,
}
data
=
{
"model"
:
MODEL
,
"messages"
:
[
{
"role"
:
"user"
,
"content"
:
prompt
},
],
"max_tokens"
:
100
,
}
response
=
requests
.
post
(
API_URL
,
headers
=
headers
,
json
=
data
)
response
.
raise_for_status
()
result
=
response
.
json
()
return
result
[
"choices"
][
0
][
"message"
][
"content"
]
except
Exception
as
e
:
print
(
f
"An error occurred while requesting:
{
e
}
"
)
return
None
headers
=
{
"Authorization"
:
f
"Bearer
{
API_KEY
}
"
,
"Content-Type"
:
"application/json"
,
}
data
=
{
"model"
:
MODEL
,
"messages"
:
[
{
"role"
:
"user"
,
"content"
:
prompt
},
],
"max_tokens"
:
100
,
}
response
=
requests
.
post
(
API_URL
,
headers
=
headers
,
json
=
data
)
response
.
raise_for_status
()
result
=
response
.
json
()
return
result
[
"choices"
][
0
][
"message"
][
"content"
]
def
create_test_prompt
(
demo_prompt
,
query
,
response
):
...
...
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