-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgemini_code.py
More file actions
41 lines (30 loc) · 1.27 KB
/
gemini_code.py
File metadata and controls
41 lines (30 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import rizaio
import google.generativeai as genai
# Get an API key for Gemini from Google and set it as the value of an environment variable named GEMINI_API_KEY
genai.configure(api_key=os.environ.get("GEMINI_API_KEY"))
# Get an API key from https://dashboard.riza.io and set it as the value of an environment variable named RIZA_API_KEY
riza_client = rizaio.Riza()
def execute_python(code:str):
""" Executes a Python script and returns whatever was printed to stdout.
The Python runtime does not have filesystem access, but does include the entire standard library. Read input from stdin and write output to stdout.
"""
resp = riza_client.command.exec(
language="python",
code=code
)
return resp.stdout
def main():
GEMINI_MODEL = "gemini-2.0-flash"
model = genai.GenerativeModel(
GEMINI_MODEL,
tools=[execute_python]
)
chat = model.start_chat(enable_automatic_function_calling=True)
response = chat.send_message('Please base32 encode this message (use a tool if needed): purple monkey dishwasher')
print(response.text)
for content in chat.history:
print(content.role, "->", [type(part).to_dict(part) for part in content.parts])
print('-'*80)
if __name__ == "__main__":
main()