chatbot-app
View on GitHub ↗
Configuration

Configuration & LLM Providers

llm_provider.py's get_llm(model_override=None) reads LLM_PROVIDER and dispatches to one _get_<provider>_llm() per provider — each validates only its own requirements and fails fast with an actionable message if something's missing.

Environment variables

VariableDescription
LLM_PROVIDERgemini (default), openai, anthropic, or ollama — chat model backend.
GEMINI_API_KEYRequired when LLM_PROVIDER=gemini — Google AI Studio API key.
GEMINI_LLM_MODELRequired when LLM_PROVIDER=gemini, unless --model is passed.
OPENAI_API_KEYRequired when LLM_PROVIDER=openai or EMBEDDINGS_PROVIDER=openai — same key covers both.
ANTHROPIC_API_KEYRequired when LLM_PROVIDER=anthropic.
EMBEDDINGS_PROVIDERollama (default) or openai — embeddings backend for --rag (unrelated to LLM_PROVIDER).
API_SECRETREST API only — pre-shared secret exchanged for a JWT via POST /auth/token.
JWT_SECRET_KEYREST API only — signs issued JWTs (HS256); must differ from API_SECRET.
CORS_ORIGINSREST API only — comma-separated allowed origins; unset/empty = none allowed (fail closed).
GEMINI_API_KEY/GEMINI_LLM_MODEL are only required while LLM_PROVIDER is unset or gemini. RAG variables are only needed with --rag (or the REST API, which builds the RAG store at startup regardless of a flag). Generate API_SECRET/JWT_SECRET_KEY independently with openssl rand -hex 32 — never reuse one as the other.

Provider dispatch

Each provider is a functionally separate concern from the RAG embeddings provider below — they are not interchangeable or merged, even though the dispatch pattern is structurally similar.

ProviderChat classRequiresDefault model
geminiChatGoogleGenerativeAIGEMINI_API_KEY + (--model or GEMINI_LLM_MODEL)none — must be set explicitly
openaiChatOpenAIOPENAI_API_KEY (reused from RAG embeddings)gpt-4o-mini
anthropicChatAnthropicANTHROPIC_API_KEY (adds langchain-anthropic)claude-3-5-haiku-latest
ollamaChatOllamalocal server reachable + model pulledllama3.2:3b

The ollama provider has no cloud key, but checks that Ollama is reachable and the model is pulled before starting, failing fast with the exact ollama pull <model> fix if not. At invocation time, ollama/langchain_ollama raise a builtin ConnectionError on an unreachable server and ollama.ResponseError on other API errors — both are caught explicitly in main.py/api/main.py alongside openai.OpenAIError/anthropic.AnthropicError, next to the pre-existing Gemini-specific catches.

--model overrides the model name for whichever provider is active. --llm-provider overrides LLM_PROVIDER for the process. chain_builder.py never constructs the chat model directly — llm_provider.get_llm() is the single code path for building it, called from both main.py's build_chain()/build_agent_graph() and api/main.py's lifespan().

Next steps