pub struct GenerationOptions {
pub max_tokens: Option<u32>,
pub temperature: Option<f32>,
pub top_p: Option<f32>,
pub top_k: Option<u32>,
pub frequency_penalty: Option<f32>,
pub presence_penalty: Option<f32>,
pub stop: Option<Vec<String>>,
pub seed: Option<u64>,
}Expand description
Provider 无关的 LLM 生成参数。
所有字段均为 Option,None 表示使用 provider/model 默认值。
支持多级合并:Request 级 > Agent 级 > Model 级 > Provider 默认。
§Examples
use katu_core::GenerationOptions;
let opts = GenerationOptions::new()
.with_max_tokens(4096)
.with_temperature(0.7);
assert_eq!(opts.max_tokens, Some(4096));
assert_eq!(opts.temperature, Some(0.7));Fields§
§max_tokens: Option<u32>最大输出 token 数
temperature: Option<f32>采样温度 (0.0 = 确定性, 2.0 = 最大随机)
top_p: Option<f32>Top-p (nucleus) 采样阈值
top_k: Option<u32>Top-k 采样(部分 provider 支持)
frequency_penalty: Option<f32>频率惩罚 (-2.0 ~ 2.0)
presence_penalty: Option<f32>存在惩罚 (-2.0 ~ 2.0)
stop: Option<Vec<String>>停止序列
seed: Option<u64>随机种子(可复现生成)
Implementations§
Source§impl GenerationOptions
impl GenerationOptions
Sourcepub fn with_max_tokens(self, max_tokens: u32) -> Self
pub fn with_max_tokens(self, max_tokens: u32) -> Self
设置 max_tokens。
Sourcepub fn with_temperature(self, temperature: f32) -> Self
pub fn with_temperature(self, temperature: f32) -> Self
设置 temperature。
Sourcepub fn with_top_p(self, top_p: f32) -> Self
pub fn with_top_p(self, top_p: f32) -> Self
设置 top_p。
Sourcepub fn with_top_k(self, top_k: u32) -> Self
pub fn with_top_k(self, top_k: u32) -> Self
设置 top_k。
Sourcepub fn with_frequency_penalty(self, penalty: f32) -> Self
pub fn with_frequency_penalty(self, penalty: f32) -> Self
设置 frequency_penalty。
Sourcepub fn with_presence_penalty(self, penalty: f32) -> Self
pub fn with_presence_penalty(self, penalty: f32) -> Self
设置 presence_penalty。
Sourcepub fn merge(&self, other: &GenerationOptions) -> GenerationOptions
pub fn merge(&self, other: &GenerationOptions) -> GenerationOptions
合并两个 GenerationOptions,other 的非 None 值覆盖 self。
用于实现参数合并链:Request > Agent > Model > Provider。
Trait Implementations§
Source§impl Clone for GenerationOptions
impl Clone for GenerationOptions
Source§fn clone(&self) -> GenerationOptions
fn clone(&self) -> GenerationOptions
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for GenerationOptions
impl Debug for GenerationOptions
Source§impl Default for GenerationOptions
impl Default for GenerationOptions
Source§fn default() -> GenerationOptions
fn default() -> GenerationOptions
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for GenerationOptions
impl<'de> Deserialize<'de> for GenerationOptions
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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 PartialEq for GenerationOptions
impl PartialEq for GenerationOptions
Source§fn eq(&self, other: &GenerationOptions) -> bool
fn eq(&self, other: &GenerationOptions) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl Serialize for GenerationOptions
impl Serialize for GenerationOptions
impl StructuralPartialEq for GenerationOptions
Auto Trait Implementations§
impl Freeze for GenerationOptions
impl RefUnwindSafe for GenerationOptions
impl Send for GenerationOptions
impl Sync for GenerationOptions
impl Unpin for GenerationOptions
impl UnsafeUnpin for GenerationOptions
impl UnwindSafe for GenerationOptions
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more