Instruction file imported from Bryan-Roe/Aria (
.github/instructions/chat-providers.instructions.md). Copyright stays with the author.
Chat Providers — Instruction Guide
Provider Detection Chain
Order matters — first match wins:
- Explicit choice —
--providerflag or API parameter - LMStudio — if
LMSTUDIO_BASE_URLis set - Ollama — if
OLLAMA_BASE_URLis set (or auto-detected athttp://127.0.0.1:11434/v1) - Azure OpenAI — needs ALL 4:
AZURE_OPENAI_API_KEY,AZURE_OPENAI_ENDPOINT,AZURE_OPENAI_DEPLOYMENT,AZURE_OPENAI_API_VERSION - OpenAI — needs
OPENAI_API_KEY - Groq — needs
GROQ_API_KEY; auto-detected by probinghttps://api.groq.com/openai/v1/models - LoRA — explicit
--provider lorawith adapter path - Local echo — zero-dependency fallback with context-aware intent recognition
Provider Contract (BaseChatProvider)
class BaseChatProvider:
def __init__(self, model=None, temperature=0.7, max_output_tokens=2048): ...
def complete(self, messages: List[Dict], stream: bool = True) -> Union[str, Generator]:
# If stream=True: yield string chunks
# If stream=False: return complete string
Key Implementations
GroqProvider
- OpenAI-compatible provider for Groq cloud inference
- Requires
GROQ_API_KEY(get one at https://console.groq.com/keys) - Default model:
llama-3.1-8b-instant; override withGROQ_MODELor--model - Default endpoint:
https://api.groq.com/openai/v1; override withGROQ_BASE_URL - Thread-safe availability cache (
_groq_availability_cache, 30 s TTL) - Friendly error messages for auth failures, connection errors, and model-not-found
LoraLocalProvider
- Bridges torch + subprocess for local LoRA inference
- Requires
adapter_config.json+adapter_model.safetensors - Thread-safe response caching
LocalEchoProvider
- Zero external dependencies
- Context-aware intent recognition (greetings, questions, coding)
- Deterministic responses for testing
Streaming Pattern
for chunk in provider.complete(messages, stream=True):
yield f"data: {json.dumps({'content': chunk})}\n\n"
yield "data: [DONE]\n\n"
Rate Limit Handling
- Providers implement exponential backoff on rate limits
- Automatic fallback to next provider in chain on persistent failures
Coding Conventions
- Never hardcode API keys — always use env vars
- Always support both
stream=Trueandstream=False - The
shared/chat_providers.pyre-exports fromai-projects/chat-cli/src/chat_providers.py - Test with
/api/ai/statusendpoint to verify provider detection detect_provider()returns tuple:(provider_instance, provider_name)