-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add first chat samples for rest * Add Chat rest examples * last message should be 'role:user' Change-Id: I3e06e9e0ffb553cfc70add5ed0365cb56e9fddff --------- Co-authored-by: Mark Daoust <markdaoust@google.com>
- Loading branch information
1 parent
7c21486
commit 950a666
Showing
1 changed file
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
set -eu | ||
|
||
SCRIPT_DIR=$(dirname "$0") | ||
MEDIA_DIR=$(realpath ${SCRIPT_DIR}/../../third_party) | ||
|
||
echo "[START chat]" | ||
# [START chat] | ||
curl https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=$GOOGLE_API_KEY \ | ||
-H 'Content-Type: application/json' \ | ||
-X POST \ | ||
-d '{ | ||
"contents": [ | ||
{"role":"user", | ||
"parts":[{ | ||
"text": "Hello"}]}, | ||
{"role": "model", | ||
"parts":[{ | ||
"text": "Great to meet you. What would you like to know?"}]}, | ||
{"role":"user", | ||
"parts":[{ | ||
"text": "I have two dogs in my house. How many paws are in my house?"}]}, | ||
] | ||
}' 2> /dev/null | grep "text" | ||
# [END chat] | ||
|
||
echo "[START chat_streaming]" | ||
# [START chat_streaming] | ||
curl https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:streamGenerateContent?key=$GOOGLE_API_KEY \ | ||
-H 'Content-Type: application/json' \ | ||
-X POST \ | ||
-d '{ | ||
"contents": [ | ||
{"role":"user", | ||
"parts":[{ | ||
"text": "Hello"}]}, | ||
{"role": "model", | ||
"parts":[{ | ||
"text": "Great to meet you. What would you like to know?"}]}, | ||
{"role":"user", | ||
"parts":[{ | ||
"text": "I have two dogs in my house. How many paws are in my house?"}]}, | ||
] | ||
}' 2> /dev/null | grep "text" | ||
# [END chat_streaming] | ||
|
||
echo "[START chat_streaming_with_images]" | ||
# [START chat_streaming_with_images] | ||
IMG_PATH=${MEDIA_DIR}/organ.jpg | ||
|
||
if [[ "$(base64 --version 2>&1)" = *"FreeBSD"* ]]; then | ||
B64FLAGS="--input" | ||
else | ||
B64FLAGS="-w0" | ||
fi | ||
|
||
curl https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:streamGenerateContent?key=$GOOGLE_API_KEY \ | ||
-H 'Content-Type: application/json' \ | ||
-X POST \ | ||
-d '{ | ||
"contents": [ | ||
{ | ||
"role": "user", | ||
"parts": [ | ||
{ | ||
"text": "Hello, I am interested in learning about musical instruments. Can I show you one?" | ||
} | ||
] | ||
}, | ||
{ | ||
"role": "model", | ||
"parts": [ | ||
{ | ||
"text": "Certainly." | ||
}, | ||
] | ||
}, | ||
{ | ||
"role": "user", | ||
"parts": [ | ||
{ | ||
"text": "Tell me about this instrument" | ||
}, | ||
{ | ||
"inline_data": { | ||
"mime_type": "image/jpeg", | ||
"data": "'$(base64 $B64FLAGS $IMG_PATH)'" | ||
} | ||
} | ||
] | ||
} | ||
] | ||
}' 2> /dev/null | grep "text" | ||
# [END chat_streaming_with_images] |