Skip to content

Commit e9b5e30

Browse files
committed
Allow dict-type logprobs parsing
1 parent 908ace2 commit e9b5e30

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

verifiers/utils/response_utils.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,29 @@ async def parse_response_tokens(
2828
return None
2929
if response.choices[0].logprobs is None:
3030
return None
31-
if not hasattr(response.choices[0].logprobs, "content"):
32-
return None
33-
if response.choices[0].logprobs.content is None:
31+
has_logprobs_obj = (
32+
hasattr(response.choices[0].logprobs, "content")
33+
and response.choices[0].logprobs.content is not None
34+
)
35+
has_logprobs_dict = (
36+
isinstance(response.choices[0].logprobs, dict)
37+
and "content" in response.choices[0].logprobs.keys()
38+
and response.choices[0].logprobs["content"] is not None
39+
)
40+
if not (has_logprobs_obj or has_logprobs_dict):
3441
return None
3542
prompt_ids = getattr(response, "prompt_token_ids")
3643
prompt_mask = [0] * len(prompt_ids)
3744
completion_ids = getattr(response.choices[0], "token_ids")
3845
completion_mask = [1] * len(completion_ids)
39-
completion_logprobs = [
40-
token.logprob for token in response.choices[0].logprobs.content
41-
]
46+
if has_logprobs_obj:
47+
assert response.choices[0].logprobs.content is not None
48+
logprobs_content = response.choices[0].logprobs.content
49+
completion_logprobs = [token.logprob for token in logprobs_content]
50+
else:
51+
assert isinstance(response.choices[0].logprobs, dict)
52+
logprobs_content = response.choices[0].logprobs["content"]
53+
completion_logprobs = [token["logprob"] for token in logprobs_content]
4254
elif message_type == "completion":
4355
assert isinstance(response, Completion)
4456
if not hasattr(response.choices[0], "prompt_token_ids"):

0 commit comments

Comments
 (0)