@@ -128,9 +128,8 @@ async fn test_groq_asr() {
128128#[ derive( Debug , Clone , serde:: Serialize ) ]
129129pub struct StableLlmRequest {
130130 stream : bool ,
131- #[ serde( rename = "chatId" ) ]
132- #[ serde( skip_serializing_if = "String::is_empty" ) ]
133- chat_id : String ,
131+ #[ serde( flatten, skip_serializing_if = "Option::is_none" ) ]
132+ extra : Option < serde_json:: Value > ,
134133 messages : Vec < llm:: Content > ,
135134 #[ serde( skip_serializing_if = "String::is_empty" ) ]
136135 model : String ,
@@ -140,6 +139,23 @@ pub struct StableLlmRequest {
140139 tool_choice : & ' static str ,
141140}
142141
142+ #[ test]
143+ fn test_stable_llm_request_json ( ) {
144+ let request = StableLlmRequest {
145+ stream : true ,
146+ extra : Some ( serde_json:: json!( {
147+ "chat_id" : "test-chat-id" ,
148+ } ) ) ,
149+ messages : vec ! [ ] ,
150+ model : "test-model" . to_string ( ) ,
151+ tools : vec ! [ ] ,
152+ tool_choice : "" ,
153+ } ;
154+
155+ let json_str = serde_json:: to_string_pretty ( & request) . unwrap ( ) ;
156+ println ! ( "StableLlmRequest json: {}" , json_str) ;
157+ }
158+
143159pub enum StableLLMResponseChunk {
144160 Functions ( Vec < llm:: ToolCall > ) ,
145161 Text ( String ) ,
@@ -417,7 +433,7 @@ pub async fn llm_stable<'p, I: IntoIterator<Item = C>, C: AsRef<llm::Content>>(
417433 llm_url : & str ,
418434 token : & str ,
419435 model : & str ,
420- chat_id : Option < String > ,
436+ extra : Option < serde_json :: Value > ,
421437 prompts : I ,
422438 tools : Vec < llm:: Tool > ,
423439) -> anyhow:: Result < StableLlmResponse > {
@@ -443,22 +459,22 @@ pub async fn llm_stable<'p, I: IntoIterator<Item = C>, C: AsRef<llm::Content>>(
443459 serde_json:: to_string_pretty( & serde_json:: json!(
444460 {
445461 "stream" : true ,
446- "chat_id" : chat_id,
447462 "messages" : messages,
448463 "model" : model. to_string( ) ,
449464 "tools" : tool_name,
465+ "extra" : extra,
450466 "tool_choice" : tool_choice,
451467 }
452468 ) ) ?
453469 ) ;
454470
455471 let request = StableLlmRequest {
456472 stream : true ,
457- chat_id : chat_id. unwrap_or_default ( ) ,
458473 messages,
459474 model : model. to_string ( ) ,
460475 tools,
461476 tool_choice,
477+ extra,
462478 } ;
463479
464480 let response = response_builder
@@ -549,7 +565,7 @@ async fn test_stable_llm() {
549565pub struct ChatSession {
550566 pub api_key : String ,
551567 pub model : String ,
552- pub chat_id : Option < String > ,
568+ pub extra : Option < serde_json :: Value > ,
553569 pub url : String ,
554570
555571 pub history : usize ,
@@ -564,15 +580,15 @@ impl ChatSession {
564580 url : String ,
565581 api_key : String ,
566582 model : String ,
567- chat_id : Option < String > ,
583+ extra : Option < serde_json :: Value > ,
568584 history : usize ,
569585 tools : ToolSet < McpToolAdapter > ,
570586 ) -> Self {
571587 Self {
572588 api_key,
573589 model,
574590 url,
575- chat_id ,
591+ extra ,
576592 history,
577593 system_prompts : Vec :: new ( ) ,
578594 messages : LinkedList :: new ( ) ,
@@ -673,7 +689,7 @@ impl ChatSession {
673689 self . url . as_str ( ) ,
674690 & self . api_key ,
675691 & self . model ,
676- self . chat_id . clone ( ) ,
692+ self . extra . clone ( ) ,
677693 prompts,
678694 tools,
679695 )
0 commit comments