use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Usage {
pub prompt_tokens: u32,
pub completion_tokens: u32,
pub total_tokens: u32,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Tool {
#[serde(rename = "type")]
pub kind: String,
pub function: FunctionDef,
}
impl Tool {
pub fn function(
name: impl Into<String>,
description: impl Into<String>,
parameters: serde_json::Value,
) -> Self {
Tool {
kind: "function".to_owned(),
function: FunctionDef {
name: name.into(),
description: Some(description.into()),
parameters: Some(parameters),
},
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FunctionDef {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub parameters: Option<serde_json::Value>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ToolCall {
pub id: String,
#[serde(rename = "type")]
pub kind: String,
pub function: FunctionCall,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct FunctionCall {
pub name: String,
pub arguments: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ToolChoice {
Mode(String),
Named(NamedToolChoice),
}
impl ToolChoice {
pub fn auto() -> Self {
ToolChoice::Mode("auto".to_owned())
}
pub fn none() -> Self {
ToolChoice::Mode("none".to_owned())
}
pub fn required() -> Self {
ToolChoice::Mode("required".to_owned())
}
pub fn function(name: impl Into<String>) -> Self {
ToolChoice::Named(NamedToolChoice {
kind: "function".to_owned(),
function: NamedFunction { name: name.into() },
})
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct NamedToolChoice {
#[serde(rename = "type")]
pub kind: String,
pub function: NamedFunction,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct NamedFunction {
pub name: String,
}