-
Notifications
You must be signed in to change notification settings - Fork 4
/
gemini.js
58 lines (51 loc) · 1.41 KB
/
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
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
const { VertexAI } = require('@google-cloud/vertexai');
const vertex_ai = new VertexAI({ project: process.env.GCP_PROJECT, location: process.env.GCP_LOCATION});
const model = 'gemini-pro';
const generativeModel = vertex_ai.preview.getGenerativeModel({
model,
generation_config: {
"max_output_tokens": 2048,
"temperature": 0.5,
"top_p": 0.2,
"top_k": 5
},
safety_settings: [
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
},
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"threshold": "BLOCK_LOW_AND_ABOVE"
},
{
"category": "HARM_CATEGORY_HARASSMENT",
"threshold": "BLOCK_LOW_AND_ABOVE"
}
],
});
async function getSummary(text) {
const prompt = "As an expert writer with more than a decade of experience please summarize the following in under 125 words words. You are allowed to rephrase given the summary means the same as the original text:\n\n";
const req = {
contents: [
{
role: 'user',
parts: [
{
text: `${prompt}${text}`
}
]
}
],
};
const resp = await generativeModel.generateContent(req);
const summary = resp.response?.candidates[0]?.content.parts[0].text;
return summary;
};
module.exports = {
getSummary
}