Skip to content

feat: add Ollama as an LLM provider (Ollama Cloud, default gpt-oss:120b-cloud)#37

Merged
harshithmullapudi merged 4 commits into
RedPlanetHQ:mainfrom
omjeem:feat/ollama-provider
Jul 9, 2026
Merged

feat: add Ollama as an LLM provider (Ollama Cloud, default gpt-oss:120b-cloud)#37
harshithmullapudi merged 4 commits into
RedPlanetHQ:mainfrom
omjeem:feat/ollama-provider

Conversation

@omjeem

@omjeem omjeem commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds Ollama as a third LLM provider alongside Anthropic and OpenAI, using Ollama Cloud's OpenAI-compatible endpoint. The goal is to make it easier to run Town with a free or lower-cost model, without requiring an Anthropic or OpenAI API key.

Changes

  • Added apps/web/src/lib/ollama.ts using @ai-sdk/openai-compatible, so it integrates with the existing AI SDK call sites without requiring call-site changes.

  • Added support for:

    • LLM_PROVIDER=ollama (chat)
    • CREATOR_PROVIDER=ollama (creator)
  • Defaults to https://ollama.com/v1, with OLLAMA_BASE_URL available for local Ollama instances.

  • Added the required configuration to .env.example.

  • Existing deployments are unaffected—the provider priority remains anthropic → openai → ollama, so adding an Ollama configuration won't change existing behavior.

Notes for Review

  • @ai-sdk/openai-compatible is intentionally pinned to 2.0.57. Version 3.x targets provider spec v4, while ai@6.0.205 still uses v3, which causes type-check failures.
  • supportsStructuredOutputs: true is required. Without it, the SDK omits the JSON schema, causing gpt-oss to return invalid JSON for the moderator's generateObject. Enabling it correctly sends the schema as response_format.

The default model is gpt-oss:120b-cloud, which works with both Ollama Cloud and local Ollama. This can be overridden using OLLAMA_MODEL.

Verification

Tested against Ollama Cloud:

  • ✅ Typecheck passes
  • ✅ Build passes
  • ✅ Structured outputs (test-moderator.ts)
  • ✅ Tool calling
  • ✅ Streaming
  • ✅ Verified no regression with the default Anthropic flow

Out of Scope

lib/llm/router.ts (currently unused) and openai-image.ts (OpenAI-specific) were intentionally left unchanged.

@harshithmullapudi

Copy link
Copy Markdown
Member

hey @omjeem where you able to run a town with the npc and having a chat?

@omjeem

omjeem commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Yep! Ran a town locally with LLM_PROVIDER=ollama on gpt-oss:120b-cloud and had real NPC conversations end-to-end.

NPC chat (Founder) - streaming, in-context replies
Screenshot 2026-07-08 at 9 10 27 PM

Creator/town-building chat - works
Screenshot 2026-07-08 at 9 09 57 PM

Moderator routing (generateObject structured output) - smoke test passes all cases
Screenshot 2026-07-08 at 9 06 03 PM

All three call shapes (streaming, structured output, tool calling) verified against Ollama Cloud.

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.

2 participants