OpenAI API Examples-Summarize for a 2nd grader

Open API Platformのexamplesをnode.jsで試す旅です。この記事ではSummarize for a 2nd graderを試してみます。

サンプルのソースはこちらにあります。

https://platform.openai.com/examples/default-summarize

サンプルソースのままだと動かないので少し修正を加えます。ソースコードは次の通りです。

[user@somewhere stub]$ cat  examples_summarize.js 
require('dotenv').config(); 
const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
async function run(){
    const response = await openai.createCompletion({
    model: "text-davinci-003",
 prompt: "Explain this joke to a second-grade student:\n\nWhy don't we ever tell secrets on the beach?\n\nBecause the waves might spill the beans!",
    temperature: 1,
    max_tokens: 64,
    top_p: 1.0,
    frequency_penalty: 0.0,
    presence_penalty: 0.0,
    });

    if (response.data && response.data.choices && response.data.choices.length > 0) {
        console.log(response.data.choices[0].text);
    } else {
        console.log("No response received or empty choices.");
    }
}
run();

実行結果

[user@www stub]$ node examples_summarize.js 
This joke means that when you tell secrets, you should be careful. If you tell a secret on the beach, someone might overhear it, just like the waves might carry the secret away.

「OpenAI API Examples-Summarize for a 2nd grader」への1件のフィードバック

コメントする