-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgemini.js
32 lines (30 loc) · 868 Bytes
/
gemini.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
const { GoogleGenerativeAI } = require('@google/generative-ai');
const client = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY);
const { codeExtracter } = require('./utils');
const sendQuery = async params => {
const {
focalCode,
temperature,
maxOutputTokens,
stopSequences,
topP,
topK,
} = params;
const generationConfig = {
temperature,
maxOutputTokens,
topP,
topK,
stopSequences,
};
const model = client.getGenerativeModel({
model: 'gemini-pro',
generationConfig,
});
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 model.generateContent(SYSTEM_PROMPT + focalCode);
const response = output.response;
return codeExtracter(response.text());
};
module.exports = sendQuery;