Skip to content

Consider "tool_calls" instead of "content" in messages #63

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

Merged
merged 3 commits into from
May 15, 2025

Conversation

grf53
Copy link
Contributor

@grf53 grf53 commented Apr 24, 2025

In the latest document of transformers(link), a message containing 'tool calls' contains member with key "tool_calls" instead of "content".

{
  "role": "assistant",
  "tool_calls": [
    {
      "type": "function",
      "function": {
        "name": "multiply",
        "arguments": {
          "a": 5,
          "b": 6
        }
      }
    }
  ]
}

The 'tool call' messages are not necessarily included as input messages because they are model outputs rather than model inputs. However, they are necessary to provide context during the process of providing tool execution results or after.

Currently, a message without "content" cannot be put into chat_template::apply() due to the validation logic as follows.

if (!message.contains("role") || !message.contains("content")) {
throw std::runtime_error("message must have 'role' and 'content' fields: " + message.dump());

When referencing other lines of code, it seems like it's required to include a member with a "content" key, even if it's null or an empty string. However, I don't think it's very persuasive to require even an empty "content" when "tool_calls" can replace it. So I propose to require only one of "content" and "tool_calls", as in this PR.

Copy link

google-cla bot commented Apr 24, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@grf53
Copy link
Contributor Author

grf53 commented May 1, 2025

@ochafik Hello, I think you've seen this. How is your opinion on this changes? If there are more points to modify, please let me know. :)

@ochafik ochafik merged commit f06140f into google:main May 15, 2025
3 of 11 checks passed
ochafik added a commit to ggml-org/llama.cpp that referenced this pull request May 15, 2025
Erick-0923 pushed a commit to Erick-0923/llama.cpp that referenced this pull request May 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants