Config

Struct Config 

Source
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: String

The LLM provider name (e.g., “openai”, “anthropic”).

§model: String

The 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: RetryConfig

Configuration 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

Source

pub fn new(provider: impl Into<String>, model: impl Into<String>) -> Self

Creates a new configuration with the specified provider and model.

All optional fields are initialized to their defaults.

§Arguments
  • provider - The LLM provider name
  • model - The model identifier
§Examples
use neuromance_common::Config;

let config = Config::new("openai", "gpt-4");
Source

pub fn with_base_url(self, base_url: impl Into<String>) -> Self

Sets a custom base URL for API requests.

§Arguments
  • base_url - The base URL for the API
Source

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
Source

pub fn with_organization(self, organization: impl Into<String>) -> Self

Sets the organization identifier.

§Arguments
  • organization - The organization ID
Source

pub fn with_timeout(self, timeout_seconds: u64) -> Self

Sets the request timeout.

§Arguments
  • timeout_seconds - Timeout in seconds
Source

pub fn with_temperature(self, temperature: f32) -> Self

Sets the default sampling temperature.

§Arguments
  • temperature - Value between 0.0 and 2.0
Source

pub fn with_max_tokens(self, max_tokens: u32) -> Self

Sets the default maximum tokens to generate.

§Arguments
  • max_tokens - Maximum tokens in responses
Source

pub fn with_top_p(self, top_p: f32) -> Self

Sets the default nucleus sampling threshold.

§Arguments
  • top_p - Value between 0.0 and 1.0
Source

pub fn with_frequency_penalty(self, frequency_penalty: f32) -> Self

Sets the default frequency penalty.

§Arguments
  • frequency_penalty - Value between -2.0 and 2.0
Source

pub fn with_presence_penalty(self, presence_penalty: f32) -> Self

Sets the default presence penalty.

§Arguments
  • presence_penalty - Value between -2.0 and 2.0
Source

pub fn with_stop_sequences( self, stop_sequences: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Sets the default stop sequences.

§Arguments
  • stop_sequences - An iterable of stop sequences
Source

pub fn with_metadata(self, metadata: HashMap<String, Value>) -> Self

Sets the default metadata.

§Arguments
  • metadata - Key-value pairs of metadata
Source

pub fn with_retry_config(self, retry_config: RetryConfig) -> Self

Sets the retry configuration.

§Arguments
  • retry_config - The retry configuration
Source§

impl Config

Source

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]);
Source

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:

  • temperature must be between 0.0 and 2.0
  • top_p must be between 0.0 and 1.0
  • frequency_penalty must be between -2.0 and 2.0
  • presence_penalty must be between -2.0 and 2.0

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Config

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Config

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,