Skip to main content

zai_rs/model/
chat_models.rs

1//! # AI Model Type Definitions
2//!
3//! Defines all available AI model types for the Zhipu AI API, together with
4//! their capability markers and message-type bindings.
5//!
6//! # Model Categories
7//!
8//! ## Text Models
9//!
10//! | Model | Struct | Thinking | ReasoningEffort | Async | ToolStream |
11//! |-------|--------|----------|-----------------|-------|------------|
12//! | glm-5.2 | [`GLM5_2`] | yes | yes | yes | yes |
13//! | glm-5.1 | [`GLM5_1`] | yes | no | yes | yes |
14//! | glm-5 | [`GLM5`] | yes | no | yes | yes |
15//! | glm-5-turbo | [`GLM5_turbo`] | yes | no | yes | yes |
16//! | glm-4.7 | [`GLM4_7`] | yes | no | yes | yes |
17//! | glm-4.7-flash | [`GLM4_7_flash`] | yes | no | yes | no |
18//! | glm-4.7-flashx | [`GLM4_7_flashx`] | yes | no | yes | no |
19//! | glm-4.6 | [`GLM4_6`] | yes | no | yes | yes |
20//! | glm-4.5 | [`GLM4_5`] | yes | no | yes | no |
21//! | glm-4.5-X | [`GLM4_5_x`] | yes | no | yes | no |
22//! | glm-4.5-flash | [`GLM4_5_flash`] | yes | no | yes | no |
23//! | glm-4.5-air | [`GLM4_5_air`] | yes | no | yes | no |
24//! | glm-4.5-airx | [`GLM4_5_airx`] | yes | no | yes | no |
25//!
26//! ## Vision Models
27//!
28//! | Model | Struct | Thinking | Message Type |
29//! |-------|--------|----------|--------------|
30//! | autoglm-phone | [`autoglm_phone`] | no | [`VisionMessage`](super::chat_message_types::VisionMessage) |
31//! | glm-4.6v | [`GLM4_6v`] | no | [`VisionMessage`] |
32//! | glm-4.6v-flash | [`GLM4_6v_flash`] | no | [`VisionMessage`] |
33//! | glm-4.6v-flashx | [`GLM4_6v_flashx`] | no | [`VisionMessage`] |
34//! | glm-4.5v | [`GLM4_5v`] | no | [`VisionMessage`] |
35//! | glm-5v-turbo | [`GLM5V_turbo`] | yes | [`VisionMessage`] |
36//!
37//! ## Voice Models
38//!
39//! | Model | Struct | Message Type |
40//! |-------|--------|--------------|
41//! | glm-4-voice | [`GLM4_voice`] | [`VoiceMessage`](super::chat_message_types::VoiceMessage) |
42//!
43//! # Usage
44//!
45//! ```rust,ignore
46//! use zai_rs::model::chat_models::*;
47//! use zai_rs::model::chat_message_types::TextMessage;
48//! use zai_rs::model::chat::data::ChatCompletion;
49//!
50//! let model = GLM5_2 {};
51//! let messages = TextMessage::user("Hello");
52//! let client = ChatCompletion::new(model, messages, api_key);
53//! ```
54//!
55//! # Defining New Models
56//!
57//! Use the [`define_model_type!`](crate::define_model_type) macro to create
58//! model structs, [`impl_message_binding!`](crate::impl_message_binding) to
59//! bind compatible message types, and
60//! [`impl_model_markers!`](crate::impl_model_markers) to declare capabilities.
61
62use super::traits::*;
63use crate::{
64    define_model_type, impl_message_binding, impl_model_markers,
65    model::chat_message_types::{TextMessage, VisionMessage, VoiceMessage},
66};
67
68// ============================================================================
69// Text Models
70// ============================================================================
71
72// GLM-5.2 — flagship model for the long-task era. Supports thinking mode and
73// the new `reasoning_effort` parameter for controlling reasoning depth.
74define_model_type!(GLM5_2, "glm-5.2");
75impl_message_binding!(GLM5_2, TextMessage);
76impl_model_markers!(GLM5_2: Chat, AsyncChat, ThinkEnable, ReasoningEffortEnable);
77impl ToolStreamEnable for GLM5_2 {}
78
79define_model_type!(GLM5_1, "glm-5.1");
80impl_message_binding!(GLM5_1, TextMessage);
81impl_model_markers!(GLM5_1: Chat, AsyncChat, ThinkEnable, ToolStreamEnable);
82
83define_model_type!(
84    #[allow(non_camel_case_types)]
85    GLM5_turbo,
86    "glm-5-turbo"
87);
88impl_message_binding!(GLM5_turbo, TextMessage);
89impl_model_markers!(GLM5_turbo: Chat, AsyncChat, ThinkEnable, ToolStreamEnable);
90
91define_model_type!(GLM5, "glm-5");
92impl_message_binding!(GLM5, TextMessage);
93impl_model_markers!(GLM5: Chat, AsyncChat, ThinkEnable, ToolStreamEnable);
94
95// GLM-5V-Turbo — multimodal coding base model (vision). Natively handles
96// image / video / text input; ideal for design-to-code and visual programming.
97// Supports thinking mode.
98// See <https://docs.bigmodel.cn/cn/guide/models/vlm/glm-5v-turbo>.
99define_model_type!(
100    #[allow(non_camel_case_types)]
101    GLM5V_turbo,
102    "glm-5v-turbo"
103);
104impl_message_binding!(GLM5V_turbo, VisionMessage);
105impl_model_markers!(GLM5V_turbo: Chat, AsyncChat, ThinkEnable);
106
107define_model_type!(GLM4_7, "glm-4.7");
108impl_message_binding!(GLM4_7, TextMessage);
109impl_model_markers!(GLM4_7: Chat, AsyncChat, ThinkEnable, ToolStreamEnable);
110
111define_model_type!(
112    #[allow(non_camel_case_types)]
113    GLM4_7_flash,
114    "glm-4.7-flash"
115);
116impl_message_binding!(GLM4_7_flash, TextMessage);
117impl_model_markers!(GLM4_7_flash: Chat, AsyncChat, ThinkEnable);
118
119define_model_type!(
120    #[allow(non_camel_case_types)]
121    GLM4_7_flashx,
122    "glm-4.7-flashx"
123);
124impl_message_binding!(GLM4_7_flashx, TextMessage);
125impl_model_markers!(GLM4_7_flashx: Chat, AsyncChat, ThinkEnable);
126
127define_model_type!(GLM4_6, "glm-4.6");
128impl_message_binding!(GLM4_6, TextMessage);
129impl_model_markers!(GLM4_6: Chat, AsyncChat, ThinkEnable);
130impl ToolStreamEnable for GLM4_6 {}
131
132define_model_type!(GLM4_5, "glm-4.5");
133impl_message_binding!(GLM4_5, TextMessage);
134impl_model_markers!(GLM4_5: Chat, AsyncChat, ThinkEnable);
135
136define_model_type!(
137    #[allow(non_camel_case_types)]
138    GLM4_5_x,
139    "glm-4.5-X"
140);
141impl_message_binding!(GLM4_5_x, TextMessage);
142impl_model_markers!(GLM4_5_x: Chat, AsyncChat, ThinkEnable);
143
144define_model_type!(
145    #[allow(non_camel_case_types)]
146    GLM4_5_flash,
147    "glm-4.5-flash"
148);
149impl_message_binding!(GLM4_5_flash, TextMessage);
150impl_model_markers!(GLM4_5_flash: Chat, AsyncChat, ThinkEnable);
151
152define_model_type!(
153    #[allow(non_camel_case_types)]
154    GLM4_5_air,
155    "glm-4.5-air"
156);
157impl_message_binding!(GLM4_5_air, TextMessage);
158impl_model_markers!(GLM4_5_air: Chat, AsyncChat, ThinkEnable);
159
160define_model_type!(
161    #[allow(non_camel_case_types)]
162    GLM4_5_airx,
163    "glm-4.5-airx"
164);
165impl_message_binding!(GLM4_5_airx, TextMessage);
166impl_model_markers!(GLM4_5_airx: Chat, AsyncChat, ThinkEnable);
167
168// ============================================================================
169// Multimodal Models - Vision
170// ============================================================================
171
172define_model_type!(
173    #[allow(non_camel_case_types)]
174    autoglm_phone,
175    "autoglm-phone"
176);
177impl_message_binding!(autoglm_phone, VisionMessage);
178impl_model_markers!(autoglm_phone: Chat, AsyncChat);
179
180define_model_type!(
181    #[allow(non_camel_case_types)]
182    GLM4_6v,
183    "glm-4.6v"
184);
185impl_message_binding!(GLM4_6v, VisionMessage);
186impl_model_markers!(GLM4_6v: Chat, AsyncChat);
187
188define_model_type!(
189    #[allow(non_camel_case_types)]
190    GLM4_6v_flash,
191    "glm-4.6v-flash"
192);
193impl_message_binding!(GLM4_6v_flash, VisionMessage);
194impl_model_markers!(GLM4_6v_flash: Chat, AsyncChat);
195
196define_model_type!(
197    #[allow(non_camel_case_types)]
198    GLM4_6v_flashx,
199    "glm-4.6v-flashx"
200);
201impl_message_binding!(GLM4_6v_flashx, VisionMessage);
202impl_model_markers!(GLM4_6v_flashx: Chat, AsyncChat);
203
204define_model_type!(
205    #[allow(non_camel_case_types)]
206    GLM4_5v,
207    "glm-4.5v"
208);
209impl_message_binding!(GLM4_5v, VisionMessage);
210impl_model_markers!(GLM4_5v: Chat, AsyncChat);
211
212// ============================================================================
213// Multimodal Models - Voice
214// ============================================================================
215
216define_model_type!(
217    #[allow(non_camel_case_types)]
218    GLM4_voice,
219    "glm-4-voice"
220);
221impl_message_binding!(GLM4_voice, VoiceMessage);
222impl_model_markers!(GLM4_voice: Chat, AsyncChat);
223
224// ============================================================================
225// Realtime Models (marker: crate::realtime::RealtimeModel)
226// ============================================================================
227
228// GLM-Realtime — the realtime (WebSocket) conversation model family. Used with
229// `crate::realtime`. The protocol does not transmit the model on the wire;
230// this id exists for type-safe session construction.
231define_model_type!(
232    #[allow(non_camel_case_types)]
233    GLM_realtime,
234    "glm-realtime"
235);
236impl_model_markers!(GLM_realtime: Chat, AsyncChat);
237
238// GLM-4.5 Voice — realtime voice-capable model id.
239define_model_type!(
240    #[allow(non_camel_case_types)]
241    GLM4_5_voice,
242    "glm-4.5-voice"
243);
244impl_model_markers!(GLM4_5_voice: Chat, AsyncChat);
245
246#[cfg(test)]
247mod tests {
248    use super::*;
249
250    #[test]
251    fn official_chat_model_names_match_snapshot() {
252        let models = [
253            String::from(GLM5_2 {}),
254            String::from(GLM5_1 {}),
255            String::from(GLM5_turbo {}),
256            String::from(GLM5 {}),
257            String::from(GLM4_7 {}),
258            String::from(GLM4_6 {}),
259            String::from(GLM4_5_air {}),
260            String::from(GLM4_5_airx {}),
261            String::from(GLM4_5_flash {}),
262        ];
263
264        assert_eq!(
265            models,
266            [
267                "glm-5.2",
268                "glm-5.1",
269                "glm-5-turbo",
270                "glm-5",
271                "glm-4.7",
272                "glm-4.6",
273                "glm-4.5-air",
274                "glm-4.5-airx",
275                "glm-4.5-flash",
276            ]
277        );
278    }
279}