mistral_openapi_client/apis/
classifiers_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ChatClassificationsV1ChatClassificationsPostError {
22 Status422(models::HttpValidationError),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum ChatModerationsV1ChatModerationsPostError {
30 Status422(models::HttpValidationError),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum ClassificationsV1ClassificationsPostError {
38 Status422(models::HttpValidationError),
39 UnknownValue(serde_json::Value),
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum ModerationsV1ModerationsPostError {
46 Status422(models::HttpValidationError),
47 UnknownValue(serde_json::Value),
48}
49
50
51pub async fn chat_classifications_v1_chat_classifications_post(configuration: &configuration::Configuration, chat_classification_request: models::ChatClassificationRequest) -> Result<models::ClassificationResponse, Error<ChatClassificationsV1ChatClassificationsPostError>> {
52 let p_body_chat_classification_request = chat_classification_request;
54
55 let uri_str = format!("{}/v1/chat/classifications", configuration.base_path);
56 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
57
58 if let Some(ref user_agent) = configuration.user_agent {
59 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
60 }
61 if let Some(ref token) = configuration.bearer_access_token {
62 req_builder = req_builder.bearer_auth(token.to_owned());
63 };
64 req_builder = req_builder.json(&p_body_chat_classification_request);
65
66 let req = req_builder.build()?;
67 let resp = configuration.client.execute(req).await?;
68
69 let status = resp.status();
70 let content_type = resp
71 .headers()
72 .get("content-type")
73 .and_then(|v| v.to_str().ok())
74 .unwrap_or("application/octet-stream");
75 let content_type = super::ContentType::from(content_type);
76
77 if !status.is_client_error() && !status.is_server_error() {
78 let content = resp.text().await?;
79 match content_type {
80 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
81 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClassificationResponse`"))),
82 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClassificationResponse`")))),
83 }
84 } else {
85 let content = resp.text().await?;
86 let entity: Option<ChatClassificationsV1ChatClassificationsPostError> = serde_json::from_str(&content).ok();
87 Err(Error::ResponseError(ResponseContent { status, content, entity }))
88 }
89}
90
91pub async fn chat_moderations_v1_chat_moderations_post(configuration: &configuration::Configuration, chat_moderation_request: models::ChatModerationRequest) -> Result<models::ModerationResponse, Error<ChatModerationsV1ChatModerationsPostError>> {
92 let p_body_chat_moderation_request = chat_moderation_request;
94
95 let uri_str = format!("{}/v1/chat/moderations", configuration.base_path);
96 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
97
98 if let Some(ref user_agent) = configuration.user_agent {
99 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
100 }
101 if let Some(ref token) = configuration.bearer_access_token {
102 req_builder = req_builder.bearer_auth(token.to_owned());
103 };
104 req_builder = req_builder.json(&p_body_chat_moderation_request);
105
106 let req = req_builder.build()?;
107 let resp = configuration.client.execute(req).await?;
108
109 let status = resp.status();
110 let content_type = resp
111 .headers()
112 .get("content-type")
113 .and_then(|v| v.to_str().ok())
114 .unwrap_or("application/octet-stream");
115 let content_type = super::ContentType::from(content_type);
116
117 if !status.is_client_error() && !status.is_server_error() {
118 let content = resp.text().await?;
119 match content_type {
120 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
121 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ModerationResponse`"))),
122 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ModerationResponse`")))),
123 }
124 } else {
125 let content = resp.text().await?;
126 let entity: Option<ChatModerationsV1ChatModerationsPostError> = serde_json::from_str(&content).ok();
127 Err(Error::ResponseError(ResponseContent { status, content, entity }))
128 }
129}
130
131pub async fn classifications_v1_classifications_post(configuration: &configuration::Configuration, classification_request: models::ClassificationRequest) -> Result<models::ClassificationResponse, Error<ClassificationsV1ClassificationsPostError>> {
132 let p_body_classification_request = classification_request;
134
135 let uri_str = format!("{}/v1/classifications", configuration.base_path);
136 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
137
138 if let Some(ref user_agent) = configuration.user_agent {
139 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
140 }
141 if let Some(ref token) = configuration.bearer_access_token {
142 req_builder = req_builder.bearer_auth(token.to_owned());
143 };
144 req_builder = req_builder.json(&p_body_classification_request);
145
146 let req = req_builder.build()?;
147 let resp = configuration.client.execute(req).await?;
148
149 let status = resp.status();
150 let content_type = resp
151 .headers()
152 .get("content-type")
153 .and_then(|v| v.to_str().ok())
154 .unwrap_or("application/octet-stream");
155 let content_type = super::ContentType::from(content_type);
156
157 if !status.is_client_error() && !status.is_server_error() {
158 let content = resp.text().await?;
159 match content_type {
160 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
161 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClassificationResponse`"))),
162 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClassificationResponse`")))),
163 }
164 } else {
165 let content = resp.text().await?;
166 let entity: Option<ClassificationsV1ClassificationsPostError> = serde_json::from_str(&content).ok();
167 Err(Error::ResponseError(ResponseContent { status, content, entity }))
168 }
169}
170
171pub async fn moderations_v1_moderations_post(configuration: &configuration::Configuration, classification_request: models::ClassificationRequest) -> Result<models::ModerationResponse, Error<ModerationsV1ModerationsPostError>> {
172 let p_body_classification_request = classification_request;
174
175 let uri_str = format!("{}/v1/moderations", configuration.base_path);
176 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
177
178 if let Some(ref user_agent) = configuration.user_agent {
179 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
180 }
181 if let Some(ref token) = configuration.bearer_access_token {
182 req_builder = req_builder.bearer_auth(token.to_owned());
183 };
184 req_builder = req_builder.json(&p_body_classification_request);
185
186 let req = req_builder.build()?;
187 let resp = configuration.client.execute(req).await?;
188
189 let status = resp.status();
190 let content_type = resp
191 .headers()
192 .get("content-type")
193 .and_then(|v| v.to_str().ok())
194 .unwrap_or("application/octet-stream");
195 let content_type = super::ContentType::from(content_type);
196
197 if !status.is_client_error() && !status.is_server_error() {
198 let content = resp.text().await?;
199 match content_type {
200 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
201 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ModerationResponse`"))),
202 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ModerationResponse`")))),
203 }
204 } else {
205 let content = resp.text().await?;
206 let entity: Option<ModerationsV1ModerationsPostError> = serde_json::from_str(&content).ok();
207 Err(Error::ResponseError(ResponseContent { status, content, entity }))
208 }
209}
210