async_llm/types/
chat_choice.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
4pub struct ChatChoice {
5    /// The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence, `length` if the maximum number of tokens specified in the request was reached, `content_filter` if content was omitted due to a flag from our content filters, `tool_calls` if the model called a tool, or `function_call` (deprecated) if the model called a function.
6    pub finish_reason: Option<String>,
7
8    /// The index of the choice in the list of choices.
9    pub index: Option<u32>,
10
11    /// A chat completion message generated by the model.
12    pub message: Option<ChatChoiceMessage>,
13
14    /// Log probability information for the choice.
15    pub logprobs: Option<ChatLogprobs>,
16}
17
18#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
19pub struct ChatChoiceStream {
20    /// The reason the model stopped generating tokens. This will be `stop` if the model hit a natural stop point or a provided stop sequence, `length` if the maximum number of tokens specified in the request was reached, `content_filter` if content was omitted due to a flag from our content filters, `tool_calls` if the model called a tool, or `function_call` (deprecated) if the model called a function.
21    pub finish_reason: Option<String>,
22
23    /// The index of the choice in the list of choices.
24    pub index: Option<u32>,
25
26    /// A chat completion delta generated by streamed model responses.
27    pub delta: Option<ChatChoiceMessageStream>,
28
29    /// Log probability information for the choice.
30    pub logprobs: Option<ChatLogprobs>,
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
34pub struct ChatLogprobs {
35    /// A list of message content tokens with log probability information.
36    pub content: Option<Vec<ChatLogprobsMessage>>,
37
38    /// A list of message refusal tokens with log probability information.
39    pub refusal: Option<Vec<ChatLogprobsMessage>>,
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
43pub struct ChatLogprobsMessage {
44    /// The token
45    pub token: Option<String>,
46    /// The log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value -9999.0 is used to signify that the token is very unlikely.
47    pub logprob: Option<f32>,
48    /// A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be null if there is no bytes representation for the token.
49    pub bytes: Option<Vec<u8>>,
50    /// List of the most likely tokens and their log probability, at this token position. In rare cases, there may be fewer than the number of requested top_logprobs returned.
51    pub top_logprobs: Option<Vec<ChatLogprobsLogProb>>,
52}
53
54#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
55pub struct ChatLogprobsLogProb {
56    /// The token
57    pub token: Option<String>,
58    /// The log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value -9999.0 is used to signify that the token is very unlikely.
59    pub logprob: Option<f32>,
60    /// A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be null if there is no bytes representation for the token.
61    pub bytes: Option<Vec<u8>>,
62}
63
64#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
65pub struct ChatChoiceMessage {
66    /// The contents of the message.
67    pub content: Option<String>,
68
69    /// The refusal message generated by the model.
70    pub refusal: Option<String>,
71
72    /// The tool calls generated by the model, such as function calls.
73    pub tool_calls: Option<Vec<ChatMessageToolCall>>,
74
75    /// The role of the author of this message.
76    pub role: Option<String>,
77
78    /// Deprecated and replaced by tool_calls. The name and arguments of a function that should be called, as generated by the model.
79    pub function_call: Option<ChatMessageFunctionCall>,
80
81    /// If the audio output modality is requested, this object contains data about the audio response from the model. [Learn more](https://platform.openai.com/docs/guides/audio).
82    pub audio: Option<ChatMessageAudio>,
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
86pub struct ChatChoiceMessageStream {
87    /// The contents of the message.
88    pub content: Option<String>,
89
90    /// The refusal message generated by the model.
91    pub refusal: Option<String>,
92
93    /// The tool calls generated by the model, such as function calls.
94    pub tool_calls: Option<Vec<ChatMessageToolCall>>,
95
96    /// The role of the author of this message.
97    pub role: Option<String>,
98
99    /// Deprecated and replaced by tool_calls. The name and arguments of a function that should be called, as generated by the model.
100    pub function_call: Option<ChatMessageFunctionCall>,
101}
102
103#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
104pub struct ChatMessageToolCall {
105    /// The ID of the tool call.
106    pub id: Option<String>,
107    /// The type of the tool. Currently, only function is supported.
108    pub r#type: Option<String>,
109
110    /// The function that the model called.
111    pub function: Option<ChatMessageFunctionCall>,
112}
113
114#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
115pub struct ChatMessageFunctionCall {
116    /// The name of the function to call.
117    pub name: Option<String>,
118
119    /// The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function.
120    pub arguments: Option<String>,
121}
122
123#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
124pub struct ChatMessageAudio {
125    /// Unique identifier for this audio response.
126    pub id: Option<String>,
127
128    /// The Unix timestamp (in seconds) for when this audio response will no longer be accessible on the server for use in multi-turn conversations.
129    pub expires_at: Option<u32>,
130
131    /// Base64 encoded audio bytes generated by the model, in the format specified in the request.
132    pub data: Option<String>,
133
134    /// Transcript of the audio generated by the model.
135    pub transcript: Option<String>,
136}