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.26k stars 4.6k forks source link

[BUG] ChatCompletionsFunctionToolCall does not set Type to "function" #40838

Open joakimriedel opened 9 months ago

joakimriedel commented 9 months ago

Library name and version

Azure.AI.OpenAI_1.0.0-beta.12

Describe the bug

When using the ChatCompletionsFunctionToolCall(id, name, arguments) constructor to reconstruct an assistant message for history, the Type is not set to "function". See https://github.com/Azure/azure-sdk-for-net/blob/806d914d1581def963ad055b8b5662938ec8dbd8/sdk/openai/Azure.AI.OpenAI/src/Custom/ChatCompletions/ChatCompletionsFunctionToolCall.cs#L43-L48 and note that the other constructor ChatCompletionsFunctionToolCall(string id, FunctionCall function) does set Type to "function": https://github.com/Azure/azure-sdk-for-net/blob/806d914d1581def963ad055b8b5662938ec8dbd8/sdk/openai/Azure.AI.OpenAI/src/Custom/ChatCompletions/ChatCompletionsFunctionToolCall.cs#L54-L61 but it's internal 😕

Expected behavior

Type should be "function" after constructing the object. Since Type is internal, it is not possible to correct it after construction.

Actual behavior

Type is null.

Reproduction Steps

Construct ChatCompletionsFunctionToolCall using ChatCompletionsFunctionToolCall(id, name, arguments) constructor. Note that Type is null. If you call Azure OpenAI endpoint with a message like this in history, you get the following exception

Azure.RequestFailedException: None is not of type 'string' - 'messages.2.tool_calls.0.type'
Status: 400 (model_error)

Content:
{
  "error": {
    "message": "None is not of type 'string' - 'messages.2.tool_calls.0.type'",
    "type": "invalid_request_error",
    "param": null,
    "code": null
  }
}

Workaround

Ugly but this works

var call = new ChatCompletionsFunctionToolCall(tc.ToolCallId, tc.Name, tc.Arguments);
call.GetType().GetProperty("Type", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(call, "function");
return call;

Environment

No response

github-actions[bot] commented 9 months ago

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

github-actions[bot] commented 9 months ago

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

alennartz commented 8 months ago

We can see this was fixed in the main branch 2 weeks ago in #40987 but that the code in the tagged branch for beta 12 does not include this fix.

ycandrewkao commented 8 months ago

Please let me know when this issue is released. We are stuck on this as well.