-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
77 lines (55 loc) · 2.08 KB
/
index.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
67
68
69
70
71
72
73
74
75
76
77
const { TextServiceClient } = require("@google-ai/generativelanguage");
const { GoogleAuth } = require("google-auth-library");
const MODEL_NAME = "models/text-bison-001";
const API_KEY = "AIzaSyANcPpddwHuKTllSEkBzcfvZZDjjF-t4yg";
const client = new TextServiceClient({
authClient: new GoogleAuth().fromAPIKey(API_KEY),
});
const input = 'having indian prices';
const promptString = `best prinses brands${input}`;
const stopSequences = [];
client.generateText({
// required, which model to use to generate the result
model: MODEL_NAME,
// optional, 0.0 always uses the highest-probability result
temperature: 0.7,
// optional, how many candidate results to generate
candidateCount: 1,
// optional, number of most probable tokens to consider for generation
top_k: 40,
// optional, for nucleus sampling decoding strategy
top_p: 0.95,
// optional, maximum number of output tokens to generate
max_output_tokens: 1024,
// optional, sequences at which to stop model generation
stop_sequences: stopSequences,
// optional, safety settings
safety_settings: [{"category":"HARM_CATEGORY_DEROGATORY","threshold":1},{"category":"HARM_CATEGORY_TOXICITY","threshold":1},{"category":"HARM_CATEGORY_VIOLENCE","threshold":2},{"category":"HARM_CATEGORY_SEXUAL","threshold":2},{"category":"HARM_CATEGORY_MEDICAL","threshold":2},{"category":"HARM_CATEGORY_DANGEROUS","threshold":2}],
prompt: {
text: promptString,
},
}).then(result => {
console.log(JSON.stringify(result, null, 2));
});
/*
const { TextServiceClient } =
require("@google-ai/generativelanguage").v1beta2;
const { GoogleAuth } = require("google-auth-library");
const MODEL_NAME = "models/text-bison-001";
const API_KEY = "AIzaSyANcPpddwHuKTllSEkBzcfvZZDjjF-t4yg";
const client = new TextServiceClient({
authClient: new GoogleAuth().fromAPIKey(API_KEY),
});
const prompt = `name 3 best gamaing laptops to buy`;
client
.generateText({
model: MODEL_NAME,
prompt: {
text: prompt,
},
})
.then((result) => {
generatedOutput = result.candidates[0].output;
console.log(generatedOutput);
});
*/