openai_struct/models/chat_completion_request_tool_message.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
11#[allow(unused_imports)]
12use serde_json::Value;
13
14/// # on openapi.yaml
15///
16/// ```yaml
17/// ChatCompletionRequestToolMessage:
18/// type: object
19/// title: Tool message
20/// properties:
21/// role:
22/// type: string
23/// enum:
24/// - tool
25/// description: The role of the messages author, in this case `tool`.
26/// x-stainless-const: true
27/// content:
28/// oneOf:
29/// - type: string
30/// description: The contents of the tool message.
31/// title: Text content
32/// - type: array
33/// description:
34/// An array of content parts with a defined type. For tool messages,
35/// only type `text` is supported.
36/// title: Array of content parts
37/// items:
38/// $ref: "#/components/schemas/ChatCompletionRequestToolMessageContentPart"
39/// minItems: 1
40/// description: The contents of the tool message.
41/// tool_call_id:
42/// type: string
43/// description: Tool call that this message is responding to.
44/// required:
45/// - role
46/// - content
47/// - tool_call_id
48/// ```
49#[derive(Debug, Serialize, Deserialize, PartialEq)]
50pub struct ChatCompletionRequestToolMessage {
51 /// The contents of the tool message.
52 #[serde(rename = "content")]
53 pub content: ChatCompletionRequestToolMessageContent,
54 /// Tool call that this message is responding to.
55 #[serde(rename = "tool_call_id")]
56 pub tool_call_id: String,
57}
58
59/// # on openapi.yaml
60///
61/// ```yaml
62/// content:
63/// oneOf:
64/// - type: string
65/// description: The contents of the tool message.
66/// title: Text content
67/// - type: array
68/// description:
69/// An array of content parts with a defined type. For tool messages,
70/// only type `text` is supported.
71/// title: Array of content parts
72/// items:
73/// $ref: "#/components/schemas/ChatCompletionRequestToolMessageContentPart"
74/// minItems: 1
75/// description: The contents of the tool message.
76/// ```
77#[derive(Debug, Serialize, Deserialize, PartialEq)]
78#[serde(untagged)]
79pub enum ChatCompletionRequestToolMessageContent {
80 Text(String),
81 Array(Vec<crate::ChatCompletionRequestToolMessageContentPart>),
82}
83
84#[test]
85fn chat_message_developer_message_content() {
86 assert_eq!(
87 serde_json::to_string(&ChatCompletionRequestToolMessage {
88 content: ChatCompletionRequestToolMessageContent::Array(vec![
89 crate::ChatCompletionRequestToolMessageContentPart::Text(
90 crate::ChatCompletionRequestMessageContentPartText {
91 text: "233".into(),
92 _type: "qw".into(),
93 }
94 ),
95 crate::ChatCompletionRequestToolMessageContentPart::Text(
96 crate::ChatCompletionRequestMessageContentPartText {
97 text: "emm".into(),
98 _type: "hk".into(),
99 }
100 ),
101 ]),
102 tool_call_id: "1228".into(),
103 })
104 .unwrap(),
105 r#"{"content":[{"text":"233","type":"qw"},{"text":"emm","type":"hk"}],"tool_call_id":"1228"}"#
106 );
107}