Ironclad / rivet

The open-source visual AI programming environment and TypeScript library
https://rivet.ironcladapp.com
MIT License
2.55k stars 226 forks source link

[Bug]: Parallel function calling does not work (completions API, not assistants) #381

Open ai-made-approachable opened 3 months ago

ai-made-approachable commented 3 months ago

What happened?

It all starts with the fact that rivet cannot handle the assistants message in case of parallel function calling = it contains no content and multiple tool calls:

{
  "role": "assistant",
  "content": null,
  "tool_calls": [
    {
      "id": "call_BC3h2tFBsCGp7HuVQTY05EHG",
      "type": "function",
      "function": {
        "name": "test_a",
        "arguments": "{}"
      }
    },
    {
      "id": "call_1Y9o2pEdCgx0dYcw2R2hZ4rk",
      "type": "function",
      "function": {
        "name": "test_b",
        "arguments": "{}"
      }
    }
  ]
}

The all-messages node in rivet just returns one function_call instead of both:

{
  "type": "chat-message[]",
  "value": [
    {
      "type": "user",
      "message": "Use both functions at the same time"
    },
    {
      "type": "assistant",
      "message": "",
      "function_call": {
        "name": "test_a",
        "arguments": "{}",
        "id": "call_tB0RYGG2UkAS0YKGFFwh1bQz"
      }
    }
  ]
}

So later when we want to send the message back to OpenAI, we cannot reach the proper format necessary. This is a proper example that works fine.

{
    "messages": [
        {
            "role": "user",
            "content": "Use \"Test A\" and \"Test B\" function at the same time"
        },
        {
            "role": "assistant",
            "content": null,
            "tool_calls": [
                {
                    "id": "call_KNWJCI2h3vQD3q7gz63M9aQx",
                    "type": "function",
                    "function": {
                        "name": "test_a",
                        "arguments": "{}"
                    }
                },
                {
                    "id": "call_TrWFBOwx1NrfZt4ESx36PdJj",
                    "type": "function",
                    "function": {
                        "name": "test_b",
                        "arguments": "{}"
                    }
                }
            ]
        },
        {
            "role": "tool",
            "content": "Success",
            "name": "test_a",
            "tool_call_id": "call_KNWJCI2h3vQD3q7gz63M9aQx"
        },
        {
            "role": "tool",
            "content": "Success",
            "name": "test_b",
            "tool_call_id": "call_TrWFBOwx1NrfZt4ESx36PdJj"
        }
    ],
    "model": "gpt-3.5-turbo-1106",
    "temperature": 0.5,
    "max_tokens": 1024,
    "stream": false
}

What was the expected functionality?

Describe your environment

MacOS, Node 14.0.0, etc.

Relevant log output

No response

Relevant screenshots

No response

Code of Conduct

T9xz commented 2 months ago

Thnx for ticket. In the current version, this issue can be resolved, but in a very suboptimal way. We're eagerly looking forward to the fix)))