chat_gpt_sdk icon indicating copy to clipboard operation
chat_gpt_sdk copied to clipboard

Function Calling: None is not of type 'object' - 'messages.0.function_call

Open ChargerMc opened this issue 1 year ago • 1 comments

Hello! Im trying function calling feature with this example:

  void gptFunctionCalling() async {
    final request = ChatCompleteText(
        messages: [
          Messages(
              role: Role.user,
              content: "What is the weather like in Boston?",
              name: "get_current_weather"),
        ],
        maxToken: 200,
        model: GptTurbo0631Model(),
        functions: [
          FunctionData(
              name: "get_current_weather",
              description: "Get the current weather in a given location",
              parameters: {
                "type": "object",
                "properties": {
                  "location": {
                    "type": "string",
                    "description": "The city and state, e.g. San Francisco, CA"
                  },
                  "unit": {
                    "type": "string",
                    "enum": ["celsius", "fahrenheit"]
                  }
                },
                "required": ["location"]
              })
        ],
        functionCall: FunctionCall.auto);

    ChatCTResponse? response = await openAI.onChatCompletion(request: request);
    debugPrint("$response");
  }

But dont work, i'm getting this error: Unhandled Exception: status code :400 message :{message: None is not of type 'object' - 'messages.0.function_call', code: null, type: invalid_request_error}

ChargerMc avatar Jul 06 '23 15:07 ChargerMc

@ChargerMc you have to backend api

redevrx avatar Jul 07 '23 05:07 redevrx