Skip to content

feat(llm): add built-in Ollama Cloud provider preset - #310

Closed
chethanuk wants to merge 2 commits into
alibaba:mainfrom
chethanuk:fix/issue-305-ollama-cloud-provider
Closed

chethanuk wants to merge 2 commits into
alibaba:mainfrom
chethanuk:fix/issue-305-ollama-cloud-provider

Conversation

@chethanuk

Copy link
Copy Markdown
Contributor

Description

Adds a built-in ollama-cloud provider preset to the registry in internal/llm/providers.go, so Ollama Cloud can be selected directly instead of hand-configured as a custom provider.

The preset uses the OpenAI-compatible protocol against https://ollama.com/v1, reading the API key from OLLAMA_API_KEY (sent as Authorization: Bearer <key>, the shared default for OpenAI-protocol entries — no per-provider AuthHeader). It ships two models, gpt-oss:120b and gpt-oss:20b. The base URL, env var, and model naming match Ollama Cloud's documented OpenAI-compatible endpoint.

Opened against my own fork first as a staging/review step.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • CI / Build / Tooling

How Has This Been Tested?

gofmt -l reports no diffs, go vet ./internal/llm/ is clean, and go test ./internal/llm/ passes (176 tests). Coverage includes the existing TestListProviders_Order (updated for the new sorted position) and a new TestLookupProvider_OllamaCloudDetails that pins Protocol, BaseURL, EnvVar, empty AuthHeader, and each model name individually.

Whether Ollama Cloud's OpenAI endpoint reliably supports the tool-calls flow that ocr review needs is a runtime/e2e concern, out of scope for this preset addition.

  • make test passes locally
  • Manual testing (describe below)

Checklist

  • My code follows the project's coding style (go fmt, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (if applicable)
  • I have signed the CLA

Related Issues

Closes #305

Add an ollama-cloud entry to the provider registry: OpenAI protocol,
base URL https://ollama.com/v1, env OLLAMA_API_KEY, models gpt-oss:120b
and gpt-oss:20b. Values match Ollama Cloud's OpenAI-compatible endpoint.
Tests cover provider order/count and per-field lookup details.

Closes alibaba#305
@CLAassistant

CLAassistant commented Jul 6, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 OpenCodeReview found 1 issue(s) in this PR.

  • ✅ 1 posted as inline comment(s)
  • 📝 0 posted as summary

