SlZeroth / chatgpt-api

openai chatgpt api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CHAT GPT API

You can use chatgpt through javascript through this package.

Features

  • Send prompt and receive result

Installation

npm install chatgpt-api --save

Get your session token

Go to https://chat.openai.com/chat and log in or sign up

  1. Open console with F12
  2. Open Application tab > Cookies image
  3. Copy the value for __Secure-next-auth.session-token and paste it into authToken variable
  4. Save the modified file to config.json (In the current working directory)

How to use

import ChatBot from "chatgpt-api";

console.log(response);

async function main() {
    // check Get your session token section
    const authToken = "YOUR_AUTH_TOKEN";
    const chat = new ChatBot(authToken)
  
    try {
        let response = await chat.sendPrompt("how to make pizza");
        console.log(response);
    } catch (error) {
        // when authToken is unaithorized
        console.log(error);
    }
}

Response

{
  message: 'To make a pizza, you will need the following ingredients:\n' +
    '\n' +
    '- 1 pound of pizza dough\n' +
    '- 1/2 cup of tomato sauce\n' +
    '- 8 ounces of mozzarella cheese, grated\n' +
    '- your choice of toppings (such as mushrooms, onions, olives, pepperoni, etc.)\n' +
    '\n' +
    'Here are the steps to make a pizza:\n' +
    '\n' +
    '1. Preheat your oven to 450 degrees Fahrenheit (230 degrees Celsius).\n' +
    '\n' +
    '2. Roll out the pizza dough on a floured surface to your desired shape and thickness.\n' +
    '\n' +
    'Enjoy your homemade pizza!',
  id: '2f82dd65-be02-454c-97aa-b40c9c1f2a53'
}

About

openai chatgpt api

License:MIT License


Languages

Language:TypeScript 100.0%