Skip to content

Tool calls with arguments error in streaming mode #45

@ar-jan

Description

@ar-jan

Using tool-calling in streaming mode with a function with arguments (here with an inline Python function) results in an error. Looks to be caused by arguments sometimes still represented as strings instead of dicts (chunks below with "arguments":"2" and "arguments":"") repeated as complete JSON object once "finish_reason":"tool_calls" is reached.

LLM_OPENAI_SHOW_RESPONSES=1 llm -m venice/mistral-31-24b --functions '
def multiply(x: int, y: int) -> int:
    """Multiply two numbers."""
    return x * y
' "What is 1337 times 42?" --tools-debug
Request: POST https://api.venice.ai/api/v1/chat/completions
  Headers:
    host: api.venice.ai
    connection: keep-alive
    accept: application/json
    content-type: application/json
    user-agent: OpenAI/Python 1.107.2
    ....
    content-length: 356
  Body:
    {
      "messages": [
        {
          "role": "user",
          "content": "What is 1337 times 42?"
        }
      ],
      "model": "mistral-31-24b",
      "stream": true,
      "stream_options": {
        "include_usage": true
      },
      "tools": [
        {
          "type": "function",
          "function": {
            "name": "multiply",
            "description": "Multiply two numbers.",
            "parameters": {
              "properties": {
                "x": {
                  "type": "integer"
                },
                "y": {
                  "type": "integer"
                }
              },
              "required": [
                "x",
                "y"
              ],
              "type": "object"
            }
          }
        }
      ]
    }
Response: status_code=200
  Headers:
    date: Mon, 06 Oct 2025 17:20:57 GMT
    content-type: text/event-stream; charset=utf-8
    transfer-encoding: chunked
    ...
  Body:
data: {"id":"chatcmpl-f89a0df1a37449c587c4d5552cd96527","object":"chat.completion.chunk","created":1759771256,"model":"mistral-31-24b","choices":[{"index":0,"delta":{"role":"assistant","content":""},"logprobs":null,"finish_reason":null}]}

data: {"id":"chatcmpl-f89a0df1a37449c587c4d5552cd96527","object":"chat.completion.chunk","created":175977125
6,"model":"mistral-31-24b","choices":[{"index":0,"delta":{"tool_calls":[{"id":"lvJpv512O","type":"function","index":0,"function":{"name":"multiply","arguments":"{}"}}]},"logprobs":null,"finish_reason":null}]}

data: {"id":"chatcmpl-f89a0df1a37449c587c4d5552cd96527","object":"chat.completion.chunk","created":1759771256,"model":"mistral-31-24b","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"{\"x\": "}}]},"logprobs":null,"finish_reason":null}]}

data: {"id":"chatcmpl-f89a0df1a37449c587c4d5552cd96527","object":"chat.completion.chunk","created":1759771256,"model":"mistral-31-24b","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":", \"y\": 4"}}]},"logprobs":null,"finish_reason":null}]}

data: {"id":"chatcmpl-f89a0df1a37449c587c4d5552cd96527","object":"chat.completion.chunk","created":1759771256,"model":"mistral-31-24b","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"2"}}]},"logprobs":null,"finish_reason":null}]}

data: {"id":"chatcmpl-f89a0df1a37449c587c4d5552cd96527","object":"chat.completion.chunk","created":1759771256,"model":"mistral-31-24b","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":""}}]},"logprobs":null,"finish_reason":null}]}

data: {"id":"chatcmpl-f89a0df1a37449c587c4d5552cd96527","object":"chat.completion.chunk","created":1759771256,"model":"mistral-31-24b","choices":[{"index":0,"delta":{"tool_calls":[{"index":0,"function":{"arguments":"{\"x\": 1337, \"y\": 42}"}}]},"logprobs":null,"finish_reason":"tool_calls","stop_reason":null}]}

data: {"id":"chatcmpl-f89a0df1a37449c587c4d5552cd96527","object":"chat.completion.chunk","created":1759771256,"model":"mistral-31-24b","choices":[],"usage":{"prompt_tokens":1079,"total_tokens":1109,"completion_tokens":30}}

data: [DONE]

Error: Extra data: line 1 column 3 (char 2)

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