JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3870
  • Score
    100M100P100Q155133F
  • License MIT

Node.js library for the Azure OpenAI API

Package Exports

  • azure-openai
  • azure-openai/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (azure-openai) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Azure OpenAI Node.js Library

This is a fork of the official OpenAI Node.js library that has been adapted to support the Azure OpenAI API. The objective of this library is to minimize the changes required to migrate from the official OpenAI library to Azure OpenAI or revert back to OpenAI.

Installation

To install this library, use the following command:

$ npm install azure-openai

Usage

The library needs to be configured with your Azure OpenAI's key, endpoint and deploymentId. you can obtain these credentials from Azure Portal. Please see the below screenshot: image

To migrate from the official OpenAI model to the Azure OpenAI model, please follow these steps:

  1. Install the library by running the following command:

    $ npm install azure-openai
  2. Update the import statement from "openai" to "azure-openai":

    //import { Configuration, OpenAIApi } from "openai"; 
    import { Configuration, OpenAIApi } from "azure-openai"; 
  3. Pass the key and endpoint in the configuration:

    this.openAiApi = new OpenAIApi(
      new Configuration({
        // this is the key of auzre openai resource
        apiKey: {your-azure-openai-resource-key},
        // this is the endpoint of auzre openai resource. Add this line to pass the base path
        basePath: "https://${your-azure-openai-resource-name}.openai.azure.com/",
      })
    );
  4. update deploymentId in model parameter when send request to Azure OpenAI:

    const completion = await this.openAiApi.createCompletion({
       // this is the deploymentId of auzre openai resource. pass the deployment id into model parameter
       model: ${your-azure-openai-resource-deploymentId},
       prompt: "Hello world",
       ......
     });
  5. optional, if you use stream = true. you may need to change response

    // Azure OpenAI donot response delta data, so you need to change the response to text
    // const delta = parsed.choices[0].delta.content;
    const delta = parsed.choices[0].text;

Test

Currently, only "gpt-3.5-turbo" API has been tested. Please feel free to submit your issues or pull requests to support other APIs.