Skip to content

Commit

Permalink
[C#] bump: dotnet to 1.9.0 (#2230)
Browse files Browse the repository at this point in the history
## Linked issues

closes: #minor

## Details
- #2210
- #2214
- #2227

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Lily Du <[email protected]>
Co-authored-by: lilydu <[email protected]>
Co-authored-by: Tarek Mahmoud Sayed <[email protected]>
Co-authored-by: Steven Ickman <[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
10 people authored Dec 11, 2024
1 parent d3356b6 commit 5d1cf55
Show file tree
Hide file tree
Showing 29 changed files with 248 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ public async Task Test_CompletePromptAsync_PromptResponse_NotSuccess()
LLMClientOptions<object> options = new(promptCompletionModel, promptTemplate) { MaxHistoryMessages = 1 };
LLMClient<object> client = new(options, null);
TestMemory memory = new();
ChatMessage message = new ChatMessage("Hi there");
promptCompletionModel.Results.Enqueue(new()
{
Input = new List<ChatMessage>() { message },
Status = PromptResponseStatus.Error,
Error = new TeamsAIException("test")
});
Expand All @@ -113,7 +115,10 @@ public async Task Test_CompletePromptAsync_PromptResponse_NotSuccess()
Assert.Equal(PromptResponseStatus.Error, response.Status);
Assert.NotNull(response.Error);
Assert.Equal("test", response.Error.Message);
Assert.Empty(memory.Values);
Assert.Single(memory.Values);

IList<ChatMessage> conversation_history = (IList<ChatMessage>)memory.GetValue("conversation.history")!;
Assert.True(conversation_history[0].Content == message.Content);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Bot.Builder;
using Google.Protobuf.WellKnownTypes;
using Microsoft.Bot.Builder;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Teams.AI.AI.Models;
Expand Down Expand Up @@ -155,7 +156,6 @@ public async Task<PromptResponse> CompletePromptAsync(
)
{
// Define event handlers
bool isStreaming = false;
StreamingResponse? streamer = null;

BeforeCompletionHandler handleBeforeCompletion = new((object sender, BeforeCompletionEventArgs args) =>
Expand All @@ -168,22 +168,26 @@ public async Task<PromptResponse> CompletePromptAsync(

if (args.Streaming)
{
isStreaming = true;

// Create streamer and send initial message
streamer = new StreamingResponse(context);
memory.SetValue("temp.streamer", streamer);

if (this._enableFeedbackLoop != null)
// Attach to any existing streamer
// - see tool call note below to understand.
streamer = (StreamingResponse?)memory.GetValue("temp.streamer");
if (streamer == null)
{
streamer.EnableFeedbackLoop = this._enableFeedbackLoop;
}
// Create streamer and send initial message
streamer = new StreamingResponse(context);
memory.SetValue("temp.streamer", streamer);

streamer.EnableGeneratedByAILabel = true;
if (this._enableFeedbackLoop != null)
{
streamer.EnableFeedbackLoop = this._enableFeedbackLoop;
}

if (!string.IsNullOrEmpty(this._startStreamingMessage))
{
streamer.QueueInformativeUpdate(this._startStreamingMessage!);
streamer.EnableGeneratedByAILabel = true;

if (!string.IsNullOrEmpty(this._startStreamingMessage))
{
streamer.QueueInformativeUpdate(this._startStreamingMessage!);
}
}
}
});
Expand All @@ -195,6 +199,15 @@ public async Task<PromptResponse> CompletePromptAsync(
return;
}


// Ignore content without text
// - The chunk is likely for a Tool Call.
// - See the tool call note below to understand why we're ignoring them.
if (args.Chunk.delta?.GetContent<string>() == null)
{
return;
}

// Send chunk to client
string text = args.Chunk.delta?.GetContent<string>() ?? "";
IList<Citation>? citations = args.Chunk.delta?.Context?.Citations ?? null;
Expand Down Expand Up @@ -234,23 +247,32 @@ public async Task<PromptResponse> CompletePromptAsync(
cancellationToken
);

if (response.Status != PromptResponseStatus.Success)
{
return response;
}
else
// Handle streaming responses
if (streamer != null)
{
if (isStreaming)
// Tool call handling
// - We need to keep the streamer around during tool calls so we're just letting them return as normal
// messages minus the message content. The text content is being streamed to the client in chunks.
// - When the tool call completes we'll call back into ActionPlanner and end up re-attaching to the
// streamer. This will result in us continuing to stream the response to the client.
if (response.Message?.ActionCalls != null && response.Message.ActionCalls.Count > 0)
{
// Delete the message from the response to avoid sending it twice.
response.Message = null;
// Ensure content is empty for tool calls
response.Message.Content = "";
}
}
else
{
if (response.Status == PromptResponseStatus.Success)
{
// Delete message from response to avoid sending it twice
response.Message = null;
}

// End the stream
if (streamer != null)
{
await streamer.EndStream();
// End the stream and remove pointer from memory
// - We're not listening for the response received event because we can't await the completion of events.
await streamer.EndStream();
memory.DeleteValue("temp.streamer");
}
}

// Get input message/s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Microsoft.Teams.AI.Application;
using System.Reflection;
using System.Runtime.CompilerServices;
using Microsoft.Extensions.Options;

[assembly: InternalsVisibleTo("Microsoft.Teams.AI.Tests")]
#pragma warning disable AOAI001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
Expand Down Expand Up @@ -214,7 +215,6 @@ public async Task<PromptResponse> CompletePromptAsync(ITurnContext turnContext,

ChatCompletionOptions chatCompletionOptions = new()
{
MaxOutputTokenCount = completion.MaxTokens,
Temperature = (float)completion.Temperature,
TopP = (float)completion.TopP,
PresencePenalty = (float)completion.PresencePenalty,
Expand All @@ -223,6 +223,7 @@ public async Task<PromptResponse> CompletePromptAsync(ITurnContext turnContext,

if (isO1Model)
{
chatCompletionOptions.MaxOutputTokenCount = completion.MaxTokens;
chatCompletionOptions.Temperature = 1;
chatCompletionOptions.TopP = 1;
chatCompletionOptions.PresencePenalty = 0;
Expand Down Expand Up @@ -282,6 +283,7 @@ public async Task<PromptResponse> CompletePromptAsync(ITurnContext turnContext,
};
AsyncCollectionResult<StreamingChatCompletionUpdate> streamCompletion = _openAIClient.GetChatClient(_deploymentName).CompleteChatStreamingAsync(chatMessages, chatCompletionOptions, cancellationToken);

var toolCallBuilder = new StreamingChatToolCallsBuilder();
await foreach (StreamingChatCompletionUpdate delta in streamCompletion)
{
if (delta.Role != null)
Expand All @@ -295,9 +297,19 @@ public async Task<PromptResponse> CompletePromptAsync(ITurnContext turnContext,
message.Content += delta.ContentUpdate[0].Text;
}

// TODO: Handle tool calls
// Handle tool calls
if (isToolsAugmentation && delta.ToolCallUpdates != null && delta.ToolCallUpdates.Count > 0)
{
foreach (var toolCallUpdate in delta.ToolCallUpdates)
{
toolCallBuilder.Append(toolCallUpdate);
}
}

ChatMessage currDeltaMessage = new(delta);
ChatMessage currDeltaMessage = new(delta)
{
ActionCalls = message.ActionCalls // Ensure ActionCalls are included
};
PromptChunk chunk = new()
{
delta = currDeltaMessage
Expand All @@ -311,7 +323,19 @@ public async Task<PromptResponse> CompletePromptAsync(ITurnContext turnContext,
_logger.LogTrace("CHUNK", delta);
}

Events!.OnChunkReceived(args);
Events!.OnChunkReceived(args);
}

// Add any tool calls to message
var toolCalls = toolCallBuilder.Build();
if (toolCalls.Count > 0)
{
message.ActionCalls = new List<ActionCall>();
foreach (var toolCall in toolCalls)
{
var actionCall = new ActionCall(toolCall);
message.ActionCalls.Add(actionCall);
}
}

promptResponse.Message = message;
Expand Down
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

View workflow job for this annotation

GitHub Actions / Build/Test/Lint / Build/Test/Lint (6.0)

Missing XML comment for publicly visible type or member 'SequenceBuilder<T>'

Check warning on line 6 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Analyze

Missing XML comment for publicly visible type or member 'SequenceBuilder<T>'

Check warning on line 6 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint (7.0)

Missing XML comment for publicly visible type or member 'SequenceBuilder<T>'

Check warning on line 6 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint / Build/Test/Lint (7.0)

Missing XML comment for publicly visible type or member 'SequenceBuilder<T>'

Check warning on line 6 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint (6.0)

Missing XML comment for publicly visible type or member 'SequenceBuilder<T>'

Check warning on line 6 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Publish (7.0)

Missing XML comment for publicly visible type or member 'SequenceBuilder<T>'

Check warning on line 6 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Publish (6.0)

Missing XML comment for publicly visible type or member 'SequenceBuilder<T>'
{
private Segment _first;

Check warning on line 8 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint / Build/Test/Lint (6.0)

Non-nullable field '_first' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 8 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint / Build/Test/Lint (6.0)

Non-nullable field '_first' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 8 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Analyze

Non-nullable field '_first' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 8 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Analyze

Non-nullable field '_first' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 8 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint (7.0)

Non-nullable field '_first' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 8 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint (7.0)

Non-nullable field '_first' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 8 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint / Build/Test/Lint (7.0)

Non-nullable field '_first' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 8 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint / Build/Test/Lint (7.0)

Non-nullable field '_first' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 8 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint (6.0)

Non-nullable field '_first' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 8 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint (6.0)

Non-nullable field '_first' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 8 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Publish (7.0)

Non-nullable field '_first' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 8 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Publish (6.0)

Non-nullable field '_first' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
private Segment _last;

Check warning on line 9 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint / Build/Test/Lint (6.0)

Non-nullable field '_last' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 9 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint / Build/Test/Lint (6.0)

Non-nullable field '_last' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 9 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Analyze

Non-nullable field '_last' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 9 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Analyze

Non-nullable field '_last' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 9 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint (7.0)

Non-nullable field '_last' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 9 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint (7.0)

Non-nullable field '_last' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 9 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint / Build/Test/Lint (7.0)

Non-nullable field '_last' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 9 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint / Build/Test/Lint (7.0)

Non-nullable field '_last' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 9 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint (6.0)

Non-nullable field '_last' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 9 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint (6.0)

Non-nullable field '_last' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 9 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Publish (7.0)

Non-nullable field '_last' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 9 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Publish (6.0)

Non-nullable field '_last' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

public void Append(ReadOnlyMemory<T> data)

Check warning on line 11 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint / Build/Test/Lint (6.0)

Missing XML comment for publicly visible type or member 'SequenceBuilder<T>.Append(ReadOnlyMemory<T>)'

Check warning on line 11 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Analyze

Missing XML comment for publicly visible type or member 'SequenceBuilder<T>.Append(ReadOnlyMemory<T>)'

Check warning on line 11 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint (7.0)

Missing XML comment for publicly visible type or member 'SequenceBuilder<T>.Append(ReadOnlyMemory<T>)'

Check warning on line 11 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint / Build/Test/Lint (7.0)

Missing XML comment for publicly visible type or member 'SequenceBuilder<T>.Append(ReadOnlyMemory<T>)'

Check warning on line 11 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint (6.0)

Missing XML comment for publicly visible type or member 'SequenceBuilder<T>.Append(ReadOnlyMemory<T>)'

Check warning on line 11 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Publish (7.0)

Missing XML comment for publicly visible type or member 'SequenceBuilder<T>.Append(ReadOnlyMemory<T>)'

Check warning on line 11 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Publish (6.0)

Missing XML comment for publicly visible type or member 'SequenceBuilder<T>.Append(ReadOnlyMemory<T>)'
{
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

View workflow job for this annotation

GitHub Actions / Build/Test/Lint / Build/Test/Lint (6.0)

Missing XML comment for publicly visible type or member 'SequenceBuilder<T>.Build()'

Check warning on line 25 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Analyze

Missing XML comment for publicly visible type or member 'SequenceBuilder<T>.Build()'

Check warning on line 25 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint (7.0)

Missing XML comment for publicly visible type or member 'SequenceBuilder<T>.Build()'

Check warning on line 25 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint / Build/Test/Lint (7.0)

Missing XML comment for publicly visible type or member 'SequenceBuilder<T>.Build()'

Check warning on line 25 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint (6.0)

Missing XML comment for publicly visible type or member 'SequenceBuilder<T>.Build()'

Check warning on line 25 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Publish (7.0)

Missing XML comment for publicly visible type or member 'SequenceBuilder<T>.Build()'

Check warning on line 25 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/SequenceBuilder.cs

View workflow job for this annotation

GitHub Actions / Publish (6.0)

Missing XML comment for publicly visible type or member 'SequenceBuilder<T>.Build()'
{
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;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using OpenAI.Chat;
using System.Buffers;

namespace Microsoft.Teams.AI.AI.Models
{
public class StreamingChatToolCallsBuilder

Check warning on line 6 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/StreamingChatToolCallsBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint / Build/Test/Lint (6.0)

Missing XML comment for publicly visible type or member 'StreamingChatToolCallsBuilder'

Check warning on line 6 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/StreamingChatToolCallsBuilder.cs

View workflow job for this annotation

GitHub Actions / Analyze

Missing XML comment for publicly visible type or member 'StreamingChatToolCallsBuilder'

Check warning on line 6 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/StreamingChatToolCallsBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint (7.0)

Missing XML comment for publicly visible type or member 'StreamingChatToolCallsBuilder'

Check warning on line 6 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/StreamingChatToolCallsBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint / Build/Test/Lint (7.0)

Missing XML comment for publicly visible type or member 'StreamingChatToolCallsBuilder'

Check warning on line 6 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/StreamingChatToolCallsBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint (6.0)

Missing XML comment for publicly visible type or member 'StreamingChatToolCallsBuilder'

Check warning on line 6 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/StreamingChatToolCallsBuilder.cs

View workflow job for this annotation

GitHub Actions / Publish (7.0)

Missing XML comment for publicly visible type or member 'StreamingChatToolCallsBuilder'

Check warning on line 6 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/StreamingChatToolCallsBuilder.cs

View workflow job for this annotation

GitHub Actions / Publish (6.0)

Missing XML comment for publicly visible type or member 'StreamingChatToolCallsBuilder'
{
private readonly Dictionary<int, string> _indexToToolCallId = [];
private readonly Dictionary<int, string> _indexToFunctionName = [];
private readonly Dictionary<int, SequenceBuilder<byte>> _indexToFunctionArguments = [];

public void Append(StreamingChatToolCallUpdate toolCallUpdate)

Check warning on line 12 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/StreamingChatToolCallsBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint / Build/Test/Lint (6.0)

Missing XML comment for publicly visible type or member 'StreamingChatToolCallsBuilder.Append(StreamingChatToolCallUpdate)'

Check warning on line 12 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/StreamingChatToolCallsBuilder.cs

View workflow job for this annotation

GitHub Actions / Analyze

Missing XML comment for publicly visible type or member 'StreamingChatToolCallsBuilder.Append(StreamingChatToolCallUpdate)'

Check warning on line 12 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/StreamingChatToolCallsBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint (7.0)

Missing XML comment for publicly visible type or member 'StreamingChatToolCallsBuilder.Append(StreamingChatToolCallUpdate)'

Check warning on line 12 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/StreamingChatToolCallsBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint / Build/Test/Lint (7.0)

Missing XML comment for publicly visible type or member 'StreamingChatToolCallsBuilder.Append(StreamingChatToolCallUpdate)'

Check warning on line 12 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/StreamingChatToolCallsBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint (6.0)

Missing XML comment for publicly visible type or member 'StreamingChatToolCallsBuilder.Append(StreamingChatToolCallUpdate)'

Check warning on line 12 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/StreamingChatToolCallsBuilder.cs

View workflow job for this annotation

GitHub Actions / Publish (7.0)

Missing XML comment for publicly visible type or member 'StreamingChatToolCallsBuilder.Append(StreamingChatToolCallUpdate)'

Check warning on line 12 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/StreamingChatToolCallsBuilder.cs

View workflow job for this annotation

GitHub Actions / Publish (6.0)

Missing XML comment for publicly visible type or member 'StreamingChatToolCallsBuilder.Append(StreamingChatToolCallUpdate)'
{
// Keep track of which tool call ID belongs to this update index.
if (toolCallUpdate.ToolCallId != null)
{
_indexToToolCallId[toolCallUpdate.Index] = toolCallUpdate.ToolCallId;
}

// Keep track of which function name belongs to this update index.
if (toolCallUpdate.FunctionName != null)
{
_indexToFunctionName[toolCallUpdate.Index] = toolCallUpdate.FunctionName;
}

// Keep track of which function arguments belong to this update index,
// and accumulate the arguments as new updates arrive.
if (toolCallUpdate.FunctionArgumentsUpdate != null && !toolCallUpdate.FunctionArgumentsUpdate.ToMemory().IsEmpty)
{
if (!_indexToFunctionArguments.TryGetValue(toolCallUpdate.Index, out SequenceBuilder<byte> argumentsBuilder))
{
argumentsBuilder = new SequenceBuilder<byte>();
_indexToFunctionArguments[toolCallUpdate.Index] = argumentsBuilder;
}

argumentsBuilder.Append(toolCallUpdate.FunctionArgumentsUpdate);
}
}

public IReadOnlyList<ChatToolCall> Build()

Check warning on line 40 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/StreamingChatToolCallsBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint / Build/Test/Lint (6.0)

Missing XML comment for publicly visible type or member 'StreamingChatToolCallsBuilder.Build()'

Check warning on line 40 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/StreamingChatToolCallsBuilder.cs

View workflow job for this annotation

GitHub Actions / Analyze

Missing XML comment for publicly visible type or member 'StreamingChatToolCallsBuilder.Build()'

Check warning on line 40 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/StreamingChatToolCallsBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint (7.0)

Missing XML comment for publicly visible type or member 'StreamingChatToolCallsBuilder.Build()'

Check warning on line 40 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/StreamingChatToolCallsBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint / Build/Test/Lint (7.0)

Missing XML comment for publicly visible type or member 'StreamingChatToolCallsBuilder.Build()'

Check warning on line 40 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/StreamingChatToolCallsBuilder.cs

View workflow job for this annotation

GitHub Actions / Build/Test/Lint (6.0)

Missing XML comment for publicly visible type or member 'StreamingChatToolCallsBuilder.Build()'

Check warning on line 40 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/StreamingChatToolCallsBuilder.cs

View workflow job for this annotation

GitHub Actions / Publish (7.0)

Missing XML comment for publicly visible type or member 'StreamingChatToolCallsBuilder.Build()'

Check warning on line 40 in dotnet/packages/Microsoft.TeamsAI/Microsoft.TeamsAI/AI/Models/StreamingChatToolCallsBuilder.cs

View workflow job for this annotation

GitHub Actions / Publish (6.0)

Missing XML comment for publicly visible type or member 'StreamingChatToolCallsBuilder.Build()'
{
List<ChatToolCall> toolCalls = [];

foreach (KeyValuePair<int, string> indexToToolCallIdPair in _indexToToolCallId)
{
ReadOnlySequence<byte> sequence = _indexToFunctionArguments[indexToToolCallIdPair.Key].Build();

ChatToolCall toolCall = ChatToolCall.CreateFunctionToolCall(
id: indexToToolCallIdPair.Value,
functionName: _indexToFunctionName[indexToToolCallIdPair.Key],
functionArguments: BinaryData.FromBytes(sequence.ToArray()));

toolCalls.Add(toolCall);
}

return toolCalls;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class GPTTokenizer : ITokenizer
/// Creates an instance of `GPTTokenizer`
/// </summary>
/// <param name="model">model to encode/decode for</param>
public GPTTokenizer(string model) => this._encoding = TiktokenTokenizer.CreateForModel("gpt-4");
public GPTTokenizer(string model) => this._encoding = TiktokenTokenizer.CreateForModel(model);

/// <summary>
/// Encode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Nullable>enable</Nullable>
<PackageId>Microsoft.Teams.AI</PackageId>
<Product>Microsoft Teams AI SDK</Product>
<Version>1.8.1</Version>
<Version>1.9.0</Version>
<Authors>Microsoft</Authors>
<Company>Microsoft</Company>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
Expand Down Expand Up @@ -38,16 +38,17 @@
<PackageReference Include="AdaptiveCards" Version="3.1.0" />
<PackageReference Include="Azure.AI.ContentSafety" Version="1.0.0" />
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0-beta.1" />
<PackageReference Include="JsonSchema.Net" Version="5.5.1" />
<PackageReference Include="JsonSchema.Net" Version="6.1.2" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
<PackageReference Include="Microsoft.Bot.Builder" Version="4.22.9" />
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.22.9" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.22.9" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.61.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.ML.Tokenizers" Version="0.22.0-preview.24378.1" />
<PackageReference Include="Microsoft.ML.Tokenizers.Data.Cl100kBase" Version="1.0.0" /> <!-- This package is required to support gpt-3.x and gpt-4 models -->
<PackageReference Include="Microsoft.ML.Tokenizers.Data.O200kBase" Version="1.0.0" /> <!-- This package is required to support gpt-4o models -->
<PackageReference Include="OpenAI" Version="2.1.0-beta.1" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion dotnet/samples/01.messaging.echoBot/EchoBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<ItemGroup>
<PackageReference Include="AdaptiveCards.Templating" Version="1.3.1" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.22.9" />
<PackageReference Include="Microsoft.Teams.AI" Version="1.8.*" />
<PackageReference Include="Microsoft.Teams.AI" Version="1.9.*" />
</ItemGroup>

<!-- Exclude Teams Toolkit files from build output, but can still be viewed from Solution Explorer -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="AdaptiveCards.Templating" Version="1.4.0" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.22.9" />
<PackageReference Include="Microsoft.Teams.AI" Version="1.8.*" />
<PackageReference Include="Microsoft.Teams.AI" Version="1.9.*" />
</ItemGroup>

<!-- Exclude Teams Toolkit files from build output, but can still be viewed from Solution Explorer -->
Expand Down
Loading

0 comments on commit 5d1cf55

Please sign in to comment.