| 1 | //! Onde credentials baked in. Wraps `smbcloud_gresiq_sdk` so callers only |
| 2 | //! need to pass the user's access token. |
| 3 | use smbcloud_gresiq_sdk::{CreateModelParams, Environment, OndeApp, OndeModel}; |
| 4 | |
| 5 | fn api_key() -> &'static str { |
| 6 | crate::app::GRESIQ_API_KEY |
| 7 | } |
| 8 | |
| 9 | fn api_secret() -> &'static str { |
| 10 | crate::app::GRESIQ_API_SECRET |
| 11 | } |
| 12 | |
| 13 | pub async fn load_apps(token: &str) -> anyhow::Result<Vec<OndeApp>> { |
| 14 | smbcloud_gresiq_sdk::list_apps(&Environment::Production, api_key(), api_secret(), token) |
| 15 | .await |
| 16 | .map_err(|e| anyhow::anyhow!("{e}")) |
| 17 | } |
| 18 | |
| 19 | pub async fn create_app(token: &str, name: &str) -> anyhow::Result<OndeApp> { |
| 20 | smbcloud_gresiq_sdk::create_app( |
| 21 | &Environment::Production, |
| 22 | api_key(), |
| 23 | api_secret(), |
| 24 | token, |
| 25 | name, |
| 26 | ) |
| 27 | .await |
| 28 | .map_err(|e| anyhow::anyhow!("{e}")) |
| 29 | } |
| 30 | |
| 31 | pub async fn load_models(token: &str) -> anyhow::Result<Vec<OndeModel>> { |
| 32 | smbcloud_gresiq_sdk::list_models(&Environment::Production, api_key(), api_secret(), token) |
| 33 | .await |
| 34 | .map_err(|e| anyhow::anyhow!("{e}")) |
| 35 | } |
| 36 | |
| 37 | /// Registers a fine-tuned model (just uploaded to Hugging Face) into the |
| 38 | /// catalog, private to this account, so it can then be assigned to an app. |
| 39 | #[allow(clippy::too_many_arguments)] |
| 40 | pub async fn create_model( |
| 41 | token: &str, |
| 42 | hf_repo_id: &str, |
| 43 | name: &str, |
| 44 | family: &str, |
| 45 | parameter_class: &str, |
| 46 | gguf_file: Option<&str>, |
| 47 | approx_size_bytes: Option<i64>, |
| 48 | ) -> anyhow::Result<OndeModel> { |
| 49 | smbcloud_gresiq_sdk::create_model( |
| 50 | &Environment::Production, |
| 51 | api_key(), |
| 52 | api_secret(), |
| 53 | token, |
| 54 | CreateModelParams { |
| 55 | hf_repo_id, |
| 56 | name, |
| 57 | org: "Custom", |
| 58 | family, |
| 59 | parameter_class, |
| 60 | format: "gguf", |
| 61 | gguf_file, |
| 62 | modality: Some("text"), |
| 63 | description: Some("Fine-tuned with onde-cli."), |
| 64 | approx_size_bytes, |
| 65 | }, |
| 66 | ) |
| 67 | .await |
| 68 | .map_err(|e| anyhow::anyhow!("{e}")) |
| 69 | } |
| 70 | |
| 71 | pub async fn assign_model(token: &str, onde_app_id: &str, model_id: &str) -> anyhow::Result<()> { |
| 72 | smbcloud_gresiq_sdk::assign_model( |
| 73 | &Environment::Production, |
| 74 | api_key(), |
| 75 | api_secret(), |
| 76 | token, |
| 77 | onde_app_id, |
| 78 | model_id, |
| 79 | ) |
| 80 | .await |
| 81 | .map_err(|e| anyhow::anyhow!("{e}")) |
| 82 | } |
| 83 | |
| 84 | pub async fn rename_app(token: &str, onde_app_id: &str, new_name: &str) -> anyhow::Result<OndeApp> { |
| 85 | smbcloud_gresiq_sdk::rename_app( |
| 86 | &Environment::Production, |
| 87 | api_key(), |
| 88 | api_secret(), |
| 89 | token, |
| 90 | onde_app_id, |
| 91 | new_name, |
| 92 | ) |
| 93 | .await |
| 94 | .map_err(|e| anyhow::anyhow!("{e}")) |
| 95 | } |