[GH-ISSUE #6462] Make tool call response compatible with OpenAI format #66102

Closed
opened 2026-05-03 23:58:39 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @eliasfroehner on GitHub (Aug 22, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/6462

Description

Currently, the response for a tool call looks like this:

{
  "model": "llama3.1",
  "created_at": "2024-07-22T20:33:28.123648Z",
  "message": {
    "role": "assistant",
    "content": "",
    "tool_calls": [
      {
        "function": {
          "name": "get_current_weather",
          "arguments": {
            "format": "celsius",
            "location": "Paris, FR"
          }
        }
      }
    ]
  },
  "done_reason": "stop",
  "done": true,
  "total_duration": 885095291,
  "load_duration": 3753500,
  "prompt_eval_count": 122,
  "prompt_eval_duration": 328493000,
  "eval_count": 33,
  "eval_duration": 552222000
}

However, I would like the response to be compatible with the OpenAI format, which includes an id and type field for each tool call. The desired format is as follows:

{
  "model": "llama3.1",
  "created_at": "2024-07-22T20:33:28.123648Z",
  "message": {
    "role": "assistant",
    "content": "",
    "tool_calls": [
      {
        "id": "call_62136354",
        "type":  "function",
        "function": {
          "name": "get_current_weather",
          "arguments": {
            "format": "celsius",
            "location": "Paris, FR"
          }
        }
      }
    ]
  },
  "done_reason": "stop",
  "done": true,
  "total_duration": 885095291,
  "load_duration": 3753500,
  "prompt_eval_count": 122,
  "prompt_eval_duration": 328493000,
  "eval_count": 33,
  "eval_duration": 552222000
}

Additionally, the lack of an id field in the current format prevents a software from responding to multiple simultaneous calls to a tool.

Steps to Reproduce

  1. Make a tool call request.
  2. Observe the response format.

Expected Behavior

The response should include an id and type field for each tool call, making it compatible with the OpenAI format.

Actual Behavior

The response does not include an id and type field for each tool call.

Additional Information

This change is necessary to ensure compatibility with the OpenAI API and to handle multiple simultaneous tool calls effectively.

Labels

  • enhancement
  • compatibility
  • api
Originally created by @eliasfroehner on GitHub (Aug 22, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/6462 ### Description Currently, the response for a tool call looks like this: ```json { "model": "llama3.1", "created_at": "2024-07-22T20:33:28.123648Z", "message": { "role": "assistant", "content": "", "tool_calls": [ { "function": { "name": "get_current_weather", "arguments": { "format": "celsius", "location": "Paris, FR" } } } ] }, "done_reason": "stop", "done": true, "total_duration": 885095291, "load_duration": 3753500, "prompt_eval_count": 122, "prompt_eval_duration": 328493000, "eval_count": 33, "eval_duration": 552222000 } ``` However, I would like the response to be compatible with the OpenAI format, which includes an `id` and `type` field for each tool call. The desired format is as follows: ```json { "model": "llama3.1", "created_at": "2024-07-22T20:33:28.123648Z", "message": { "role": "assistant", "content": "", "tool_calls": [ { "id": "call_62136354", "type": "function", "function": { "name": "get_current_weather", "arguments": { "format": "celsius", "location": "Paris, FR" } } } ] }, "done_reason": "stop", "done": true, "total_duration": 885095291, "load_duration": 3753500, "prompt_eval_count": 122, "prompt_eval_duration": 328493000, "eval_count": 33, "eval_duration": 552222000 } ``` Additionally, the lack of an `id` field in the current format prevents a software from responding to multiple simultaneous calls to a tool. ### Steps to Reproduce 1. Make a tool call request. 2. Observe the response format. ### Expected Behavior The response should include an `id` and `type` field for each tool call, making it compatible with the OpenAI format. ### Actual Behavior The response does not include an `id` and `type` field for each tool call. ### Additional Information This change is necessary to ensure compatibility with the OpenAI API and to handle multiple simultaneous tool calls effectively. ### Labels - enhancement - compatibility - api
GiteaMirror added the feature request label 2026-05-03 23:58:40 -05:00
Author
Owner

@rick-github commented on GitHub (Aug 22, 2024):

If you use the openai compatibility endpoint (/v1/chat/completions), you get a response with id and type fields. Don't know how compatible the rest of the structure is, eg the arguments are a string rather than a dict.

{
  "id": "chatcmpl-625",
  "object": "chat.completion",
  "created": 1724330640,
  "model": "llama3.1",
  "system_fingerprint": "fp_ollama",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "",
        "tool_calls": [
          {
            "id": "call_5dytv9km",
            "type": "function",
            "function": {
              "name": "get_current_weather",
              "arguments": "{\"format\":\"celsius\",\"location\":\"Paris\"}"
            }
          }
        ]
      },
      "finish_reason": "tool_calls"
    }
  ],
  "usage": {
    "prompt_tokens": 204,
    "completion_tokens": 25,
    "total_tokens": 229
  }
}
<!-- gh-comment-id:2304598853 --> @rick-github commented on GitHub (Aug 22, 2024): If you use the openai compatibility endpoint (`/v1/chat/completions`), you get a response with `id` and `type` fields. Don't know how compatible the rest of the structure is, eg the `arguments` are a string rather than a dict. ```json { "id": "chatcmpl-625", "object": "chat.completion", "created": 1724330640, "model": "llama3.1", "system_fingerprint": "fp_ollama", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "", "tool_calls": [ { "id": "call_5dytv9km", "type": "function", "function": { "name": "get_current_weather", "arguments": "{\"format\":\"celsius\",\"location\":\"Paris\"}" } } ] }, "finish_reason": "tool_calls" } ], "usage": { "prompt_tokens": 204, "completion_tokens": 25, "total_tokens": 229 } } ```
Author
Owner

@eliasfroehner commented on GitHub (Aug 22, 2024):

@rick-github Thank you very much for pointing out.

<!-- gh-comment-id:2304757159 --> @eliasfroehner commented on GitHub (Aug 22, 2024): @rick-github Thank you very much for pointing out.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#66102