|
| 1 | +/* |
| 2 | + * otari |
| 3 | + * |
| 4 | + * Otari, an OpenAI-compatible LLM gateway with API key management |
| 5 | + * |
| 6 | + * The version of the OpenAPI document: 0.0.0-dev |
| 7 | + * |
| 8 | + * Generated by: https://openapi-generator.tech |
| 9 | + */ |
| 10 | + |
| 11 | +use super::{configuration, ContentType, Error}; |
| 12 | +use crate::{apis::ResponseContent, models}; |
| 13 | +use reqwest; |
| 14 | +use serde::{de::Error as _, Deserialize, Serialize}; |
| 15 | + |
| 16 | +/// struct for typed errors of method [`delete_alias_v1_aliases_name_delete`] |
| 17 | +#[derive(Debug, Clone, Serialize, Deserialize)] |
| 18 | +#[serde(untagged)] |
| 19 | +pub enum DeleteAliasV1AliasesNameDeleteError { |
| 20 | + Status422(models::HttpValidationError), |
| 21 | + UnknownValue(serde_json::Value), |
| 22 | +} |
| 23 | + |
| 24 | +/// struct for typed errors of method [`list_aliases_v1_aliases_get`] |
| 25 | +#[derive(Debug, Clone, Serialize, Deserialize)] |
| 26 | +#[serde(untagged)] |
| 27 | +pub enum ListAliasesV1AliasesGetError { |
| 28 | + UnknownValue(serde_json::Value), |
| 29 | +} |
| 30 | + |
| 31 | +/// struct for typed errors of method [`set_alias_v1_aliases_post`] |
| 32 | +#[derive(Debug, Clone, Serialize, Deserialize)] |
| 33 | +#[serde(untagged)] |
| 34 | +pub enum SetAliasV1AliasesPostError { |
| 35 | + Status422(models::HttpValidationError), |
| 36 | + UnknownValue(serde_json::Value), |
| 37 | +} |
| 38 | + |
| 39 | +/// Delete a stored alias. |
| 40 | +pub async fn delete_alias_v1_aliases_name_delete( |
| 41 | + configuration: &configuration::Configuration, |
| 42 | + name: &str, |
| 43 | +) -> Result<(), Error<DeleteAliasV1AliasesNameDeleteError>> { |
| 44 | + // add a prefix to parameters to efficiently prevent name collisions |
| 45 | + let p_path_name = name; |
| 46 | + |
| 47 | + let uri_str = format!( |
| 48 | + "{}/v1/aliases/{name}", |
| 49 | + configuration.base_path, |
| 50 | + name = crate::apis::urlencode(p_path_name) |
| 51 | + ); |
| 52 | + let mut req_builder = configuration |
| 53 | + .client |
| 54 | + .request(reqwest::Method::DELETE, &uri_str); |
| 55 | + |
| 56 | + if let Some(ref user_agent) = configuration.user_agent { |
| 57 | + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); |
| 58 | + } |
| 59 | + if let Some(ref apikey) = configuration.api_key { |
| 60 | + let key = apikey.key.clone(); |
| 61 | + let value = match apikey.prefix { |
| 62 | + Some(ref prefix) => format!("{} {}", prefix, key), |
| 63 | + None => key, |
| 64 | + }; |
| 65 | + req_builder = req_builder.header("Otari-Key", value); |
| 66 | + }; |
| 67 | + |
| 68 | + let req = req_builder.build()?; |
| 69 | + let resp = configuration.client.execute(req).await?; |
| 70 | + |
| 71 | + let status = resp.status(); |
| 72 | + |
| 73 | + if !status.is_client_error() && !status.is_server_error() { |
| 74 | + Ok(()) |
| 75 | + } else { |
| 76 | + let content = resp.text().await?; |
| 77 | + let entity: Option<DeleteAliasV1AliasesNameDeleteError> = |
| 78 | + serde_json::from_str(&content).ok(); |
| 79 | + Err(Error::ResponseError(ResponseContent { |
| 80 | + status, |
| 81 | + content, |
| 82 | + entity, |
| 83 | + })) |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +/// List every alias in force, from config.yml and from storage. |
| 88 | +pub async fn list_aliases_v1_aliases_get( |
| 89 | + configuration: &configuration::Configuration, |
| 90 | +) -> Result<Vec<models::AliasResponse>, Error<ListAliasesV1AliasesGetError>> { |
| 91 | + let uri_str = format!("{}/v1/aliases", configuration.base_path); |
| 92 | + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); |
| 93 | + |
| 94 | + if let Some(ref user_agent) = configuration.user_agent { |
| 95 | + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); |
| 96 | + } |
| 97 | + if let Some(ref apikey) = configuration.api_key { |
| 98 | + let key = apikey.key.clone(); |
| 99 | + let value = match apikey.prefix { |
| 100 | + Some(ref prefix) => format!("{} {}", prefix, key), |
| 101 | + None => key, |
| 102 | + }; |
| 103 | + req_builder = req_builder.header("Otari-Key", value); |
| 104 | + }; |
| 105 | + |
| 106 | + let req = req_builder.build()?; |
| 107 | + let resp = configuration.client.execute(req).await?; |
| 108 | + |
| 109 | + let status = resp.status(); |
| 110 | + let content_type = resp |
| 111 | + .headers() |
| 112 | + .get("content-type") |
| 113 | + .and_then(|v| v.to_str().ok()) |
| 114 | + .unwrap_or("application/octet-stream"); |
| 115 | + let content_type = super::ContentType::from(content_type); |
| 116 | + |
| 117 | + if !status.is_client_error() && !status.is_server_error() { |
| 118 | + let content = resp.text().await?; |
| 119 | + match content_type { |
| 120 | + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), |
| 121 | + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::AliasResponse>`"))), |
| 122 | + ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::AliasResponse>`")))), |
| 123 | + } |
| 124 | + } else { |
| 125 | + let content = resp.text().await?; |
| 126 | + let entity: Option<ListAliasesV1AliasesGetError> = serde_json::from_str(&content).ok(); |
| 127 | + Err(Error::ResponseError(ResponseContent { |
| 128 | + status, |
| 129 | + content, |
| 130 | + entity, |
| 131 | + })) |
| 132 | + } |
| 133 | +} |
| 134 | + |
| 135 | +/// Create or update a stored alias. |
| 136 | +pub async fn set_alias_v1_aliases_post( |
| 137 | + configuration: &configuration::Configuration, |
| 138 | + alias_request: models::AliasRequest, |
| 139 | +) -> Result<models::AliasResponse, Error<SetAliasV1AliasesPostError>> { |
| 140 | + // add a prefix to parameters to efficiently prevent name collisions |
| 141 | + let p_body_alias_request = alias_request; |
| 142 | + |
| 143 | + let uri_str = format!("{}/v1/aliases", configuration.base_path); |
| 144 | + let mut req_builder = configuration |
| 145 | + .client |
| 146 | + .request(reqwest::Method::POST, &uri_str); |
| 147 | + |
| 148 | + if let Some(ref user_agent) = configuration.user_agent { |
| 149 | + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); |
| 150 | + } |
| 151 | + if let Some(ref apikey) = configuration.api_key { |
| 152 | + let key = apikey.key.clone(); |
| 153 | + let value = match apikey.prefix { |
| 154 | + Some(ref prefix) => format!("{} {}", prefix, key), |
| 155 | + None => key, |
| 156 | + }; |
| 157 | + req_builder = req_builder.header("Otari-Key", value); |
| 158 | + }; |
| 159 | + req_builder = req_builder.json(&p_body_alias_request); |
| 160 | + |
| 161 | + let req = req_builder.build()?; |
| 162 | + let resp = configuration.client.execute(req).await?; |
| 163 | + |
| 164 | + let status = resp.status(); |
| 165 | + let content_type = resp |
| 166 | + .headers() |
| 167 | + .get("content-type") |
| 168 | + .and_then(|v| v.to_str().ok()) |
| 169 | + .unwrap_or("application/octet-stream"); |
| 170 | + let content_type = super::ContentType::from(content_type); |
| 171 | + |
| 172 | + if !status.is_client_error() && !status.is_server_error() { |
| 173 | + let content = resp.text().await?; |
| 174 | + match content_type { |
| 175 | + ContentType::Json => serde_json::from_str(&content).map_err(Error::from), |
| 176 | + ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AliasResponse`"))), |
| 177 | + 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::AliasResponse`")))), |
| 178 | + } |
| 179 | + } else { |
| 180 | + let content = resp.text().await?; |
| 181 | + let entity: Option<SetAliasV1AliasesPostError> = serde_json::from_str(&content).ok(); |
| 182 | + Err(Error::ResponseError(ResponseContent { |
| 183 | + status, |
| 184 | + content, |
| 185 | + entity, |
| 186 | + })) |
| 187 | + } |
| 188 | +} |
0 commit comments