Skip to main content

hanzo_client/apis/
engine_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 [`engine_model`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum EngineModelError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`engine_models`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum EngineModelsError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`engine_status`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum EngineStatusError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`engine_system`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum EngineSystemError {
43    UnknownValue(serde_json::Value),
44}
45
46
47/// Model reads one model's load state — loaded, unloading, or not_found, as the engine itself reports it.
48pub async fn engine_model(configuration: &configuration::Configuration, model: Option<&str>) -> Result<serde_json::Value, Error<EngineModelError>> {
49    // add a prefix to parameters to efficiently prevent name collisions
50    let p_model = model;
51
52    let uri_str = format!("{}/v1/engine/model", configuration.base_path);
53    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
54
55    if let Some(ref param_value) = p_model {
56        req_builder = req_builder.query(&[("model", &param_value.to_string())]);
57    }
58    if let Some(ref user_agent) = configuration.user_agent {
59        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
60    }
61    if let Some(ref token) = configuration.bearer_access_token {
62        req_builder = req_builder.bearer_auth(token.to_owned());
63    };
64
65    let req = req_builder.build()?;
66    let resp = configuration.client.execute(req).await?;
67
68    let status = resp.status();
69    let content_type = resp
70        .headers()
71        .get("content-type")
72        .and_then(|v| v.to_str().ok())
73        .unwrap_or("application/octet-stream");
74    let content_type = super::ContentType::from(content_type);
75
76    if !status.is_client_error() && !status.is_server_error() {
77        let content = resp.text().await?;
78        match content_type {
79            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
80            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
81            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`")))),
82        }
83    } else {
84        let content = resp.text().await?;
85        let entity: Option<EngineModelError> = serde_json::from_str(&content).ok();
86        Err(Error::ResponseError(ResponseContent { status, content, entity }))
87    }
88}
89
90/// Models lists the models the engine serves, each with its load state — the server's own model table (its standard list envelope, load status included), relayed verbatim.
91pub async fn engine_models(configuration: &configuration::Configuration, ) -> Result<serde_json::Value, Error<EngineModelsError>> {
92
93    let uri_str = format!("{}/v1/engine/models", 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 `serde_json::Value`"))),
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 `serde_json::Value`")))),
120        }
121    } else {
122        let content = resp.text().await?;
123        let entity: Option<EngineModelsError> = serde_json::from_str(&content).ok();
124        Err(Error::ResponseError(ResponseContent { status, content, entity }))
125    }
126}
127
128/// Status reports whether the engine deployment is reachable and which build revision it runs — an honest lens for \"is the serving runtime up\", never a fabricated ok.
129pub async fn engine_status(configuration: &configuration::Configuration, ) -> Result<models::EngineStatus, Error<EngineStatusError>> {
130
131    let uri_str = format!("{}/v1/engine/status", configuration.base_path);
132    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
133
134    if let Some(ref user_agent) = configuration.user_agent {
135        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
136    }
137    if let Some(ref token) = configuration.bearer_access_token {
138        req_builder = req_builder.bearer_auth(token.to_owned());
139    };
140
141    let req = req_builder.build()?;
142    let resp = configuration.client.execute(req).await?;
143
144    let status = resp.status();
145    let content_type = resp
146        .headers()
147        .get("content-type")
148        .and_then(|v| v.to_str().ok())
149        .unwrap_or("application/octet-stream");
150    let content_type = super::ContentType::from(content_type);
151
152    if !status.is_client_error() && !status.is_server_error() {
153        let content = resp.text().await?;
154        match content_type {
155            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
156            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::EngineStatus`"))),
157            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::EngineStatus`")))),
158        }
159    } else {
160        let content = resp.text().await?;
161        let entity: Option<EngineStatusError> = serde_json::from_str(&content).ok();
162        Err(Error::ResponseError(ResponseContent { status, content, entity }))
163    }
164}
165
166/// System reads the engine host's inventory: OS, CPU, memory, every accelerator device with its VRAM and compute capability, and the build's capabilities (CUDA/Metal/flash-attention) — the real hardware under the serving runtime, relayed verbatim.
167pub async fn engine_system(configuration: &configuration::Configuration, ) -> Result<serde_json::Value, Error<EngineSystemError>> {
168
169    let uri_str = format!("{}/v1/engine/system", configuration.base_path);
170    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
171
172    if let Some(ref user_agent) = configuration.user_agent {
173        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
174    }
175    if let Some(ref token) = configuration.bearer_access_token {
176        req_builder = req_builder.bearer_auth(token.to_owned());
177    };
178
179    let req = req_builder.build()?;
180    let resp = configuration.client.execute(req).await?;
181
182    let status = resp.status();
183    let content_type = resp
184        .headers()
185        .get("content-type")
186        .and_then(|v| v.to_str().ok())
187        .unwrap_or("application/octet-stream");
188    let content_type = super::ContentType::from(content_type);
189
190    if !status.is_client_error() && !status.is_server_error() {
191        let content = resp.text().await?;
192        match content_type {
193            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
194            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
195            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`")))),
196        }
197    } else {
198        let content = resp.text().await?;
199        let entity: Option<EngineSystemError> = serde_json::from_str(&content).ok();
200        Err(Error::ResponseError(ResponseContent { status, content, entity }))
201    }
202}
203