groq / groq-typescript

The official Node.js / Typescript library for the Groq API
Apache License 2.0
145 stars 17 forks source link

Incorrect type definition for CompletionCreateParams.ToolChoice #38

Closed domleboss97 closed 1 month ago

domleboss97 commented 3 months ago

The definition of CompletionCreateParams.ToolChoice is the following interface:

export interface ToolChoice {
  string?: string;

  toolChoice?: ToolChoice.ToolChoice;
}

I inferred from this type, that to specify tool_choice: "none", one would have to do the following.

    const completion = await groq.chat.completions.create({
      model,
      messages,
      tools,
      tool_choice: { string: "none" },
})

However this leads to the following 400 error:

Error: 400 {"error":{"message":"Requested tool '' does not exist.","type":"invalid_request_error"}}

When I instead specify the tool_choice directly (i.e. tool_choice: "none"), the request is successful and no tools are invoked, as expected. However, this causes a TS error that I need to ignore.

It appears to me that the type definition of tool choice is incorrect. The toolchoice field of the CompletionCreateParams should be of type string | ToolChoice.

gradenr commented 3 months ago

Thanks for pointing this out. This should be fixed in the latest release (v0.4.0).

gradenr commented 3 months ago

Please let me know if the issue is fixed

domleboss97 commented 3 months ago

Yes, thank you very much! Types are way cleaner with this release. One question - the tools_choice type still excludes the required value that the openai api supports. Have you all not implemented that on your end? Just confirming.

gradenr commented 3 months ago

Groq API does not currently support required. I believe this is being worked on.

gradenr commented 1 month ago

We have added support for required