-
Notifications
You must be signed in to change notification settings - Fork 1
/
openai.js
49 lines (45 loc) · 1.06 KB
/
openai.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
const openai = require('openai');
const { codeExtracter } = require('./utils');
require('dotenv').config();
const client = new openai({
apiKey: process.env.OPENAI_API_KEY,
});
const sendQuery = async params => {
const {
focalCode,
temperature,
maxLength,
stopSequences,
topP,
frequencyPenalty,
presencePenalty,
modelSelection,
} = params;
const SYSTEM_PROMPT = `You are a unit test generator for Python codes.\
User will give you plain Python codes and you are going to output plain Python unit test codes for it.`;
const output = await client.chat.completions.create({
model: modelSelection,
messages: [
{
role: 'system',
content: SYSTEM_PROMPT,
},
{
role: 'user',
content: focalCode,
},
],
max_tokens: maxLength,
temperature,
top_p: topP,
frequency_penalty: frequencyPenalty,
presence_penalty: presencePenalty,
stop: stopSequences,
});
// console.log(output.choices[0].message.content);
return {
code: 200,
testFunction: codeExtracter(output.choices[0].message.content),
};
};
module.exports = sendQuery;