1use 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 DeletePromptByNameError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetPromptError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetPromptByNameError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetPromptCatalogError {
43 UnknownValue(serde_json::Value),
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetPromptMetricsError {
50 UnknownValue(serde_json::Value),
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum PostPromptError {
57 UnknownValue(serde_json::Value),
58}
59
60
61pub async fn delete_prompt_by_name(configuration: &configuration::Configuration, name: &str) -> Result<(), Error<DeletePromptByNameError>> {
63 let p_name = name;
65
66 let uri_str = format!("{}/v1/prompt/{name}", configuration.base_path, name=crate::apis::urlencode(p_name));
67 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
68
69 if let Some(ref user_agent) = configuration.user_agent {
70 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
71 }
72 if let Some(ref token) = configuration.bearer_access_token {
73 req_builder = req_builder.bearer_auth(token.to_owned());
74 };
75
76 let req = req_builder.build()?;
77 let resp = configuration.client.execute(req).await?;
78
79 let status = resp.status();
80
81 if !status.is_client_error() && !status.is_server_error() {
82 Ok(())
83 } else {
84 let content = resp.text().await?;
85 let entity: Option<DeletePromptByNameError> = serde_json::from_str(&content).ok();
86 Err(Error::ResponseError(ResponseContent { status, content, entity }))
87 }
88}
89
90pub async fn get_prompt(configuration: &configuration::Configuration, ) -> Result<models::PromptList, Error<GetPromptError>> {
92
93 let uri_str = format!("{}/v1/prompt", configuration.base_path);
94 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
95
96 if let Some(ref user_agent) = configuration.user_agent {
97 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
98 }
99 if let Some(ref token) = configuration.bearer_access_token {
100 req_builder = req_builder.bearer_auth(token.to_owned());
101 };
102
103 let req = req_builder.build()?;
104 let resp = configuration.client.execute(req).await?;
105
106 let status = resp.status();
107 let content_type = resp
108 .headers()
109 .get("content-type")
110 .and_then(|v| v.to_str().ok())
111 .unwrap_or("application/octet-stream");
112 let content_type = super::ContentType::from(content_type);
113
114 if !status.is_client_error() && !status.is_server_error() {
115 let content = resp.text().await?;
116 match content_type {
117 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
118 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PromptList`"))),
119 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::PromptList`")))),
120 }
121 } else {
122 let content = resp.text().await?;
123 let entity: Option<GetPromptError> = serde_json::from_str(&content).ok();
124 Err(Error::ResponseError(ResponseContent { status, content, entity }))
125 }
126}
127
128pub async fn get_prompt_by_name(configuration: &configuration::Configuration, name: &str) -> Result<models::PromptDetail, Error<GetPromptByNameError>> {
130 let p_name = name;
132
133 let uri_str = format!("{}/v1/prompt/{name}", configuration.base_path, name=crate::apis::urlencode(p_name));
134 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
135
136 if let Some(ref user_agent) = configuration.user_agent {
137 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
138 }
139 if let Some(ref token) = configuration.bearer_access_token {
140 req_builder = req_builder.bearer_auth(token.to_owned());
141 };
142
143 let req = req_builder.build()?;
144 let resp = configuration.client.execute(req).await?;
145
146 let status = resp.status();
147 let content_type = resp
148 .headers()
149 .get("content-type")
150 .and_then(|v| v.to_str().ok())
151 .unwrap_or("application/octet-stream");
152 let content_type = super::ContentType::from(content_type);
153
154 if !status.is_client_error() && !status.is_server_error() {
155 let content = resp.text().await?;
156 match content_type {
157 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
158 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PromptDetail`"))),
159 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::PromptDetail`")))),
160 }
161 } else {
162 let content = resp.text().await?;
163 let entity: Option<GetPromptByNameError> = serde_json::from_str(&content).ok();
164 Err(Error::ResponseError(ResponseContent { status, content, entity }))
165 }
166}
167
168pub async fn get_prompt_catalog(configuration: &configuration::Configuration, ) -> Result<models::CatalogList, Error<GetPromptCatalogError>> {
170
171 let uri_str = format!("{}/v1/prompt/catalog", configuration.base_path);
172 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
173
174 if let Some(ref user_agent) = configuration.user_agent {
175 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
176 }
177 if let Some(ref token) = configuration.bearer_access_token {
178 req_builder = req_builder.bearer_auth(token.to_owned());
179 };
180
181 let req = req_builder.build()?;
182 let resp = configuration.client.execute(req).await?;
183
184 let status = resp.status();
185 let content_type = resp
186 .headers()
187 .get("content-type")
188 .and_then(|v| v.to_str().ok())
189 .unwrap_or("application/octet-stream");
190 let content_type = super::ContentType::from(content_type);
191
192 if !status.is_client_error() && !status.is_server_error() {
193 let content = resp.text().await?;
194 match content_type {
195 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
196 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CatalogList`"))),
197 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::CatalogList`")))),
198 }
199 } else {
200 let content = resp.text().await?;
201 let entity: Option<GetPromptCatalogError> = serde_json::from_str(&content).ok();
202 Err(Error::ResponseError(ResponseContent { status, content, entity }))
203 }
204}
205
206pub async fn get_prompt_metrics(configuration: &configuration::Configuration, ) -> Result<models::MetricList, Error<GetPromptMetricsError>> {
208
209 let uri_str = format!("{}/v1/prompt/metrics", configuration.base_path);
210 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
211
212 if let Some(ref user_agent) = configuration.user_agent {
213 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
214 }
215 if let Some(ref token) = configuration.bearer_access_token {
216 req_builder = req_builder.bearer_auth(token.to_owned());
217 };
218
219 let req = req_builder.build()?;
220 let resp = configuration.client.execute(req).await?;
221
222 let status = resp.status();
223 let content_type = resp
224 .headers()
225 .get("content-type")
226 .and_then(|v| v.to_str().ok())
227 .unwrap_or("application/octet-stream");
228 let content_type = super::ContentType::from(content_type);
229
230 if !status.is_client_error() && !status.is_server_error() {
231 let content = resp.text().await?;
232 match content_type {
233 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
234 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MetricList`"))),
235 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::MetricList`")))),
236 }
237 } else {
238 let content = resp.text().await?;
239 let entity: Option<GetPromptMetricsError> = serde_json::from_str(&content).ok();
240 Err(Error::ResponseError(ResponseContent { status, content, entity }))
241 }
242}
243
244pub async fn post_prompt(configuration: &configuration::Configuration, prompt_req: models::PromptReq) -> Result<models::PromptDetail, Error<PostPromptError>> {
246 let p_prompt_req = prompt_req;
248
249 let uri_str = format!("{}/v1/prompt", configuration.base_path);
250 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
251
252 if let Some(ref user_agent) = configuration.user_agent {
253 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
254 }
255 if let Some(ref token) = configuration.bearer_access_token {
256 req_builder = req_builder.bearer_auth(token.to_owned());
257 };
258 req_builder = req_builder.json(&p_prompt_req);
259
260 let req = req_builder.build()?;
261 let resp = configuration.client.execute(req).await?;
262
263 let status = resp.status();
264 let content_type = resp
265 .headers()
266 .get("content-type")
267 .and_then(|v| v.to_str().ok())
268 .unwrap_or("application/octet-stream");
269 let content_type = super::ContentType::from(content_type);
270
271 if !status.is_client_error() && !status.is_server_error() {
272 let content = resp.text().await?;
273 match content_type {
274 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
275 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PromptDetail`"))),
276 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::PromptDetail`")))),
277 }
278 } else {
279 let content = resp.text().await?;
280 let entity: Option<PostPromptError> = serde_json::from_str(&content).ok();
281 Err(Error::ResponseError(ResponseContent { status, content, entity }))
282 }
283}
284