forked from suryanshsk/Python-Voice-Assistant-Suryanshsk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gemini_info.py
74 lines (63 loc) · 2.3 KB
/
gemini_info.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import google.generativeai as genai
# Configure the API key
genai.configure(api_key="API Key") # Replace with your actual API key
# Set up the model configuration
generation_config = {
"temperature": 0.9,
"top_p": 1,
"top_k": 1,
"max_output_tokens": 2048,
}
safety_settings = [
{
"category": "HARM_CATEGORY_HARASSMENT",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
},
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
},
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"threshold": "BLOCK_MEDIUM_AND_ABOVE"
}
]
# Initialize the model (ensure this method is correct)
model = genai.GenerativeModel(
model_name="gemini-pro",
generation_config=generation_config,
safety_settings=safety_settings
)
def get_gemini_response(prompt):
try:
response = model.generate_content(prompt) # Verify this method
return response.text.strip()
except Exception as e:
return f"Error: {e}"
if __name__ == "__main__":
q = """
I have a list of tools that can perform specific actions. Based on the user query, select the appropriate tool from the list and extract the necessary inputs. Please respond in the following JSON format:
{{
"tool": "<tool_name>",
"inputs": {{
"input1": "<value1>",
"input2": "<value2>",
...
}}
}}
Here is the list of tools:
1. "just_print": Requires general response if none of the following tools fits best.
2. "set_reminder": Requires "time" (strictly in ISO format . that is,'date+T+time', including both date and time) and "message".
3. "search_wikipedia": Requires "search_query".
4. "get_weather": Requires "city_name".
5. "tell_joke": Requires no inputs.
6. "play_music": Requires "song_name".
7. "open_website": Requires "website_name".
If the tool requires no inputs, leave the "inputs" field empty.
Query: "Heyy.... How is weather in hyderabad"
"""
print(get_gemini_response(q))