C# Documentation and Tutorials for Azure.AI.OpenAI_2.0.0
Library name and version
Azure.AI.OpenAI_2.0.0
Describe the bug
Hello,
With Azure.AI.OpenAI_2.0.0 some parameters and functions of Tools changed.
For example ChatToolCall.CreateFunctionToolCall requires BinaryData. AssistantChatMessage doesn't accept List<ChatToolCall> and string.
Is it possible to update these tutorials according to the new version? https://learn.microsoft.com/en-us/dotnet/api/overview/azure/ai.openai-readme?view=azure-dotnet-preview
Also, OpenAI changed many things. https://github.com/openai/openai-dotnet/commit/31c2ba63c625b1b4fc2640ddf378a97e89b89167#diff-bb91299aa08fe83868f1510a0907da91148364647aa2de0273ddc57ba6bbe7efR50
Expected behavior
New C# tutorials for Azure.AI.OpenAI_2.0.0
Actual behavior
- With
Azure.AI.OpenAI_2.0.0some parameters and functions of Tools changed. - OpenAI changed many things on Tools.
Reproduction Steps
Dictionary<int, string> toolCallIdsByIndex = [];
Dictionary<int, string> functionNamesByIndex = [];
Dictionary<int, StringBuilder> functionArgumentBuildersByIndex = [];
StringBuilder contentBuilder = new();
foreach (StreamingChatCompletionUpdate streamingChatUpdate
in chatClient.CompleteChatStreaming(conversationMessages, options))
{
foreach (ChatMessageContentPart contentPart in streamingChatUpdate.ContentUpdate)
{
contentBuilder.Append(contentPart.Text);
}
foreach (StreamingChatToolCallUpdate toolCallUpdate in streamingChatUpdate.ToolCallUpdates)
{
if (!string.IsNullOrEmpty(toolCallUpdate.Id))
{
toolCallIdsByIndex[toolCallUpdate.Index] = toolCallUpdate.Id;
}
if (!string.IsNullOrEmpty(toolCallUpdate.FunctionName))
{
functionNamesByIndex[toolCallUpdate.Index] = toolCallUpdate.FunctionName;
}
if (!string.IsNullOrEmpty(toolCallUpdate.FunctionArgumentsUpdate))
{
StringBuilder argumentsBuilder
= functionArgumentBuildersByIndex.TryGetValue(toolCallUpdate.Index, out StringBuilder existingBuilder)
? existingBuilder
: new();
argumentsBuilder.Append(toolCallUpdate.FunctionArgumentsUpdate);
functionArgumentBuildersByIndex[toolCallUpdate.Index] = argumentsBuilder;
}
}
}
List<ChatToolCall> toolCalls = [];
foreach (KeyValuePair<int, string> indexToIdPair in toolCallIdsByIndex)
{
toolCalls.Add(ChatToolCall.CreateFunctionToolCall(
indexToIdPair.Value,
functionNamesByIndex[indexToIdPair.Key],
functionArgumentBuildersByIndex[indexToIdPair.Key].ToString()));
}
var assistantChatMessage = new AssistantChatMessage(toolCalls);
assistantChatMessage.Content.Add(ChatMessageContentPart.CreateTextPart(contentBuilder.ToString()));
conversationMessages.Add(assistantChatMessage);
// Placeholder: each tool call must be resolved, like in the non-streaming case
string GetToolCallOutput(ChatToolCall toolCall) => null;
foreach (ChatToolCall toolCall in toolCalls)
{
conversationMessages.Add(new ToolChatMessage(toolCall.Id, GetToolCallOutput(toolCall)));
}
// Repeat with the history and all tool call resolution messages added
Environment
.NET 8
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @jpalvarezl @ralph-msft @trrwilson.
Hi @fatihyildizhan,
Thank you for raising this issue. We are going to take a look and push some updates ASAP.