Unverified Commit a11adafd authored by Jan Kessler's avatar Jan Kessler Committed by GitHub
Browse files

Gracefully handle edge cases in harmony utils (#23155)


Signed-off-by: default avatarJan Kessler <jakessle@uni-mainz.de>
Co-authored-by: default avatarChen Zhang <zhangch99@outlook.com>
Co-authored-by: default avatarCyrus Leung <tlleungac@connect.ust.hk>
parent a781e84e
......@@ -155,7 +155,7 @@ def parse_chat_input(chat_msg) -> Message:
contents = [TextContent(text=content)]
else:
# TODO: Support refusal.
contents = [TextContent(text=c["text"]) for c in content]
contents = [TextContent(text=c.get("text", "")) for c in content]
msg = Message.from_role_and_contents(role, contents)
return msg
......@@ -218,8 +218,8 @@ def parse_output_message(message: Message) -> list[ResponseOutputItem]:
)
output_items.append(reasoning_item)
elif message.channel == "commentary":
if message.recipient.startswith("functions."):
function_name = message.recipient.split(".")[-1]
if recipient is not None and recipient.startswith("functions."):
function_name = recipient.split(".")[-1]
for content in message.content:
random_id = random_uuid()
response_item = ResponseFunctionToolCall(
......@@ -230,8 +230,8 @@ def parse_output_message(message: Message) -> list[ResponseOutputItem]:
id=f"ft_{random_id}",
)
output_items.append(response_item)
elif message.recipient.startswith(
"python") or message.recipient.startswith("browser"):
elif recipient is not None and (recipient.startswith("python")
or recipient.startswith("browser")):
for content in message.content:
reasoning_item = ResponseReasoningItem(
id=f"rs_{random_uuid()}",
......@@ -245,7 +245,7 @@ def parse_output_message(message: Message) -> list[ResponseOutputItem]:
)
output_items.append(reasoning_item)
else:
raise ValueError(f"Unknown recipient: {message.recipient}")
raise ValueError(f"Unknown recipient: {recipient}")
elif message.channel == "final":
contents = []
for content in message.content:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment