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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//! OpenAI Chat Completions API Response Types
//!
//! This module provides data structures for deserializing responses from the
//! OpenAI Chat Completions API. It includes all the necessary types to handle
//! complete API responses, including messages, choices, tool calls, log probabilities,
//! and usage statistics.
//!
//! # Examples
//!
//! ```rust,no_run
//! use serde_json;
//! use openai_tools::chat::response::Response;
//!
//! // Deserialize a simple chat response
//! let json = r#"{
//! "id": "chatcmpl-123",
//! "object": "chat.completion",
//! "created": 1677652288,
//! "model": "gpt-3.5-turbo-0613",
//! "choices": [{
//! "index": 0,
//! "message": {
//! "role": "assistant",
//! "content": "Hello! How can I help you today?"
//! },
//! "finish_reason": "stop"
//! }],
//! "usage": {
//! "prompt_tokens": 12,
//! "completion_tokens": 8,
//! "total_tokens": 20
//! }
//! }"#;
//!
//! let response: Response = serde_json::from_str(json).unwrap();
//! let text = response.choices[0].message.content.as_ref().unwrap().text.clone().unwrap();
//! assert_eq!(text, "Hello! How can I help you today?");
//! ```
//!
//! # Tool Calls
//!
//! When the model makes function calls, the response will include tool calls:
//!
//! ```rust,no_run
//! # use serde_json;
//! # use openai_tools::chat::response::Response;
//! let json_with_tools = r#"{
//! "id": "chatcmpl-456",
//! "object": "chat.completion",
//! "created": 1677652288,
//! "model": "gpt-3.5-turbo-0613",
//! "choices": [{
//! "index": 0,
//! "message": {
//! "role": "assistant",
//! "content": null,
//! "tool_calls": [{
//! "id": "call_abc123",
//! "type": "function",
//! "function": {
//! "name": "get_weather",
//! "arguments": "{\"location\": \"Tokyo\"}"
//! }
//! }]
//! },
//! "finish_reason": "tool_calls"
//! }],
//! "usage": {
//! "prompt_tokens": 25,
//! "completion_tokens": 15,
//! "total_tokens": 40
//! }
//! }"#;
//!
//! let response: Response = serde_json::from_str(json_with_tools).unwrap();
//! let tool_calls = response.choices[0].message.tool_calls.as_ref().unwrap();
//! assert_eq!(tool_calls[0].function.name, "get_weather");
//! ```
use crate;
use str;
use ;
/// Top log probability item for a token
///
/// Contains information about a high-probability token alternative.
/// Log probability item for a token
///
/// Contains detailed probability information for a single token,
/// including alternatives.
/// Log probabilities container
///
/// Contains log probability information for all tokens in the response.
/// Choice structure representing a single response option
///
/// Each choice represents one possible completion generated by the model.
/// When `n > 1` is specified in the request, multiple choices may be returned.
/// Complete response structure from OpenAI Chat Completions API
///
/// This structure contains all information returned by the OpenAI API,
/// including generated choices, usage statistics, and metadata.