1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* OpenAI API
*
* The OpenAI REST API. Please see https://platform.openai.com/docs/api-reference for more details.
*
* The version of the OpenAPI document: 2.3.0
*
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
/// FunctionTool : Defines a function in your own code the model can choose to call. Learn more about [function calling](https://platform.openai.com/docs/guides/function-calling).
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct FunctionTool {
/// The type of the function tool. Always `function`.
#[serde(rename = "type")]
pub r#type: Type,
/// The name of the function to call.
#[serde(rename = "name")]
pub name: String,
/// A description of the function. Used by the model to determine whether or not to call the function.
#[serde(
rename = "description",
default,
with = "::serde_with::rust::double_option",
skip_serializing_if = "Option::is_none"
)]
pub description: Option<Option<String>>,
/// A JSON schema object describing the parameters of the function.
#[serde(rename = "parameters", deserialize_with = "Option::deserialize")]
pub parameters: Option<std::collections::HashMap<String, serde_json::Value>>,
/// Whether to enforce strict parameter validation. Default `true`.
#[serde(rename = "strict", deserialize_with = "Option::deserialize")]
pub strict: Option<bool>,
/// Whether this function is deferred and loaded via tool search.
#[serde(rename = "defer_loading", skip_serializing_if = "Option::is_none")]
pub defer_loading: Option<bool>,
}
impl FunctionTool {
/// Defines a function in your own code the model can choose to call. Learn more about [function calling](https://platform.openai.com/docs/guides/function-calling).
pub fn new(
r#type: Type,
name: String,
parameters: Option<std::collections::HashMap<String, serde_json::Value>>,
strict: Option<bool>,
) -> FunctionTool {
FunctionTool {
r#type,
name,
description: None,
parameters,
strict,
defer_loading: None,
}
}
}
/// The type of the function tool. Always `function`.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Type {
#[serde(rename = "function")]
Function,
}
impl Default for Type {
fn default() -> Type {
Self::Function
}
}
impl std::fmt::Display for FunctionTool {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match serde_json::to_string(self) {
Ok(s) => write!(f, "{}", s),
Err(_) => Err(std::fmt::Error),
}
}
}