[PR #5614] [MERGED] OpenAI: Support Tools #11851

Closed
opened 2026-04-12 23:40:37 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/5614
Author: @royjhan
Created: 7/10/2024
Status: Merged
Merged: 7/17/2024
Merged by: @royjhan

Base: mainHead: royh-openai-tools


📝 Commits (7)

📊 Changes

1 file changed (+53 additions, -4 deletions)

View changed files

📝 openai/openai.go (+53 -4)

📄 Description

curl -s 127.0.0.1:11434/v1/chat/completions -d '{
  "model": "mike/mistral",
  "messages": [
    {
      "role": "user",
      "content": "What'\''s the weather like today in Paris?"
    },
    {
      "role": "assistant",
      "tool_calls": [
        {
          "id": "89a1e453-0bce-4de3-a456-c54bed09c520",
          "type": "function",
          "function": {
            "name": "get_current_weather",
            "arguments": "{\"location\": \"Paris, France\", \"format\": \"celsius\"}"
          }
        }
      ]
    },
    {
      "role": "tool",
      "tool_call_id": "89a1e453-0bce-4de3-a456-c54bed09c520",
      "content": "22"
    },
    {
      "role": "assistant",
      "content": "The weather in Paris is 22 degrees celsius."
    },
    {
      "role": "user",
      "content": "What'\''s the weather like today in San Francisco and Toronto?"
    }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_current_weather",
        "description": "Get the current weather",
        "parameters": {
          "type": "object",
          "properties": {
            "location": {
              "type": "string",
              "description": "The city and state, e.g. San Francisco, CA"
            },
            "format": {
              "type": "string",
              "enum": [
                "celsius",
                "fahrenheit"
              ],
              "description": "The temperature unit to use. Infer this from the users location."
            }
          },
          "required": [
            "location",
            "format"
          ]
        }
      }
    }
  ],
  "stream": false,
  "temperature": 0
}' | jq
{
  "id": "chatcmpl-920",
  "object": "chat.completion",
  "created": 1721187203,
  "model": "mike/mistral",
  "system_fingerprint": "fp_ollama",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "",
        "tool_calls": [
          {
            "id": "call_q9jtgbw2",
            "type": "function",
            "function": {
              "name": "get_current_weather",
              "arguments": "{\"format\":\"celsius\",\"location\":\"San Francisco, CA\"}"
            }
          },
          {
            "id": "call_9chg85cd",
            "type": "function",
            "function": {
              "name": "get_current_weather",
              "arguments": "{\"format\":\"celsius\",\"location\":\"Toronto, Canada\"}"
            }
          }
        ]
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 198,
    "completion_tokens": 65,
    "total_tokens": 263
  }
}

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/5614 **Author:** [@royjhan](https://github.com/royjhan) **Created:** 7/10/2024 **Status:** ✅ Merged **Merged:** 7/17/2024 **Merged by:** [@royjhan](https://github.com/royjhan) **Base:** `main` ← **Head:** `royh-openai-tools` --- ### 📝 Commits (7) - [`761b5b6`](https://github.com/ollama/ollama/commit/761b5b683e052490dd42358c1c731059427565a8) reopen pr - [`a1e0415`](https://github.com/ollama/ollama/commit/a1e04153183fea2f936813dba0943547f19d1e42) tools - [`30707e3`](https://github.com/ollama/ollama/commit/30707e3c29f4800a51384ba47de4c89f38851064) remove tc from stream for now - [`e9aaf84`](https://github.com/ollama/ollama/commit/e9aaf842e1167427be6190df98fa676847d1fb46) ID and Function - [`9873fd5`](https://github.com/ollama/ollama/commit/9873fd5719a5c3394e7091bfda032c19182d372a) openai expects arguments to be a string (#5739) - [`dd319d5`](https://github.com/ollama/ollama/commit/dd319d5d613d992ecb2d55d7e9db4abbf5e5d717) mutually exclusive content and tool calls - [`61bb456`](https://github.com/ollama/ollama/commit/61bb45659c2788732b0318793b393cc56b139de3) clean up ### 📊 Changes **1 file changed** (+53 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `openai/openai.go` (+53 -4) </details> ### 📄 Description ``` curl -s 127.0.0.1:11434/v1/chat/completions -d '{ "model": "mike/mistral", "messages": [ { "role": "user", "content": "What'\''s the weather like today in Paris?" }, { "role": "assistant", "tool_calls": [ { "id": "89a1e453-0bce-4de3-a456-c54bed09c520", "type": "function", "function": { "name": "get_current_weather", "arguments": "{\"location\": \"Paris, France\", \"format\": \"celsius\"}" } } ] }, { "role": "tool", "tool_call_id": "89a1e453-0bce-4de3-a456-c54bed09c520", "content": "22" }, { "role": "assistant", "content": "The weather in Paris is 22 degrees celsius." }, { "role": "user", "content": "What'\''s the weather like today in San Francisco and Toronto?" } ], "tools": [ { "type": "function", "function": { "name": "get_current_weather", "description": "Get the current weather", "parameters": { "type": "object", "properties": { "location": { "type": "string", "description": "The city and state, e.g. San Francisco, CA" }, "format": { "type": "string", "enum": [ "celsius", "fahrenheit" ], "description": "The temperature unit to use. Infer this from the users location." } }, "required": [ "location", "format" ] } } } ], "stream": false, "temperature": 0 }' | jq ``` ``` { "id": "chatcmpl-920", "object": "chat.completion", "created": 1721187203, "model": "mike/mistral", "system_fingerprint": "fp_ollama", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "", "tool_calls": [ { "id": "call_q9jtgbw2", "type": "function", "function": { "name": "get_current_weather", "arguments": "{\"format\":\"celsius\",\"location\":\"San Francisco, CA\"}" } }, { "id": "call_9chg85cd", "type": "function", "function": { "name": "get_current_weather", "arguments": "{\"format\":\"celsius\",\"location\":\"Toronto, Canada\"}" } } ] }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 198, "completion_tokens": 65, "total_tokens": 263 } } ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-12 23:40:37 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#11851