Fix samples to work with foundry-local-sdk 1.2.1#769
Open
samuel100 wants to merge 5 commits into
Open
Conversation
Patches across Python/JS/C#/Rust samples to bring them up to date with
the foundry-local-sdk 1.2.0 release.
Python — guard against empty `chunk.choices` on streaming chat completions.
The final OpenAI SSE chunk now contains an empty `choices` array (just
`finish_reason` and `usage`), which crashed three samples with
`IndexError` on `chunk.choices[0]`:
* samples/python/native-chat-completions/src/app.py
* samples/python/tutorial-chat-assistant/src/app.py
* samples/python/web-server/src/app.py
JS — fix two API/UX bugs:
* samples/js/tutorial-tool-calling/app.js — `chatClient.completeChat`
in SDK 1.2.0 takes the tools array directly as its second argument,
not wrapped in `{ tools }`. Both call sites updated.
* samples/js/tutorial-tool-calling/app.js and
samples/js/tutorial-chat-assistant/app.js — `askQuestion` now
resolves to `'quit'` when readline emits `close` (e.g. on stdin
EOF) instead of throwing `ERR_USE_AFTER_CLOSE`.
* samples/js/chat-and-audio-foundry-local/src/app.js — swap chat
model from `phi-3.5-mini` to `qwen2.5-0.5b` so the sample runs
against the smaller default catalog model.
C# — pin Betalgo.Ranul.OpenAI to 9.1.0:
* samples/cs/Directory.Packages.props — the 9.2.0 pin removed the
`ReasoningEfforts` type and changed
`AudioCreateTranscriptionRequest.ResponseFormat`, causing
TypeLoadException/MissingMethodException in the 1.2.0 SDK's
serialization context. Bumped down to 9.1.0 (matches the SDK's
transitive requirement), fixing four tutorial samples.
Rust — share the model cache across tutorial samples:
* samples/rust/tutorial-tool-calling/src/main.rs
* samples/rust/tutorial-voice-to-text/src/main.rs
* samples/rust/tutorial-chat-assistant/src/main.rs
* samples/rust/tutorial-document-summarizer/src/main.rs
Each tutorial used its own `app_name` which scoped the cache directory
separately and forced re-download of already-cached models. Standardized
on `foundry_local_samples` so the samples reuse the shared cache.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
The sample reads `path.resolve("recording.mp3")` from the current
working directory. Ship the audio fixture (a copy of the audio file
already used by samples/python/audio-transcription/Recording.mp3) so
the sample is runnable out of the box.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Updates multi-language samples so they run cleanly against foundry-local-sdk 1.2.0 by addressing SDK surface changes and runtime behavior differences (streaming chunk shape, JS tools parameter shape, and sample dependency / cache configuration).
Changes:
- Python: guard against streaming chunks that contain an empty
choicesarray. - JS: align
completeChattool-calling signature and make readline input handling more resilient to stdin EOF/close. - C#/Rust: pin a compatible Betalgo package version for samples and standardize Rust
app_nameto share the model cache across tutorials.
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| samples/rust/tutorial-voice-to-text/src/main.rs | Standardizes Rust sample app_name to share the model cache. |
| samples/rust/tutorial-tool-calling/src/main.rs | Standardizes Rust sample app_name to share the model cache. |
| samples/rust/tutorial-document-summarizer/src/main.rs | Standardizes Rust sample app_name to share the model cache. |
| samples/rust/tutorial-chat-assistant/src/main.rs | Standardizes Rust sample app_name to share the model cache. |
| samples/python/web-server/src/app.py | Adds an empty-choices guard for streaming chat output. |
| samples/python/tutorial-chat-assistant/src/app.py | Adds an empty-choices guard for streaming chat output. |
| samples/python/native-chat-completions/src/app.py | Adds an empty-choices guard for streaming chat output. |
| samples/js/tutorial-tool-calling/app.js | Updates tool-calling API usage and improves readline EOF handling (needs a small race-condition fix). |
| samples/js/tutorial-chat-assistant/app.js | Improves readline EOF handling (needs a small race-condition fix). |
| samples/js/chat-and-audio-foundry-local/src/app.js | Switches default chat model alias to qwen2.5-0.5b. |
| samples/cs/Directory.Packages.props | Pins Betalgo dependency to a version compatible with the samples/SDK. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Mirror the autofix applied to tutorial-chat-assistant in 938f4d3: the `rl.closed` check leaves a race window where rl can close before `rl.question()` runs, and `rl.question()` throws synchronously on a closed readline interface. Wrap the call in try/catch and resolve to 'quit' so stdin EOF is handled reliably. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Patches across Python / JS / C# / Rust samples so they run cleanly against the latest
foundry-local-sdk1.2.0 release. Verified by running every affected sample end-to-end on macOS (arm64).Changes
Python — empty-choices guard on streaming chat (3 samples)
The final OpenAI SSE chunk now contains an empty
choicesarray (justfinish_reasonandusage), which crashed three samples withIndexErroronchunk.choices[0]. Addedif not chunk.choices: continueguard.samples/python/native-chat-completions/src/app.pysamples/python/tutorial-chat-assistant/src/app.pysamples/python/web-server/src/app.pyJS — API mismatches and readline EOF handling
samples/js/tutorial-tool-calling/app.js—chatClient.completeChatin SDK 1.2.0 takes the tools array directly as its second argument, not wrapped in{ tools }. Both call sites updated.samples/js/tutorial-tool-calling/app.jsandsamples/js/tutorial-chat-assistant/app.js—askQuestionnow resolves to'quit'when readline emitsclose(e.g. on stdin EOF) instead of throwingERR_USE_AFTER_CLOSE.samples/js/chat-and-audio-foundry-local/src/app.js— swap chat model fromphi-3.5-minitoqwen2.5-0.5bso the sample runs against the smaller default catalog model.C# — Betalgo package pin (4 tutorial samples fixed by one line)
samples/cs/Directory.Packages.propspinnedBetalgo.Ranul.OpenAI = 9.2.0, but that version removed theReasoningEffortstype and changedAudioCreateTranscriptionRequest.ResponseFormat. The 1.2.0 SDK reflects on these types in itsJsonSerializationContext, throwingTypeLoadException/MissingMethodException. Pinned down to 9.1.0 (the version the SDK transitively requires), which fixes all 4 tutorial samples that explicitly depend on Betalgo.Rust — share model cache across tutorials (4 samples)
Each Rust tutorial set its own
app_name(tool-calling-app,note-taker,chat-assistant,doc-summarizer), which scopes the cache directory separately and forces re-download of already-cached models. Standardized onfoundry_local_samplesso the samples share the cache:samples/rust/tutorial-tool-calling/src/main.rssamples/rust/tutorial-voice-to-text/src/main.rssamples/rust/tutorial-chat-assistant/src/main.rssamples/rust/tutorial-document-summarizer/src/main.rsTesting
Ran the full samples matrix on macOS arm64 against
foundry-local-sdk1.2.0:JS skips are for Windows-only WinML samples, an Electron GUI sample, and samples that pull
phi-4-mini(not in the macOS test cache).