.NET: Clean / address some message warnings (#291)

* WIP

* Structured Output sample

* Update dotnet/samples/GettingStarted/Steps/Step06_ChatClientAgent_StructuredOutputs.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Address xml and comment targeting the Structured Output context

* Update with proposed fix for Persistent ChatClient

* Address PR feedback

* Address minor warnings

* Address initialization

* Address initialization

* Address PR comments, update suggestions

* Revert changes to NullableAttributese.cs

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Chris <66376200+crickman@users.noreply.github.com>
This commit is contained in:
Roger Barreto
2025-08-05 13:55:44 +01:00
committed by GitHub
Unverified
parent cbb05e210f
commit 9faa27b8eb
19 changed files with 63 additions and 73 deletions
@@ -105,26 +105,21 @@ public sealed class Step03_ChatClientAgent_UsingCodeInterpreterTools(ITestOutput
/// <param name="provider">Provider of the chat client that is used to determine how to extract the output.</param>
/// <returns>The code interpreter output as a string.</returns>
private static string? GetCodeInterpreterOutput(object rawRepresentation, ChatClientProviders provider)
{
switch (provider)
=> provider switch
{
case ChatClientProviders.OpenAIAssistant
when rawRepresentation is OpenAI.Assistants.RunStepDetailsUpdate stepDetails:
return $"{stepDetails.CodeInterpreterInput}{string.Join(
string.Empty,
stepDetails.CodeInterpreterOutputs.SelectMany(l => l.Logs)
)}";
ChatClientProviders.OpenAIAssistant
when rawRepresentation is OpenAI.Assistants.RunStepDetailsUpdate stepDetails => $"{stepDetails.CodeInterpreterInput}{string.Join(
string.Empty,
stepDetails.CodeInterpreterOutputs.SelectMany(l => l.Logs)
)}",
case ChatClientProviders.AzureAIAgentsPersistent
when rawRepresentation is Azure.AI.Agents.Persistent.RunStepDetailsUpdate stepDetails:
return $"{stepDetails.CodeInterpreterInput}{string.Join(
string.Empty,
stepDetails.CodeInterpreterOutputs.OfType<RunStepDeltaCodeInterpreterLogOutput>().SelectMany(l => l.Logs)
)}";
}
return null;
}
ChatClientProviders.AzureAIAgentsPersistent
when rawRepresentation is Azure.AI.Agents.Persistent.RunStepDetailsUpdate stepDetails => $"{stepDetails.CodeInterpreterInput}{string.Join(
string.Empty,
stepDetails.CodeInterpreterOutputs.OfType<RunStepDeltaCodeInterpreterLogOutput>().SelectMany(l => l.Logs)
)}",
_ => null,
};
#endregion
}
@@ -40,7 +40,7 @@ public sealed class Step04_ChatClientAgent_DependencyInjection(ITestOutputHelper
loggerFactory: sp.GetRequiredService<ILoggerFactory>()));
// Build the service provider.
using var serviceProvider = services.BuildServiceProvider();
await using var serviceProvider = services.BuildServiceProvider();
// Get the agent from the service provider.
var agent = serviceProvider.GetRequiredService<AIAgent>();
@@ -23,14 +23,16 @@ public sealed class Step06_ChatClientAgent_StructuredOutputs(ITestOutputHelper o
[InlineData(ChatClientProviders.OpenAIResponses)]
public async Task RunWithCustomSchema(ChatClientProviders provider)
{
var agentOptions = new ChatClientAgentOptions(name: "HelpfulAssistant", instructions: "You are a helpful assistant.");
agentOptions.ChatOptions = new()
var agentOptions = new ChatClientAgentOptions(name: "HelpfulAssistant", instructions: "You are a helpful assistant.")
{
ResponseFormat = ChatResponseFormatJson.ForJsonSchema(
schema: AIJsonUtilities.CreateJsonSchema(typeof(PersonInfo)),
schemaName: "PersonInfo",
schemaDescription: "Information about a person including their name, age, and occupation"
)
ChatOptions = new()
{
ResponseFormat = ChatResponseFormatJson.ForJsonSchema(
schema: AIJsonUtilities.CreateJsonSchema(typeof(PersonInfo)),
schemaName: "PersonInfo",
schemaDescription: "Information about a person including their name, age, and occupation"
)
}
};
// Create the server-side agent Id when applicable (depending on the provider).
@@ -100,17 +100,12 @@ public sealed class Step07_ChatClientAgent_UsingFileSearchTools(ITestOutputHelpe
}
private Task<string> CreateVectorStoreAsync(IEnumerable<string> fileIds, ChatClientProviders provider)
{
switch (provider)
=> provider switch
{
case ChatClientProviders.OpenAIAssistant:
return CreateVectorStoreOpenAIAssistantAsync(fileIds);
case ChatClientProviders.AzureAIAgentsPersistent:
return CreateVectorStoreAzureAIAgentsPersistentAsync(fileIds);
default:
throw new NotSupportedException($"Client provider {provider} is not supported.");
}
}
ChatClientProviders.OpenAIAssistant => CreateVectorStoreOpenAIAssistantAsync(fileIds),
ChatClientProviders.AzureAIAgentsPersistent => CreateVectorStoreAzureAIAgentsPersistentAsync(fileIds),
_ => throw new NotSupportedException($"Client provider {provider} is not supported."),
};
private async Task<string> CreateVectorStoreOpenAIAssistantAsync(IEnumerable<string> fileIds)
{