mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-21 02:55:49 +00:00
Fixed a misleading tool calling error after a stopped or interrupted answer (#1202)
Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
1 parent
fb8f51dec4
commit
ca7413d84c
18 files changed
+272
-76
No files matched your search
@@ -17,7 +17,7 @@ namespace AIStudio.Provider.Anthropic;
|
||||
/// </remarks>
|
||||
public sealed class AnthropicToolCallingAdapter(Model chatModel, IList<IMessageBase> baseMessages, string systemPrompt, int maxTokens,
|
||||
IDictionary<string, object> apiParameters, IReadOnlyList<(ToolDefinition Definition, IToolImplementation Implementation)> runnableTools,
|
||||
Func<ChatRequest, CancellationToken, IAsyncEnumerable<ServerSentEvent>> streamRequestAsync) : IToolCallingProviderAdapter
|
||||
Func<ChatRequest, ServerSentEventStreamEnd, CancellationToken, IAsyncEnumerable<ServerSentEvent>> streamRequestAsync) : IToolCallingProviderAdapter
|
||||
{
|
||||
private readonly List<IMessageBase> internalMessages = [];
|
||||
private readonly List<AnthropicToolResultContent> pendingToolResults = [];
|
||||
@@ -61,14 +61,19 @@ public sealed class AnthropicToolCallingAdapter(Model chatModel, IList<IMessageB
|
||||
// out with every round: which of them describes the conversation is the loop's decision,
|
||||
// which knows which round this is.
|
||||
//
|
||||
var streamEnd = new ServerSentEventStreamEnd();
|
||||
var accumulator = new AnthropicMessageStreamAccumulator();
|
||||
await foreach (var serverSentEvent in streamRequestAsync(request, token))
|
||||
await foreach (var serverSentEvent in streamRequestAsync(request, streamEnd, token))
|
||||
{
|
||||
var part = accumulator.Process(serverSentEvent);
|
||||
if (part.HasContent || part.Usage.IsKnown)
|
||||
yield return ToolCallingStreamEvent.TextDelta(new ContentStreamChunk(part.TextDelta, [], Usage: part.Usage));
|
||||
}
|
||||
|
||||
// A stream which was cut off ends the round without an outcome, cf. IToolCallingProviderAdapter.ExecuteRoundAsync:
|
||||
if (!streamEnd.IsReached)
|
||||
yield break;
|
||||
|
||||
var response = accumulator.Build();
|
||||
if (response is null)
|
||||
yield break;
|
||||
|
||||
Reference in new issue
Block a user