@@ -26,6 +26,10 @@ pub struct LlmConfig {
2626 pub max_tokens : Option < usize > ,
2727 /// Extended thinking budget in tokens (Anthropic only).
2828 pub thinking_budget : Option < usize > ,
29+ /// Request token-level log probabilities from OpenAI-compatible providers.
30+ pub logprobs : Option < bool > ,
31+ /// Number of alternative logprobs per token when logprobs are requested.
32+ pub top_logprobs : Option < usize > ,
2933 /// When true, temperature is never sent to the API (e.g., o1 models).
3034 pub disable_temperature : bool ,
3135}
@@ -47,6 +51,8 @@ impl std::fmt::Debug for LlmConfig {
4751 . field ( "temperature" , & self . temperature )
4852 . field ( "max_tokens" , & self . max_tokens )
4953 . field ( "thinking_budget" , & self . thinking_budget )
54+ . field ( "logprobs" , & self . logprobs )
55+ . field ( "top_logprobs" , & self . top_logprobs )
5056 . field ( "disable_temperature" , & self . disable_temperature )
5157 . finish ( )
5258 }
@@ -70,6 +76,8 @@ impl LlmConfig {
7076 temperature : None ,
7177 max_tokens : None ,
7278 thinking_budget : None ,
79+ logprobs : None ,
80+ top_logprobs : None ,
7381 disable_temperature : false ,
7482 }
7583 }
@@ -114,6 +122,17 @@ impl LlmConfig {
114122 self
115123 }
116124
125+ pub fn with_logprobs ( mut self , enabled : bool ) -> Self {
126+ self . logprobs = Some ( enabled) ;
127+ self
128+ }
129+
130+ pub fn with_top_logprobs ( mut self , top_logprobs : usize ) -> Self {
131+ self . logprobs = Some ( true ) ;
132+ self . top_logprobs = Some ( top_logprobs) ;
133+ self
134+ }
135+
117136 pub ( crate ) fn resolved_headers ( & self ) -> HashMap < String , String > {
118137 let mut headers = self . headers . clone ( ) ;
119138 if let ( Some ( header_name) , Some ( session_id) ) = ( & self . session_id_header , & self . session_id ) {
@@ -168,6 +187,12 @@ pub fn create_client_with_config(config: LlmConfig) -> Arc<dyn LlmClient> {
168187 if let Some ( max) = config. max_tokens {
169188 client = client. with_max_tokens ( max) ;
170189 }
190+ if let Some ( enabled) = config. logprobs {
191+ client = client. with_logprobs ( enabled) ;
192+ }
193+ if let Some ( top_logprobs) = config. top_logprobs {
194+ client = client. with_top_logprobs ( top_logprobs) ;
195+ }
171196 Arc :: new ( client)
172197 }
173198 "glm" | "zhipu" | "bigmodel" => {
@@ -183,6 +208,12 @@ pub fn create_client_with_config(config: LlmConfig) -> Arc<dyn LlmClient> {
183208 if let Some ( max) = config. max_tokens {
184209 client = client. with_max_tokens ( max) ;
185210 }
211+ if let Some ( enabled) = config. logprobs {
212+ client = client. with_logprobs ( enabled) ;
213+ }
214+ if let Some ( top_logprobs) = config. top_logprobs {
215+ client = client. with_top_logprobs ( top_logprobs) ;
216+ }
186217 Arc :: new ( client)
187218 }
188219 // OpenAI-compatible providers (deepseek, groq, together, ollama, etc.)
@@ -208,6 +239,12 @@ pub fn create_client_with_config(config: LlmConfig) -> Arc<dyn LlmClient> {
208239 if let Some ( max) = config. max_tokens {
209240 client = client. with_max_tokens ( max) ;
210241 }
242+ if let Some ( enabled) = config. logprobs {
243+ client = client. with_logprobs ( enabled) ;
244+ }
245+ if let Some ( top_logprobs) = config. top_logprobs {
246+ client = client. with_top_logprobs ( top_logprobs) ;
247+ }
211248 Arc :: new ( client)
212249 }
213250 }
0 commit comments