-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdarwin.js
79 lines (74 loc) · 2.5 KB
/
darwin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { Configuration, OpenAIApi } from 'openai'
import * as dotenv from 'dotenv'
dotenv.config()
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
let task = process.env.TASK
let prompt = task
let generation = null
let settings = {
"temperature": 0.5,
"top_p": 1,
"frequency_penalty": 0,
"presence_penalty": 0,
}
while (true){
//EXECUTE TASK
const taskCompletion = await openai.createCompletion({
model: "text-davinci-003",
prompt: prompt,
max_tokens: 2000,
...settings
});
const taskResponse = taskCompletion.data.choices[0].text
console.log("Task Response: " + taskResponse);
//GENERATE IMPROVED PROMPT
const promptImprovementPrompt = `
You are an AI improvement agent that optimizes the prompt for an AI task execution agent.
Your goal is to alter the current prompt so the task execution agent produces the optimal response.
The task execution needs to execute this task:
${task}
The current prompt is ${prompt}
The task execution agent generated the following response to the current prompt:
${taskResponse}
Improved prompt:
`
const promptImprovementCompletion = await openai.createCompletion({
model: "text-davinci-003",
prompt: promptImprovementPrompt,
max_tokens: 1000,
temperature: 0.5
});
prompt = promptImprovementCompletion.data.choices[0].text
//console.log("Improved Prompt: " + prompt);
//GENERATE IMPROVED SETTINGS
const settingsImprovementPrompt = `
You are an AI improvement agent that optimizes the settings for an AI task execution agent.
Your goal is to alter the current settings so the task execution agent produces the optimal response for the promopt.
Return the improved settings as valid JSON in the format: {
"temperature": ,
"top_p": ,
"frequency_penalty": ,
"presence_penalty": ,
}
The task execution needs to respond to this prompt:
${prompt}
Here are its current settings:
${settings}
`
const settingsImprovementCompletion = await openai.createCompletion({
model: "text-davinci-003",
prompt: settingsImprovementPrompt,
max_tokens: 250,
temperature: 0.2
});
try{
settings = JSON.parse(settingsImprovementCompletion.data.choices[0].text)
//console.log("Improved Settings: " + settings);
}
catch(error){
continue
}
}