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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//! Raw API data structures
//!
//! This module provides the raw data structures that map directly to the DeepSeek API's JSON schema.
//! These types are intended for users who need precise control over request and response payloads.
//!
//! # Module layout
//!
//! - [`request`]
//! - [`response`]
//!
//! # Main types
//!
//! ## Request types
//!
//! - [`ChatCompletionRequest`]
//! - [`Message`]
//! - [`Model`]
//! - [`Tool`]
//! - [`ResponseFormat`]
//! - [`Thinking`]
//! - [`Stop`]
//! - [`StreamOptions`]
//!
//! ## Response types
//!
//! - [`ChatCompletionResponse`]
//! - [`ChatCompletionChunk`]
//! - [`Choice`]
//! - [`Usage`]
//!
//! # Use cases
//!
//! Use these raw structures when you need one of the following:
//!
//! 1. Full control over the API request payload (set every field explicitly).
//! 2. Advanced features such as tool/function calls or reasoning modes.
//! 3. Performance optimizations where avoiding builder overhead matters.
//! 4. Integration with existing code that expects direct Serde serialization/deserialization.
//!
//! # Examples
//!
//! The following examples illustrate common usage patterns with the raw types.
//!
//! ```rust
//! use ds_api::raw::{ChatCompletionRequest, Message, Model, Role};
//! use serde_json::json;
//!
//! fn main() {
//! // Example 1: Basic chat completion request
//! let basic_request = ChatCompletionRequest {
//! messages: vec![
//! Message::new(Role::System, "You are a helpful assistant."),
//! Message::new(Role::User, "What is the capital of France?"),
//! ],
//! model: Model::DeepseekChat,
//! max_tokens: Some(100),
//! temperature: Some(0.7),
//! stream: Some(false),
//! ..Default::default()
//! };
//!
//! println!("Basic request JSON:");
//! let json = serde_json::to_string_pretty(&basic_request).unwrap();
//! println!("{}\n", json);
//!
//! // Example 2: Request with a tool/function definition
//! use ds_api::raw::{Tool, ToolChoice, ToolChoiceType, ToolType, Function};
//!
//! let tool_request = ChatCompletionRequest {
//! messages: vec![Message::new(Role::User, "What's the weather like in Tokyo?")],
//! model: Model::DeepseekChat,
//! max_tokens: Some(200),
//! temperature: Some(0.8),
//! stream: Some(false),
//! tools: Some(vec![Tool {
//! r#type: ToolType::Function,
//! function: Function {
//! name: "get_weather".to_string(),
//! description: Some("Get the current weather for a location".to_string()),
//! parameters: json!({
//! "type": "object",
//! "properties": {
//! "location": {
//! "type": "string",
//! "description": "The city and country, e.g. Tokyo, Japan"
//! }
//! },
//! "required": ["location"]
//! }),
//! strict: Some(true),
//! },
//! }]),
//! tool_choice: Some(ToolChoice::String(ToolChoiceType::Auto)),
//! ..Default::default()
//! };
//!
//! println!("Tool request JSON:");
//! let json = serde_json::to_string_pretty(&tool_request).unwrap();
//! println!("{}\n", json);
//!
//! // Example 3: Using the Deepseek Reasoner model
//! use ds_api::raw::{Thinking, ThinkingType};
//!
//! let reasoner_request = ChatCompletionRequest {
//! messages: vec![
//! Message::new(Role::System, "You are a helpful assistant that explains your reasoning."),
//! Message::new(Role::User, "Solve this math problem: What is 15% of 200?"),
//! ],
//! model: Model::DeepseekReasoner,
//! thinking: Some(Thinking {
//! r#type: ThinkingType::Enabled,
//! }),
//! max_tokens: Some(150),
//! temperature: Some(0.3),
//! stream: Some(false),
//! ..Default::default()
//! };
//!
//! println!("Reasoner request JSON:");
//! let json = serde_json::to_string_pretty(&reasoner_request).unwrap();
//! println!("{}\n", json);
//!
//! // Example 4: JSON response format
//! use ds_api::raw::{ResponseFormat, ResponseFormatType};
//!
//! let json_request = ChatCompletionRequest {
//! messages: vec![
//! Message::new(Role::System, "You are a helpful assistant that always responds in valid JSON format."),
//! Message::new(Role::User, "Give me information about Paris in JSON format with fields: name, country, population, and landmarks."),
//! ],
//! model: Model::DeepseekChat,
//! max_tokens: Some(200),
//! temperature: Some(0.5),
//! stream: Some(false),
//! response_format: Some(ResponseFormat {
//! r#type: ResponseFormatType::JsonObject,
//! }),
//! ..Default::default()
//! };
//!
//! println!("JSON mode request:");
//! let json = serde_json::to_string_pretty(&json_request).unwrap();
//! println!("{}\n", json);
//! }
//! ```
//!
//! # Serialization / Deserialization
//!
//! All structs implement `Serialize` and `Deserialize` and can be used with `serde_json` directly:
//!
//! ```rust
//! use ds_api::raw::{ChatCompletionRequest, Message, Model, Role};
//!
//! let request = ChatCompletionRequest {
//! messages: vec![Message::new(Role::User, "Hello")],
//! model: Model::DeepseekChat,
//! ..Default::default()
//! };
//! let json_string = serde_json::to_string(&request).unwrap();
//! let parsed_request: ChatCompletionRequest = serde_json::from_str(&json_string).unwrap();
//! ```
//!
//! # Relationship to higher-level APIs
//!
//! The higher-level APIs (for example, the builder-style `Request` types) are implemented on top
//! of these raw structures and provide ergonomic builders and validation. If you prefer an easier
//! or more opinionated interface, consider using the higher-level APIs instead.
pub use *;
pub use *;