crabtalk_core/model/
tool.rs1use schemars::Schema;
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Deserialize, Serialize)]
8pub struct Tool {
9 pub name: String,
11
12 pub description: String,
14
15 pub parameters: Schema,
17
18 pub strict: bool,
20}
21
22#[derive(Debug, Clone, Default, Deserialize, Serialize)]
24pub struct ToolCall {
25 #[serde(default, skip_serializing_if = "String::is_empty")]
27 pub id: String,
28
29 #[serde(default, skip_serializing)]
31 pub index: u32,
32
33 #[serde(default, rename = "type")]
35 pub call_type: String,
36
37 pub function: FunctionCall,
39}
40
41impl ToolCall {
42 pub fn merge(&mut self, call: &Self) {
44 if !call.id.is_empty() {
45 self.id = call.id.clone();
46 }
47 if !call.call_type.is_empty() {
48 self.call_type = call.call_type.clone();
49 }
50 if !call.function.name.is_empty() {
51 self.function.name = call.function.name.clone();
52 }
53 self.function.arguments.push_str(&call.function.arguments);
54 }
55}
56
57#[derive(Debug, Clone, Default, Deserialize, Serialize)]
59pub struct FunctionCall {
60 #[serde(default, skip_serializing_if = "String::is_empty")]
62 pub name: String,
63
64 #[serde(skip_serializing_if = "String::is_empty")]
66 pub arguments: String,
67}
68
69pub use crabllm_core::ToolChoice;