Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.57k stars 4.83k forks source link

C# Documentation and Tutorials for Azure.AI.OpenAI_2.0.0 #46384

Open fatihyildizhan opened 2 months ago

fatihyildizhan commented 2 months ago

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 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

image

image

Expected behavior

New C# tutorials for Azure.AI.OpenAI_2.0.0

Actual behavior

1) With Azure.AI.OpenAI_2.0.0 some parameters and functions of Tools changed. 2) 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

github-actions[bot] commented 2 months ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @jpalvarezl @ralph-msft @trrwilson.

AngelosP commented 1 month ago

Hi @fatihyildizhan,

Thank you for raising this issue. We are going to take a look and push some updates ASAP.