2023-04-12 09:08:06 -04:00
|
|
|
import * as dotenv from "dotenv";
|
|
|
|
import { Configuration, OpenAIApi } from "openai";
|
2023-04-12 09:36:43 -04:00
|
|
|
import PlotGenerator from "@xeserv/plottoriffic";
|
2023-04-12 09:08:06 -04:00
|
|
|
|
|
|
|
dotenv.config();
|
|
|
|
|
2023-04-12 09:36:43 -04:00
|
|
|
const pg = new PlotGenerator({});
|
|
|
|
const plot = pg.generate();
|
|
|
|
|
2023-04-12 09:08:06 -04:00
|
|
|
const configuration = new Configuration({
|
|
|
|
apiKey: process.env.OPENAI_API_KEY,
|
|
|
|
});
|
|
|
|
const openai = new OpenAIApi(configuration);
|
|
|
|
|
|
|
|
const completion = await openai.createChatCompletion({
|
|
|
|
model: "gpt-3.5-turbo",
|
2023-04-12 09:36:43 -04:00
|
|
|
messages: [
|
|
|
|
{
|
|
|
|
role: "user",
|
|
|
|
content: "Write me a plot summary for the following story:\n\n" + plot.plot,
|
|
|
|
},
|
|
|
|
],
|
2023-04-12 09:08:06 -04:00
|
|
|
});
|
|
|
|
console.log(completion.data.choices[0].message);
|