From 1bfbf2ff39b4712b4240cf88cf9d44d4d86c9791 Mon Sep 17 00:00:00 2001 From: Cory Hendrixson Date: Fri, 30 May 2025 09:57:58 -0700 Subject: [PATCH 1/2] Cleanup readme for publish --- sdk/rust/README.md | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/sdk/rust/README.md b/sdk/rust/README.md index 52841f3..cf2e2af 100644 --- a/sdk/rust/README.md +++ b/sdk/rust/README.md @@ -1,6 +1,6 @@ # Foundry Local Rust SDK -A Rust SDK for interacting with the Microsoft Foundry Local service. This SDK allows you to manage and use AI models locally on your device. +A Rust SDK for interacting with the Microsoft Foundry Local service. This SDK allows you to manage and use AI models locally on your device. See [Foundry Local](http://aka.ms/foundrylocal) for more infromation. ## Features - Start and manage the Foundry Local service @@ -17,17 +17,20 @@ use anyhow::Result; #[tokio::main] async fn main() -> Result<()> { - // Create a FoundryLocalManager instance with default options - let manager = FoundryLocalManager::new("phi-3.5-mini", true).await?; + // Create a FoundryLocalManager instance with the option to automatically download and start the service and a model + let manager = FoundryLocalManager::builder() + .alias_or_model_id("phi-3.5-mini") + .bootstrap(true) + .build() + .await?; // Use the OpenAI compatible API to interact with the model let client = reqwest::Client::new(); - let response = client.post(&format!("{}/chat/completions", manager.endpoint())) - .header("Content-Type", "application/json") - .header("Authorization", format!("Bearer {}", manager.api_key())) + let response = client + .post(format!("{}/chat/completions", manager.endpoint()?)) .json(&serde_json::json!({ - "model": manager.get_model_info("phi-3.5-mini").await?.id, - "messages": [{"role": "user", "content": "What is the golden ratio?"}], + "model": model_info.id, + "messages": [{"role": "user", "content": prompt}], })) .send() .await?; @@ -50,7 +53,10 @@ foundry-local = "0.1.0" ## Requirements -- Foundry Local must be installed and available on the PATH +- Foundry Local must be installed. On Windows you can run the following to install latest. +```powershell +winget install Microsoft.FoundryLocal +``` - Rust 1.70.0 or later ## License From 8778c52bb2936345dc135335ebcb67c3e3ed1388 Mon Sep 17 00:00:00 2001 From: Cory Hendrixson Date: Fri, 30 May 2025 10:16:05 -0700 Subject: [PATCH 2/2] Add a test workflow --- .github/workflows/rusttest.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/rusttest.yml diff --git a/.github/workflows/rusttest.yml b/.github/workflows/rusttest.yml new file mode 100644 index 0000000..b837e90 --- /dev/null +++ b/.github/workflows/rusttest.yml @@ -0,0 +1,24 @@ +name: Rust-test + +on: + pull_request: + paths: + - 'sdk/rust/**' + push: + paths: + - 'sdk/rust/**' + branches: + - main + workflow_dispatch: + +jobs: + check: + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Update toolchain + run: rustup update --no-self-update stable && rustup default stable + - name: Run Unit Tests + working-directory: sdk/rust + run: cargo test