-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathgenerate-content-from-text.mjs
67 lines (62 loc) · 1.6 KB
/
generate-content-from-text.mjs
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
import common from "../common/generate-content.mjs";
import utils from "../../common/utils.mjs";
export default {
...common,
key: "google_gemini-generate-content-from-text",
name: "Generate Content from Text",
description: "Generates content from text input using the Google Gemini API. [See the documentation](https://ai.google.dev/tutorials/rest_quickstart#text-only_input)",
version: "0.2.0",
type: "action",
async run({ $ }) {
const {
app,
model,
text,
history,
safetySettings,
responseFormat,
responseSchema,
maxOutputTokens,
temperature,
topP,
topK,
stopSequences,
} = this;
const contents = [
...this.formatHistoryToContent(history),
{
parts: [
{
text,
},
],
role: "user",
},
];
const response = await app.generateContent({
$,
model,
data: {
contents,
safetySettings: this.formatSafetySettings(safetySettings),
...(
responseFormat || maxOutputTokens || temperature || topP || topK || stopSequences?.length
? {
generationConfig: {
responseMimeType: "application/json",
responseSchema: utils.parse(responseSchema),
maxOutputTokens,
temperature,
topP,
topK,
stopSequences,
},
}
: {}
),
},
});
$.export("$summary", "Successfully generated content from text input.");
return response;
},
};