feat: 修复 JSON 字符串处理逻辑,确保字符串格式的有效性

This commit is contained in:
oudecheng 2026-05-13 10:39:32 +08:00
parent 79f9e36871
commit 84b3fd064c

View File

@ -137,11 +137,11 @@ impl OpenAIProvider {
Value::String(raw) => { Value::String(raw) => {
// If the string is already valid JSON, keep it as-is // If the string is already valid JSON, keep it as-is
// Otherwise, ensure it's a proper JSON string // Otherwise, ensure it's a proper JSON string
if serde_json::from_str::<Value>(raw).is_ok() { if serde_json::from_str::<Value>(&raw).is_ok() {
Value::String(raw) Value::String(raw)
} else { } else {
// Invalid JSON string - wrap it as a proper JSON string // Invalid JSON string - wrap it as a proper JSON string
serde_json::to_string(&raw).unwrap_or_else(|_| "null".to_string()) Value::String(serde_json::to_string(&raw).unwrap_or_else(|_| "null".to_string()))
} }
} }
value => Value::String( value => Value::String(