27 lines
633 B
Rust
27 lines
633 B
Rust
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) => {
|
||
|
|
serde_json::from_str(s).unwrap_or_else(|_| args.clone())
|
||
|
|
}
|
||
|
|
obj @ Value::Object(_) => obj.clone(),
|
||
|
|
other => other.clone(),
|
||
|
|
}
|
||
|
|
}
|