Skip to main content

hanzo_client/apis/
prompt_api.rs

1/*
2 * Hanzo Cloud API
3 *
4 * The Hanzo Cloud API as a customer calls it: every operation under /v1/ except the operator's admin product, relay routes, legacy spellings and capabilities still reached by flag. Tagged by product: the first path segment after /v1/.
5 *
6 * The version of the OpenAPI document: v1
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`delete_prompt_by_name`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeletePromptByNameError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`get_prompt`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetPromptError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_prompt_by_name`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetPromptByNameError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`get_prompt_catalog`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum GetPromptCatalogError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`get_prompt_metrics`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum GetPromptMetricsError {
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`post_prompt`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum PostPromptError {
57    UnknownValue(serde_json::Value),
58}
59
60
61/// Delete removes one of the caller org's prompts and every version of it, answering 204. It is scoped to the caller's org, so a name another tenant owns is the same 404 an unknown name gives. There is no undo: the version history goes with it.
62pub async fn delete_prompt_by_name(configuration: &configuration::Configuration, name: &str) -> Result<(), Error<DeletePromptByNameError>> {
63    // add a prefix to parameters to efficiently prevent name collisions
64    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
90/// List returns the caller org's prompt library as one row per prompt: its name, type, every version number it has, its taxonomy and when it last changed. The template bodies are deliberately absent — fetch one prompt to read its text.
91pub 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
128/// Get returns one of the caller org's prompts: its CURRENT template text plus the metadata of every version it has had. The history carries version numbers, types and timestamps only — not each version's body — so a long history cannot inflate this response. A name the caller's org does not own is 404, whoever owns it.
129pub async fn get_prompt_by_name(configuration: &configuration::Configuration, name: &str) -> Result<models::PromptDetail, Error<GetPromptByNameError>> {
130    // add a prefix to parameters to efficiently prevent name collisions
131    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
168/// Catalog returns the read-only starter prompt library shipped with the binary — reference content every tenant sees the same, NOT the caller's own prompts and never mixed into them. An org's library stays honestly empty until someone explicitly imports a starter, which is an ordinary POST /v1/prompt. Entries that would fail the create guards are dropped, so everything offered here can actually be imported.
169pub 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
206/// Metrics returns real per-prompt statistics for the caller's org: how many versions each prompt has, which one is current, and when it was created and last changed. Every number is counted from the store — nothing here is estimated or fabricated.
207pub 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
244/// Create records a prompt for the caller's org and answers 201 with it. A name the org already uses is NOT an error and NOT an overwrite: it appends a new version, so the library keeps real, inspectable history and the response carries the whole version list. The name is also the URL segment the prompt is fetched by, which is why its shape is constrained and a handful of names are reserved.
245pub async fn post_prompt(configuration: &configuration::Configuration, prompt_req: models::PromptReq) -> Result<models::PromptDetail, Error<PostPromptError>> {
246    // add a prefix to parameters to efficiently prevent name collisions
247    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