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