Skip to content
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

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

Closed
4 tasks done
feloy opened this issue Oct 21, 2024 · 1 comment · Fixed by #1807
Closed
4 tasks done

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

feloy opened this issue Oct 21, 2024 · 1 comment · Fixed by #1807

Comments

@feloy
Copy link
Contributor

feloy commented Oct 21, 2024

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.

@feloy
Copy link
Contributor Author

feloy commented Oct 21, 2024

I propose the fix #1807 , which makes content not required (instead of optional) in assistant message.

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 a pull request may close this issue.

1 participant