openai_struct/models/
chat_completion_tool_choice_option.rs

1/*
2 * OpenAI API
3 *
4 * The OpenAI REST API. Please see pub https:///platform.openai.com/docs/api-reference for more details.
5 *
6 * OpenAPI spec pub version: 2.3.0
7 *
8 * Generated pub by: https:///github.com/swagger-api/swagger-codegen.git
9 */
10/// pub ChatCompletionToolChoiceOption : Controls which (if any) tool is called by the model. `none` means the model will not call any tool and instead generates a message. `auto` means the model can pick between generating a message or calling one or more tools. `required` means the model must call one or more tools. Specifying a particular tool via `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}` forces the model to call that tool.  `none` is the default when no tools are present. `auto` is the default if tools are present.
11
12#[allow(unused_imports)]
13use serde_json::Value;
14
15use crate::ChatCompletionNamedToolChoice;
16
17/// # on openapi.yaml
18///
19/// ```yaml
20/// ChatCompletionToolChoiceOption:
21///   description: >
22///     Controls which (if any) tool is called by the model.
23///
24///     `none` means the model will not call any tool and instead generates a
25///     message.
26///
27///     `auto` means the model can pick between generating a message or calling
28///     one or more tools.
29///
30///     `required` means the model must call one or more tools.
31///
32///     Specifying a particular tool via `{"type": "function", "function":
33///     {"name": "my_function"}}` forces the model to call that tool.
34///
35///
36///     `none` is the default when no tools are present. `auto` is the default
37///     if tools are present.
38///   oneOf:
39///     - type: string
40///       description: >
41///         `none` means the model will not call any tool and instead generates
42///         a message. `auto` means the model can pick between generating a
43///         message or calling one or more tools. `required` means the model
44///         must call one or more tools.
45///       enum:
46///         - none
47///         - auto
48///         - required
49///     - $ref: "#/components/schemas/ChatCompletionNamedToolChoice"
50/// ```
51#[derive(Debug, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum ChatCompletionToolChoiceOption {
54    /// Str
55    String(ChatCompletionToolChoiceStrEnum),
56    /// Named tool choice variant for specific tool selection
57    VariantNamedToolChoice(ChatCompletionNamedToolChoice),
58}
59
60#[derive(Debug, Serialize, Deserialize)]
61#[serde(rename_all = "lowercase")]
62pub enum ChatCompletionToolChoiceStrEnum {
63    /// Model will not call any tool and instead generates a message
64    #[serde(rename = "none")]
65    None,
66    /// Model can pick between generating a message or calling tools
67    #[serde(rename = "auto")]
68    Auto,
69    /// Model must call one or more tools
70    #[serde(rename = "required")]
71    Required,
72}
73
74#[test]
75fn test_cct_co() {
76    assert_eq!(
77        serde_json::to_string(&ChatCompletionToolChoiceOption::String(
78            ChatCompletionToolChoiceStrEnum::None
79        ))
80        .unwrap(),
81        r#""none""#
82    );
83    assert_eq!(
84        serde_json::to_string(&ChatCompletionToolChoiceOption::VariantNamedToolChoice(
85            ChatCompletionNamedToolChoice {
86                function: crate::models::AssistantsNamedToolChoiceFunction { name: "Emm".into() },
87                _type: "function".into()
88            }
89        ))
90        .unwrap()
91        .to_string(),
92        r#"{"function":{"name":"Emm"},"type":"function"}"#
93    );
94}