windmill_api/apis/
ai_api.rs1use reqwest;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ListAiUsageError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum RecordAiUsageError {
29 UnknownValue(serde_json::Value),
30}
31
32
33pub async fn list_ai_usage(configuration: &configuration::Configuration, workspace: &str, days: Option<i32>, group_by: Option<&str>, scope: Option<&str>) -> Result<models::ListAiUsage200Response, Error<ListAiUsageError>> {
34 let local_var_configuration = configuration;
35
36 let local_var_client = &local_var_configuration.client;
37
38 let local_var_uri_str = format!("{}/w/{workspace}/ai/usage", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
39 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
40
41 if let Some(ref local_var_str) = days {
42 local_var_req_builder = local_var_req_builder.query(&[("days", &local_var_str.to_string())]);
43 }
44 if let Some(ref local_var_str) = group_by {
45 local_var_req_builder = local_var_req_builder.query(&[("group_by", &local_var_str.to_string())]);
46 }
47 if let Some(ref local_var_str) = scope {
48 local_var_req_builder = local_var_req_builder.query(&[("scope", &local_var_str.to_string())]);
49 }
50 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
51 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
52 }
53 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
54 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
55 };
56
57 let local_var_req = local_var_req_builder.build()?;
58 let local_var_resp = local_var_client.execute(local_var_req).await?;
59
60 let local_var_status = local_var_resp.status();
61 let local_var_content = local_var_resp.text().await?;
62
63 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
64 crate::from_str_patched(&local_var_content).map_err(Error::from)
65 } else {
66 let local_var_entity: Option<ListAiUsageError> = crate::from_str_patched(&local_var_content).ok();
67 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
68 Err(Error::ResponseError(local_var_error))
69 }
70}
71
72pub async fn record_ai_usage(configuration: &configuration::Configuration, workspace: &str, record_ai_usage_request: models::RecordAiUsageRequest) -> Result<(), Error<RecordAiUsageError>> {
73 let local_var_configuration = configuration;
74
75 let local_var_client = &local_var_configuration.client;
76
77 let local_var_uri_str = format!("{}/w/{workspace}/ai/usage", local_var_configuration.base_path, workspace=crate::apis::urlencode(workspace));
78 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
79
80 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
81 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
82 }
83 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
84 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
85 };
86 local_var_req_builder = local_var_req_builder.json(&record_ai_usage_request);
87
88 let local_var_req = local_var_req_builder.build()?;
89 let local_var_resp = local_var_client.execute(local_var_req).await?;
90
91 let local_var_status = local_var_resp.status();
92 let local_var_content = local_var_resp.text().await?;
93
94 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
95 Ok(())
96 } else {
97 let local_var_entity: Option<RecordAiUsageError> = crate::from_str_patched(&local_var_content).ok();
98 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
99 Err(Error::ResponseError(local_var_error))
100 }
101}
102