Skip to content

Commit 7ad2ef0

Browse files
Fix documentation anomalies: incorrect API signatures, missing SDK links, wrong streaming patterns (#598)
## Summary Systematic audit of all SDK documentation against actual source code revealed **10 documentation anomalies** across 6 files. All fixes are documentation-only — no source code changes. ## Changes by File ### Root `README.md` | Fix | Before | After | |-----|--------|-------| | C# unload method name | `await model.Unload()` | `await model.UnloadAsync()` | | C# streaming missing parameter | `CompleteChatStreamingAsync(messages)` | `CompleteChatStreamingAsync(messages, CancellationToken.None)` | ### `sdk/cs/README.md` | Fix | Before | After | |-----|--------|-------| | Non-existent factory methods (3 occurrences) | `ChatMessage.FromUser("...")` / `ChatMessage.FromSystem("...")` | `new ChatMessage { Role = "user", Content = "..." }` | | Streaming property doesn't exist | `chunk.Choices?[0]?.Delta?.Content` | `chunk.Choices?[0]?.Message?.Content` | | Internal property used in public example | `m.SelectedVariant.Info.DisplayName` | `m.Info.DisplayName` | ### `sdk/js/README.md` | Fix | Before | After | |-----|--------|-------| | Streaming chunk access (2 occurrences) | `chunk.choices?.[0]?.message?.content` | `chunk.choices?.[0]?.delta?.content` | ### `sdk/python/README.md` | Fix | Before | After | |-----|--------|-------| | Streaming pattern | Callback: `client.complete_streaming_chat(messages, on_chunk)` | Generator: `for chunk in client.complete_streaming_chat(messages):` | ### `sdk/rust/README.md` | Fix | Before | After | |-----|--------|-------| | Non-existent trait | "All models implement the `IModel` trait" | "All models are represented by the `Model` type" | | Missing error variant | 8 variants listed | 9 variants (added `Internal { reason }`) | | Wrong license | "MIT" | "Microsoft Software License Terms" | ### `docs/README.md` | Fix | Before | After | |-----|--------|-------| | Missing SDK references | Only C# and JS listed | Added Python and Rust SDK links | ## Verification Method Each fix was verified by reading the actual source code: - C# `ChatMessage` constructor syntax confirmed in `ChatCompletionsTests.cs` - C# streaming `Message.Content` (not `Delta`) confirmed in `ChatClient.cs` — both streaming and non-streaming return `ChatCompletionCreateResponse` - JS streaming `delta.content` confirmed in `chatClient.ts` JSDoc - Python generator return confirmed in `chat_client.py:263-290` - Rust `Model` struct confirmed in `lib.rs:16`; no trait exists - Rust error variants confirmed in `error.rs:4-33` - LICENSE file confirmed as Microsoft Software License Terms Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: baijumeswani <12852605+baijumeswani@users.noreply.github.com> Co-authored-by: Baiju Meswani <baijumeswani@gmail.com>
1 parent aa6c9be commit 7ad2ef0

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,13 @@ The Foundry Local SDK makes it easy to integrate local AI models into your appli
157157
new() { Role = "user", Content = "What is the golden ratio?" }
158158
};
159159
160-
await foreach (var chunk in chatClient.CompleteChatStreamingAsync(messages))
160+
await foreach (var chunk in chatClient.CompleteChatStreamingAsync(messages, CancellationToken.None))
161161
{
162162
Console.Write(chunk.Choices[0].Message.Content);
163163
}
164164
165165
// Unload the model when done
166-
await model.Unload();
166+
await model.UnloadAsync();
167167
```
168168
169169
</details>

docs/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Documentation for Foundry Local can be found in the following resources:
66
- SDK Reference:
77
- [C# SDK Reference](../sdk/cs/README.md): This documentation provides detailed information about the C# SDK for Foundry Local, including API references, usage examples, and best practices for integrating Foundry Local into your applications.
88
- [JavaScript SDK Reference](../sdk/js/README.md): This documentation offers detailed information about the JavaScript SDK for Foundry Local, including API references, usage examples, and best practices for integrating Foundry Local into your web applications.
9+
- [Python SDK Reference](../sdk/python/README.md): This documentation provides detailed information about the Python SDK for Foundry Local, including API references, usage examples, and best practices for integrating Foundry Local into your Python applications.
10+
- [Rust SDK Reference](../sdk/rust/README.md): This documentation provides detailed information about the Rust SDK for Foundry Local, including API references, usage examples, and best practices for integrating Foundry Local into your Rust applications.
911
- [Foundry Local Lab](https://github.com/Microsoft-foundry/foundry-local-lab): This GitHub repository contains a lab designed to help you learn how to use Foundry Local effectively. It includes hands-on exercises, sample code, and step-by-step instructions to guide you through the process of setting up and using Foundry Local in various scenarios.
1012

1113
## Supported Capabilities

sdk/cs/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ await model.LoadAsync();
126126
var chatClient = await model.GetChatClientAsync();
127127
var response = await chatClient.CompleteChatAsync(new[]
128128
{
129-
ChatMessage.FromUser("Why is the sky blue?")
129+
new ChatMessage { Role = "user", Content = "Why is the sky blue?" }
130130
});
131131

132132
Console.WriteLine(response.Choices![0].Message.Content);
@@ -159,7 +159,7 @@ var catalog = await FoundryLocalManager.Instance.GetCatalogAsync();
159159
// List all available models
160160
var models = await catalog.ListModelsAsync();
161161
foreach (var m in models)
162-
Console.WriteLine($"{m.Alias} — {m.SelectedVariant.Info.DisplayName}");
162+
Console.WriteLine($"{m.Alias} — {m.Info.DisplayName}");
163163

164164
// Get a specific model by alias
165165
var model = await catalog.GetModelAsync("phi-3.5-mini")
@@ -214,8 +214,8 @@ var chatClient = await model.GetChatClientAsync();
214214

215215
var response = await chatClient.CompleteChatAsync(new[]
216216
{
217-
ChatMessage.FromSystem("You are a helpful assistant."),
218-
ChatMessage.FromUser("Explain async/await in C#.")
217+
new ChatMessage { Role = "system", Content = "You are a helpful assistant." },
218+
new ChatMessage { Role = "user", Content = "Explain async/await in C#." }
219219
});
220220

221221
Console.WriteLine(response.Choices![0].Message.Content);
@@ -229,9 +229,9 @@ Use `IAsyncEnumerable` for token-by-token output:
229229
using var cts = new CancellationTokenSource();
230230

231231
await foreach (var chunk in chatClient.CompleteChatStreamingAsync(
232-
new[] { ChatMessage.FromUser("Write a haiku about .NET") }, cts.Token))
232+
new[] { new ChatMessage { Role = "user", Content = "Write a haiku about .NET" } }, cts.Token))
233233
{
234-
Console.Write(chunk.Choices?[0]?.Delta?.Content);
234+
Console.Write(chunk.Choices?[0]?.Message?.Content);
235235
}
236236
```
237237

