mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
* change namespaces for agents and extension methods of the Microsoft.Agents.AI.OpenAI package * remove unnecessary namespace * remove unused namespaces * fix compilation issues and rrolled back removed run methods * sort usings * add extension methods for AIAgent to work with OpenAI Responses primitives * Move OpenAIChatClientAgent and OpenAIResponseClientAgent to samples * sort usings * sort usings
46 lines
1.8 KiB
C#
46 lines
1.8 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using Microsoft.Agents.AI;
|
|
using Microsoft.Shared.Diagnostics;
|
|
using OpenAI.Chat;
|
|
using OpenAI.Responses;
|
|
|
|
namespace Microsoft.Agents.AI;
|
|
|
|
/// <summary>
|
|
/// Provides extension methods for <see cref="AgentRunResponse"/> and <see cref="AgentRunResponseUpdate"/> instances to
|
|
/// create or extract native OpenAI response objects from the Microsoft Agent Framework responses.
|
|
/// </summary>
|
|
public static class AgentRunResponseExtensions
|
|
{
|
|
/// <summary>
|
|
/// Creates or extracts a native OpenAI <see cref="ChatCompletion"/> object from an <see cref="AgentRunResponse"/>.
|
|
/// </summary>
|
|
/// <param name="response">The agent response.</param>
|
|
/// <returns>The OpenAI <see cref="ChatCompletion"/> object.</returns>
|
|
/// <exception cref="ArgumentNullException"><paramref name="response"/> is <see langword="null"/>.</exception>
|
|
public static ChatCompletion AsOpenAIChatCompletion(this AgentRunResponse response)
|
|
{
|
|
Throw.IfNull(response);
|
|
|
|
return
|
|
response.RawRepresentation as ChatCompletion ??
|
|
response.AsChatResponse().AsOpenAIChatCompletion();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates or extracts a native OpenAI <see cref="OpenAIResponse"/> object from an <see cref="AgentRunResponse"/>.
|
|
/// </summary>
|
|
/// <param name="response">The agent response.</param>
|
|
/// <returns>The OpenAI <see cref="OpenAIResponse"/> object.</returns>
|
|
/// <exception cref="ArgumentNullException"><paramref name="response"/> is <see langword="null"/>.</exception>
|
|
public static OpenAIResponse AsOpenAIResponse(this AgentRunResponse response)
|
|
{
|
|
Throw.IfNull(response);
|
|
|
|
return
|
|
response.RawRepresentation as OpenAIResponse ??
|
|
response.AsChatResponse().AsOpenAIResponse();
|
|
}
|
|
}
|