-
Notifications
You must be signed in to change notification settings - Fork 826
Draft: parse tool_calls arguments #4921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -811,6 +811,26 @@ def _transform_messages( | |
| ) | ||
| new_message = dict(msg) | ||
| new_message["content"] = new_content if new_content else None | ||
| # Parse JSON-encoded arguments in tool_calls to dicts, | ||
| # so Jinja2 templates can iterate them with |items. | ||
| if new_message.get("tool_calls"): | ||
| tool_calls = [] | ||
| for tc in new_message["tool_calls"]: | ||
| tc = dict(tc) | ||
| func = tc.get("function") | ||
| if isinstance(func, dict) and isinstance( | ||
| func.get("arguments"), str | ||
| ): | ||
| func = dict(func) | ||
| try: | ||
| parsed_args = json.loads(func["arguments"]) | ||
| if isinstance(parsed_args, dict): | ||
| func["arguments"] = parsed_args | ||
| except (json.JSONDecodeError, TypeError): | ||
| pass | ||
| tc["function"] = func | ||
| tool_calls.append(tc) | ||
| new_message["tool_calls"] = tool_calls | ||
|
Comment on lines
+814
to
+833
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change introduces a breaking change for models whose chat templates expect |
||
| transformed_messages.append(new_message) | ||
|
|
||
| return transformed_messages | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.