Skip to content

Assistant message with tool_calls and without content raises an error #1805

Closed
@feloy

Description

@feloy

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • I am running the latest code. Development is very rapid so there are no tagged versions as of now.
  • I carefully followed the README.md.
  • I searched using keywords relevant to my issue to make sure that I am creating a new issue that is not already open (or closed).
  • I reviewed the Discussions, and have a new bug or useful enhancement to share.

Expected Behavior

Sending this request:

{
  "model" : my-model,
  "messages" : [ {
    "role" : "system",
    "content" : "You are an helpful assistant"
  }, {
    "role" : "user",
    "content" : "What is the square root of 101?"
  }, {
    "role" : "assistant",
    "tool_calls" : [ {
      "id" : "call__0_sqrt_cmpl-c359a11f-68fa-4b8e-9960-1917b96a8b23",
      "type" : "function",
      "function" : {
        "name" : "sqrt",
        "arguments" : "{\"arg0\": 101}"
      }
    } ]
  }, {
    "role" : "tool",
    "tool_call_id" : "call__0_sqrt_cmpl-c359a11f-68fa-4b8e-9960-1917b96a8b23",
    "content" : "10.05"
  } ],
  "temperature" : 0.7
}

the request should be valid.

Current Behavior

The request raises the following error:

{
  "error":{
    "message":"[
      {
        'type': 'literal_error', 
        'loc': ('body', 'messages', 2, 'typed-dict', 'role'), 
        'msg': \"Input should be 'system'\", 
        'input': 'assistant', 
        'ctx': {'expected': \"'system'\"}
      }, {
        'type': 'missing', 
        'loc': ('body', 'messages', 2, 'typed-dict', 'content'), 
        'msg': 'Field required', 
        'input': {'role': 'assistant', 'tool_calls': [{'id': 'call__0_sqrt_cmpl-c359a11f-68fa-4b8e-9960-1917b96a8b23', 'type': 'function', 'function': {'name': 'sqrt', 'arguments': '{\"arg0\": 101}'}}]}
     }, {
       'type': 'literal_error', 
       'loc': ('body', 'messages', 2, 'typed-dict', 'role'), 
       'msg': \"Input should be 'user'\", 
       'input': 'assistant', 
       'ctx': {'expected': \"'user'\"}
     }, {
       'type': 'missing', 
       'loc': ('body', 'messages', 2, 'typed-dict', 'content'), 
       'msg': 'Field required', 
       'input': {'role': 'assistant', 'tool_calls': [{'id': 'call__0_sqrt_cmpl-c359a11f-68fa-4b8e-9960-1917b96a8b23', 'type': 'function', 'function': {'name': 'sqrt', 'arguments': '{\"arg0\": 101}'}}]}
     }, {
       'type': 'missing',
       'loc': ('body', 'messages', 2, 'typed-dict', 'content'), 
       'msg': 'Field required', 
       'input': {'role': 'assistant', 'tool_calls': [{'id': 'call__0_sqrt_cmpl-c359a11f-68fa-4b8e-9960-1917b96a8b23', 'type': 'function', 'function': {'name': 'sqrt', 'arguments': '{\"arg0\": 101}'}}]}
     }, {
       'type': 'literal_error', 
       'loc': ('body', 'messages', 2, 'typed-dict', 'role'),
       'msg': \"Input should be 'tool'\", 
       'input': 'assistant', 
       'ctx': {'expected': \"'tool'\"}
     }, {
       'type': 'missing', 
       'loc': ('body', 'messages', 2, 'typed-dict', 'content'), 
       'msg': 'Field required', 
       'input': {'role': 'assistant', 'tool_calls': [{'id': 'call__0_sqrt_cmpl-c359a11f-68fa-4b8e-9960-1917b96a8b23', 'type': 'function', 'function': {'name': 'sqrt', 'arguments': '{\"arg0\": 101}'}}]}
     }, {
       'type': 'missing', 
       'loc': ('body', 'messages', 2, 'typed-dict', 'tool_call_id'), 
       'msg': 'Field required', 
       'input': {'role': 'assistant', 'tool_calls': [{'id': 'call__0_sqrt_cmpl-c359a11f-68fa-4b8e-9960-1917b96a8b23', 'type': 'function', 'function': {'name': 'sqrt', 'arguments': '{\"arg0\": 101}'}}]}
     }, {
       'type': 'literal_error', 
       'loc': ('body', 'messages', 2, 'typed-dict', 'role'),
       'msg': \"Input should be 'function'\", 'input': 'assistant', 'ctx': {'expected': \"'function'\"}}, {'type': 'missing', 'loc': ('body', 'messages', 2, 'typed-dict', 'content'), 'msg': 'Field required', 'input': {'role': 'assistant', 'tool_calls': [{'id': 'call__0_sqrt_cmpl-c359a11f-68fa-4b8e-9960-1917b96a8b23', 'type': 'function', 'function': {'name': 'sqrt', 'arguments': '{\"arg0\": 101}'}}]}
     }, {
       'type': 'missing', 
       'loc': ('body', 'messages', 2, 'typed-dict', 'name'), 
       'msg': 'Field required', 
       'input': {'role': 'assistant', 'tool_calls': [{'id': 'call__0_sqrt_cmpl-c359a11f-68fa-4b8e-9960-1917b96a8b23', 'type': 'function', 'function': {'name': 'sqrt', 'arguments': '{\"arg0\": 101}'}}]}
    }
    ]","type":"internal_server_error","param":null,"code":null}}

Note that if "content": null is added to the third message (the one with tool_calls), the request succeeds.

The same request on GPT API works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions