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.25k
stars
4.59k
forks
source link
[BUG] Setting ChatCompetionOption.ToolChoice always leads to throw #45598
Creating a ChatCompletionOptions instance (including ToolChoice property)
Calling CompleteChatStreamingAsync (where the exception happens)
If I don't use any tool/function, setting the ToolChoice property always leads to throwing with the following error.
I tried both ChatToolChoice.Auto and ChatToolChoice.None (which apparently is the default value when it is not specified) but both values will cause the exception.
'HTTP 400 (invalid_request_error: )
Parameter: tool_choice
Invalid value for 'tool_choice': 'tool_choice' is only allowed when 'tools' are specified.'
If instead, I don't specify the ToolChoice at all, the call completes successfully.
The point is that when I prepare the ChatCompletionOptions, and since the ToolChoice is an init property, I cannot set its value after creating the instance. But if I set it, I get the exception.
Expected behavior
I expect to be always able to set a value for ToolChoice.
When I don't use the tools/functions, I should specify None which is the default value and the call should succeed.
Actual behavior
If I set the ToolChoice property and I don't specify tools/functions, the completion always throws with the error specified above.
Reproduction Steps
Create a ChatCompletionOptions instance (specifying ToolChoice = ChatToolChoice.None)
Call CompleteChatStreamingAsync
Expect to receive the above exception
Runtime Environment:
OS Name: Windows
OS Version: 10.0.22631
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.100-preview.7.24407.12\
.NET workloads installed:
Configured to use loose manifests when installing new manifests.
[wasm-tools]
Installation Source: VS 17.12.35209.166
Manifest Version: 9.0.0-preview.7.24405.7/9.0.100-preview.7
Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.7\microsoft.net.workload.mono.toolchain.current\9.0.0-preview.7.24405.7\WorkloadManifest.json
Install Type: Msi
Library name and version
Azure.AI.OpenAI 2.0.0-beta.2
Describe the bug
The sequence of calls in the app is:
ChatCompletionOptions
instance (includingToolChoice
property)CompleteChatStreamingAsync
(where the exception happens)If I don't use any tool/function, setting the
ToolChoice
property always leads to throwing with the following error. I tried bothChatToolChoice.Auto
andChatToolChoice.None
(which apparently is the default value when it is not specified) but both values will cause the exception.If instead, I don't specify the
ToolChoice
at all, the call completes successfully.The point is that when I prepare the
ChatCompletionOptions
, and since theToolChoice
is aninit
property, I cannot set its value after creating the instance. But if I set it, I get the exception.Expected behavior
I expect to be always able to set a value for
ToolChoice
. When I don't use the tools/functions, I should specifyNone
which is the default value and the call should succeed.Actual behavior
If I set the
ToolChoice
property and I don't specify tools/functions, the completion always throws with the error specified above.Reproduction Steps
ChatCompletionOptions
instance (specifyingToolChoice = ChatToolChoice.None
)CompleteChatStreamingAsync
Expect to receive the above exceptionEnvironment
Runtime Environment: OS Name: Windows OS Version: 10.0.22631 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\9.0.100-preview.7.24407.12\
.NET workloads installed: Configured to use loose manifests when installing new manifests. [wasm-tools] Installation Source: VS 17.12.35209.166 Manifest Version: 9.0.0-preview.7.24405.7/9.0.100-preview.7 Manifest Path: C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.7\microsoft.net.workload.mono.toolchain.current\9.0.0-preview.7.24405.7\WorkloadManifest.json Install Type: Msi
[aspire] Installation Source: VS 17.12.35209.166 Manifest Version: 8.1.0/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.1.0\WorkloadManifest.json Install Type: FileBased
Host: Version: 9.0.0-preview.7.24405.7 Architecture: x64 Commit: static
.NET SDKs installed: 9.0.100-preview.7.24407.12 [C:\Program Files\dotnet\sdk]
.NET runtimes installed: Microsoft.AspNetCore.App 8.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 9.0.0-preview.7.24406.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 9.0.0-preview.7.24405.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 9.0.0-preview.7.24405.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables: Not set
global.json file: Not found
VS 2022 Preview 17.12 P1