-
Notifications
You must be signed in to change notification settings - Fork 783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add AsChatClient for OpenAI's AssistantClient #5852
Add AsChatClient for OpenAI's AssistantClient #5852
Conversation
src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatOptions.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIAssistantClient.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIAssistantClient.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIAssistantClient.cs
Outdated
Show resolved
Hide resolved
🎉 Good job! The coverage increased 🎉
Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=943532&view=codecoverage-tab |
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/FunctionCallContent.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIAssistantClient.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIAssistantClient.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIAssistantClient.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatOptions.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIAssistantClient.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIAssistantClient.cs
Outdated
Show resolved
Hide resolved
- Adds ChatOptions/ChatCompletion/StreamingChatCompletionUpdate.ChatThreadId. - Adds an AsChatClient extension method for creating an IChatClient from an AssistantClient. - Updates FunctionInvokingChatClient to have KeepFunctionCallingMessages be false by default, and to handle ChatThreadId. - Fixes handling of ChatCompletion.Usage in ToChatCompletion{Async}.
368e9d9
to
a7826db
Compare
src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatOptions.cs
Show resolved
Hide resolved
...crosoft.Extensions.AI.Abstractions/ChatCompletion/StreamingChatCompletionUpdateExtensions.cs
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs
Outdated
Show resolved
Hide resolved
🎉 Good job! The coverage increased 🎉
Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=944576&view=codecoverage-tab |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Overview
This pull request adds chat thread IDs for managing stateful conversations, introduces a new AsChatClient extension method for AssistantClient, and modifies the default value for KeepFunctionCallingMessages in FunctionInvokingChatClient from true to false. It also refactors how function-calling messages are retained or cleared, updates the handling of usage data aggregation, and includes various serialization, testing, and maintenance improvements.
- Adds ChatThreadId properties to ChatOptions, ChatCompletion, and StreamingChatCompletionUpdate.
- Changes the default KeepFunctionCallingMessages to false and removes the message-tracking cleanup code.
- Provides a new AsChatClient(AssistantClient, string, string?) extension method returning OpenAIAssistantClient.
- Enhances usage content coalescing in streaming updates and aggregates usage details properly in ChatCompletion.
Changes
File | Description |
---|---|
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIAssistantClient.cs | Implements an IChatClient that uses an AssistantClient, optionally with a shared thread ID. |
src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs | Updates default KeepFunctionCallingMessages, refactors function call message handling and usage updates. |
src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatCompletion.cs | Adds ChatThreadId property and usage aggregation improvements. |
test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/ChatCompletion/ChatOptionsTests.cs | Tests for new ChatThreadId property. |
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIClientExtensions.cs | Implements the new AsChatClient method for AssistantClient. |
src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatOptions.cs | Adds ChatThreadId property to ChatOptions and updates clone logic. |
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIChatClient.cs | Minor internal refactoring for default endpoint handling. |
test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientTests.cs | Updates tests to cover the new KeepFunctionCallingMessages default and thread ID behaviors. |
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIModelMapper.ChatCompletion.cs | Exposes DefaultParameterSchema as a property and updates usage accordingly. |
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIJsonContext.cs | Adds support for string array serialization in JSON context. |
src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/StreamingChatCompletionUpdate.cs | Adds ChatThreadId property for streaming completion updates. |
src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatMessage.cs | Adds a shallow Clone method for ChatMessage. |
src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/StreamingChatCompletionUpdateExtensions.cs | Improves how usage content is extracted and aggregated in streaming updates. |
Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (1)
src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs:283
- Fix the typo 'Expecteded' to 'Expected'.
Debug.Assert(functionCount > 0, "Expecteded {nameof(functionCount)} to be > 0, got {functionCount}.");
Tip: Turn on automatic Copilot reviews for this repository to get quick feedback on every pull request. Learn more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
- Personally I'd be more inclined to leave
KeepFunctionCallingMessages
on by default as per https://github.com/dotnet/extensions/pull/5852/files?w=1#r1948821474 but I know this is a subjective call - Should there be some additional tests covering the
FunctionInvokingChatClient
behaviors around its detection/handling ofChatThreadId
? - Technically also we have a load of integration tests for
OpenAIChatClient
that don't have an equivalent in the newOpenAIAssistantClient
. However I know it's a huge pain to create them so will leave it with you to decide if there's enough value in doing so.
Yes, added. Thanks. |
🎉 Good job! The coverage increased 🎉
Full code coverage report: https://dev.azure.com/dnceng-public/public/_build/results?buildId=946767&view=codecoverage-tab |
be false by default, and to handle ChatThreadId.