langfuse_rs/apis/
prompts_api.rs1use super::{configuration, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{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_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
76 if !status.is_client_error() && !status.is_server_error() {
77 let content = resp.text().await?;
78 serde_json::from_str(&content).map_err(Error::from)
79 } else {
80 let content = resp.text().await?;
81 let entity: Option<PromptsCreateError> = serde_json::from_str(&content).ok();
82 Err(Error::ResponseError(ResponseContent { status, content, entity }))
83 }
84}
85
86pub async fn prompts_get(
88 configuration: &configuration::Configuration,
89 prompt_name: &str,
90 version: Option<i32>,
91 label: Option<&str>,
92) -> Result<models::Prompt, Error<PromptsGetError>> {
93 let p_prompt_name = prompt_name;
95 let p_version = version;
96 let p_label = label;
97
98 let uri_str = format!(
99 "{}/api/public/v2/prompts/{promptName}",
100 configuration.base_path,
101 promptName = crate::apis::urlencode(p_prompt_name)
102 );
103 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
104
105 if let Some(ref param_value) = p_version {
106 req_builder = req_builder.query(&[("version", ¶m_value.to_string())]);
107 }
108 if let Some(ref param_value) = p_label {
109 req_builder = req_builder.query(&[("label", ¶m_value.to_string())]);
110 }
111 if let Some(ref user_agent) = configuration.user_agent {
112 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
113 }
114 if let Some(ref auth_conf) = configuration.basic_auth {
115 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
116 };
117
118 let req = req_builder.build()?;
119 let resp = configuration.client.execute(req).await?;
120
121 let status = resp.status();
122
123 if !status.is_client_error() && !status.is_server_error() {
124 let content = resp.text().await?;
125 serde_json::from_str(&content).map_err(Error::from)
126 } else {
127 let content = resp.text().await?;
128 let entity: Option<PromptsGetError> = serde_json::from_str(&content).ok();
129 Err(Error::ResponseError(ResponseContent { status, content, entity }))
130 }
131}
132
133pub async fn prompts_list(
135 configuration: &configuration::Configuration,
136 name: Option<&str>,
137 label: Option<&str>,
138 tag: Option<&str>,
139 page: Option<i32>,
140 limit: Option<i32>,
141 from_updated_at: Option<String>,
142 to_updated_at: Option<String>,
143) -> Result<models::PromptMetaListResponse, Error<PromptsListError>> {
144 let p_name = name;
146 let p_label = label;
147 let p_tag = tag;
148 let p_page = page;
149 let p_limit = limit;
150 let p_from_updated_at = from_updated_at;
151 let p_to_updated_at = to_updated_at;
152
153 let uri_str = format!("{}/api/public/v2/prompts", configuration.base_path);
154 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
155
156 if let Some(ref param_value) = p_name {
157 req_builder = req_builder.query(&[("name", ¶m_value.to_string())]);
158 }
159 if let Some(ref param_value) = p_label {
160 req_builder = req_builder.query(&[("label", ¶m_value.to_string())]);
161 }
162 if let Some(ref param_value) = p_tag {
163 req_builder = req_builder.query(&[("tag", ¶m_value.to_string())]);
164 }
165 if let Some(ref param_value) = p_page {
166 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
167 }
168 if let Some(ref param_value) = p_limit {
169 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
170 }
171 if let Some(ref param_value) = p_from_updated_at {
172 req_builder = req_builder.query(&[("fromUpdatedAt", ¶m_value.to_string())]);
173 }
174 if let Some(ref param_value) = p_to_updated_at {
175 req_builder = req_builder.query(&[("toUpdatedAt", ¶m_value.to_string())]);
176 }
177 if let Some(ref user_agent) = configuration.user_agent {
178 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
179 }
180 if let Some(ref auth_conf) = configuration.basic_auth {
181 req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
182 };
183
184 let req = req_builder.build()?;
185 let resp = configuration.client.execute(req).await?;
186
187 let status = resp.status();
188
189 if !status.is_client_error() && !status.is_server_error() {
190 let content = resp.text().await?;
191 serde_json::from_str(&content).map_err(Error::from)
192 } else {
193 let content = resp.text().await?;
194 let entity: Option<PromptsListError> = serde_json::from_str(&content).ok();
195 Err(Error::ResponseError(ResponseContent { status, content, entity }))
196 }
197}