Comment thread internal/llm/providers.go Outdated
Comment on lines +232 to +237
BaseURL: "https://ollama.com/v1",
EnvVar: "OLLAMA_API_KEY",
Models: []string{
"gpt-oss:120b",
"gpt-oss:20b",
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential issue: The BaseURL https://ollama.com/v1 does not appear to be a documented or verified Ollama Cloud API endpoint. Ollama is primarily known as a local LLM runtime (default http://localhost:11434), and there is no well-known public cloud API at this URL. Similarly, the model names gpt-oss:120b and gpt-oss:20b do not correspond to any known publicly available models.

Please verify:

  1. Is this BaseURL correct and currently active?
  2. Are these model names accurate for this provider?

If this is a placeholder or speculative entry, consider adding a comment or marking it accordingly to avoid confusion.

@lizhengfeng101

Copy link
Copy Markdown
Contributor

Thanks for the contribution! A few concerns before we can move forward:

1. Endpoint & model verification

While issue #305 references Ollama Cloud docs, we'd like confirmation that https://ollama.com/v1 is currently active and accepting requests with the listed models (gpt-oss:120b, gpt-oss:20b). Could you share:

  • A successful ocr llm test output against this endpoint?
  • Or a simple curl/API call showing the endpoint responds correctly?

2. Tool-calling compatibility

OCR's review flow relies heavily on tools/tool_calls in the OpenAI-compatible protocol. Both #222 and #234 showed that Ollama models can fail silently on tool calls. Has this been tested end-to-end?

Ideally we'd like to see:

  • A minimal ocr review run that exercises the tool-calling path
  • Confirmation of which models actually support function calling on Ollama Cloud

3. Registry ordering

Minor nit: the new entry is appended at the end of the registry array, but the sorted test expectation suggests providers are alphabetically ordered at runtime. For source-level consistency, consider placing it between minimax and openai in the source file as well.


Summary: The code itself is clean and well-tested. The blocker is runtime verification — we'd appreciate a brief test report showing the endpoint works with OCR's tool-calling flow before merging. If tool-calling is not yet reliable, we should document that limitation in the provider entry or PR description.

…urce

Move the ollama-cloud provider block from the end of the registry slice to
immediately after minimax (before baidu-qianfan), per PR alibaba#310 review nit from
@lizhengfeng101. ListProviders() already sorts output, so this only affects
source layout, not runtime order; TestListProviders_Order stays green.

Kept Protocol: "openai" as a string literal to match every sibling entry in
the registry (minimax, baidu-qianfan, etc. all use the literal, not the
ProtocolOpenAIChatCompletions constant).
@chethanuk

Copy link
Copy Markdown
Contributor Author

Thanks for the review @lizhengfeng101 — all three points addressed. 🙏

1. Live endpoint verification (ocr llm test)

Configured the preset (ocr config set provider ollama-cloud) with OLLAMA_API_KEY in the environment and ran ocr llm test against https://ollama.com/v1 for both models:

$ ocr llm test          # model: gpt-oss:120b
Source: provider:ollama-cloud
URL:    https://ollama.com/v1
Model:  gpt-oss:120b
I'm open-code-review, an AI assistant that provides code reviews ...
✓ Connection test successful

$ ocr llm test          # model: gpt-oss:20b
Source: provider:ollama-cloud
URL:    https://ollama.com/v1
Model:  gpt-oss:20b
I am ChatGPT, a virtual assistant ...
✓ Connection test successful

Endpoint + auth + both models confirmed reachable. Also verified at the raw API level — GET /v1/models returns 200 and lists both gpt-oss:120b and gpt-oss:20b.

2. End-to-end tool-calling verification (ocr review)

Ran a real ocr review --format json over a small diff containing deliberate issues (hardcoded credential, unguarded division, ignored os.Open error / nil-file read). The code_comment tool round-trip is what matters here — both models drove it successfully:

Model status tool calls files comments elapsed
gpt-oss:120b success code_comment ×1, file_read ×1 2 5 16s
gpt-oss:20b success code_comment ×1, file_read ×2 2 3 36s

Sample comments emitted via the code_comment tool (gpt-oss:120b):

  • L6 — "Hardcoding the API token exposes sensitive credentials. Tokens should be injected via environment variables or a secure configuration store."
  • L8 — "riskyDivide performs division without checking for a zero divisor, which will panic at runtime. Add a guard or return an error."
  • L13 — "The error from os.Open is ignored, so a nil file handle can be used later and cause a runtime panic..."

Both models complete the full tool-calling loop (file_read → code_comment) and produce accurate, well-targeted review comments. gpt-oss:20b is slower (36s vs 16s) but functionally correct — no need to drop it.

Raw-API cross-check (one chat/completions call with a tools array) also returns a proper tool_calls response for both models.

3. Registry ordering nit

Done — moved the ollama-cloud block to sit immediately after minimax in the registry source (commit pushed to this branch). ListProviders() already sorts its output, so this is purely source layout; TestListProviders_Order stays green.

One note: I kept Protocol: "openai" as a string literal rather than switching to the ProtocolOpenAIChatCompletions constant — every sibling entry in the registry (minimax, baidu-qianfan, etc.) uses the string literal, so the literal is what keeps this block consistent with its neighbors. Happy to switch the whole registry to the constant in a separate cleanup PR if you'd prefer that direction.

$ go test ./internal/llm/ -run 'TestListProviders_Order|TestLookupProvider_OllamaCloudDetails' -v
PASS

(API key redacted throughout; it was only ever passed via env, never printed.)

@lizhengfeng101

Copy link
Copy Markdown
Contributor

Thanks for the detailed follow-up and verification, @chethanuk!

I want to let you know that #375 has since been submitted, which covers a broader set of models (all 18 currently available on Ollama Cloud's /v1/models endpoint) with full runtime verification for each. Additionally, this PR currently has merge conflicts that would need to be resolved.

Given the more comprehensive coverage in #375, I'd like to propose merging that one instead. To acknowledge your earlier work on this feature, I'll add you as a Co-Authored-By in the merge commit message.

Hope that works for you — and thanks again for pioneering this contribution!

@lizhengfeng101

Copy link
Copy Markdown
Contributor

This has been merged via #375 in commit 22b07fa, with you credited as a co-author. Thanks for your contribution!

Closing this PR now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add built-in Ollama Cloud provider preset

3 participants