Uh oh!
There was an error while loading. Please reload this page.
Add ToChatCompletion{Async} methods for combining StreamingChatCompletionUpdates - #5605
Conversation
dd9e6d5 to
bdf387fCompareUh oh!
There was an error while loading. Please reload this page.
eiriktsarpalis
commented
Nov 7, 2024
I hadn't realized that |
stephentoub
commented
Nov 7, 2024
Neither of them update the chat history with the resulting message. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
The naming of Do any of the following feel right to you? awaitforeach(varupdateinclient.CompleteStreamingAsync(messages).AppendMessageTo(messages))awaitforeach(varupdateinclient.CompleteStreamingAsync(messages).AppendResultTo(messages))awaitforeach(varupdateinclient.CompleteStreamingAsync(messages).AppendResponseTo(messages))awaitforeach(varupdateinclient.CompleteStreamingAsync(messages).WithAppendTo(messages))awaitforeach(varupdateinclient.CompleteStreamingAsync(messages).ThenAppendTo(messages))I mildly lean towards |
eiriktsarpalis
commented
Nov 7, 2024
I tend to associate the |
Uh oh!
There was an error while loading. Please reload this page.
The hard part here is the ToChatCompletion. With that, someone can do the equivalent of List<StreamingChatCompletionUpdate>updates=[];awaitforeach(varupdateinclient.CompleteStreamingAsync(messages)){Console.Write(update);updates.Add(update);}messages.Add(updates.ToChatCompletion().Message);Given that all of the raised concerns are about |
This is now just: publicstaticChatCompletionToChatCompletion(thisIEnumerable<StreamingChatCompletionUpdate>updates,boolcoalesceContent=true) |
stephentoub
commented
Nov 7, 2024
(though now that I write that out, I'm wondering if I should add one for IAsyncEnumerable as well) |
0e845f5 to
dda3072Comparestephentoub
commented
Nov 7, 2024
Refactored to have ToChatCompletion{Async} and to have them in the Abstractions library. Having them there means a leaf client can choose to use e.g. ToChatCompletionAsync to implement its CompleteAsync method around its CompleteStreamingAsync, if desired. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
eiriktsarpalis
left a comment
There was a problem hiding this comment.
As Microsoft.Extensions.AI.Abstractions is accumulating more and more helper methods, I'm growing somewhat uncomfortable with the "Abstractions" suffix in this project. Would it make sense to rename this to be just Microsoft.Extensions.AI and then have the existing Microsoft.Extensions.AI called something along the lines of Microsoft.Extensions.AI.Middlewares?
I think it's fine. These helpers are to aid in the development of implementations of the abstractions. It's very much in line with other M.E libs. |
SteveSandersonMS
left a comment
There was a problem hiding this comment.
Looks good.
In a previous iteration of this PR, I think you were able to remove the equivalent logic from CachingChatClient and use your new helper instead. But in the current version of the PR that's no longer the case. Is it no longer possible to avoid having two versions of this logic?
stephentoub
commented
Nov 8, 2024
I put these into m.e.ai.abstractions, and the caching stuff is up in m.e.ai. We could reconsolidate if we wanted to expose the coalescing publicly from abstractions. |
stephentoub
commented
Nov 11, 2024
Went another way: #5616 |
WithMessageAddedAsyncenables writing code like:and upon completion of the loop,
messageswill contain aChatMessagemerged from all of the updates.ToChatCompletionis what's used to achieve that, but is also exposed on its own so that code which has an enumerable ofStreamingChatCompletionUpdates can merge them into aChatCompletion. This enables a non-streaming implementation to easily be authored in terms of a streaming one.Microsoft Reviewers: Open in CodeFlow