1
+ set -eu
2
+
3
+ SCRIPT_DIR=$( dirname " $0 " )
4
+ MEDIA_DIR=$( realpath ${SCRIPT_DIR} /../../third_party)
5
+
6
+ echo " [START chat]"
7
+ # [START chat]
8
+ curl https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent? key=$GOOGLE_API_KEY \
9
+ -H ' Content-Type: application/json' \
10
+ -X POST \
11
+ -d ' {
12
+ "contents": [
13
+ {"role":"user",
14
+ "parts":[{
15
+ "text": "Hello"}]},
16
+ {"role": "model",
17
+ "parts":[{
18
+ "text": "Great to meet you. What would you like to know?"}]},
19
+ {"role":"user",
20
+ "parts":[{
21
+ "text": "I have two dogs in my house. How many paws are in my house?"}]},
22
+ ]
23
+ }' 2> /dev/null | grep " text"
24
+ # [END chat]
25
+
26
+ echo " [START chat_streaming]"
27
+ # [START chat_streaming]
28
+ curl https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:streamGenerateContent? key=$GOOGLE_API_KEY \
29
+ -H ' Content-Type: application/json' \
30
+ -X POST \
31
+ -d ' {
32
+ "contents": [
33
+ {"role":"user",
34
+ "parts":[{
35
+ "text": "Hello"}]},
36
+ {"role": "model",
37
+ "parts":[{
38
+ "text": "Great to meet you. What would you like to know?"}]},
39
+ {"role":"user",
40
+ "parts":[{
41
+ "text": "I have two dogs in my house. How many paws are in my house?"}]},
42
+ ]
43
+ }' 2> /dev/null | grep " text"
44
+ # [END chat_streaming]
45
+
46
+ echo " [START chat_streaming_with_images]"
47
+ # [START chat_streaming_with_images]
48
+ IMG_PATH=${MEDIA_DIR} /organ.jpg
49
+
50
+ if [[ " $( base64 --version 2>&1 ) " = * " FreeBSD" * ]]; then
51
+ B64FLAGS=" --input"
52
+ else
53
+ B64FLAGS=" -w0"
54
+ fi
55
+
56
+ curl https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:streamGenerateContent? key=$GOOGLE_API_KEY \
57
+ -H ' Content-Type: application/json' \
58
+ -X POST \
59
+ -d ' {
60
+ "contents": [
61
+ {
62
+ "role": "user",
63
+ "parts": [
64
+ {
65
+ "text": "Hello, I am interested in learning about musical instruments. Can I show you one?"
66
+ }
67
+ ]
68
+ },
69
+ {
70
+ "role": "model",
71
+ "parts": [
72
+ {
73
+ "text": "Certainly."
74
+ },
75
+ ]
76
+ },
77
+ {
78
+ "role": "user",
79
+ "parts": [
80
+ {
81
+ "text": "Tell me about this instrument"
82
+ },
83
+ {
84
+ "inline_data": {
85
+ "mime_type": "image/jpeg",
86
+ "data": "' $( base64 $B64FLAGS $IMG_PATH ) ' "
87
+ }
88
+ }
89
+ ]
90
+ }
91
+ ]
92
+ }' 2> /dev/null | grep " text"
93
+ # [END chat_streaming_with_images]
0 commit comments