-
Notifications
You must be signed in to change notification settings - Fork 284
Fix Tool Call API & Minor Change #1080
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
Conversation
Summary of ChangesHello @flyinglandlord, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly upgrades the system's capability to handle function and tool calls from various large language models. It brings the Tool Call API in line with the latest OpenAI standards, resolves a specific issue, and introduces a more modular and robust parsing architecture. The changes ensure broader compatibility and improved performance when interacting with advanced models that utilize complex tool calling mechanisms, particularly in streaming and parallel contexts. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces significant improvements to the tool calling API, aligning it with the latest OpenAI version and adding support for new model formats like Kimi-K2 and DeepSeek. The refactoring of the function_call_parser.py is a major step forward in terms of modularity and extensibility. The changes to the API models and the OpenAI API implementation are well-executed to support the new features, including robust streaming logic. I've identified one issue in the function_call_parser.py where tool_index is not correctly assigned during non-streaming parsing, for which I've provided a suggestion. Overall, this is a high-quality contribution.
| for act in action: | ||
| name = act.get("name") | ||
| if name and name in tool_indices: | ||
| results.append( | ||
| ToolCallItem( | ||
| tool_index=tool_indices[name], | ||
| tool_index=-1, # Caller should update this based on the actual tools array called | ||
| name=name, | ||
| parameters=json.dumps( | ||
| act.get("parameters") or act.get("arguments", {}), | ||
| ensure_ascii=False, | ||
| ), | ||
| ) | ||
| ) | ||
| else: | ||
| logger.warning(f"Model attempted to call undefined function: {name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tool_index is consistently set to -1 for all tool calls parsed in non-streaming mode. This is incorrect as tool_index should represent the index of the tool call within the list of calls in the assistant's message. A value of -1 will be passed to the ToolCall object, which is not ideal.
I suggest using enumerate to get the correct index for each tool call.
| for act in action: | |
| name = act.get("name") | |
| if name and name in tool_indices: | |
| results.append( | |
| ToolCallItem( | |
| tool_index=tool_indices[name], | |
| tool_index=-1, # Caller should update this based on the actual tools array called | |
| name=name, | |
| parameters=json.dumps( | |
| act.get("parameters") or act.get("arguments", {}), | |
| ensure_ascii=False, | |
| ), | |
| ) | |
| ) | |
| else: | |
| logger.warning(f"Model attempted to call undefined function: {name}") | |
| for i, act in enumerate(action): | |
| name = act.get("name") | |
| if name and name in tool_indices: | |
| results.append( | |
| ToolCallItem( | |
| tool_index=i, | |
| name=name, | |
| parameters=json.dumps( | |
| act.get("parameters") or act.get("arguments", {}), | |
| ensure_ascii=False, | |
| ), | |
| ) | |
| ) | |
| else: | |
| logger.warning(f"Model attempted to call undefined function: {name}") |
Uh oh!
There was an error while loading. Please reload this page.