Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"tools" property not being serialized leading to error #101

Closed
BWhiteApps opened this issue Mar 5, 2024 · 4 comments
Closed

"tools" property not being serialized leading to error #101

BWhiteApps opened this issue Mar 5, 2024 · 4 comments

Comments

@BWhiteApps
Copy link

BWhiteApps commented Mar 5, 2024

Using ChatCompleteText the tools property is not getting serialized in the toJson function leading to error:

ChatCompleteText({
    required this.model,
    required this.messages,
    this.temperature = .3,
    this.topP = 1.0,
    this.n = 1,
    this.stream = false,
    this.stop,
    this.maxToken = 100,
    this.presencePenalty = .0,
    this.frequencyPenalty = .0,
    this.user = "",
    this.functions,
    this.functionCall,
    this.responseFormat,
    this.logprobs = false,
    this.logitBias,
    this.topLogprobs,
    this.seed,
    this.tools,
    this.toolChoice,
  });

  Map<String, dynamic> toJson() {
    Map<String, dynamic> json;
    json = Map.of({
      "model": model.model,
      "messages": messages,
      "temperature": temperature,
      "top_p": topP,
      "n": n,
      "stream": stream,
      "stop": stop,
      "max_tokens": maxToken,
      "presence_penalty": presencePenalty,
      "frequency_penalty": frequencyPenalty,
      "user": user,
      "response_format": responseFormat?.toJson(),
      "logit_bias": logitBias,
      "logprobs": logprobs,
      "top_logprobs": topLogprobs,
      "seed": seed,
      "tool_choice": toolChoice,
    })
      ..removeWhere((key, value) => value == null);

    return json;
  }

The 400 error that is returned when making the request is:
data:{error: {message: Invalid value for 'tool_choice': 'tool_choice' is only allowed when 'tools' are specified., type: invalid_request_error, param: tool_choice, code: null}}

Even if this was successful the response also does not appear to be correctly deserializing the function call, trying to use "function_call" instead of "tool_calls".

@redevrx
Copy link
Owner

redevrx commented Mar 6, 2024

hi @BWhiteApps I have fixed it and will update soon.

@redevrx
Copy link
Owner

redevrx commented Mar 6, 2024

Tools support by @ventskus-roman #98

@redevrx
Copy link
Owner

redevrx commented Mar 6, 2024

@BWhiteApps you can try version 3.0.4

@redevrx redevrx closed this as completed Mar 6, 2024
@bwhiteFC
Copy link

bwhiteFC commented Mar 6, 2024

great thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants