block-quote On this pagechevron-down
copy Copy chevron-down
API Reference llm_service.rs — Multi-Provider Inference & Routing The llm_service.rs module powers Oxyde’s dynamic routing across multiple LLMs. It supports OpenAI, Groq, Anthropic, xAI, Perplexity, and more — with a uniform trait interface.
Copy trait LLMProvider {
fn generate ( & self , prompt : & str , stream : bool ) -> Result < String >;
fn name ( & self ) -> & ' static str ;
} Each provider implements this trait with their own:
🧭 Provider Selection Logic
Oxyde includes a router that picks a provider based on:
Short prompts → low-latency models (Groq)
Aggressive tone → model with higher creativity
Fall back if 429 errors occur
You can hard-prefer OpenAI, etc.
🔁 Routing Example
🔒 Rate Limiting & Failover
If a provider returns:
HTTP 429 → retry with exponential backoff
HTTP 5xx → fallback to next preferred model
You can also implement caching or queueing middleware here.
🔊 Streaming Support
If stream = true, providers return output token-by-token:
This is handled via futures::Stream in async Rust.
🧩 Adding a New Provider
Just implement the LLMProvider trait:
Then add to the router map in llm_service.rs.