[PR #6948] Fix Ollama silently failing on extra, unsupported openai parameters. #43518

Open
opened 2026-04-24 23:07:56 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/6948
Author: @MadcowD
Created: 9/25/2024
Status: 🔄 Open

Base: mainHead: patch-1


📝 Commits (3)

  • ae03496 Update openai.go
  • 85f6358 Update openai.go
  • bc0a60f Adding testsa nd more descriptive erorr messages for validation

📊 Changes

2 files changed (+135 additions, -7 deletions)

View changed files

📝 openai/openai.go (+36 -4)
📝 openai/openai_test.go (+99 -3)

📄 Description

Currently Ollama will just let you send unsupported api params to the openai compatible endpoint and just silently fail. This wreaks havoc on downstream uses causing unexpected behaviour.

# Retrieve the API key and ensure it's set
ollama_api_key = os.getenv("OLLAMA_API_KEY")
if not ollama_api_key:
    raise ValueError("API key not found. Please ensure that the OLLAMA_API_KEY is set in your .env.local file.")

# Initialize the OpenAI client
ollama_client = OpenAI(
    base_url="http://localhost:11434/v1",
    api_key=ollama_api_key,
)
model = "llama3.1:latest"


# Construct the completion request with n=2
response = openai.Completion.create(
    model=model,
    prompt="Once upon a time",
    max_tokens=50,
    n=2,  # Requesting two completions
    temperature=0.7
)

print(f"Number of completions requested: 2")
print(f"Number of completions received: {len(response.choices)}\n")
assert len(response.choices) == 2, "Shouldn't ever get here"

# Iterate and print each completion
for idx, choice in enumerate(response.choices, 1):
    print(f"Completion {idx}: {choice.text.strip()}")

This leads to

umber of completions requested: 2
Number of completions received: 1

Completion 1: Once upon a time, in a land where the sun always shone brightly, there lived a young adventurer eager to explore uncharted territories and uncover hidden treasures.

My change would cause the API to error because that parameter is just plainly not supported by ollama


🔄 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/6948 **Author:** [@MadcowD](https://github.com/MadcowD) **Created:** 9/25/2024 **Status:** 🔄 Open **Base:** `main` ← **Head:** `patch-1` --- ### 📝 Commits (3) - [`ae03496`](https://github.com/ollama/ollama/commit/ae03496a488a15c199c25c349020298efdf5adc7) Update openai.go - [`85f6358`](https://github.com/ollama/ollama/commit/85f635877de38a83e89e0dae183b8a6bb559d8a4) Update openai.go - [`bc0a60f`](https://github.com/ollama/ollama/commit/bc0a60f617be02e8bfe45d6ed5bf254aa7f74fee) Adding testsa nd more descriptive erorr messages for validation ### 📊 Changes **2 files changed** (+135 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `openai/openai.go` (+36 -4) 📝 `openai/openai_test.go` (+99 -3) </details> ### 📄 Description Currently Ollama will just let you send unsupported api params to the openai compatible endpoint and just silently fail. This wreaks havoc on downstream uses causing unexpected behaviour. ```python # Retrieve the API key and ensure it's set ollama_api_key = os.getenv("OLLAMA_API_KEY") if not ollama_api_key: raise ValueError("API key not found. Please ensure that the OLLAMA_API_KEY is set in your .env.local file.") # Initialize the OpenAI client ollama_client = OpenAI( base_url="http://localhost:11434/v1", api_key=ollama_api_key, ) model = "llama3.1:latest" # Construct the completion request with n=2 response = openai.Completion.create( model=model, prompt="Once upon a time", max_tokens=50, n=2, # Requesting two completions temperature=0.7 ) print(f"Number of completions requested: 2") print(f"Number of completions received: {len(response.choices)}\n") assert len(response.choices) == 2, "Shouldn't ever get here" # Iterate and print each completion for idx, choice in enumerate(response.choices, 1): print(f"Completion {idx}: {choice.text.strip()}") ``` This leads to ``` umber of completions requested: 2 Number of completions received: 1 Completion 1: Once upon a time, in a land where the sun always shone brightly, there lived a young adventurer eager to explore uncharted territories and uncover hidden treasures. ``` My change would cause the API to error because that parameter is just plainly not supported by ollama --- <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-24 23:07:57 -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#43518