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
support Microsoft Azure OpenAI service endpoints #53
Comments
+1 |
Azure OpenAI APIHere is something I came up with that works for Azure OpenAI. I'm going to use this until OpenAI adds support. You'll have to deploy a model in Azure make sure you name it the same as the selected deployed name, ie. Another thing to note is Azure's completion object removes the data key from the completions object. So instead of Feel free to add to Create a file and copy paste this class:
To use the AzureOpenAIApi class, first import it:
Next, create an instance of the class and pass in a Configuration object as an argument to the constructor. The
Finally, you can call the
|
Another take while they decide to add the api type:
|
+1 I would be happy if the Node.js library could be used as easily as Python's OpenAI module. Using axios is a hassle. |
I published a npm package to support Azure OpenAI API. check this repo: https://github.com/1openwindow/azure-openai-node To migrate from the official OpenAI model to the Azure OpenAI model, you can just simply add azure info into configuration to migrate, that is it. You donot need to change any code. Please see the below steps:
|
Any update on this? +1 |
even simpler than the example from jtvcodes: you can add the headers/params to the configuration as baseOptions const apiKey = loadYourApiKeySomehow();
const configuration = new Configuration({
apiKey,
basePath: 'https://[your-deployment-name].openai.azure.com/openai/deployments/[your-model-name]',
baseOptions: {
headers: {'api-key': apiKey},
params: {
'api-version': '2023-03-15-preview' // this might change. I got the current value from the sample code at https://oai.azure.com/portal/chat
}
}
}); The completion call is then just const completion = await openai.createCompletion({prompt}); |
@zoellner's solution works well. Here is some public information on the https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#chat-completions |
The upcoming v4 release of this library can be used with Azure as demonstrated in this example: https://github.com/openai/openai-node/blob/v4/examples/azure.ts (it's quite similar to @zoellner 's example – thank you for that!) We do hope to make usage with Azure more convenient in the future. There's also a separate Azure OpenAI client here: https://www.npmjs.com/package/@azure/openai |
Describe the feature or improvement you're requesting
Update the API configuration to support Azure openai endpoints as well.
In order to use the Python OpenAI library with Microsoft Azure endpoints, we need to set the api_type, api_base and api_version in addition to the api_key. The api_type must be set to 'azure' and the others correspond to the properties of your endpoint. In addition, the deployment name must be passed as the engine parameter.
python
import openai
openai.api_type = "azure"
openai.api_key = "..."
openai.api_base = "https://example-endpoint.openai.azure.com"
openai.api_version = "2022-12-01"
create a completion
completion = openai.Completion.create(engine="deployment-name", prompt="Hello world")
print the completion
print(completion.choices[0].text)
Additional context
No response
The text was updated successfully, but these errors were encountered: