[PR #952] [MERGED] support raw generation requests #10401

Closed
opened 2026-04-12 22:59:48 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/952
Author: @BruceMacD
Created: 10/30/2023
Status: Merged
Merged: 11/8/2023
Merged by: @BruceMacD

Base: mainHead: brucemacd/raw-generate


📝 Commits (3)

  • 9814503 support raw generation requests
  • d1b6f74 Add raw request to docs
  • 4e330a7 remove duplicate generate req validation

📊 Changes

3 files changed (+50 additions, -5 deletions)

View changed files

📝 api/types.go (+1 -0)
📝 docs/api.md (+31 -0)
📝 server/routes.go (+18 -5)

📄 Description

  • add the optional raw generate request parameter to bypass prompt formatting and response context

Add a raw parameter to /generate requests that allow directly specifying the prompt without the Ollama server applying additional formatting.

curl -X "POST" -d '{"model":"mistral", "prompt": "[INST] hi [/INST]", "raw": true, "stream": false}' 'http://127.0.0.1:11434/api/generate'

Example use case, few-shot prompting:

import requests

def call_generate_endpoint(prompt, model="mistral", raw=True, stream=False):
    url = "http://127.0.0.1:11434/api/generate"
    formatted_prompt = f"""[INST] This is awesome! [/INST]
Postive
[INST] This is bad! [/INST]
Negative
[INST] I love this movie [/INST]
Positive
[INST] {prompt} [/INST]
"""
    
    payload = {
        "model": model,
        "prompt": formatted_prompt,
        "raw": raw,
        "stream": stream
    }
    
    response = requests.post(url, json=payload)
    
    return response.json()

resp = call_generate_endpoint("I hate this book")
print(resp.response) # Negative

🔄 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/952 **Author:** [@BruceMacD](https://github.com/BruceMacD) **Created:** 10/30/2023 **Status:** ✅ Merged **Merged:** 11/8/2023 **Merged by:** [@BruceMacD](https://github.com/BruceMacD) **Base:** `main` ← **Head:** `brucemacd/raw-generate` --- ### 📝 Commits (3) - [`9814503`](https://github.com/ollama/ollama/commit/981450385ee873c03d343a2cd2f4e53aeb8fbed1) support raw generation requests - [`d1b6f74`](https://github.com/ollama/ollama/commit/d1b6f74339237d2e6c514e30eb214d5f7980158c) Add raw request to docs - [`4e330a7`](https://github.com/ollama/ollama/commit/4e330a7ed49ba87e1f5e115db3d5a7b2bf093043) remove duplicate generate req validation ### 📊 Changes **3 files changed** (+50 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `api/types.go` (+1 -0) 📝 `docs/api.md` (+31 -0) 📝 `server/routes.go` (+18 -5) </details> ### 📄 Description - add the optional `raw` generate request parameter to bypass prompt formatting and response context Add a `raw` parameter to `/generate` requests that allow directly specifying the prompt without the Ollama server applying additional formatting. ```bash curl -X "POST" -d '{"model":"mistral", "prompt": "[INST] hi [/INST]", "raw": true, "stream": false}' 'http://127.0.0.1:11434/api/generate' ``` Example use case, few-shot prompting: ```python import requests def call_generate_endpoint(prompt, model="mistral", raw=True, stream=False): url = "http://127.0.0.1:11434/api/generate" formatted_prompt = f"""[INST] This is awesome! [/INST] Postive [INST] This is bad! [/INST] Negative [INST] I love this movie [/INST] Positive [INST] {prompt} [/INST] """ payload = { "model": model, "prompt": formatted_prompt, "raw": raw, "stream": stream } response = requests.post(url, json=payload) return response.json() resp = call_generate_endpoint("I hate this book") print(resp.response) # Negative ``` --- <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 22:59:48 -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#10401