Skip to content

Latest commit

 

History

History
executable file
·
60 lines (45 loc) · 1.34 KB

aiGptApi.md

File metadata and controls

executable file
·
60 lines (45 loc) · 1.34 KB

GPT 4

const { Configuration, OpenAIApi } = require("openai");

const { apiKey } = require("./config");

const configuration = new Configuration({
    apiKey: apiKey,
});

const openai = new OpenAIApi(configuration);

async function run() {
    const response = await openai.createChatCompletion({
        model: "gpt-4",
        messages: [
            { role: "system", content: "You are a helpful assistant." },
            { role: "user", content: "Who won the world series in 2020?" },
            { role: "assistant", content: "The Los Angeles Dodgers." },
        ],
        max_tokens: 2000,
        n: 1,
        stop: null,
        temperature: 0,
    });

    console.log(response.data.choices[0].message.content);
}

run();

GPT 3

const { Configuration, OpenAIApi } = require("openai");

const { organization, apiKey } = require("./config");

const configuration = new Configuration({
    organization: organization,
    apiKey: apiKey,
});

const openai = new OpenAIApi(configuration);

async function run() {
    const completion = await openai.createCompletion({
        model: "text-davinci-003",
        prompt: "Who won the world series in 2020?",
        max_tokens: 3000,
        temperature: 0,
    });

    console.log(completion.data.choices[0].text);
}

run();