sdk/js/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ console.log('\nTesting streaming completion...');
111111
for await (const chunk of chatClient.completeStreamingChat(
112112
[{ role: 'user', content: 'Write a short poem about programming.' }]
113113
)) {
114-
const content = chunk.choices?.[0]?.message?.content;
114+
const content = chunk.choices?.[0]?.delta?.content;
115115
if (content) {
116116
process.stdout.write(content);
117117
}
@@ -198,7 +198,7 @@ For real-time output, use streaming:
198198
for await (const chunk of chatClient.completeStreamingChat(
199199
[{ role: 'user', content: 'Write a short poem about programming.' }]
200200
)) {
201-
const content = chunk.choices?.[0]?.message?.content;
201+
const content = chunk.choices?.[0]?.delta?.content;
202202
if (content) {
203203
process.stdout.write(content);
204204
}

sdk/python/README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,9 @@ print(result.choices[0].message.content) # "42"
232232
# Streaming chat
233233
messages = [{"role": "user", "content": "Tell me a joke"}]
234234

235-
def on_chunk(chunk):
236-
delta = chunk.choices[0].delta
237-
if delta and delta.content:
238-
print(delta.content, end="", flush=True)
239-
240-
client.complete_streaming_chat(messages, on_chunk)
235+
for chunk in client.complete_streaming_chat(messages):
236+
if chunk.choices[0].delta.content:
237+
print(chunk.choices[0].delta.content, end="", flush=True)
241238

242239
# Unload when done
243240
model.unload()

sdk/rust/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ let loaded = catalog.get_loaded_models().await?;
175175

176176
### Model Lifecycle
177177

178-
Each model may have multiple variants (different quantizations, hardware targets). The SDK auto-selects the best available variant, preferring cached versions. All models implement the `IModel` trait.
178+
Each model may have multiple variants (different quantizations, hardware targets). The SDK auto-selects the best available variant, preferring cached versions. All models are represented by the `Model` type.
179179

180180
```rust
181181
let model = catalog.get_model("phi-3.5-mini").await?;
@@ -445,6 +445,7 @@ match manager.catalog().get_model("nonexistent").await {
445445
| `Serialization(serde_json::Error)` | JSON serialization/deserialization failed |
446446
| `Validation { reason }` | A validation check on user-supplied input failed |
447447
| `Io(std::io::Error)` | An I/O error occurred |
448+
| `Internal { reason }` | An internal SDK error (e.g. poisoned lock) |
448449

449450
## Configuration
450451

@@ -520,4 +521,4 @@ cargo run -p native-chat-completions
520521

521522
## License
522523

523-
MIT — see [LICENSE](../../LICENSE) for details.
524+
Microsoft Software License Terms — see [LICENSE](../../LICENSE) for details.

0 commit comments

Comments
 (0)