mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
* Improve fidelity of OpenAI Responses server and add Conversations * Merge * nit * Undo prior change * Undo prior change * Review feedback * Review feedback * Fix test * Use simpler JsonDocument approach for polymorphic deserialization * More review feedback * dotnet format
63 lines
2.0 KiB
C#
63 lines
2.0 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text.Json;
|
|
using Microsoft.Agents.AI.Hosting.OpenAI.Responses.Models;
|
|
using Microsoft.Extensions.AI;
|
|
|
|
namespace Microsoft.Agents.AI.Hosting.OpenAI.Responses.Streaming;
|
|
|
|
/// <summary>
|
|
/// A generator for streaming events from function call content.
|
|
/// </summary>
|
|
internal sealed class FunctionCallEventGenerator(
|
|
IdGenerator idGenerator,
|
|
SequenceNumber seq,
|
|
int outputIndex,
|
|
JsonSerializerOptions jsonSerializerOptions) : StreamingEventGenerator
|
|
{
|
|
public override bool IsSupported(AIContent content) => content is FunctionCallContent;
|
|
|
|
public override IEnumerable<StreamingResponseEvent> ProcessContent(AIContent content)
|
|
{
|
|
if (content is not FunctionCallContent functionCallContent)
|
|
{
|
|
throw new InvalidOperationException("FunctionCallEventGenerator only supports FunctionCallContent.");
|
|
}
|
|
|
|
var item = functionCallContent.ToFunctionToolCallItemResource(idGenerator.GenerateFunctionCallId(), jsonSerializerOptions);
|
|
yield return new StreamingOutputItemAdded
|
|
{
|
|
SequenceNumber = seq.Increment(),
|
|
OutputIndex = outputIndex,
|
|
Item = item
|
|
};
|
|
|
|
yield return new StreamingFunctionCallArgumentsDelta
|
|
{
|
|
SequenceNumber = seq.Increment(),
|
|
ItemId = item.Id,
|
|
OutputIndex = outputIndex,
|
|
Delta = item.Arguments
|
|
};
|
|
|
|
yield return new StreamingFunctionCallArgumentsDone
|
|
{
|
|
SequenceNumber = seq.Increment(),
|
|
ItemId = item.Id,
|
|
OutputIndex = outputIndex,
|
|
Arguments = item.Arguments
|
|
};
|
|
|
|
yield return new StreamingOutputItemDone
|
|
{
|
|
SequenceNumber = seq.Increment(),
|
|
OutputIndex = outputIndex,
|
|
Item = item
|
|
};
|
|
}
|
|
|
|
public override IEnumerable<StreamingResponseEvent> Complete() => [];
|
|
}
|