Skip to main content

ds_api/raw/request/
tool.rs

1use serde::{Deserialize, Serialize};
2
3use super::message::ToolType;
4
5#[derive(Debug, Serialize, Deserialize)]
6pub struct Tool {
7    /// tool 的类型。目前仅支持 function。
8    pub r#type: ToolType,
9    pub function: Function,
10}
11
12#[derive(Debug, Serialize, Deserialize)]
13pub struct Function {
14    /// 要调用的 function 名称。必须由 a-z、A-Z、0-9 字符组成,或包含下划线和连字符,最大长度为 64 个字符。
15    pub name: String,
16
17    /// function 的功能描述,供模型理解何时以及如何调用该 function。
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub description: Option<String>,
20
21    /// function 的输入参数,以 JSON Schema 对象描述。请参阅Tool Calls 指南获取示例,并参阅JSON Schema 参考了解有关格式的文档。省略 parameters 会定义一个参数列表为空的 function。
22    pub parameters: serde_json::Value,
23
24    /// Beta 功能:如果设置为 true,API 将在函数调用中使用 strict 模式
25    /// 如果设置为 true,API 将在函数调用中使用 strict 模式,以确保输出始终符合函数的 JSON schema 定义。该功能为 Beta 功能,详细使用方式请参阅Tool Calls 指南
26    #[serde(skip_serializing_if = "Option::is_none")]
27    pub strict: Option<bool>,
28}