Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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.

@google-cla
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
justinryan-0923 pushed a commit to justinryan-0923/llama.cpp that referenced this pull request May 30, 2025
ochafik added a commit to ochafik/minja that referenced this pull request Nov 2, 2025
* fix: require one of 'content' or 'tool_calls' in messages

* fix: check content is given during polyfill tool_calls

---------

Co-authored-by: Olivier Chafik <[email protected]>
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