1import { Actor } from 'apify';
2import { Configuration, OpenAIApi } from "openai";
3import {template} from './consts.js'
4
5await Actor.init()
6
7console.log('Loading input');
8const input = await Actor.getInput();
9
10const configuration = new Configuration({
11 apiKey: input?.apiKey,
12});
13const openai = new OpenAIApi(configuration);
14
15if (!configuration.apiKey) {
16 throw new Error("OpenAI API key not configured, please add it in the Input")
17}
18
19const readmeExamplesList = input?.readmeExamples.map((example, index) => `\n${index + 1}. ${example}`);
20
21const prompt = `
22Create a README for an Apify Actor with the name "${input?.actorTitle}".
23
24The actor ${input?.actorDescription}.
25
26${input?.targetWebsite ? `The actor's target website is ${input?.targetWebsite}.` : ''}
27
28Use a neutral, informative tone of voice.
29
30Use GitHub-flavoured Markdown.
31
32Base the README on the following examples of Apify Actors READMES:
33${readmeExamplesList}
34
35Use this template as a suggested structure, but you can modify it if it helps make the content clearer: ${template}.
36
37${input?.sampleData ? `Here is a sample of the data that the Actor produces ${JSON.stringify(input?.sampleData)}` : ''}
38`;
39
40console.log('\n\n***************\n\n')
41console.log('Prompt:\n\n\n', prompt)
42console.log('\n\n\n\nEnd of prompt')
43console.log('\n\n\n\n************************\n\n\n\n')
44
45console.log('Generating the README........')
46const response = await openai.createChatCompletion({
47 model: "gpt-3.5-turbo",
48 messages: [{ role: "user", content: prompt }],
49 temperature: 0.7
50});
51
52const readme = response?.data.choices[0].message.content;
53
54console.log('\n\n\n\n')
55console.log('Saving...')
56
57await Actor.pushData({prompt, readme});
58await Actor.setValue('README.md', readme);
59
60console.log('\n\n\n\n')
61await Actor.exit();