langfuse_client/apis/
prompts_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 PromptsCreateError {
22 Status400(serde_json::Value),
23 Status401(serde_json::Value),
24 Status403(serde_json::Value),
25 Status404(serde_json::Value),
26 Status405(serde_json::Value),
27 UnknownValue(serde_json::Value),
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum PromptsGetError {
34 Status400(serde_json::Value),
35 Status401(serde_json::Value),
36 Status403(serde_json::Value),
37 Status404(serde_json::Value),
38 Status405(serde_json::Value),
39 UnknownValue(serde_json::Value),
40}
41
42#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum PromptsListError {
46 Status400(serde_json::Value),
47 Status401(serde_json::Value),
48 Status403(serde_json::Value),
49 Status404(serde_json::Value),
50 Status405(serde_json::Value),
51 UnknownValue(serde_json::Value),
52}
53
54
55pub async fn prompts_create(configuration: &configuration::Configuration, create_prompt_request: models::CreatePromptRequest) -> Result<models::Prompt, Error<PromptsCreateError>> {
57 let p_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.client.request(reqwest::Method::POST, &uri_str);
62
63 if let Some(ref user_agent) = configuration.user_agent {
64 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
65 }
66 if let Some(ref auth_conf) = configuration.basic_auth {
67 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
68 };
69 req_builder = req_builder.json(&p_create_prompt_request);
70
71 let req = req_builder.build()?;
72 let resp = configuration.client.execute(req).await?;
73
74 let status = resp.status();
75 let content_type = resp
76 .headers()
77 .get("content-type")
78 .and_then(|v| v.to_str().ok())
79 .unwrap_or("application/octet-stream");
80 let content_type = super::ContentType::from(content_type);
81
82 if !status.is_client_error() && !status.is_server_error() {
83 let content = resp.text().await?;
84 match content_type {
85 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
86 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Prompt`"))),
87 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`")))),
88 }
89 } else {
90 let content = resp.text().await?;
91 let entity: Option<PromptsCreateError> = serde_json::from_str(&content).ok();
92 Err(Error::ResponseError(ResponseContent { status, content, entity }))
93 }
94}
95
96pub async fn prompts_get(configuration: &configuration::Configuration, prompt_name: &str, version: Option<i32>, label: Option<&str>) -> Result<models::Prompt, Error<PromptsGetError>> {
98 let p_prompt_name = prompt_name;
100 let p_version = version;
101 let p_label = label;
102
103 let uri_str = format!("{}/api/public/v2/prompts/{promptName}", configuration.base_path, promptName=crate::apis::urlencode(p_prompt_name));
104 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
105
106 if let Some(ref param_value) = p_version {
107 req_builder = req_builder.query(&[("version", ¶m_value.to_string())]);
108 }
109 if let Some(ref param_value) = p_label {
110 req_builder = req_builder.query(&[("label", ¶m_value.to_string())]);
111 }
112 if let Some(ref user_agent) = configuration.user_agent {
113 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
114 }
115 if let Some(ref auth_conf) = configuration.basic_auth {
116 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
117 };
118
119 let req = req_builder.build()?;
120 let resp = configuration.client.execute(req).await?;
121
122 let status = resp.status();
123 let content_type = resp
124 .headers()
125 .get("content-type")
126 .and_then(|v| v.to_str().ok())
127 .unwrap_or("application/octet-stream");
128 let content_type = super::ContentType::from(content_type);
129
130 if !status.is_client_error() && !status.is_server_error() {
131 let content = resp.text().await?;
132 match content_type {
133 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
134 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Prompt`"))),
135 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`")))),
136 }
137 } else {
138 let content = resp.text().await?;
139 let entity: Option<PromptsGetError> = serde_json::from_str(&content).ok();
140 Err(Error::ResponseError(ResponseContent { status, content, entity }))
141 }
142}
143
144pub async fn prompts_list(configuration: &configuration::Configuration, name: Option<&str>, label: Option<&str>, tag: Option<&str>, page: Option<i32>, limit: Option<i32>, from_updated_at: Option<String>, to_updated_at: Option<String>) -> Result<models::PromptMetaListResponse, Error<PromptsListError>> {
146 let p_name = name;
148 let p_label = label;
149 let p_tag = tag;
150 let p_page = page;
151 let p_limit = limit;
152 let p_from_updated_at = from_updated_at;
153 let p_to_updated_at = to_updated_at;
154
155 let uri_str = format!("{}/api/public/v2/prompts", configuration.base_path);
156 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
157
158 if let Some(ref param_value) = p_name {
159 req_builder = req_builder.query(&[("name", ¶m_value.to_string())]);
160 }
161 if let Some(ref param_value) = p_label {
162 req_builder = req_builder.query(&[("label", ¶m_value.to_string())]);
163 }
164 if let Some(ref param_value) = p_tag {
165 req_builder = req_builder.query(&[("tag", ¶m_value.to_string())]);
166 }
167 if let Some(ref param_value) = p_page {
168 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
169 }
170 if let Some(ref param_value) = p_limit {
171 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
172 }
173 if let Some(ref param_value) = p_from_updated_at {
174 req_builder = req_builder.query(&[("fromUpdatedAt", ¶m_value.to_string())]);
175 }
176 if let Some(ref param_value) = p_to_updated_at {
177 req_builder = req_builder.query(&[("toUpdatedAt", ¶m_value.to_string())]);
178 }
179 if let Some(ref user_agent) = configuration.user_agent {
180 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
181 }
182 if let Some(ref auth_conf) = configuration.basic_auth {
183 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
184 };
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::PromptMetaListResponse`"))),
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::PromptMetaListResponse`")))),
203 }
204 } else {
205 let content = resp.text().await?;
206 let entity: Option<PromptsListError> = serde_json::from_str(&content).ok();
207 Err(Error::ResponseError(ResponseContent { status, content, entity }))
208 }
209}
210