-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
… calls (#2214) ## Linked issues closes: #2098 ## Details Port the streaming support for tools augmentation to C#. #### Change details - Added StreamingChatToolCallsBuilder and SequenceBuilder helper classes. - Updated OpenAIModel class to process tool call chunks and return them as a message with ActionCalls. - Updated the LLMClient class to pass through the ActionCalls without closing the streaming response session. **code snippets**: **screenshots**: ## Attestation Checklist - [ ] My code follows the style guidelines of this project - I have checked for/fixed spelling, linting, and other errors - I have commented my code for clarity - I have made corresponding changes to the documentation (updating the doc strings in the code is sufficient) - My changes generate no new warnings - I have added tests that validates my changes, and provides sufficient test coverage. I have tested with: - Local testing - E2E testing in Teams - New and existing unit tests pass locally with my changes ### Additional information > Feel free to add other relevant information below --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: kavin <[email protected]> Co-authored-by: Lily Du <[email protected]> Co-authored-by: lilydu <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Corina <[email protected]> Co-authored-by: Yiqing Zhao <[email protected]> Co-authored-by: Yiqing Zhao <[email protected]> Co-authored-by: Alex Acebo <[email protected]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System.Buffers; | ||
using System.Diagnostics; | ||
|
||
namespace Microsoft.Teams.AI.AI.Models | ||
{ | ||
public class SequenceBuilder<T> | ||
Check warning on line 6 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs GitHub Actions / Build/Test/Lint (6.0)
|
||
{ | ||
private Segment _first; | ||
Check warning on line 8 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs GitHub Actions / Build/Test/Lint (6.0)
Check warning on line 8 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs GitHub Actions / Build/Test/Lint (6.0)
Check warning on line 8 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs GitHub Actions / Build/Test/Lint (7.0)
Check warning on line 8 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs GitHub Actions / Build/Test/Lint (7.0)
|
||
private Segment _last; | ||
Check warning on line 9 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs GitHub Actions / Build/Test/Lint (6.0)
Check warning on line 9 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs GitHub Actions / Build/Test/Lint (6.0)
Check warning on line 9 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs GitHub Actions / Build/Test/Lint (7.0)
Check warning on line 9 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs GitHub Actions / Build/Test/Lint (7.0)
|
||
|
||
public void Append(ReadOnlyMemory<T> data) | ||
Check warning on line 11 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs GitHub Actions / Build/Test/Lint (6.0)
|
||
{ | ||
if (_first == null) | ||
{ | ||
Debug.Assert(_last == null); | ||
_first = new Segment(data); | ||
_last = _first; | ||
} | ||
else | ||
{ | ||
_last = _last!.Append(data); | ||
} | ||
} | ||
|
||
public ReadOnlySequence<T> Build() | ||
Check warning on line 25 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs GitHub Actions / Build/Test/Lint (6.0)
|
||
{ | ||
if (_first == null) | ||
{ | ||
Debug.Assert(_last == null); | ||
return ReadOnlySequence<T>.Empty; | ||
} | ||
|
||
if (_first == _last) | ||
{ | ||
Debug.Assert(_first.Next == null); | ||
return new ReadOnlySequence<T>(_first.Memory); | ||
} | ||
|
||
return new ReadOnlySequence<T>(_first, 0, _last!, _last!.Memory.Length); | ||
} | ||
|
||
private sealed class Segment : ReadOnlySequenceSegment<T> | ||
{ | ||
public Segment(ReadOnlyMemory<T> items) : this(items, 0) | ||
{ | ||
} | ||
|
||
private Segment(ReadOnlyMemory<T> items, long runningIndex) | ||
{ | ||
Debug.Assert(runningIndex >= 0); | ||
Memory = items; | ||
RunningIndex = runningIndex; | ||
} | ||
|
||
public Segment Append(ReadOnlyMemory<T> items) | ||
{ | ||
long runningIndex; | ||
checked { runningIndex = RunningIndex + Memory.Length; } | ||
Segment segment = new(items, runningIndex); | ||
Next = segment; | ||
return segment; | ||
} | ||
} | ||
} | ||
} |