-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMakeShorter.js
executable file
·66 lines (61 loc) · 2.16 KB
/
MakeShorter.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
// #popclip extension for Google Gemini
// name: Gemini Make Shorter
// icon: "iconify:mdi:file-minus"
// language: javascript
// module: true
// entitlements: [network]
// options: [{
// identifier: apikey, label: API Key, type: string,
// description: 'Obtain API key from Google Cloud Console'
// },
// {
// identifier: model, label: 'model', type: multiple,
// values:['gemini-1.5-flash-latest','gemini-1.5-pro-latest','gemini-1.0-pro']
// }, {
// identifier: prompt, label: 'Make Shorter Prompt', type: string,
// defaultValue: "I'll give you text. You'll rewrite it and output it shorter to be no more than half the number of characters of the original text.Keep the meaning the same. Only give me the output and nothing else.Now, using the concepts above, re-write the following text. Respond in the same language variety or dialect of the following text:{input}",
// description: 'Enter the prompt template using {input} as a placeholder for the text'
// }]
const axios = require("axios");
async function generateContent(input, options) {
const prompt=options.prompt.replace('{input}', input.text);
const requestBody = {
"contents": [{
"parts": [
{"text": prompt}
]
}],
"safetySettings": [
{
"category": "HARM_CATEGORY_HARASSMENT",
"threshold": "BLOCK_ONLY_HIGH"
}
],
"generationConfig": {
"stopSequences": [
"Title"
],
"temperature": 1.0,
"maxOutputTokens": 8192,
"topP": 0.95,
"topK": 64
}
};
try {
const response = await axios.post(
`https://generativelanguage.googleapis.com/v1beta/models/${options.model}:generateContent?key=${options.apikey}`,
requestBody,
{ headers: { 'Content-Type': 'application/json' } }
);
const generatedText = response.data.candidates[0].content.parts.map(part => part.text).join('\n');
return generatedText;
} catch (error) {
console.error("Error generating content:", error);
return "Error generating content: " + error.message;
}
}
exports.actions = [{
title: "Gemini Make Shorter",
after: "paste-result",
code: async (input, options) => generateContent(input, options),
}];