Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Libraries/Microsoft.Extensions.AI.OpenAI/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## NOT YET RELEASED

- Fixed issue with IChatClient for Assistants API where a chat history including unrelated function calls would cause an exception.

## 9.9.1-preview.1.25474.6

- Updated to depend on OpenAI 2.5.0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,10 @@ public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(

// Get the thread ID.
string? threadId = options?.ConversationId ?? _defaultThreadId;
if (threadId is null && toolResults is not null)
{
Throw.ArgumentException(nameof(messages), "No thread ID was provided, but chat messages includes tool results.");
}

// Get any active run ID for this thread. This is necessary in case a thread has been left with an
// active run, in which all attempts other than submitting tools will fail. We thus need to cancel
// any active run on the thread.
// active run, in which case all attempts other than submitting tools will fail. We thus need to cancel
// any active run on the thread if we're not submitting tool results to it.
ThreadRun? threadRun = null;
if (threadId is not null)
{
Expand All @@ -111,7 +107,7 @@ public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
ConvertFunctionResultsToToolOutput(toolResults, out List<ToolOutput>? toolOutputs) is { } toolRunId &&
toolRunId == threadRun.Id)
{
// There's an active run and we have tool results to submit, so submit the results and continue streaming.
// There's an active run and, critically, we have tool results to submit for that exact run, so submit the results and continue streaming.
// This is going to ignore any additional messages in the run options, as we are only submitting tool outputs,
// but there doesn't appear to be a way to submit additional messages, and having such additional messages is rare.
updates = _client.SubmitToolOutputsToRunStreamingAsync(threadRun.ThreadId, threadRun.Id, toolOutputs, cancellationToken);
Expand Down Expand Up @@ -487,7 +483,7 @@ void AppendSystemInstructions(string? toAppend)
messageContents.Add(MessageContent.FromImageUri(image.Uri));
break;

case FunctionResultContent result:
case FunctionResultContent result when chatMessage.Role == ChatRole.Tool:
(functionResults ??= []).Add(result);
break;
}
Expand Down
Loading