File tree Expand file tree Collapse file tree
crates/brightstaff/src/handlers/llm Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -259,6 +259,36 @@ async fn llm_chat_inner(
259259 obj. insert ( "maxTokens" . to_string ( ) , max_output_tokens) ;
260260 }
261261 }
262+
263+ if let Some ( input) = obj. get_mut ( "input" ) . and_then ( |v| v. as_array_mut ( ) ) {
264+ for item in input {
265+ if let Some ( message_obj) = item. as_object_mut ( ) {
266+ if let Some ( content) = message_obj. get_mut ( "content" ) {
267+ if let Some ( parts) = content. as_array ( ) {
268+ let text = parts
269+ . iter ( )
270+ . filter_map ( |part| {
271+ let part_obj = part. as_object ( ) ?;
272+ match part_obj. get ( "type" ) . and_then ( |v| v. as_str ( ) ) {
273+ Some ( "input_text" ) | Some ( "output_text" ) => part_obj
274+ . get ( "text" )
275+ . and_then ( |v| v. as_str ( ) )
276+ . map ( str:: to_owned) ,
277+ _ => None ,
278+ }
279+ } )
280+ . filter ( |s| !s. is_empty ( ) )
281+ . collect :: < Vec < _ > > ( )
282+ . join ( "\n " ) ;
283+
284+ if !text. is_empty ( ) {
285+ * content = serde_json:: Value :: String ( text) ;
286+ }
287+ }
288+ }
289+ }
290+ }
291+ }
262292 }
263293 match serde_json:: to_vec ( & value) {
264294 Ok ( bytes) => bytes. into ( ) ,
You can’t perform that action at this time.
0 commit comments