How to create an assistant message after a function call in the new tools API? – Deprecations


Hello!

We are trying to update our code to use the new tools API instead of the functions API (which is marked deprecated in the API reference: https://platform.openai.com/docs/api-reference/chat/create#chat-create-functions).

AFAIU, when using the new tools API, one is supposed to add the output of a function call as tool message (e.g. the temperature for a weather lookup) and then call the API again to let GPT formulate a human-friendly answer.

In our use case, for the majority of function calls we just reply with a fixed utterance (mainly to avoid a second round trip). Until now we just added an Assistant message after a function call. But doesn’t seem to be not allowed anymore:

{
  "error": {
    "message": "An assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'. The following tool_call_ids did not have response messages: call_xxxxxxxxxxxxx",
    "type": "invalid_request_error",
    "param": "messages.[3].role",
    "code": null
  }
}

We have to questions:

  1. For how long will the old API (using functions instead of tools) be supported?
  2. What is the solution in our particular use case?

Tools requires a matching ID between the tool call and the tool return. The assistant call and the tool reply must be paired as followup messages.

This helps the AI endpoint match two parallel calls to the same function name with their respective returns.



Source link

Leave a Comment