Azure / azure-sdk-for-js

This repository is for active development of the Azure SDK for JavaScript (NodeJS & Browser). For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/javascript/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-js.
MIT License
2.03k stars 1.19k forks source link

@azure/openai - Additional OPTIONS request made before POST request for `getChatCompletions` call #29572

Closed jamesmcroft closed 3 weeks ago

jamesmcroft commented 4 months ago

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

When calling the getChatCompletions function of an OpenAIClient, an OPTIONS call to the API is made before the POST call is successfully processed.

For most scenarios calling Azure OpenAI directly, this works fine. However, scenarios that implement proxies to multiple Azure OpenAI backend instances do not. This is because the OPTIONS request is not defined in the OpenAPI specification for the Azure OpenAI APIs. Those implementing the spec will not handle OPTIONS requests as is not expected.

Exploring the JS SDK, I cannot find where this request is being made as it is not clear in the OpenAI specific source that this is the case.

To confirm functionality across Azure OpenAI SDKs, the .NET SDK will only perform the POST request resulting in a successful response via a proxy.

To Reproduce Steps to reproduce the behavior:

  1. Create a new OpenAIClient with default Azure OpenAI configuration
  2. Using a traffic monitoring tool (such as Fiddler), make a request using the OpenAIClient using the getChatCompletions function.

Notice that there are two requests made. The initial OPTIONS request, and the subsequent POST request.

Expected behavior A clear and concise description of what you expected to happen.

Only the POST request should be made.

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

Additional context Add any other context about the problem here.

github-actions[bot] commented 4 months ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @glharper.

jamesmcroft commented 4 months ago

Attempting to hijack the requests with a custom HttpClient implementation from the @azure/core-rest-pipeline library also does not work as expected.

I can assume that the OPTIONS request is part of a downstream function called by the default HTTP client provided by the core-rest-pipeline SDK.

xirzec commented 4 months ago

@jamesmcroft this is odd, I don't think we should be making OPTIONS requests in Node. I'd expect this to only happen in a browser due to CORS. Can you confirm the environment you're executing your code in is Node 20?

github-actions[bot] commented 1 month ago

Hi @jamesmcroft. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

deyaaeldeen commented 1 month ago

We strongly recommend that you migrate to using the AzureOpenAI client exported by the official OpenAI client library for JavaScript. Please checkout the migration guide for information on how to do so.

github-actions[bot] commented 1 month ago

Hi @jamesmcroft, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!