mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
.NET: Fix bugbash issues (#448)
* Fix bugbash issues * Update dotnet/samples/GettingStarted/Providers/AIAgent_With_OpenAIResponseClient.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
4277aa2576
commit
0982aa9d6d
@@ -26,12 +26,10 @@ public sealed class AIAgent_With_OpenAIAssistant(ITestOutputHelper output) : Age
|
||||
AIAgent agent = openAIClient
|
||||
.GetAssistantClient()
|
||||
.CreateAIAgent(
|
||||
TestConfiguration.OpenAI.ChatModelId,
|
||||
options: new()
|
||||
{
|
||||
Name = JokerName,
|
||||
Instructions = JokerInstructions,
|
||||
});
|
||||
model: TestConfiguration.OpenAI.ChatModelId,
|
||||
name: JokerName,
|
||||
instructions: JokerInstructions
|
||||
);
|
||||
|
||||
// Start a new thread for the agent conversation.
|
||||
AgentThread thread = agent.GetNewThread();
|
||||
|
||||
@@ -18,7 +18,7 @@ public sealed class AIAgent_With_OpenAIClient(ITestOutputHelper output) : AgentS
|
||||
[Fact]
|
||||
public async Task RunWithChatCompletion()
|
||||
{
|
||||
// Get the agent directly from OpenAIClient.
|
||||
// Create the agent using the OpenAI ChatClient.
|
||||
AIAgent agent = new OpenAIClient(TestConfiguration.OpenAI.ApiKey)
|
||||
.GetChatClient(TestConfiguration.OpenAI.ChatModelId)
|
||||
.CreateAIAgent(JokerInstructions, JokerName);
|
||||
|
||||
@@ -4,7 +4,6 @@ using Microsoft.Extensions.AI;
|
||||
using Microsoft.Extensions.AI.Agents;
|
||||
using Microsoft.Shared.Samples;
|
||||
using OpenAI;
|
||||
using OpenAI.Responses;
|
||||
|
||||
namespace Providers;
|
||||
|
||||
@@ -60,13 +59,7 @@ public sealed class AIAgent_With_OpenAIResponseClient(ITestOutputHelper output)
|
||||
{
|
||||
Name = JokerName,
|
||||
Instructions = JokerInstructions,
|
||||
ChatOptions = new ChatOptions
|
||||
{
|
||||
// We can use the RawRepresentationFactory to provide Response service specific
|
||||
// options. Here we can indicate that we do not want the service to store the
|
||||
// conversation in a service managed thread.
|
||||
RawRepresentationFactory = (_) => new ResponseCreationOptions() { StoredOutputEnabled = false }
|
||||
}
|
||||
ChatOptions = new ChatOptions().WithResponseStoredOutputDisabled()
|
||||
});
|
||||
|
||||
// Start a new thread for the agent conversation based on the type.
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
using Microsoft.Shared.Diagnostics;
|
||||
using OpenAI.Responses;
|
||||
|
||||
namespace Microsoft.Extensions.AI.Agents;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="ChatOptions"/>
|
||||
/// </summary>
|
||||
public static class ChatOptionsExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Disables the storage of response output in the chat options.
|
||||
/// </summary>
|
||||
/// <param name="options">Instance of <see cref="ChatOptions"/></param>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public static ChatOptions WithResponseStoredOutputDisabled(this ChatOptions options)
|
||||
{
|
||||
Throw.IfNull(options);
|
||||
|
||||
// We can use the RawRepresentationFactory to provide Response service specific
|
||||
// options. Here we can indicate that we do not want the service to store the
|
||||
// conversation in a service managed thread.
|
||||
options.RawRepresentationFactory = (_) => new ResponseCreationOptions() { StoredOutputEnabled = false };
|
||||
|
||||
return options;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user