[PR #3303] [CLOSED] Add OpenAI Function Calling #36985

Closed
opened 2026-04-22 21:38:45 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/3303
Author: @adrienbrault
Created: 3/22/2024
Status: Closed

Base: mainHead: openai-function-calling


📝 Commits (1)

  • 58db5aa Add OpenAI Function Calling

📊 Changes

2 files changed (+169 additions, -15 deletions)

View changed files

📝 docs/openai.md (+1 -1)
📝 openai/openai.go (+168 -14)

📄 Description

See https://platform.openai.com/docs/guides/function-calling

Using https://huggingface.co/NousResearch/Hermes-2-Pro-Mistral-7B-GGUF

This is a proof of concept! I am thinking that all the Hermes2Pro specifics should be modeled somehow in the Modelfile.

Script to compare `gpt-3.5-turbo-0125` with this branch using `adrienbrault/nous-hermes2pro:Q4_K_M`
export OPENAI_FUNCTION_CALLING_REQUEST='{
  "model": "${MODEL}",
  "messages": [
    {
      "role": "user",
      "content": "What is the weather like in Seattle today?"
    }
  ],
  "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"]
        }
      }
    }
  ]
}'

export MODEL_OLLAMA="adrienbrault/nous-hermes2pro:Q4_K_M"
export MODEL_OPENAI="gpt-3.5-turbo-0125"
export OLLAMA_HOST=127.0.0.1:11435

go build . && ./ollama serve

curl "${OLLAMA_HOST}/v1/chat/completions" \
  -H "Content-Type: application/json" \
  -d "$(echo "${OPENAI_FUNCTION_CALLING_REQUEST}" | MODEL="${MODEL_OLLAMA}" envsubst '${MODEL}')" -s \
  | jq . \
  | tee ollama.json

curl "https://api.openai.com/v1/chat/completions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${OPENAI_API_KEY}" \
  -d "$(echo "${OPENAI_FUNCTION_CALLING_REQUEST}" | MODEL="${MODEL_OPENAI}" envsubst '${MODEL}')" -s \
  | jq . \
  | tee openai.json

git diff --no-index openai.json ollama.json
diff --git a/openai.json b/ollama.json
index 59d4977..faaa2d6 100644
--- a/openai.json
+++ b/ollama.json
@@ -1,33 +1,32 @@
 {
-  "id": "chatcmpl-95hyRBATFpkeeajKuAc1D4y8gw29w",
+  "id": "chatcmpl-395",
   "object": "chat.completion",
-  "created": 1711147703,
-  "model": "gpt-3.5-turbo-0125",
+  "created": 1711149126,
+  "model": "adrienbrault/nous-hermes2pro:Q4_K_M",
+  "system_fingerprint": "fp_ollama",
   "choices": [
     {
       "index": 0,
       "message": {
         "role": "assistant",
-        "content": null,
+        "content": "",
         "tool_calls": [
           {
-            "id": "call_DBgXGrqufbzrp7rDN0VspAdw",
+            "id": "call_YxkK26AReyBuOGUJiQbLNGHq",
             "type": "function",
             "function": {
               "name": "get_current_weather",
-              "arguments": "{\"location\":\"Seattle\",\"format\":\"celsius\"}"
+              "arguments": "{\"format\":\"celsius\",\"location\":\"Seattle, WA\"}"
             }
           }
         ]
       },
-      "logprobs": null,
       "finish_reason": "tool_calls"
     }
   ],
   "usage": {
-    "prompt_tokens": 93,
-    "completion_tokens": 20,
-    "total_tokens": 113
-  },
-  "system_fingerprint": "fp_3bc1b5746c"
+    "prompt_tokens": 349,
+    "completion_tokens": 45,
+    "total_tokens": 394
+  }
 }

🔄 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/3303 **Author:** [@adrienbrault](https://github.com/adrienbrault) **Created:** 3/22/2024 **Status:** ❌ Closed **Base:** `main` ← **Head:** `openai-function-calling` --- ### 📝 Commits (1) - [`58db5aa`](https://github.com/ollama/ollama/commit/58db5aae628662cea6e0244057a55f8b26e182f7) Add OpenAI Function Calling ### 📊 Changes **2 files changed** (+169 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `docs/openai.md` (+1 -1) 📝 `openai/openai.go` (+168 -14) </details> ### 📄 Description See https://platform.openai.com/docs/guides/function-calling Using https://huggingface.co/NousResearch/Hermes-2-Pro-Mistral-7B-GGUF This is a proof of concept! I am thinking that all the Hermes2Pro specifics should be modeled somehow in the Modelfile. <details> <summary>Script to compare `gpt-3.5-turbo-0125` with this branch using `adrienbrault/nous-hermes2pro:Q4_K_M`</summary> ```bash export OPENAI_FUNCTION_CALLING_REQUEST='{ "model": "${MODEL}", "messages": [ { "role": "user", "content": "What is the weather like in Seattle today?" } ], "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"] } } } ] }' export MODEL_OLLAMA="adrienbrault/nous-hermes2pro:Q4_K_M" export MODEL_OPENAI="gpt-3.5-turbo-0125" export OLLAMA_HOST=127.0.0.1:11435 go build . && ./ollama serve curl "${OLLAMA_HOST}/v1/chat/completions" \ -H "Content-Type: application/json" \ -d "$(echo "${OPENAI_FUNCTION_CALLING_REQUEST}" | MODEL="${MODEL_OLLAMA}" envsubst '${MODEL}')" -s \ | jq . \ | tee ollama.json curl "https://api.openai.com/v1/chat/completions" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer ${OPENAI_API_KEY}" \ -d "$(echo "${OPENAI_FUNCTION_CALLING_REQUEST}" | MODEL="${MODEL_OPENAI}" envsubst '${MODEL}')" -s \ | jq . \ | tee openai.json git diff --no-index openai.json ollama.json ``` </details> ```diff diff --git a/openai.json b/ollama.json index 59d4977..faaa2d6 100644 --- a/openai.json +++ b/ollama.json @@ -1,33 +1,32 @@ { - "id": "chatcmpl-95hyRBATFpkeeajKuAc1D4y8gw29w", + "id": "chatcmpl-395", "object": "chat.completion", - "created": 1711147703, - "model": "gpt-3.5-turbo-0125", + "created": 1711149126, + "model": "adrienbrault/nous-hermes2pro:Q4_K_M", + "system_fingerprint": "fp_ollama", "choices": [ { "index": 0, "message": { "role": "assistant", - "content": null, + "content": "", "tool_calls": [ { - "id": "call_DBgXGrqufbzrp7rDN0VspAdw", + "id": "call_YxkK26AReyBuOGUJiQbLNGHq", "type": "function", "function": { "name": "get_current_weather", - "arguments": "{\"location\":\"Seattle\",\"format\":\"celsius\"}" + "arguments": "{\"format\":\"celsius\",\"location\":\"Seattle, WA\"}" } } ] }, - "logprobs": null, "finish_reason": "tool_calls" } ], "usage": { - "prompt_tokens": 93, - "completion_tokens": 20, - "total_tokens": 113 - }, - "system_fingerprint": "fp_3bc1b5746c" + "prompt_tokens": 349, + "completion_tokens": 45, + "total_tokens": 394 + } } ``` --- <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-22 21:38:45 -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#36985