in wearable/main.py [0:0]
def get_gemini_response(query: str) -> str:
headers = {
"Content-Type": "application/json",
}
url = urlunparse(
URLComponents(
netloc="generativelanguage.googleapis.com",
path=["v1beta", "models", "gemini-pro:generateContent"],
query={"key": params.GOOGLE_API_KEY},
).to_tuple()
)
data = {
"contents": [
{
"role": "user",
"parts": [
{
"text": "You are a helpful and hilarious bot embedded "
"in a Raspberry Pi. Answer in one sentence only; but "
"inject some disfluencies to sound more human."
}
],
},
{"role": "model", "parts": [{"text": "Ok!"}]},
{"role": "user", "parts": [{"text": query}]},
],
"safetySettings": [
{
"category": "HARM_CATEGORY_HARASSMENT",
"threshold": "BLOCK_NONE",
},
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"threshold": "BLOCK_NONE",
},
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"threshold": "BLOCK_NONE",
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"threshold": "BLOCK_NONE",
},
],
"generationConfig": {
"temperature": 1.0,
},
}
response = requests.post(url, headers=headers, data=json.dumps(data))
logging.debug(response.text)
# Arbitrary return the first response (assuming it exists).
return response.json()["candidates"][0]["content"]["parts"][0]["text"]