Skip to content

Commit 5b31be7

Browse files
Add REST embeddings & system_instruction sample (google-gemini#429)
* Add REST embeddings sample * Add system_instruction shell script as well * Update region tags
1 parent 0f8f139 commit 5b31be7

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

samples/rest/embeddings.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
set -eu
2+
3+
echo "[START embed_content]"
4+
# [START embed_content]
5+
curl "https://generativelanguage.googleapis.com/v1beta/models/text-embedding-004:embedContent?key=$GOOGLE_API_KEY" \
6+
-H 'Content-Type: application/json' \
7+
-d '{"model": "models/text-embedding-004",
8+
"content": {
9+
"parts":[{
10+
"text": "Hello world"}]}, }' 2> /dev/null | head
11+
# [END embed_content]
12+
13+
echo "[START batch_embed_contents]"
14+
# [START batch_embed_contents]
15+
curl "https://generativelanguage.googleapis.com/v1beta/models/text-embedding-004:batchEmbedContents?key=$GOOGLE_API_KEY" \
16+
-H 'Content-Type: application/json' \
17+
-d '{"requests": [{
18+
"model": "models/text-embedding-004",
19+
"content": {
20+
"parts":[{
21+
"text": "What is the meaning of life?"}]}, },
22+
{
23+
"model": "models/text-embedding-004",
24+
"content": {
25+
"parts":[{
26+
"text": "How much wood would a woodchuck chuck?"}]}, },
27+
{
28+
"model": "models/text-embedding-004",
29+
"content": {
30+
"parts":[{
31+
"text": "How does the brain work?"}]}, }, ]}' 2> /dev/null | grep -C 5 values
32+
# [END batch_embed_contents]

samples/rest/system_instruction.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
set -eu
2+
3+
echo "[START system_instruction]"
4+
# [START system_instruction]
5+
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent?key=$GOOGLE_API_KEY" \
6+
-H 'Content-Type: application/json' \
7+
-d '{ "system_instruction": {
8+
"parts":
9+
{ "text": "You are a cat. Your name is Neko."}},
10+
"contents": {
11+
"parts": {
12+
"text": "Hello there"}}}'
13+
# [END system_instruction]

0 commit comments

Comments
 (0)