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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ Cargo.lock
bin/
obj/
/src/cs/samples/ConsoleClient/test.http
logs/
10 changes: 7 additions & 3 deletions sdk_v2/cs/src/Microsoft.AI.Foundry.Local.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@
<PropertyGroup>
<!-- default version unless overridden during dotnet build/restore command -->
<FoundryLocalCoreWinMLVersion Condition="'$(FoundryLocalCoreVersion)' != ''">$(FoundryLocalCoreVersion)</FoundryLocalCoreWinMLVersion>
<FoundryLocalCoreWinMLVersion Condition="'$(FoundryLocalCoreVersion)' == ''">0.9.0.2-dev-20260226T191541-2b332047</FoundryLocalCoreWinMLVersion>
<FoundryLocalCoreVersion Condition="'$(FoundryLocalCoreVersion)' == ''">0.9.0.4-dev-20260226T191638-2b332047</FoundryLocalCoreVersion>
</PropertyGroup>
<FoundryLocalCoreWinMLVersion Condition="'$(FoundryLocalCoreVersion)' == ''">0.9.0-dev-20260227T230631-2a3af92</FoundryLocalCoreWinMLVersion>
<FoundryLocalCoreVersion Condition="'$(FoundryLocalCoreVersion)' == ''">0.9.0-dev-20260227T222239-2a3af92</FoundryLocalCoreVersion> </PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
Expand All @@ -109,6 +108,11 @@
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup>
<!-- NU1604: Transitive dependency Microsoft.ML.OnnxRuntime.Gpu.Linux lacks an inclusive lower bound.
This comes from the Microsoft.AI.Foundry.Local.Core package and cannot be fixed here. -->
<NoWarn>$(NoWarn);NU1604</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Condition="'$(UseWinML)' == 'true'"
Include="Microsoft.AI.Foundry.Local.Core.WinML" Version="$(FoundryLocalCoreWinMLVersion)" />
Expand Down
12 changes: 11 additions & 1 deletion sdk_v2/cs/src/OpenAI/AudioClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private async IAsyncEnumerable<AudioCreateTranscriptionResponse> TranscribeAudio
{
var failed = false;

await _coreInterop.ExecuteCommandWithCallbackAsync(
var res = await _coreInterop.ExecuteCommandWithCallbackAsync(
"audio_transcribe",
request,
async (callbackData) =>
Expand All @@ -163,6 +163,16 @@ await _coreInterop.ExecuteCommandWithCallbackAsync(
ct
).ConfigureAwait(false);

// If the native layer returned an error (e.g. missing audio file, invalid model)
// without invoking any callbacks, propagate it so the caller sees an exception
// instead of an empty stream.
if (res.Error != null)
{
channel.Writer.TryComplete(
new FoundryLocalException($"Error from audio_transcribe command: {res.Error}", _logger));
return;
}

// use TryComplete as an exception in the callback may have already closed the channel
_ = channel.Writer.TryComplete();
}
Expand Down
13 changes: 12 additions & 1 deletion sdk_v2/cs/src/OpenAI/ChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private async IAsyncEnumerable<ChatCompletionCreateResponse> ChatStreamingImplAs
{
var failed = false;

await _coreInterop.ExecuteCommandWithCallbackAsync(
var response = await _coreInterop.ExecuteCommandWithCallbackAsync(
"chat_completions",
request,
async (callbackData) =>
Expand All @@ -196,6 +196,17 @@ await _coreInterop.ExecuteCommandWithCallbackAsync(
ct
).ConfigureAwait(false);

// If the native layer returned an error (e.g. missing model, invalid input)
// without invoking any callbacks, propagate it so the caller sees an exception
// instead of an empty stream.
if (!failed && response.Error != null)
{
channel.Writer.TryComplete(
new FoundryLocalException($"Error from chat_completions command: {response.Error}", _logger));
failed = true;
return;
}

// use TryComplete as an exception in the callback may have already closed the channel
_ = channel.Writer.TryComplete();
}
Expand Down
56 changes: 56 additions & 0 deletions sdk_v2/cs/test/FoundryLocal.Tests/AudioClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,33 @@ public async Task AudioTranscription_NoStreaming_Succeeds_WithTemperature()
Console.WriteLine($"Response: {content}");
}

[Test]
public async Task AudioTranscription_NoStreaming_InValidFile()
{
var audioClient = await model!.GetAudioClientAsync();
await Assert.That(audioClient).IsNotNull();

audioClient.Settings.Language = "en";

var audioFilePath = Path.Combine(AppContext.BaseDirectory, "testdata/non_exist_Recording.mp3");

FoundryLocalException? caught = null;
try
{
await audioClient.TranscribeAudioAsync(audioFilePath).ConfigureAwait(false);
}
catch (FoundryLocalException ex)
{
caught = ex;
}

// Assert: a FoundryLocalException must have been thrown
await Assert.That(caught).IsNotNull();
Console.WriteLine($"Caught exception: {caught}");
await Assert.That(caught!.Message).Contains("Audio file not found");

}

[Test]
public async Task AudioTranscription_Streaming_Succeeds()
{
Expand Down Expand Up @@ -123,4 +150,33 @@ public async Task AudioTranscription_Streaming_Succeeds_WithTemperature()


}

[Test]
public async Task AudioTranscription_Streaming_InvalidFiles()
{
var audioClient = await model!.GetAudioClientAsync();
await Assert.That(audioClient).IsNotNull();

audioClient.Settings.Language = "en";

var audioFilePath = Path.Combine(AppContext.BaseDirectory, "testdata/Record.mp3");

FoundryLocalException? caught = null;
try
{
await foreach (var _ in audioClient.TranscribeAudioStreamingAsync(audioFilePath, CancellationToken.None).ConfigureAwait(false))
{
}
}
catch (FoundryLocalException ex)
{
caught = ex;
}

// Assert: a FoundryLocalException must have been thrown
await Assert.That(caught).IsNotNull();
Console.WriteLine($"Caught exception: {caught}");
await Assert.That(caught!.Message).Contains("Audio file not found");

}
}
16 changes: 0 additions & 16 deletions sdk_v2/js/logs/foundry.core20260226.log

This file was deleted.