Skip to main content

systemprompt_models/ai/
sampling.rs

1//! Provider sampling configuration (temperature, top-p, penalties).
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, Default, Serialize, Deserialize)]
9pub struct ModelPreferences {
10    pub hints: Vec<ModelHint>,
11    pub cost_priority: Option<f32>,
12}
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
15#[serde(untagged)]
16pub enum ModelHint {
17    ModelId(String),
18    Category(String),
19    Provider(String),
20}
21
22#[derive(Debug, Clone, Default, Serialize, Deserialize)]
23pub struct SamplingParams {
24    pub temperature: Option<f32>,
25    pub top_p: Option<f32>,
26    pub top_k: Option<i32>,
27    pub presence_penalty: Option<f32>,
28    pub frequency_penalty: Option<f32>,
29    pub stop_sequences: Option<Vec<String>>,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
33pub struct ProviderConfig {
34    pub provider: String,
35    pub model: String,
36    pub max_output_tokens: u32,
37}
38
39impl ProviderConfig {
40    pub fn new(
41        provider: impl Into<String>,
42        model: impl Into<String>,
43        max_output_tokens: u32,
44    ) -> Self {
45        Self {
46            provider: provider.into(),
47            model: model.into(),
48            max_output_tokens,
49        }
50    }
51}