Giter Club home page Giter Club logo

hyounoo / azure-openai-node Goto Github PK

View Code? Open in Web Editor NEW

This project forked from 1openwindow/azure-openai-node

0.0 0.0 0.0 297 KB

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.

Home Page: https://www.npmjs.com/package/azure-openai

License: MIT License

TypeScript 100.00%

azure-openai-node's Introduction

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.

This library allows you to use Azure OpenAI's API without making any changes to your existing OpenAI code. You can simply add Azure information to your configuration and start using the Azure OpenAI model.

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, 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:

  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. Add the Azure OpenAI information to your project configuration:

    this.openAiApi = new OpenAIApi(
       new Configuration({
          apiKey: this.apiKey,
          // add azure info into configuration
          azure: {
             apiKey: {your-azure-openai-resource-key},
             endpoint: {your-azure-openai-resource-endpoint},
             // deploymentName is optional, if you donot set it, you need to set it in the request parameter
             deploymentName: {your-azure-openai-resource-deployment-name},
          }
       }),
    );
  4. run your code. That's it.

  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;
    
  6. optional, you can also set your Azure deploymentName by replacing your model with deployment name, like this:

    const response = await this.openAiApi.createCompletion({
      model: {your-azure-openai-resource-deployment-name},
      prompt: prompt,
      maxTokens: 100,
      temperature: 0.9,
      topP: 1,
      presencePenalty: 0,
      frequencyPenalty: 0,
      bestOf: 1,
    });
    

Support

support latest version of OpenAI API, v3.2.0.

Test

API Test Status
createChatCompletion Pass
createCompletion Pass
createEmbedding Pass
createImage Not Support

Check Azure OpenAI Rest Spec

Please feel free to submit your issues or pull requests to support other APIs.

azure-openai-node's People

Contributors

1openwindow avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.