[PR #6658] [CLOSED] openai: support for structured outputs #17457

Closed
opened 2026-04-16 06:03:05 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/6658
Author: @iscy
Created: 9/5/2024
Status: Closed

Base: mainHead: support-json-schema


📝 Commits (1)

  • a7c7610 openai: support for structured outputs

📊 Changes

8 files changed (+94 additions, -24 deletions)

View changed files

📝 api/types.go (+27 -0)
📝 go.mod (+4 -0)
📝 go.sum (+9 -0)
📝 llm/ext_server/server.cpp (+21 -4)
📝 llm/ext_server/utils.hpp (+1 -1)
📝 llm/server.go (+12 -7)
📝 openai/openai.go (+15 -8)
📝 server/routes.go (+5 -4)

📄 Description

This PR is enabling the Structured Outputs feature available on OpenAI.

Using the math reasoning example they have on their website, here's the response of both OpenAI and Ollama using the exact same request:

OpenAI (gpt-4o-2024-08-06)

{
  "steps": [
    {
      "explanation": "We start with the equation 8x + 7 = -23. Our goal is to isolate x on one side of the equation.",
      "output": "8x + 7 = -23"
    },
    {
      "explanation": "Subtract 7 from both sides to begin isolating the term with x. This will help us get rid of the constant term on the left side.",
      "output": "8x + 7 - 7 = -23 - 7"
    },
    {
      "explanation": "Simplify both sides of the equation. On the left side, 7 - 7 cancels out, leaving us with 8x. On the right side, -23 - 7 equals -30.",
      "output": "8x = -30"
    },
    {
      "explanation": "Now, divide both sides by 8 to solve for x. This will isolate x completely.",
      "output": "8x / 8 = -30 / 8"
    },
    {
      "explanation": "Simplify the right side of the equation. -30 divided by 8 simplifies to -3.75.",
      "output": "x = -3.75"
    }
  ],
  "final_answer": "x = -3.75"
}

Ollama (llama3.1:8b)

{
  "steps": [
    {
      "explanation": "The first step is to isolate the term with the variable (in this case, x) on one side of the equation.",
      "output": "Subtract 7 from both sides: 8x + 7 - 7 = -23 - 7"
    },
    {
      "explanation": "This simplifies to:",
      "output": "8x = -30"
    },
    {
      "explanation": "The next step is to get rid of the coefficient (the number being multiplied by x).",
      "output": "Divide both sides by 8: 8x / 8 = -30 / 8"
    },
    {
      "explanation": "This simplifies to:",
      "output": "x = -3.75"
    }
  ],
  "final_answer": "-3.75"
}

🔄 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/6658 **Author:** [@iscy](https://github.com/iscy) **Created:** 9/5/2024 **Status:** ❌ Closed **Base:** `main` ← **Head:** `support-json-schema` --- ### 📝 Commits (1) - [`a7c7610`](https://github.com/ollama/ollama/commit/a7c7610c6262e27c971cd2d05975c0edb7e0e283) openai: support for structured outputs ### 📊 Changes **8 files changed** (+94 additions, -24 deletions) <details> <summary>View changed files</summary> 📝 `api/types.go` (+27 -0) 📝 `go.mod` (+4 -0) 📝 `go.sum` (+9 -0) 📝 `llm/ext_server/server.cpp` (+21 -4) 📝 `llm/ext_server/utils.hpp` (+1 -1) 📝 `llm/server.go` (+12 -7) 📝 `openai/openai.go` (+15 -8) 📝 `server/routes.go` (+5 -4) </details> ### 📄 Description This PR is enabling the [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs/supported-schemas) feature available on OpenAI. Using the math reasoning example they have on their website, here's the response of both OpenAI and Ollama using the exact same request: OpenAI (gpt-4o-2024-08-06) ``` { "steps": [ { "explanation": "We start with the equation 8x + 7 = -23. Our goal is to isolate x on one side of the equation.", "output": "8x + 7 = -23" }, { "explanation": "Subtract 7 from both sides to begin isolating the term with x. This will help us get rid of the constant term on the left side.", "output": "8x + 7 - 7 = -23 - 7" }, { "explanation": "Simplify both sides of the equation. On the left side, 7 - 7 cancels out, leaving us with 8x. On the right side, -23 - 7 equals -30.", "output": "8x = -30" }, { "explanation": "Now, divide both sides by 8 to solve for x. This will isolate x completely.", "output": "8x / 8 = -30 / 8" }, { "explanation": "Simplify the right side of the equation. -30 divided by 8 simplifies to -3.75.", "output": "x = -3.75" } ], "final_answer": "x = -3.75" } ``` Ollama (llama3.1:8b) ``` { "steps": [ { "explanation": "The first step is to isolate the term with the variable (in this case, x) on one side of the equation.", "output": "Subtract 7 from both sides: 8x + 7 - 7 = -23 - 7" }, { "explanation": "This simplifies to:", "output": "8x = -30" }, { "explanation": "The next step is to get rid of the coefficient (the number being multiplied by x).", "output": "Divide both sides by 8: 8x / 8 = -30 / 8" }, { "explanation": "This simplifies to:", "output": "x = -3.75" } ], "final_answer": "-3.75" } ``` --- <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-16 06:03:05 -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#17457