Skip to main content

aimux_core/
options.rs

1//! `CallOptions` — the provider-facing options passed to `do_generate` / `do_stream`.
2//!
3//! Aligned with V4 `LanguageModelV4CallOptions`.
4
5use std::collections::HashMap;
6
7use serde::{Deserialize, Serialize};
8use serde_json::Value;
9use ts_rs::TS;
10
11use crate::language_model_message::LanguageModelPrompt;
12pub use crate::tool::{FunctionTool, ProviderTool, Tool, ToolChoice};
13use crate::types::ReasoningEffort;
14
15/// How the model should format its response.
16#[derive(Debug, Clone, Serialize, Deserialize, TS)]
17#[ts(export)]
18pub enum ResponseFormat {
19    /// Plain text (default).
20    Text,
21    /// JSON output, optionally constrained to a schema.
22    Json {
23        schema: Option<Value>,
24        name: Option<String>,
25        description: Option<String>,
26    },
27}
28
29/// Options passed to `LanguageModel::do_generate` / `do_stream`.
30///
31/// This is the **provider-facing** options struct. Users interact with
32/// `GenerateTextOptions` (user-facing) which is converted to `CallOptions`
33/// by the `generate_text` / `stream_text` functions.
34#[derive(Debug, Clone, Serialize, Deserialize, TS)]
35#[ts(export)]
36pub struct CallOptions {
37    /// The standardized prompt (message array). Required.
38    pub prompt: LanguageModelPrompt,
39
40    /// Maximum tokens to generate.
41    pub max_output_tokens: Option<u32>,
42
43    /// Sampling temperature.
44    pub temperature: Option<f64>,
45
46    /// Stop sequences.
47    pub stop_sequences: Option<Vec<String>>,
48
49    /// Nucleus sampling `top_p`.
50    pub top_p: Option<f64>,
51
52    /// Top-k sampling.
53    pub top_k: Option<f64>,
54
55    /// Presence penalty.
56    pub presence_penalty: Option<f64>,
57
58    /// Frequency penalty.
59    pub frequency_penalty: Option<f64>,
60
61    /// Response format (text or JSON).
62    pub response_format: Option<ResponseFormat>,
63
64    /// Seed for reproducibility.
65    pub seed: Option<u64>,
66
67    /// Tools available to the model (function tools and/or provider-defined tools).
68    pub tools: Option<Vec<Tool>>,
69
70    /// How the model should choose tools.
71    pub tool_choice: ToolChoice,
72
73    /// Extra HTTP headers.
74    pub headers: Option<HashMap<String, String>>,
75
76    /// Provider-specific options (keyed by provider name).
77    pub provider_options: Option<HashMap<String, Value>>,
78
79    /// Top-level reasoning effort. Maps to OpenAI `reasoning_effort` and
80    /// Anthropic `thinking` config.
81    pub reasoning: Option<ReasoningEffort>,
82}
83
84impl CallOptions {
85    /// Create a `CallOptions` with the given prompt and all other fields set
86    /// to their defaults (`None` / `ToolChoice::Auto`).
87    ///
88    /// This is the recommended construction baseline in tests — combined with
89    /// struct-update syntax (`CallOptions { tools: Some(..), ..CallOptions::new(prompt) }`)
90    /// it avoids spelling out every `None` field, so adding a new optional
91    /// field to `CallOptions` no longer requires batch-editing every test.
92    pub fn new(prompt: LanguageModelPrompt) -> Self {
93        CallOptions {
94            prompt,
95            max_output_tokens: None,
96            temperature: None,
97            stop_sequences: None,
98            top_p: None,
99            top_k: None,
100            presence_penalty: None,
101            frequency_penalty: None,
102            response_format: None,
103            seed: None,
104            tools: None,
105            tool_choice: ToolChoice::default(),
106            headers: None,
107            provider_options: None,
108            reasoning: None,
109        }
110    }
111}