feat: add Ollama as an LLM provider (Ollama Cloud, default gpt-oss:120b-cloud)#37
Merged
Merged
Conversation
Member
|
hey @omjeem where you able to run a town with the npc and having a chat? |
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



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.tsusing@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, withOLLAMA_BASE_URLavailable 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-compatibleis intentionally pinned to 2.0.57. Version 3.x targets provider spec v4, whileai@6.0.205still uses v3, which causes type-check failures.supportsStructuredOutputs: trueis required. Without it, the SDK omits the JSON schema, causinggpt-ossto return invalid JSON for the moderator'sgenerateObject. Enabling it correctly sends the schema asresponse_format.The default model is
gpt-oss:120b-cloud, which works with both Ollama Cloud and local Ollama. This can be overridden usingOLLAMA_MODEL.Verification
Tested against Ollama Cloud:
test-moderator.ts)Out of Scope
lib/llm/router.ts(currently unused) andopenai-image.ts(OpenAI-specific) were intentionally left unchanged.