-
Notifications
You must be signed in to change notification settings - Fork 293
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
RequestMessage with tool_calls in Assistant message. #793
Comments
Hi @Jeadie! Thanks for raising the issue. I was wondering if you could just modify the code like: messages.push(IndexMap::from([
("role".to_string(), Either::Left("asistant".to_string())),
("content".to_string(), Either::Left("".to_string())),
(
"tool_calls".to_string(),
Either::Left(
json!({
"name": called.function.name,
"arguments": called.function.arguments,
})
.to_string(),
),
),
])); I think I'm a bit confused on the limitation here, as any JSON objects would need to be stringified eventually. Perhaps the above would work? |
The issue is that certain common open-source Jinja For example {%- if not message.tool_calls|length == 1 %}
{{- raise_exception(\"This model only supports single tool-calls at once!\") }}
{%- endif %} This is not checking the length of the JSON string is 1, but rather that the JSON array has one entry. |
Initial comments were incorrect, the example needs to be. tool_calls = messages.push(IndexMap::from([
("role".to_string(), Either::Left("asistant".to_string())),
("content".to_string(), Either::Left("".to_string())),
(
"tool_calls".to_string(),
Either::Right(Vec![
IndexMap::from([
("Id".to_string(), tool_call.id),
("function".to_string(), json!({
"name": called.function.name,
"arguments": called.function.arguments,
}),
("type".to_string(), "function".to_string()"),
])
])
),
])); The key difference is to use However, this still does not resolve all issues found in trying to use the {{- '<|start_header_id|>assistant<|end_header_id|>\n\n' -}}
{{- '{"name": "' + tool_call.name + '", ' }}
{{- '"parameters": ' }}
{{- tool_call.arguments | tojson }}
{{- "}" }} This part of the chat_template is attempting access fields within the JSON value of json!({
"name": called.function.name,
"arguments": called.function.arguments,
}) This is a direct limitation of pub type MessageContent = Either<String, Vec<IndexMap<String, String>>>; The final IndexMap::from([
("Id".to_string(), tool_call.id),
("function".to_string(), json!({
"name": called.function.name,
"arguments": called.function.arguments,
}),
("type".to_string(), "function".to_string()"),
]) |
The impact of this issue is that |
Describe the bug
In mistral.rs, we JSON string the full
"tool_calls"
value, e.g.mistral.rs/mistralrs/examples/lower_level/tools/main.rs
Lines 127 to 139 in b6b722e
In fact, MessageContent only supports String values.
This restricts the ability to feed the result of tool calls back to various models
Also value should be
"arguments"
and not"parameters"
(parameters is used in JSONSchema fortools
key.The text was updated successfully, but these errors were encountered: