Skip to content

[TEST] feature/ollama-llm-provider — add Ollama as a second LLM backend behind askLLM#37

Merged
nitesh32 merged 3 commits into
mainfrom
feat/ollama
May 13, 2026
Merged

[TEST] feature/ollama-llm-provider — add Ollama as a second LLM backend behind askLLM#37
nitesh32 merged 3 commits into
mainfrom
feat/ollama

Conversation

@Dead-Bytes
Copy link
Copy Markdown
Collaborator

What changed

  • Added a Config.LlmProvider switch (openrouter default | ollama) with three new config keys: llm_provider, ollama_url (default http://localhost:11434), ollama_model (free-form, no default — user picks any model they've pulled).
  • New CLI commands:
    • bytebell set llm-provider <openrouter|ollama>
    • bytebell set ollama-url <url>
    • bytebell set ollama-model <model>
  • Split @bb/llm by provider:
    • packages/llm/src/openrouter.ts — extracted the existing OpenRouter HTTP path verbatim (chain resolution + /api/v1/chat/completions call).
    • packages/llm/src/ollama.ts — new, POSTs to ${ollama_url}/api/chat with { model, messages, stream: false }, maps prompt_eval_count / eval_count to inputTokens / outputTokens.
    • packages/llm/src/client.ts — now a thin dispatcher (143 → 64 lines): resolve chain → cache check → call right provider → record decision. Public askLLM signature and return shape unchanged.
  • Cache key in packages/llm/src/cache.ts now includes provider, so the same prompt+model run through different backends caches separately.
  • estimateCostUsd in packages/llm/src/pricing.ts short-circuits to $0 when the current provider is Ollama. Historical OpenRouter rows still price correctly via OpenRouter's pricing map.
  • Docs updated in the same PR: packages/llm/context.md, packages/config/context.md, and CLAUDE.md (Rule of LLM Provider widens from "OpenRouter only" to "OpenRouter or local Ollama. No direct vendor SDKs.").

Why

Users running on bounded local hardware or working offline want to bypass OpenRouter and hit a local Ollama daemon. The previous "OpenRouter only" rule was a v0 simplification; lifting it to "OpenRouter or local Ollama" keeps the no-vendor-SDK invariant intact (we still only speak HTTP — no openai / anthropic packages) while removing the cloud dependency for users who already have models pulled locally.

Decisions captured in /Users/deadbytes/.claude/plans/currenbtly-our-askllm-only-toasty-starlight.md:

  • Provider switch is a single config key, not per-call — keeps askLLM callers (ingest-github/analyze.ts, ingest-github/bigFile.ts) untouched.
  • ollama_model is free-form on purpose — any locally-pulled model works (llama3.2:latest, qwen2.5-coder:7b, custom Modelfile names). We don't validate against an allowlist.
  • Cost is $0 keyed off current provider, not persisted per usage record — keeps the change small.

How to test

  1. OpenRouter path unchanged (regression check):

    • With default config, run bytebell index <small-repo>.
    • Confirm bytebell stats reports non-zero cost and logs show openrouter.ai.
  2. Switch to Ollama:

    bytebell set llm-provider ollama
    bytebell set ollama-model llama3.2:latest   # or any model `ollama list` shows
    ollama serve                                 # in another terminal

Copilot AI review requested due to automatic review settings May 11, 2026 06:26
@Dead-Bytes Dead-Bytes added enhancement New feature or request Ready for Review Ready for review from reviewers atomic labels May 11, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds Ollama as an optional second LLM backend behind the existing askLLM API, controlled via a new config switch, while keeping the caller-facing askLLM signature and result shape unchanged.

Changes:

  • Introduces llm_provider (openrouter default | ollama) plus ollama_url and ollama_model config keys, with CLI setters for each.
  • Splits @bb/llm provider logic into openrouter.ts and new ollama.ts, and refactors client.ts into a provider dispatcher.
  • Updates cache keying to include provider, and short-circuits cost estimation to $0 when the active provider is Ollama.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/types/src/config.ts Adds new Config enum keys for provider + Ollama settings.
packages/config/src/schema.ts Adds Zod schema + types for llm_provider / ollama_* keys and CLI hints.
packages/config/src/index.ts Re-exports LLM_PROVIDERS and LlmProvider type.
packages/config/context.md Documents new config keys and provider selection.
packages/cli/src/keyMap.ts Adds bytebell set llm-provider, ollama-url, ollama-model setters with validation.
packages/llm/src/client.ts Dispatches askLLM to OpenRouter vs Ollama; includes provider in cache key input.
packages/llm/src/openrouter.ts Extracts OpenRouter HTTP implementation and chain resolution.
packages/llm/src/ollama.ts Implements Ollama /api/chat call and token-count mapping.
packages/llm/src/cache.ts Includes provider in cache key derivation to avoid cross-provider collisions.
packages/llm/src/pricing.ts Returns $0 estimate when active provider is Ollama.
packages/llm/context.md Updates package contract/docs for multi-provider behavior and caching changes.
CLAUDE.md Updates “Rule of LLM Provider” / outbound-call wording to include Ollama.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 33 to +38
log_level: z.enum(LOG_LEVELS).default("info"),
log_retention_days: z.number().int().positive().default(14),
llm_cache_enabled: z.boolean().default(true),
llm_provider: z.enum(LLM_PROVIDERS).default("openrouter"),
ollama_url: z.string().default("http://localhost:11434"),
ollama_model: z.string().default(""),
Copilot AI review requested due to automatic review settings May 13, 2026 11:36
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Comment thread packages/llm/context.md
Comment on lines +168 to +171
- Per-usage-record provider persistence — Ollama `$0` cost is keyed
off the _current_ `Config.LlmProvider`. Historical OpenRouter rows
still price correctly because their model IDs resolve in
OpenRouter's pricing map regardless of the current provider.
Comment on lines 110 to 111
1. Add a new `Config` enum entry in `src/schema.ts`.
2. Add the field to `configSchema` with a `.default(...)`.
Comment on lines +29 to 32
const provider = getConfigValue(Config.LlmProvider);
const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
const chain = provider === "ollama" ? resolveOllamaChain(opts) : resolveOpenRouterChain(opts);

@nitesh32 nitesh32 merged commit 2f6effd into main May 13, 2026
6 checks passed
@Dead-Bytes Dead-Bytes deleted the feat/ollama branch May 13, 2026 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

atomic enhancement New feature or request Ready for Review Ready for review from reviewers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants