pub struct Config {Show 14 fields
pub provider: String,
pub model: String,
pub base_url: Option<String>,
pub api_key: Option<SecretString>,
pub organization: Option<String>,
pub timeout_seconds: Option<u64>,
pub retry_config: RetryConfig,
pub temperature: Option<f32>,
pub max_tokens: Option<u32>,
pub top_p: Option<f32>,
pub frequency_penalty: Option<f32>,
pub presence_penalty: Option<f32>,
pub stop_sequences: Option<Vec<String>>,
pub metadata: HashMap<String, Value>,
}Expand description
Configuration for an LLM client.
This struct holds both connection details (API keys, URLs) and default generation parameters that will be applied to all requests unless overridden.
§Security
The api_key field uses SecretString to prevent accidental logging or
display of sensitive credentials.
§Examples
use neuromance_common::Config;
let config = Config::new("openai", "gpt-4")
.with_api_key("sk-...")
.with_temperature(0.7)
.with_max_tokens(1000);Fields§
§provider: StringThe LLM provider name (e.g., “openai”, “anthropic”).
model: StringThe default model identifier to use.
base_url: Option<String>Optional custom base URL for API requests.
Override this for self-hosted deployments or custom endpoints.
api_key: Option<SecretString>API key for authentication (stored securely).
Will not be serialized to prevent accidental exposure.
organization: Option<String>Optional organization identifier.
timeout_seconds: Option<u64>Request timeout in seconds.
retry_config: RetryConfigConfiguration for retry behavior with exponential backoff.
temperature: Option<f32>Default sampling temperature (0.0 to 2.0).
max_tokens: Option<u32>Default maximum tokens to generate.
top_p: Option<f32>Default nucleus sampling threshold (0.0 to 1.0).
frequency_penalty: Option<f32>Default frequency penalty (-2.0 to 2.0).
presence_penalty: Option<f32>Default presence penalty (-2.0 to 2.0).
stop_sequences: Option<Vec<String>>Default stop sequences.
metadata: HashMap<String, Value>Additional metadata to attach to all requests.
Implementations§
Source§impl Config
impl Config
Sourcepub fn with_base_url(self, base_url: impl Into<String>) -> Self
pub fn with_base_url(self, base_url: impl Into<String>) -> Self
Sourcepub fn with_api_key(self, api_key: impl Into<String>) -> Self
pub fn with_api_key(self, api_key: impl Into<String>) -> Self
Sets the API key for authentication.
The key is stored securely using SecretString.
§Arguments
api_key- The API key
Sourcepub fn with_organization(self, organization: impl Into<String>) -> Self
pub fn with_organization(self, organization: impl Into<String>) -> Self
Sourcepub fn with_timeout(self, timeout_seconds: u64) -> Self
pub fn with_timeout(self, timeout_seconds: u64) -> Self
Sourcepub fn with_temperature(self, temperature: f32) -> Self
pub fn with_temperature(self, temperature: f32) -> Self
Sourcepub fn with_max_tokens(self, max_tokens: u32) -> Self
pub fn with_max_tokens(self, max_tokens: u32) -> Self
Sourcepub fn with_top_p(self, top_p: f32) -> Self
pub fn with_top_p(self, top_p: f32) -> Self
Sourcepub fn with_frequency_penalty(self, frequency_penalty: f32) -> Self
pub fn with_frequency_penalty(self, frequency_penalty: f32) -> Self
Sourcepub fn with_presence_penalty(self, presence_penalty: f32) -> Self
pub fn with_presence_penalty(self, presence_penalty: f32) -> Self
Sourcepub fn with_stop_sequences(
self,
stop_sequences: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn with_stop_sequences( self, stop_sequences: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Sourcepub fn with_metadata(self, metadata: HashMap<String, Value>) -> Self
pub fn with_metadata(self, metadata: HashMap<String, Value>) -> Self
Sourcepub fn with_retry_config(self, retry_config: RetryConfig) -> Self
pub fn with_retry_config(self, retry_config: RetryConfig) -> Self
Source§impl Config
impl Config
Sourcepub fn into_chat_request(self, messages: Vec<Message>) -> ChatRequest
pub fn into_chat_request(self, messages: Vec<Message>) -> ChatRequest
Converts this configuration and messages into a chat request.
This is a convenience method that creates a ChatRequest with all
default parameters from this configuration.
§Arguments
messages- The conversation messages
§Examples
use neuromance_common::{Config, Message, MessageRole};
use uuid::Uuid;
let config = Config::new("openai", "gpt-4").with_temperature(0.7);
let msg = Message::new(Uuid::new_v4(), MessageRole::User, "Hello!");
let request = config.into_chat_request(vec![msg]);Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validates the configuration parameters.
Checks that all numeric parameters are within their valid ranges.
§Errors
Returns an error if any parameter is out of range:
temperaturemust be between 0.0 and 2.0top_pmust be between 0.0 and 1.0frequency_penaltymust be between -2.0 and 2.0presence_penaltymust be between -2.0 and 2.0