Accept wrapped text content from LLM providers (#31048)

Some providers sometimes send `{ "type": "text", "text": ... }` instead
of just the text as a string. Now we accept those instead of erroring.

Release Notes:

- N/A
This commit is contained in:
Richard Feldman 2025-05-20 16:50:02 -04:00 committed by GitHub
parent 89700c3682
commit 4bb04cef9d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 72 additions and 26 deletions

View file

@ -426,14 +426,17 @@ pub fn into_google(
}
language_model::MessageContent::ToolResult(tool_result) => {
match tool_result.content {
language_model::LanguageModelToolResultContent::Text(txt) => {
language_model::LanguageModelToolResultContent::Text(text)
| language_model::LanguageModelToolResultContent::WrappedText(
language_model::WrappedTextContent { text, .. },
) => {
vec![Part::FunctionResponsePart(
google_ai::FunctionResponsePart {
function_response: google_ai::FunctionResponse {
name: tool_result.tool_name.to_string(),
// The API expects a valid JSON object
response: serde_json::json!({
"output": txt
"output": text
}),
},
},