// Copyright (c) Microsoft. All rights reserved.
using Microsoft.Agents.AI;
using Microsoft.Shared.Diagnostics;
using OpenAI.Chat;
using OpenAI.Responses;
namespace Microsoft.Agents.AI;
///
/// Provides extension methods for and instances to
/// create or extract native OpenAI response objects from the Microsoft Agent Framework responses.
///
public static class AgentRunResponseExtensions
{
///
/// Creates or extracts a native OpenAI object from an .
///
/// The agent response.
/// The OpenAI object.
/// is .
public static ChatCompletion AsOpenAIChatCompletion(this AgentRunResponse response)
{
Throw.IfNull(response);
return
response.RawRepresentation as ChatCompletion ??
response.AsChatResponse().AsOpenAIChatCompletion();
}
///
/// Creates or extracts a native OpenAI object from an .
///
/// The agent response.
/// The OpenAI object.
/// is .
public static OpenAIResponse AsOpenAIResponse(this AgentRunResponse response)
{
Throw.IfNull(response);
return
response.RawRepresentation as OpenAIResponse ??
response.AsChatResponse().AsOpenAIResponse();
}
}