-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
85 lines (75 loc) · 2.13 KB
/
bot.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
75
76
77
78
79
80
81
82
83
84
import google.generativeai as genai
from sql import *
genai.configure(api_key=" GEMINI API KEY ")
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"
},
]
model = genai.GenerativeModel(model_name="gemini-1.0-pro",
generation_config=generation_config,
safety_settings=safety_settings)
convo = model.start_chat(history=[])
stress_forms = [
"Physical",
"Emotional",
"Psychological",
"Work-related",
"Financial",
"Academic",
"Family-related",
"Relationship",
"Environmental",
"Social",
"Chronic",
"Acute",
"Interpersonal",
"Cognitive",
"Traumatic",
"Daily hassles",
"Burnout",
"Post-traumatic disorder (PTSD)",
"Anxiety",
"Depression",
"Due to uncertainty",
"Health-related",
"Technology-induced",
"Time-related",
"Sleep deprivation-induced",
"Nutrition-related",
"Sexual harassment"
"NULL"
]
def get_Chat_response(text,userid):
define_keyword(text,userid)
convo.send_message("Respond like a therapist under 50 words whose patient said:" + text)
return str(convo.last.text)
def define_keyword(text,userid):
convo.send_message("Given category=" + str(stress_forms) + "define the statement " + text + " using category in the list and return single word from the list")
add_keyword(userid,str(convo.last.text))
def get_1st(userid):
keyword = get_keyword(userid)
if keyword == "null":
return "Hey there! What is bothering you today!"
else:
convo.send_message("Given the context of: " + str(keyword) + "return a calming response under 20 words like a therapist")
return str(convo.last.text)