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

Sending a (seemingly) valid toolChoice object produces an API error #28325

Closed
2 of 5 tasks
jmaczan opened this issue Jan 22, 2024 · 6 comments
Closed
2 of 5 tasks

Sending a (seemingly) valid toolChoice object produces an API error #28325

jmaczan opened this issue Jan 22, 2024 · 6 comments
Assignees
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported Issues that are reported by GitHub users external to the Azure organization. issue-addressed Workflow: The Azure SDK team believes it to be addressed and ready to close. OpenAI

Comments

@jmaczan
Copy link

jmaczan commented Jan 22, 2024

  • Package Name: @azure/openai
  • Package Version: tested on 1.0.0-beta.8 and 1.0.0-beta.10
  • Operating system: Windows 10
  • nodejs
    • version: 18.12.1
  • [] browser
    • name/version:
  • typescript
    • version: 4.9.5
  • Is the bug related to documentation in

Describe the bug
When sending toolChoice in third parameter object of getChatCompletions, I get an API error:

{
    message: "'$.tool_choice' is invalid. Please check the API 
reference: https://platform.openai.com/docs/api-reference.",   
    type: 'invalid_request_error',
    param: null,
    code: null
  }

toolChoice is defined as optional parameter in GetChatCompletionsOptions and it might look like this:

export declare interface ChatCompletionsNamedFunctionToolSelection {
    /** The object type, which is always 'function'. */
    type: "function";
    /** The name of the function that should be called. */
    name: string;
}

The value is send is

toolChoice: {
    type: "function",
    name: "someFunctionName",
}

To Reproduce
Steps to reproduce the behavior:

  1. Create a simple NodeJS app that sends requests to Azure OpenAI API:
import {
    AzureKeyCredential,
    ChatRequestMessage,
    OpenAIClient,
} from "@azure/openai";


try {
    const client = new OpenAIClient(
        process.env.AOAIEndpoint, // fill with your value
        new AzureKeyCredential(process.env.AOAIKey) // fill with your value
    );

    const deploymentId = process.env.AOAIDeploymentId; // fill with your value

      let result = await client
          .getChatCompletions(
              deploymentId,
              [{ role: "user", content: "Call my function", }] as ChatRequestMessage[],
              {
                  toolChoice: {
                      type: "function",
                      name: "someFunctionName",
                  },
                  tools: [
                      {
                          function: someFunction,  // 
                          type: "function",
                      },
                  ],
              }
          )

And you need to specify someFunction:

import { FunctionDefinition } from "@azure/openai";

export const someFunction: FunctionDefinition = {
    name: "someFunctionName",
    description:
        "This is a pretty nice function to call",
    parameters: {
        type: "object",
        properties: {
            question: {
                type: "string",
                description:
                    "A question that user asked to you",
            },
        },
    },
};

Expected behavior
The worst scenario is that toolChoice parameter is ignored by API. The best is that it works just like in vanilla OpenAI API - https://platform.openai.com/docs/api-reference/chat/create#chat-create-tool_choice, meaning it allows to define when tool should be called

Screenshots

Additional context

Tasks

Preview Give feedback
No tasks being tracked yet.
@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jan 22, 2024
@github-actions github-actions bot removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Jan 22, 2024
@deyaaeldeen
Copy link
Member

@jmaczan thanks for opening this report! Could you please share the exact model your deployment utilizes?

@jmaczan
Copy link
Author

jmaczan commented Jan 22, 2024

@deyaaeldeen Much appreciate your quick response! I'm using GPT-4 1106-Preview. And I'm currently working on a PR fixing this btw, but I'm new to your tooling (like rush) and so my project is still building yet. Do you accept PRs from the outside of MSFT to this repo?

deyaaeldeen added a commit that referenced this issue Jan 23, 2024
### Packages impacted by this PR
@azure/openai

### Issues associated with this PR
#28325

### Describe the problem that is addressed by this PR
@jmaczan found that the spec contains a bug in representing an input
option to chat completions. The spec is being fixed in
Azure/azure-rest-api-specs#27487.

### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?
N/A

### Are there test cases added in this PR? _(If not, why?)_
Yes

### Provide a list of related PRs _(if any)_
Azure/azure-rest-api-specs#27487

### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_

### Checklists
- [x] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so,
create an Issue in the
[Autorest/typescript](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [x] Added a changelog (if necessary)
@deyaaeldeen deyaaeldeen added bug This issue requires a change to an existing behavior in the product in order to be resolved. and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jan 23, 2024
@github-actions github-actions bot added needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team labels Jan 23, 2024
@xirzec
Copy link
Member

xirzec commented Jan 25, 2024

Do you accept PRs from the outside of MSFT to this repo?

Orthogonal to the issue in this thread, I wanted to answer this question specifically to say yes, we do!

@deyaaeldeen
Copy link
Member

@jmaczan @azure/[email protected] has been released with the fix. Please give it a try and let us know if you have any other questions or concerns!

@deyaaeldeen deyaaeldeen added the issue-addressed Workflow: The Azure SDK team believes it to be addressed and ready to close. label Jan 26, 2024
@github-actions github-actions bot removed the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Jan 26, 2024
Copy link

Hi @jmaczan. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.

@jmaczan
Copy link
Author

jmaczan commented Jan 26, 2024

Much thanks for cooperation on this issue, I’m happy I could help. All the best to you and the team!

@jmaczan jmaczan closed this as completed Jan 26, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Apr 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported Issues that are reported by GitHub users external to the Azure organization. issue-addressed Workflow: The Azure SDK team believes it to be addressed and ready to close. OpenAI
Projects
None yet
Development

No branches or pull requests

4 participants