Skip to content

Commit

Permalink
sglang support for runeval
Browse files Browse the repository at this point in the history
  • Loading branch information
jakep-allenai committed Nov 6, 2024
1 parent 592cc50 commit a14febc
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion pdelfin/eval/runeval.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def normalize_json_entry(data: dict) -> NormalizedEntry:
)
elif all(field in data for field in ["s3_path", "pagenum", "text", "error", "finish_reason"]):
return NormalizedEntry(**data)
else:
elif "response" in data and "body" in data["response"] and "choices" in data["response"]["body"]:
# OpenAI case
try:
# Attempt to parse the JSON content from OpenAI's response
Expand All @@ -120,6 +120,23 @@ def normalize_json_entry(data: dict) -> NormalizedEntry:
text=data["response"]["body"]["choices"][0]["message"]["content"],
finish_reason=data["response"]["body"]["choices"][0]["finish_reason"]
)
else:
# SGLang case
try:
# Attempt to parse the JSON content from OpenAI's response
parsed_content = json.loads(data["response"]["choices"][0]["message"]["content"])
return NormalizedEntry.from_goldkey(
goldkey=data["custom_id"],
text=parsed_content["natural_text"],
finish_reason=data["response"]["choices"][0]["finish_reason"]
)
except json.JSONDecodeError:
# Fallback if content is not valid JSON
return NormalizedEntry.from_goldkey(
goldkey=data["custom_id"],
text=data["response"]["choices"][0]["message"]["content"],
finish_reason=data["response"]["choices"][0]["finish_reason"]
)

# Load every .json file from GOLD_DATA_S3_PATH (and saves it to some temp folder for quick loading next time)
# returns map from "custom_id" ex. "s3://ai2-s2-pdfs/39ce/3db4516cd6e7d7f8e580a494c7a665a6a16a.pdf-4" (where the -4 means page 4)
Expand Down

0 comments on commit a14febc

Please sign in to comment.