pub struct LlmConfig {
pub model: String,
pub api_key: Option<String>,
pub base_url: Option<String>,
pub temp: f64,
pub max_tokens: Option<u32>,
}Expand description
LLM provider configuration — single config for any provider.
Two optional fields control routing:
api_key: None → auto from env vars (OPENAI_API_KEY, ANTHROPIC_API_KEY, etc.)base_url: None → auto-detect provider from model name; Some → custom endpoint
use sgr_agent::LlmConfig;
let c = LlmConfig::auto("gpt-4o"); // env vars
let c = LlmConfig::with_key("sk-...", "claude-3-haiku"); // explicit key
let c = LlmConfig::endpoint("sk-or-...", "https://openrouter.ai/api/v1", "gpt-4o"); // custom
let c = LlmConfig::auto("gpt-4o").temperature(0.9).max_tokens(2048); // builderFields§
§model: String§api_key: Option<String>§base_url: Option<String>§temp: f64§max_tokens: Option<u32>Implementations§
Source§impl LlmConfig
impl LlmConfig
Sourcepub fn auto(model: impl Into<String>) -> Self
pub fn auto(model: impl Into<String>) -> Self
Auto-detect provider from model name, use env vars for auth.
Sourcepub fn with_key(api_key: impl Into<String>, model: impl Into<String>) -> Self
pub fn with_key(api_key: impl Into<String>, model: impl Into<String>) -> Self
Explicit API key, auto-detect provider from model name.
Sourcepub fn endpoint(
api_key: impl Into<String>,
base_url: impl Into<String>,
model: impl Into<String>,
) -> Self
pub fn endpoint( api_key: impl Into<String>, base_url: impl Into<String>, model: impl Into<String>, ) -> Self
Custom OpenAI-compatible endpoint (OpenRouter, Ollama, LiteLLM, etc.).
Sourcepub fn temperature(self, t: f64) -> Self
pub fn temperature(self, t: f64) -> Self
Set temperature.
Sourcepub fn max_tokens(self, m: u32) -> Self
pub fn max_tokens(self, m: u32) -> Self
Set max output tokens.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for LlmConfig
impl<'de> Deserialize<'de> for LlmConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for LlmConfig
impl RefUnwindSafe for LlmConfig
impl Send for LlmConfig
impl Sync for LlmConfig
impl Unpin for LlmConfig
impl UnsafeUnpin for LlmConfig
impl UnwindSafe for LlmConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more