langfuse_client_base/apis/
prompts_api.rs1use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum PromptsCreateError {
20 Status400(serde_json::Value),
21 Status401(serde_json::Value),
22 Status403(serde_json::Value),
23 Status404(serde_json::Value),
24 Status405(serde_json::Value),
25 UnknownValue(serde_json::Value),
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum PromptsGetError {
32 Status400(serde_json::Value),
33 Status401(serde_json::Value),
34 Status403(serde_json::Value),
35 Status404(serde_json::Value),
36 Status405(serde_json::Value),
37 UnknownValue(serde_json::Value),
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum PromptsListError {
44 Status400(serde_json::Value),
45 Status401(serde_json::Value),
46 Status403(serde_json::Value),
47 Status404(serde_json::Value),
48 Status405(serde_json::Value),
49 UnknownValue(serde_json::Value),
50}
51
52pub async fn prompts_create(
54 configuration: &configuration::Configuration,
55 create_prompt_request: models::CreatePromptRequest,
56) -> Result<models::Prompt, Error<PromptsCreateError>> {
57 let p_body_create_prompt_request = create_prompt_request;
59
60 let uri_str = format!("{}/api/public/v2/prompts", configuration.base_path);
61 let mut req_builder = configuration
62 .client
63 .request(reqwest::Method::POST, &uri_str);
64
65 if let Some(ref user_agent) = configuration.user_agent {
66 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
67 }
68 if let Some(ref auth_conf) = configuration.basic_auth {
69 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
70 };
71 req_builder = req_builder.json(&p_body_create_prompt_request);
72
73 let req = req_builder.build()?;
74 let resp = configuration.client.execute(req).await?;
75
76 let status = resp.status();
77 let content_type = resp
78 .headers()
79 .get("content-type")
80 .and_then(|v| v.to_str().ok())
81 .unwrap_or("application/octet-stream");
82 let content_type = super::ContentType::from(content_type);
83
84 if !status.is_client_error() && !status.is_server_error() {
85 let content = resp.text().await?;
86 match content_type {
87 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
88 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Prompt`"))),
89 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::Prompt`")))),
90 }
91 } else {
92 let content = resp.text().await?;
93 let entity: Option<PromptsCreateError> = serde_json::from_str(&content).ok();
94 Err(Error::ResponseError(ResponseContent {
95 status,
96 content,
97 entity,
98 }))
99 }
100}
101
102pub async fn prompts_get(
104 configuration: &configuration::Configuration,
105 prompt_name: &str,
106 version: Option<i32>,
107 label: Option<&str>,
108) -> Result<models::Prompt, Error<PromptsGetError>> {
109 let p_path_prompt_name = prompt_name;
111 let p_query_version = version;
112 let p_query_label = label;
113
114 let uri_str = format!(
115 "{}/api/public/v2/prompts/{promptName}",
116 configuration.base_path,
117 promptName = crate::apis::urlencode(p_path_prompt_name)
118 );
119 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
120
121 if let Some(ref param_value) = p_query_version {
122 req_builder = req_builder.query(&[("version", ¶m_value.to_string())]);
123 }
124 if let Some(ref param_value) = p_query_label {
125 req_builder = req_builder.query(&[("label", ¶m_value.to_string())]);
126 }
127 if let Some(ref user_agent) = configuration.user_agent {
128 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
129 }
130 if let Some(ref auth_conf) = configuration.basic_auth {
131 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
132 };
133
134 let req = req_builder.build()?;
135 let resp = configuration.client.execute(req).await?;
136
137 let status = resp.status();
138 let content_type = resp
139 .headers()
140 .get("content-type")
141 .and_then(|v| v.to_str().ok())
142 .unwrap_or("application/octet-stream");
143 let content_type = super::ContentType::from(content_type);
144
145 if !status.is_client_error() && !status.is_server_error() {
146 let content = resp.text().await?;
147 match content_type {
148 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
149 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Prompt`"))),
150 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::Prompt`")))),
151 }
152 } else {
153 let content = resp.text().await?;
154 let entity: Option<PromptsGetError> = serde_json::from_str(&content).ok();
155 Err(Error::ResponseError(ResponseContent {
156 status,
157 content,
158 entity,
159 }))
160 }
161}
162
163pub async fn prompts_list(
165 configuration: &configuration::Configuration,
166 name: Option<&str>,
167 label: Option<&str>,
168 tag: Option<&str>,
169 page: Option<i32>,
170 limit: Option<i32>,
171 from_updated_at: Option<String>,
172 to_updated_at: Option<String>,
173) -> Result<models::PromptMetaListResponse, Error<PromptsListError>> {
174 let p_query_name = name;
176 let p_query_label = label;
177 let p_query_tag = tag;
178 let p_query_page = page;
179 let p_query_limit = limit;
180 let p_query_from_updated_at = from_updated_at;
181 let p_query_to_updated_at = to_updated_at;
182
183 let uri_str = format!("{}/api/public/v2/prompts", configuration.base_path);
184 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
185
186 if let Some(ref param_value) = p_query_name {
187 req_builder = req_builder.query(&[("name", ¶m_value.to_string())]);
188 }
189 if let Some(ref param_value) = p_query_label {
190 req_builder = req_builder.query(&[("label", ¶m_value.to_string())]);
191 }
192 if let Some(ref param_value) = p_query_tag {
193 req_builder = req_builder.query(&[("tag", ¶m_value.to_string())]);
194 }
195 if let Some(ref param_value) = p_query_page {
196 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
197 }
198 if let Some(ref param_value) = p_query_limit {
199 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
200 }
201 if let Some(ref param_value) = p_query_from_updated_at {
202 req_builder = req_builder.query(&[("fromUpdatedAt", ¶m_value.to_string())]);
203 }
204 if let Some(ref param_value) = p_query_to_updated_at {
205 req_builder = req_builder.query(&[("toUpdatedAt", ¶m_value.to_string())]);
206 }
207 if let Some(ref user_agent) = configuration.user_agent {
208 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
209 }
210 if let Some(ref auth_conf) = configuration.basic_auth {
211 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
212 };
213
214 let req = req_builder.build()?;
215 let resp = configuration.client.execute(req).await?;
216
217 let status = resp.status();
218 let content_type = resp
219 .headers()
220 .get("content-type")
221 .and_then(|v| v.to_str().ok())
222 .unwrap_or("application/octet-stream");
223 let content_type = super::ContentType::from(content_type);
224
225 if !status.is_client_error() && !status.is_server_error() {
226 let content = resp.text().await?;
227 match content_type {
228 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
229 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PromptMetaListResponse`"))),
230 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::PromptMetaListResponse`")))),
231 }
232 } else {
233 let content = resp.text().await?;
234 let entity: Option<PromptsListError> = serde_json::from_str(&content).ok();
235 Err(Error::ResponseError(ResponseContent {
236 status,
237 content,
238 entity,
239 }))
240 }
241}