A correct message in response to a tool call cannot validate as ChatCompletionMessage

That uses dictionary to parameter unpacking, a perfectly valid method of passing a JSON-like Python object into a function as parameters.

It uses one of “types” from the Python library, something I haven’t messed with, because a python list is just fine.

However, the input to the API chat.competions function is ALL parameters of the API call, not just the messages. Things like the model name, temperature, the tool specification, etc. Of which the messages (a list) is just one more thing that must be present.

I use that convention in my big demo of returning the assistant message with a tool call and the paired tool call return with matching IDs.

What I wrote is a linear example with fixed strings to be as demonstrative as possible. You must have the parsing that looks for multiple parallel tools, and adaptively provide a list of all of them in the return. That’s the purpose of the “for tool_call” in the code sample above.

Also, the endpoint will give you an error if you don’t have both “assistant” and “tool”, with matching IDs and length.

1 Like