[GH-ISSUE #6089] Match behavior of text-generation webui and koboldcpp by accepting requests to v1/completions that don't specify the model. #65843

Closed
opened 2026-05-03 22:52:08 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @balisujohn on GitHub (Jul 31, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/6089

This works:

url = "http://localhost:11434/v1/completions"

headers = {
    'Content-Type': 'application/json'
}

data = {
    'model':"moondream",
    'prompt': "What is the cat holding?",
    'max_tokens': 20,
    'temperature': 1,
    'top_p': 0.9,
    'seed': 10
}

# Convert data to JSON format
json_data = json.dumps(data).encode('utf-8')

# Create a request object with the URL, data, and headers
request = urllib.request.Request(url, data=json_data, headers=headers, method='POST')

While this results in a 400 error

import urllib.request
import urllib.parse
import json

url = "http://localhost:11434/v1/completions"

headers = {
    'Content-Type': 'application/json'
}

data = {
    'prompt': "What is the cat holding?",
    'max_tokens': 20,
    'temperature': 1,
    'top_p': 0.9,
    'seed': 10
}

# Convert data to JSON format
json_data = json.dumps(data).encode('utf-8')

# Create a request object with the URL, data, and headers
request = urllib.request.Request(url, data=json_data, headers=headers, method='POST')

# Send the request and read the response
with urllib.request.urlopen(request) as response:
    response_data = response.read()

# If needed, decode the response data
response = json.loads(response_data.decode('utf-8'))

new_text = response["choices"][0]["text"]

print(new_text)

If possible, I would like for the second case to work, defaulting to one of the models ollama is currently running (Doesn't matter which).

Originally created by @balisujohn on GitHub (Jul 31, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/6089 This works: ```` url = "http://localhost:11434/v1/completions" headers = { 'Content-Type': 'application/json' } data = { 'model':"moondream", 'prompt': "What is the cat holding?", 'max_tokens': 20, 'temperature': 1, 'top_p': 0.9, 'seed': 10 } # Convert data to JSON format json_data = json.dumps(data).encode('utf-8') # Create a request object with the URL, data, and headers request = urllib.request.Request(url, data=json_data, headers=headers, method='POST') ```` While this results in a 400 error ```` import urllib.request import urllib.parse import json url = "http://localhost:11434/v1/completions" headers = { 'Content-Type': 'application/json' } data = { 'prompt': "What is the cat holding?", 'max_tokens': 20, 'temperature': 1, 'top_p': 0.9, 'seed': 10 } # Convert data to JSON format json_data = json.dumps(data).encode('utf-8') # Create a request object with the URL, data, and headers request = urllib.request.Request(url, data=json_data, headers=headers, method='POST') # Send the request and read the response with urllib.request.urlopen(request) as response: response_data = response.read() # If needed, decode the response data response = json.loads(response_data.decode('utf-8')) new_text = response["choices"][0]["text"] print(new_text) ```` If possible, I would like for the second case to work, defaulting to one of the models ollama is currently running (Doesn't matter which).
GiteaMirror added the feature request label 2026-05-03 22:52:08 -05:00
Author
Owner

@thinkverse commented on GitHub (Jul 31, 2024):

The model is required as per OpenAI API and since this is Ollama's compatibility API it needs to follow OpenAI's API reference. https://platform.openai.com/docs/api-reference/completions/create#completions-create-model

<!-- gh-comment-id:2260912531 --> @thinkverse commented on GitHub (Jul 31, 2024): The `model` is required as per OpenAI API and since this is Ollama's compatibility API it needs to follow OpenAI's API reference. https://platform.openai.com/docs/api-reference/completions/create#completions-create-model
Author
Owner

@royjhan commented on GitHub (Jul 31, 2024):

Indeed, model is a required field as specified by OpenAI documentation

<!-- gh-comment-id:2261029770 --> @royjhan commented on GitHub (Jul 31, 2024): Indeed, `model` is a required field as specified by OpenAI documentation
Author
Owner

@balisujohn commented on GitHub (Jul 31, 2024):

Ah interesting so it's actually text generation webui and koboldcpp being overly permissive.

<!-- gh-comment-id:2261037821 --> @balisujohn commented on GitHub (Jul 31, 2024): Ah interesting so it's actually text generation webui and koboldcpp being overly permissive.
Author
Owner

@royjhan commented on GitHub (Jul 31, 2024):

Yeah, I took a quick look on what they're doing and I see your need, but in providing compatibility endpoints we are focused on aligning as much as possible. A default model would need to be configured on the client-side.

<!-- gh-comment-id:2261039577 --> @royjhan commented on GitHub (Jul 31, 2024): Yeah, I took a quick look on what they're doing and I see your need, but in providing compatibility endpoints we are focused on aligning as much as possible. A default model would need to be configured on the client-side.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#65843