Skip to content

Add REST embeddings & system_instruction sample #429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions samples/rest/embeddings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
set -eu

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_content]

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": [{
"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_contents]
13 changes: 13 additions & 0 deletions samples/rest/system_instruction.sh
Original file line number Diff line number Diff line change
@@ -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]
4 changes: 2 additions & 2 deletions samples/system_instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__":
Expand Down
Loading