| 31 | |
| 32 | impl OpenAiClient { |
| 33 | pub(crate) fn parse_tool_arguments(tool_name: &str, arguments: &str) -> serde_json::Value { |
| 34 | if arguments.trim().is_empty() { |
| 35 | return serde_json::Value::Object(Default::default()); |
| 36 | } |
| 37 | |
| 38 | serde_json::from_str(arguments).unwrap_or_else(|e| { |
| 39 | tracing::warn!( |
| 40 | "Failed to parse tool arguments JSON for tool '{}': {}", |
| 41 | tool_name, |
| 42 | e |
| 43 | ); |
| 44 | serde_json::json!({ |
| 45 | "__parse_error": format!( |
| 46 | "Malformed tool arguments: {}. Raw input: {}", |
| 47 | e, arguments |
| 48 | ) |
| 49 | }) |
| 50 | }) |
| 51 | } |
| 52 | |
| 53 | fn merge_stream_text(text_content: &mut String, incoming: &str) -> Option<String> { |
| 54 | if incoming.is_empty() { |