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
"""
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.1,
'candidate_count': 1,
'top_k': 40,
'top_p': 0.95,
'max_output_tokens': 1024,
}
prompt = """Remove hedging to make your writing more persuasive.
Hedged: I think the report might be ready by tomorrow.
Unhedged: The report will be ready by tomorrow.
Hedged: It is obvious that the children do enjoy playing with the trains.
Unhedged: The children enjoy playing with trains.
Hedged: It seems to me like we could use a vacation day.
Unhedged: We need a vacation day.
Hedged: If you don't mind could you send me the address of that person?
Unhedged: Please send me their address.
Hedged: I think the other option fit better with what I perceive are the company's values.
Unhedged:"""
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 = "Remove hedging to make your writing more persuasive.\nHedged: I think the report might be ready by tomorrow.\nUnhedged: The report will be ready by tomorrow.\nHedged: It is obvious that the children do enjoy playing with the trains.\nUnhedged: The children enjoy playing with trains.\nHedged: It seems to me like we could use a vacation day.\nUnhedged: We need a vacation day.\nHedged: If you don't mind could you send me the address of that person?\nUnhedged: Please send me their address.\nHedged: I think the other option fit better with what I perceive are the company's values.\nUnhedged:";
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.1,
// 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));
});