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
"""
At the command line, only need to run once to install the package via pip:
$ pip install google-generativeai
"""
import google.generativeai as genai
genai.configure(api_key="YOUR API KEY")
defaults = {
'model': 'models/text-bison-001',
'temperature': 0.7,
'candidate_count': 1,
'top_k': 40,
'top_p': 0.95,
'max_output_tokens': 1024,
}
prompt = """Generate some thoughtful and creative questions from the text provided. Structure your questions as creative speculations for where the story could go.
Text: Three people walk into a laundromat. The likely parent, a woman enters first, ushering the other two. Next, a young girl jogs to catch up, a grin on her face and holding a strange alien-like purple plushy. Lagging behind, a cloaked teenager in an oversized hoodie waddles back and forth, awkwardly stiff in their gate as to pass the time. The oldest rushes to the back, looking ready to speak to someone.
Questions: 1. Is this a family?
2. What is the reason they are in the laundromat?
3. Why is the teenager so annoyed?
4. Who else may be in this scene?
Text: A brittle and brisk morning, where everything feels weirdly washed out and slightly powder blue. Sarah steps over the threshold, tugging a tan and brown flannel, as she walks out into the tall grass still dripping in morning dew.
Questions: 1. Who is Sarah?
2. Why did she leave the house?
3. Where is she heading?
4. What kind of place is this? A farm?
Text: An empty room, barely any light other than a thin vertical strip where the slightly uneven steel door meets up awkwardly with its frame. As your eyes adjust, you can see that the walls are simple panels and the floors a standard linoleum faux tile look of a federal office building. Suddenly a harsh overhead light flashes on, casting you in a dynamic shadows.
Questions:"""
response = genai.generate_text(
**defaults,
prompt=prompt
)
print(response.result)
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
const { TextServiceClient } = require("@google-ai/generativelanguage");
const { GoogleAuth } = require("google-auth-library");
const MODEL_NAME = "models/text-bison-001";
const API_KEY = "YOUR API KEY";
const client = new TextServiceClient({
authClient: new GoogleAuth().fromAPIKey(API_KEY),
});
const promptString = "Generate some thoughtful and creative questions from the text provided. Structure your questions as creative speculations for where the story could go.\nText: Three people walk into a laundromat. The likely parent, a woman enters first, ushering the other two. Next, a young girl jogs to catch up, a grin on her face and holding a strange alien-like purple plushy. Lagging behind, a cloaked teenager in an oversized hoodie waddles back and forth, awkwardly stiff in their gate as to pass the time. The oldest rushes to the back, looking ready to speak to someone.\nQuestions: 1. Is this a family?\n2. What is the reason they are in the laundromat?\n3. Why is the teenager so annoyed?\n4. Who else may be in this scene?\nText: A brittle and brisk morning, where everything feels weirdly washed out and slightly powder blue. Sarah steps over the threshold, tugging a tan and brown flannel, as she walks out into the tall grass still dripping in morning dew.\nQuestions: 1. Who is Sarah?\n2. Why did she leave the house?\n3. Where is she heading?\n4. What kind of place is this? A farm?\nText: An empty room, barely any light other than a thin vertical strip where the slightly uneven steel door meets up awkwardly with its frame. As your eyes adjust, you can see that the walls are simple panels and the floors a standard linoleum faux tile look of a federal office building. Suddenly a harsh overhead light flashes on, casting you in a dynamic shadows.\nQuestions:";
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,
prompt: {
text: promptString,
},
}).then(result => {
console.log(JSON.stringify(result, null, 2));
});