Files
zesdex/src/dto/chat/tool.rs
T

36 lines
933 B
Rust
Raw Normal View History

use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolCall {
pub id: String,
#[serde(rename = "type")]
pub type_: String,
pub function: ToolFunction,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolFunction {
pub name: String,
pub arguments: Value,
}
pub fn sanitize_tool_arguments(args: &Value) -> Value {
match args {
Value::String(s) => {
match serde_json::from_str::<Value>(s) {
Ok(v) => v,
Err(e) => {
tracing::warn!(
"warning: tool argument is a JSON string but failed to parse: {}. Using raw string.",
e
);
args.clone()
}
}
}
obj @ Value::Object(_) => obj.clone(),
other => other.clone(),
}
}