@@ -4,13 +4,55 @@ echo "[START code_execution_basic]"
4
4
# [START code_execution_basic]
5
5
curl " https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent?key=$GOOGLE_API_KEY " \
6
6
-H ' Content-Type: application/json' \
7
- -d ' {
8
- "tools": [{"code_execution": {}}],
7
+ -d ' {"tools": [{' code_execution' : {}}],
9
8
"contents": {
10
- "parts": {
11
- "text": "What is the sum of the first 50 prime numbers? Generate
12
- and run code for the calculation, and make sure you get all 50."
9
+ "parts":
10
+ {
11
+ "text": "What is the sum of the first 50 prime numbers? Generate and run code for the calculation, and make sure you get all 50."
13
12
}
14
- }
13
+ },
15
14
}'
16
15
# [END code_execution_basic]
16
+
17
+ echo " [START code_execution_chat]"
18
+ # [START code_execution_chat]
19
+ curl " https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent?key=$GOOGLE_API_KEY " \
20
+ -H ' Content-Type: application/json' \
21
+ -d ' {"tools": [{' code_execution' : {}}],
22
+ "contents": [
23
+ {
24
+ "role": "user",
25
+ "parts": [{
26
+ "text": "Can you print \"Hello world!\"?"
27
+ }]
28
+ },{
29
+ "role": "model",
30
+ "parts": [
31
+ {
32
+ "text": ""
33
+ },
34
+ {
35
+ "executable_code": {
36
+ "language": "PYTHON",
37
+ "code": "\nprint(\"hello world!\")\n"
38
+ }
39
+ },
40
+ {
41
+ "code_execution_result": {
42
+ "outcome": "OUTCOME_OK",
43
+ "output": "hello world!\n"
44
+ }
45
+ },
46
+ {
47
+ "text": "I have printed \"hello world!\" using the provided python code block. \n"
48
+ }
49
+ ],
50
+ },{
51
+ "role": "user",
52
+ "parts": [{
53
+ "text": "What is the sum of the first 50 prime numbers? Generate and run code for the calculation, and make sure you get all 50."
54
+ }]
55
+ }
56
+ ]
57
+ }'
58
+ # [END code_execution_chat]
0 commit comments