betalgo / openai

OpenAI .NET sdk - Azure OpenAI, ChatGPT, Whisper, and DALL-E
https://betalgo.github.io/openai/
MIT License
2.85k stars 513 forks source link

FunctionCallingHelper‘s ParameterDescription Required = false not work #442

Closed wumao closed 5 months ago

wumao commented 7 months ago

Describe the bug A clear and concise description of what the bug is.

[ParameterDescription(Description = "Left Parameter", Required = false)] double left,

throw error: System.Exception:“Argument 'left' not found”

Your code piece

  [FunctionDescription("Add new Widget")]
        public string AddWidgetFunction(
             [ParameterDescription(Description = "Widget  Type Parameter", Required = true)] WidgetTypeEnum widgetType,
            [ParameterDescription(Description = "Left Parameter", Required = false)] double left,
           [ParameterDescription(Description = "Top Parameter", Required = false)] double top,

           [ParameterDescription(Description = "Width Parameter", Required = false)] double width,

           [ParameterDescription(Description = "Height Parameter", Required = false)] double height
            )
        {
            return "finish";
        }
        //------------------------
          var obj = new UIFunctionCallingClass();

  var functionCall = new FunctionCall
  {
      Name = "AddWidgetFunction",
      Arguments = "{\"widgetType\":\"Rectangle\"}"
  };

  FunctionCallingHelper.CallFunction<string>(functionCall, obj);

Result More detail about what happened when you run your code. throw error: System.Exception:“Argument 'left' not found”

Expected behavior A clear and concise description of what you expected to happen. Required = false
means you can add the Arguments = "{\"widgetType\":\"Rectangle\",\"left\":30.0}" or Arguments = "{\"widgetType\":\"Rectangle\"}"

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.