Skip to content

Commit 519d6bc

Browse files
authored
Clean up samples, tests, and docs (#619)
Fix SDK: - JS: Fixed tool.function.description.trim() TypeError when description is undefined (chatClient.ts:170) Fix samples/tests - C#: Added missing ToolCallId on tool response - Python: Removed unnecessary async/await (6 files), fixed .message.content → .delta.content crash - JS: Fixed .message → .delta in streaming (3 files), replaced broken callback with for await...of Fix documentation - Python test README: Fixed version 3.10+ → 3.11+ - Rust: Fixed stale return types, removed private ModelVariant section and selected_variant() method
1 parent 18c1173 commit 519d6bc

File tree

18 files changed

+44
-65
lines changed

18 files changed

+44
-65
lines changed

.pipelines/templates/test-cs-steps.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ steps:
2020
$testDataDir = "$(Build.SourcesDirectory)/test-data-shared"
2121
Write-Host "##vso[task.setvariable variable=repoRoot]$repoRoot"
2222
Write-Host "##vso[task.setvariable variable=testDataDir]$testDataDir"
23+
Write-Host "##vso[task.setvariable variable=FOUNDRY_TESTING_MODE]1"
2324
2425
- task: UseDotNet@2
2526
displayName: 'Use .NET 9 SDK'

.pipelines/templates/test-js-steps.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ steps:
2020
$testDataDir = "$(Build.SourcesDirectory)/test-data-shared"
2121
Write-Host "##vso[task.setvariable variable=repoRoot]$repoRoot"
2222
Write-Host "##vso[task.setvariable variable=testDataDir]$testDataDir"
23+
Write-Host "##vso[task.setvariable variable=FOUNDRY_TESTING_MODE]1"
2324
2425
- ${{ if eq(parameters.isWinML, true) }}:
2526
- task: PowerShell@2

.pipelines/templates/test-python-steps.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ steps:
2020
$testDataDir = "$(Build.SourcesDirectory)/test-data-shared"
2121
Write-Host "##vso[task.setvariable variable=repoRoot]$repoRoot"
2222
Write-Host "##vso[task.setvariable variable=testDataDir]$testDataDir"
23+
Write-Host "##vso[task.setvariable variable=FOUNDRY_TESTING_MODE]1"
2324
2425
- ${{ if eq(parameters.isWinML, true) }}:
2526
- task: PowerShell@2

.pipelines/templates/test-rust-steps.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ steps:
1818
$testDataDir = "$(Build.SourcesDirectory)/test-data-shared"
1919
Write-Host "##vso[task.setvariable variable=repoRoot]$repoRoot"
2020
Write-Host "##vso[task.setvariable variable=testDataDir]$testDataDir"
21+
Write-Host "##vso[task.setvariable variable=FOUNDRY_TESTING_MODE]1"
2122
2223
- ${{ if eq(parameters.isWinML, true) }}:
2324
- task: PowerShell@2

samples/cs/tool-calling-foundry-local-sdk/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ await model.DownloadAsync(progress =>
141141
var response = new ChatMessage
142142
{
143143
Role = "tool",
144+
ToolCallId = chunk!.Choices[0].Message.ToolCalls![0].Id,
144145
Content = result.ToString(),
145146
};
146147
messages.Add(response);

samples/js/chat-and-audio-foundry-local/src/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ async function main() {
9595
},
9696
{ role: "user", content: transcription.text },
9797
])) {
98-
const content = chunk.choices?.[0]?.message?.content;
98+
const content = chunk.choices?.[0]?.delta?.content;
9999
if (content) {
100100
process.stdout.write(content);
101101
}

samples/js/native-chat-completions/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ console.log('\nTesting streaming completion...');
8484
for await (const chunk of chatClient.completeStreamingChat(
8585
[{ role: 'user', content: 'Write a short poem about programming.' }]
8686
)) {
87-
const content = chunk.choices?.[0]?.message?.content;
87+
const content = chunk.choices?.[0]?.delta?.content;
8888
if (content) {
8989
process.stdout.write(content);
9090
}

samples/js/tutorial-chat-assistant/app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ while (true) {
7373
// Stream the response token by token
7474
process.stdout.write('Assistant: ');
7575
let fullResponse = '';
76-
await chatClient.completeStreamingChat(messages, (chunk) => {
77-
const content = chunk.choices?.[0]?.message?.content;
76+
for await (const chunk of chatClient.completeStreamingChat(messages)) {
77+
const content = chunk.choices?.[0]?.delta?.content;
7878
if (content) {
7979
process.stdout.write(content);
8080
fullResponse += content;
8181
}
82-
});
82+
}
8383
console.log('\n');
8484
// </streaming>
8585

samples/python/native-chat-completions/src/app.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# <complete_code>
22
# <imports>
3-
import asyncio
43
from foundry_local_sdk import Configuration, FoundryLocalManager
54
# </imports>
65

76

8-
async def main():
7+
def main():
98
# <init>
109
# Initialize the Foundry Local SDK
1110
config = Configuration(app_name="foundry_local_samples")
@@ -64,5 +63,5 @@ def ep_progress(ep_name: str, percent: float):
6463

6564

6665
if __name__ == "__main__":
67-
asyncio.run(main())
66+
main()
6867
# </complete_code>

samples/python/tool-calling/src/app.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# <complete_code>
22
# <imports>
3-
import asyncio
43
import json
54
from foundry_local_sdk import Configuration, FoundryLocalManager
65
# </imports>
@@ -130,7 +129,7 @@ def process_tool_calls(messages, response, client):
130129

131130

132131
# <init>
133-
async def main():
132+
def main():
134133
# Initialize the Foundry Local SDK
135134
config = Configuration(app_name="foundry_local_samples")
136135
FoundryLocalManager.initialize(config)
@@ -192,5 +191,5 @@ def ep_progress(ep_name: str, percent: float):
192191

193192

194193
if __name__ == "__main__":
195-
asyncio.run(main())
194+
main()
196195
# </complete_code>

0 commit comments

Comments
 (0)