Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk_v2/rust/.clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Clippy configuration for Foundry Local Rust SDK
msrv = "1.70"
3 changes: 3 additions & 0 deletions sdk_v2/rust/.rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
edition = "2021"
max_width = 100
use_field_init_shorthand = true
50 changes: 50 additions & 0 deletions sdk_v2/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[package]
name = "foundry-local-sdk"
version = "2.0.0"
edition = "2021"
license = "MIT"
readme = "README.md"
description = "Local AI model inference powered by the Foundry Local Core engine"
homepage = "https://www.foundrylocal.ai/"
repository = "https://github.com/microsoft/Foundry-Local"
documentation = "https://github.com/microsoft/Foundry-Local/blob/main/sdk_v2/rust/docs/api.md"
include = ["src/**", "build.rs", "Cargo.toml", "README.md", "LICENSE.txt", "deps_versions.json"]

[features]
default = []
winml = []
nightly = []

[dependencies]
libloading = "0.8"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
thiserror = "2"
tokio = { version = "1", features = ["rt-multi-thread", "macros", "sync"] }
tokio-stream = "0.1"
tokio-util = "0.7"
futures-core = "0.3"
reqwest = { version = "0.12", features = ["json"] }
urlencoding = "2"
async-openai = { version = "=0.33.1", default-features = false, features = ["chat-completion-types", "embedding-types"] }

[build-dependencies]
ureq = "3"
zip = "2"
serde_json = "1"
serde = { version = "1", features = ["derive"] }

[[example]]
name = "chat_completion"
path = "examples/chat_completion.rs"

[[example]]
name = "tool_calling"
path = "examples/tool_calling.rs"

[[example]]
name = "interactive_chat"
path = "examples/interactive_chat.rs"

[lints.clippy]
all = { level = "warn", priority = -1 }
41 changes: 41 additions & 0 deletions sdk_v2/rust/GENERATE-DOCS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Generating API Reference Docs

The Rust SDK uses `cargo doc` to generate API documentation from `///` doc comments in the source code.

## Viewing Docs Locally

To generate and open the API docs in your browser:

```bash
cd sdk/rust
cargo doc --no-deps --open
```

This generates HTML documentation at `target/doc/foundry_local_sdk/index.html`.

## Public API Surface

The SDK re-exports all public types from the crate root. Key modules:

| Module / Type | Description |
|---|---|
| `FoundryLocalManager` | Singleton entry point — SDK initialisation, web service lifecycle |
| `FoundryLocalConfig` | Configuration (app name, log level, service endpoint) |
| `Catalog` | Model discovery and lookup |
| `Model` | Grouped model (alias → best variant) |
| `ModelVariant` | Single variant — download, load, unload |
| `ChatClient` | OpenAI-compatible chat completions (sync + streaming) |
| `AudioClient` | OpenAI-compatible audio transcription (sync + streaming) |
| `CreateChatCompletionResponse` | Typed chat completion response (from `async-openai`) |
| `CreateChatCompletionStreamResponse` | Typed streaming chat chunk (from `async-openai`) |
| `AudioTranscriptionResponse` | Typed audio transcription response |
| `FoundryLocalError` | Error enum with variants for all failure modes |

## Notes

- Unlike the C# and JS SDKs which commit generated markdown docs, Rust's convention is to generate HTML docs on demand with `cargo doc`.
- Once the crate is published to crates.io, docs will be automatically hosted at [docs.rs](https://docs.rs).
- Use `--document-private-items` to include internal/private API in the generated docs:
```bash
cargo doc --no-deps --document-private-items --open
```
21 changes: 21 additions & 0 deletions sdk_v2/rust/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Microsoft Corporation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading