Giter VIP home page Giter VIP logo

openai-nodejs's Introduction

OpenAI NodeJS

A non-official OpenAI API wrapper for node.

Getting Started

Installation

If you have npm installed, start using openai-nodejs with the following commands.

npm install openai-nodejs

Usage

openai-nodejs follows the latest maintenance LTS version of Node.

Example - Complete the phrase "My name is Bond"

const OpenAI = require('openai-nodejs');
const client = new OpenAI('YOUR_API_KEY');

var prompt = 'My name is Bond';
client.complete(prompt, {stop: ['\n', '"'], temperature: 0})
.then(completion => {
    console.log(`Result: ${prompt}${completion.choices[0].text}`);
})
.catch(console.error);

The likely answer will be ", James Bond!"

If you want to see more examples, please check our documentation.

Documentation

You can check the full API reference here.

Note: Some API parameter descriptions adopted from OpenAI's API Reference. If you use the Official OpenAI's API docs as your primary reference, be aware that this library has some differences compared to it.

License

MIT

openai-nodejs's People

Contributors

useems avatar

Stargazers

jerbear4328 avatar Edson S. avatar Lucas Oliveira avatar Damon Malkiewicz avatar

Watchers

 avatar

openai-nodejs's Issues

AssertionError [ERR_ASSERTION]: invalid body content

I am using the complete() function, but I am getting the following error:

AssertionError [ERR_ASSERTION]: invalid body content
{
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '=='
}

The relavant parts of my code:

async function answer(question) {
    prompt += '\n\nUser: ' + question + '\nHomeworkBot:';
    console.log(prompt);
    let response = await gpt.complete(prompt, {
        maxTokens: 10,
        temperature: 0,
        stop: ['\n','User:']
    })
    response = response.choices[0].text;
    prompt += ' ' + response;
    return response;
}
answer('What is 5-2?').then(console.log).catch(console.error)

How do I solve this?

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.