-
Notifications
You must be signed in to change notification settings - Fork 0
/
brain.py
24 lines (19 loc) · 806 Bytes
/
brain.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import google.generativeai as genai
import json
class Brain:
def __init__(self, secrets_file="secrets.json"):
# Read the secrets.json file with the json library, then extract the key
with open(secrets_file, "r") as f:
secrets = json.load(f)
gemini_api_key = secrets["gemini_api_key"]
# Initialize the AI
genai.configure(api_key=gemini_api_key)
self.ai = genai.GenerativeModel("gemini-1.5-flash")
def process(self, message, request_type, context) -> str:
if request_type == "speech":
prompt = f"{context}\n{message}" if context is not None else message
thought = self.ai.generate_content(prompt)
output = thought.text
else:
output = "Hello world!"
return output