Skip to content

Commit 2b299b5

Browse files
committed
hack: transforming role.content.type == input_text -> text
1 parent 05ae623 commit 2b299b5

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

  • crates/brightstaff/src/handlers/llm

crates/brightstaff/src/handlers/llm/mod.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff 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(),

0 commit comments

Comments
 (0)