From 683aba3eddab36e754a45552cfc883e768583f15 Mon Sep 17 00:00:00 2001 From: Shilpa Kancharla Date: Wed, 3 Jul 2024 15:59:03 -0400 Subject: [PATCH 1/3] Add REST embeddings sample --- samples/rest/embeddings.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 samples/rest/embeddings.sh diff --git a/samples/rest/embeddings.sh b/samples/rest/embeddings.sh new file mode 100644 index 000000000..7df52a70d --- /dev/null +++ b/samples/rest/embeddings.sh @@ -0,0 +1,32 @@ +set -eu + +echo "[START embed]" +# [START embed] +curl "https://generativelanguage.googleapis.com/v1beta/models/text-embedding-004:embedContent?key=$GOOGLE_API_KEY" \ +-H 'Content-Type: application/json' \ +-d '{"model": "models/text-embedding-004", + "content": { + "parts":[{ + "text": "Hello world"}]}, }' 2> /dev/null | head +# [END embed] + +echo "[START batch_embed]" +# [START batch_embed] +curl "https://generativelanguage.googleapis.com/v1beta/models/text-embedding-004:batchEmbedContents?key=$GOOGLE_API_KEY" \ +-H 'Content-Type: application/json' \ +-d '{"requests": [{ + "model": "models/text-embedding-004", + "content": { + "parts":[{ + "text": "What is the meaning of life?"}]}, }, + { + "model": "models/text-embedding-004", + "content": { + "parts":[{ + "text": "How much wood would a woodchuck chuck?"}]}, }, + { + "model": "models/text-embedding-004", + "content": { + "parts":[{ + "text": "How does the brain work?"}]}, }, ]}' 2> /dev/null | grep -C 5 values +# [END batch_embed] \ No newline at end of file From 56f8015e6ea3e67cbb998f884fd3fd2cf1e5bfe7 Mon Sep 17 00:00:00 2001 From: Shilpa Kancharla Date: Wed, 3 Jul 2024 16:03:16 -0400 Subject: [PATCH 2/3] Add system_instruction shell script as well --- samples/rest/system_instruction.sh | 13 +++++++++++++ samples/system_instruction.py | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 samples/rest/system_instruction.sh diff --git a/samples/rest/system_instruction.sh b/samples/rest/system_instruction.sh new file mode 100644 index 000000000..6a32c8f58 --- /dev/null +++ b/samples/rest/system_instruction.sh @@ -0,0 +1,13 @@ +set -eu + +echo "[START system_instruction]" +# [START system_instruction] +curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent?key=$GOOGLE_API_KEY" \ +-H 'Content-Type: application/json' \ +-d '{ "system_instruction": { + "parts": + { "text": "You are a cat. Your name is Neko."}}, + "contents": { + "parts": { + "text": "Hello there"}}}' +# [END system_instruction] \ No newline at end of file diff --git a/samples/system_instruction.py b/samples/system_instruction.py index ad71a9481..a87932c95 100644 --- a/samples/system_instruction.py +++ b/samples/system_instruction.py @@ -19,14 +19,14 @@ class UnitTests(absltest.TestCase): def test_system_instructions(self): - # [START system_instructions] + # [START system_instruction] model = genai.GenerativeModel( "models/gemini-1.5-flash", system_instruction="You are a cat. Your name is Neko.", ) response = model.generate_content("Good morning! How are you?") print(response.text) - # [END system_instructions] + # [END system_instruction] if __name__ == "__main__": From 8c41f2bd5a5fe398bd719a493677729a6acf2090 Mon Sep 17 00:00:00 2001 From: Shilpa Kancharla Date: Mon, 22 Jul 2024 23:34:36 +0000 Subject: [PATCH 3/3] Update region tags --- samples/rest/embeddings.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/samples/rest/embeddings.sh b/samples/rest/embeddings.sh index 7df52a70d..26fa11d44 100644 --- a/samples/rest/embeddings.sh +++ b/samples/rest/embeddings.sh @@ -1,17 +1,17 @@ set -eu -echo "[START embed]" -# [START embed] +echo "[START embed_content]" +# [START embed_content] curl "https://generativelanguage.googleapis.com/v1beta/models/text-embedding-004:embedContent?key=$GOOGLE_API_KEY" \ -H 'Content-Type: application/json' \ -d '{"model": "models/text-embedding-004", "content": { "parts":[{ "text": "Hello world"}]}, }' 2> /dev/null | head -# [END embed] +# [END embed_content] -echo "[START batch_embed]" -# [START batch_embed] +echo "[START batch_embed_contents]" +# [START batch_embed_contents] curl "https://generativelanguage.googleapis.com/v1beta/models/text-embedding-004:batchEmbedContents?key=$GOOGLE_API_KEY" \ -H 'Content-Type: application/json' \ -d '{"requests": [{ @@ -29,4 +29,4 @@ curl "https://generativelanguage.googleapis.com/v1beta/models/text-embedding-004 "content": { "parts":[{ "text": "How does the brain work?"}]}, }, ]}' 2> /dev/null | grep -C 5 values -# [END batch_embed] \ No newline at end of file +# [END batch_embed_contents] \ No newline at end of file