Spaces:
Runtime error
Runtime error
Commit
·
81af296
1
Parent(s):
d2fcfe2
Mental Health Assistant RAG
Browse files- .envrc +2 -0
- .gitignore +1 -0
- Dockerfile +16 -0
- Images/Lllama distribution plot.png +0 -0
- Images/Mixtral distribution plot.png +0 -0
- Images/Streamlit.jpg +0 -0
- Images/banner.svg +124 -0
- Images/dashboard.jpg +0 -0
- Pipfile +22 -0
- Pipfile.lock +0 -0
- dataset/data.csv +0 -0
- dataset/ground_truth_data.csv +367 -0
- dataset/rag-eval-mistral.csv +0 -0
- dataset/rag_eval_llama.csv +0 -0
- docker-compose.yaml +48 -0
- grafana/dashboard.json +952 -0
- grafana/init.py +237 -0
- notebooks/.ipynb_checkpoints/data_generation-checkpoint.ipynb +542 -0
- notebooks/.ipynb_checkpoints/rag_evaluation-checkpoint.ipynb +0 -0
- notebooks/__pycache__/minsearch.cpython-39.pyc +0 -0
- notebooks/data_generation.ipynb +1336 -0
- notebooks/minsearch.py +96 -0
- notebooks/rag_evaluation.ipynb +0 -0
- src/__pycache__/ingest.cpython-39.pyc +0 -0
- src/__pycache__/minsearch.cpython-39.pyc +0 -0
- src/app.py +230 -0
- src/db.py +322 -0
- src/db_prep.py +12 -0
- src/ingest.py +19 -0
- src/minsearch.py +96 -0
- src/rag.py +145 -0
- src/synthetic_data.py +114 -0
.envrc
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
export GROQ_API_KEY="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"
|
2 |
+
export MISTRAL_API_KEY="8liS0F7zb7zNgujwgo3dgTbr6HbfvmeI"
|
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
.env
|
Dockerfile
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.12-slim
|
2 |
+
|
3 |
+
WORKDIR /app
|
4 |
+
|
5 |
+
RUN pip install pipenv
|
6 |
+
|
7 |
+
COPY dataset/data.csv dataset/data.csv
|
8 |
+
COPY ["Pipfile", "Pipfile.lock", "./"]
|
9 |
+
|
10 |
+
RUN pipenv install --deploy --ignore-pipfile --system
|
11 |
+
|
12 |
+
COPY src .
|
13 |
+
|
14 |
+
EXPOSE 8501
|
15 |
+
|
16 |
+
CMD ["streamlit", "run", "app.py", "--server.port=8501", "--server.enableCORS=false"]
|
Images/Lllama distribution plot.png
ADDED
![]() |
Images/Mixtral distribution plot.png
ADDED
![]() |
Images/Streamlit.jpg
ADDED
![]() |
Images/banner.svg
ADDED
|
Images/dashboard.jpg
ADDED
![]() |
Pipfile
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[[source]]
|
2 |
+
url = "https://pypi.org/simple"
|
3 |
+
verify_ssl = true
|
4 |
+
name = "pypi"
|
5 |
+
|
6 |
+
[packages]
|
7 |
+
mistralai = "*"
|
8 |
+
matplotlib = "*"
|
9 |
+
seaborn = "*"
|
10 |
+
streamlit = "*"
|
11 |
+
scikit-learn = "*"
|
12 |
+
groq = "*"
|
13 |
+
python-dotenv = "*"
|
14 |
+
tqdm = "*"
|
15 |
+
psycopg2-binary = "*"
|
16 |
+
gunicorn = "*"
|
17 |
+
plotly = "*"
|
18 |
+
|
19 |
+
[dev-packages]
|
20 |
+
|
21 |
+
[requires]
|
22 |
+
python_version = "3.9"
|
Pipfile.lock
ADDED
The diff for this file is too large to render.
See raw diff
|
|
dataset/data.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
dataset/ground_truth_data.csv
ADDED
@@ -0,0 +1,367 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
id,question
|
2 |
+
1590140,How do mental illnesses affect a person's daily functioning and relationships?
|
3 |
+
1590140,What are some examples of serious mental illnesses that can result in major functional impairment?
|
4 |
+
1590140,"Why is it a misconception to associate mental illness with a person's character, intelligence, or willpower?"
|
5 |
+
1590140,"How are mental illnesses treated, and what is the success rate of these treatments?"
|
6 |
+
1590140,Can a person with mental illness become independent and successful with proper treatment?
|
7 |
+
2110618,Who are the groups most commonly affected by different mental illnesses?
|
8 |
+
2110618,How do mental illnesses affect children and the elderly?
|
9 |
+
2110618,What behaviors should parents and caretakers watch out for in children that may indicate a serious emotional disturbance?
|
10 |
+
6361820,How does mental illness affect different populations?
|
11 |
+
6361820,At what age are individuals most susceptible to mental illness?
|
12 |
+
6361820,What signs should parents and caretakers look out for in children under 18 that may indicate a mental health condition?
|
13 |
+
9434130,What are some general symptoms that may indicate a mental health disorder in adults?
|
14 |
+
9434130,Can you name some symptoms that could suggest a mental health issue in older children and pre-teens?
|
15 |
+
9434130,Are there any signs that might point to mental health problems in younger children?
|
16 |
+
9434130,What kind of behavior in children might suggest they are struggling with mental health?
|
17 |
+
9434130,What are some potential indicators of mental health issues related to mood or eating habits?
|
18 |
+
7657263,Can early identification and treatment improve recovery from mental illness?
|
19 |
+
7657263,Are there effective treatments available for different types of mental illnesses?
|
20 |
+
7657263,What is the importance of a person's active engagement in their own recovery process from mental illness?
|
21 |
+
7657263,Is it common for some people with mental illness to experience a return of symptoms after treatment?
|
22 |
+
7657263,How can one live a fulfilled and productive life despite careful monitoring and management of mental illness?
|
23 |
+
1619387,What should I do if I suspect someone I know has a mental disorder?
|
24 |
+
1619387,How can I help a friend or family member who might be experiencing symptoms of a mental health condition?
|
25 |
+
1619387,What are the benefits of speaking with a mental health professional if I think a loved one has symptoms of a mental disorder?
|
26 |
+
1030153,How can I search for mental health providers in my area?
|
27 |
+
1030153,What should I consider when researching mental health professionals for myself or my child?
|
28 |
+
1030153,How can I ensure that I will feel comfortable with the mental health professional I choose?
|
29 |
+
8022026,What types of treatments are available for mental illness?
|
30 |
+
8022026,How do different treatment options work for different people?
|
31 |
+
8022026,How can I find the most effective treatment for myself or my child?
|
32 |
+
1155199,What can I expect in terms of the cause of my illness?
|
33 |
+
1155199,Are there other conditions that share my symptoms?
|
34 |
+
1155199,What kind of physical or neurological tests are usually involved?
|
35 |
+
1155199,What other specialists might be involved in my treatment and who will coordinate?
|
36 |
+
1155199,What is the typical role of the family in the treatment process?
|
37 |
+
7760466,What are the differences in education and training among mental health professionals?
|
38 |
+
7760466,How do mental health professionals specialize in different areas?
|
39 |
+
7760466,How can I find a mental health professional that fits my specific needs?
|
40 |
+
2553795,What steps can I take to find a mental health professional who is a good fit for me or my child?
|
41 |
+
2553795,How can I ensure that my child or I will feel comfortable working with a mental health professional?
|
42 |
+
2553795,What resources are available to help me research and find the right mental health professional for my needs or my child's needs?
|
43 |
+
1259439,What can you tell me about the cause of my illness?
|
44 |
+
1259439,Are there other conditions that share my symptoms?
|
45 |
+
1259439,What kinds of examinations do you usually conduct?
|
46 |
+
1259439,What is your recommended treatment program for my diagnosis?
|
47 |
+
1259439,What can I expect from the medications prescribed for my condition?
|
48 |
+
4197817,Where can I find mental health resources in my area?
|
49 |
+
4197817,What kind of organizations offer support groups for consumers and their families?
|
50 |
+
4197817,Are support groups always led by mental health professionals or can they be peer led?
|
51 |
+
3388962,What is the primary purpose of the new medication?
|
52 |
+
3388962,How long does it typically take for the medication to take effect and how will I know when it is effective?
|
53 |
+
3388962,"What are the proper directions for taking this medication, including any food, drinks, or activities to avoid?"
|
54 |
+
3388962,What side effects should I be aware of and what should I do if they occur?
|
55 |
+
3388962,What is the procedure if I accidentally miss a dose of the medication?
|
56 |
+
5343181,"If I feel better after taking medication, does that mean I can stop taking it without consulting my doctor?"
|
57 |
+
5343181,What might happen if I stop taking my medication abruptly?
|
58 |
+
5343181,How can I address side effects that make me unwilling to continue treatment?
|
59 |
+
5778437,What organizations provide prescription assistance programs for individuals with financial needs?
|
60 |
+
5778437,Do I need a doctor's consent to apply for prescription assistance programs?
|
61 |
+
5778437,What kind of proof do I need to provide for these prescription assistance programs?
|
62 |
+
9541219,Where can I find a therapist who specializes in my specific mental health condition?
|
63 |
+
9541219,Are there different types of therapy for children and adults?
|
64 |
+
9541219,What kind of therapy would be most effective for my symptoms?
|
65 |
+
3268009,What are some alternative types of mental health treatment?
|
66 |
+
3268009,Are there any self-help plans for mental health conditions?
|
67 |
+
3268009,What is the role of peer support in mental health treatment?
|
68 |
+
3340726,What are the different kinds of mental health professionals that I can choose from?
|
69 |
+
3340726,How can I find the right mental health professional for my needs?
|
70 |
+
3340726,Can you give me more information about the various types of mental health professionals?
|
71 |
+
9539480,Where can I find peer support organizations?
|
72 |
+
9539480,Are there support groups led by mental health professionals?
|
73 |
+
9539480,How can I find support groups for my family and friends?
|
74 |
+
4211025,Where can I find help for a mental health crisis?
|
75 |
+
4211025,What kinds of services does inpatient care provide for people in crisis?
|
76 |
+
4211025,How can inpatient care assist with adjusting to new medications or symptoms?
|
77 |
+
4031860,Where can I find resources to help me locate mental health therapists in my area?
|
78 |
+
4031860,How can I learn about different mental health treatment options in my community?
|
79 |
+
4031860,Can you suggest any ways I can better understand the treatment process for mental health services?
|
80 |
+
5215843,What are the risks associated with clinical trials?
|
81 |
+
5215843,How can I find out about new treatment approaches being tested?
|
82 |
+
5215843,Where can I get more information about participating in research studies?
|
83 |
+
8927672,What is a psychiatric advance directive and how does it differ from a medical advance directive?
|
84 |
+
8927672,How can I create a psychiatric advance directive and who will it impact during a mental health crisis?
|
85 |
+
8927672,What kind of treatment instructions can I include in a psychiatric advance directive?
|
86 |
+
7728364,What exactly makes up mental health?
|
87 |
+
7728364,Can you explain the components of mental health?
|
88 |
+
7728364,"How are beliefs, thoughts, feelings, and behaviors related to mental health?"
|
89 |
+
4194958,What can I do if the usual support methods don't work for me?
|
90 |
+
4194958,How can I stay hopeful while searching for the right help?
|
91 |
+
4194958,What are some other approaches I can try if the current ones don't help?
|
92 |
+
1667863,Is it possible to take steps to avoid mental health issues?
|
93 |
+
1667863,How does working on our wellbeing and resilience contribute to preventing mental health problems?
|
94 |
+
1667863,What role does seeking help early play in preventing mental health issues from becoming severe?
|
95 |
+
8904276,Are there any treatments that can help with mental health issues?
|
96 |
+
8904276,Is it possible to find relief from mental health problems through talking and counselling?
|
97 |
+
8904276,"Can medication, friendships, exercise, sleep, and nutrition play a role in addressing mental health concerns?"
|
98 |
+
4283807,What are some psychological causes of mental health problems?
|
99 |
+
4283807,What role does biology play in mental health issues?
|
100 |
+
4283807,How can social factors contribute to mental health problems?
|
101 |
+
8690253,Who are some people I can talk to if I'm worried about my mental health?
|
102 |
+
8690253,What steps can I take to find out more information about what I'm experiencing with my mental health?
|
103 |
+
8690253,How can talking to someone about my mental health help me get perspective and start getting help?
|
104 |
+
8690253,What kind of help can I expect to receive after I talk to someone about my mental health?
|
105 |
+
8690253,What can I do to get started on the path of improving my mental health?
|
106 |
+
2973656,How can I tell if my beliefs and thoughts are affecting my daily functioning?
|
107 |
+
2973656,What are the signs that my feelings and behaviors are having a significant impact on my ability to function normally?
|
108 |
+
2973656,When is it important to seek help if my mental health is affecting my daily life?
|
109 |
+
4759773,What actions can I take if I'm concerned about a loved one's mental health?
|
110 |
+
4759773,How can I approach a friend or relative about seeking mental health support?
|
111 |
+
4759773,What is the first step I should take when I notice a concern for someone's mental well-being?
|
112 |
+
1511075,How should I handle people giving me advice based on evidence?
|
113 |
+
1511075,What is the best way to find out what works for me when people tell me what to do?
|
114 |
+
1511075,How can I balance following others' advice and doing what is best for my mental health?
|
115 |
+
7069853,Why is it important for my mental health to stay informed about the pandemic?
|
116 |
+
7069853,How can reliable and up-to-date information about the coronavirus help me feel more resilient?
|
117 |
+
7069853,What are the negative effects of following the news all day and how can I avoid them?
|
118 |
+
4181750,How can I determine if a source is reliable for information about the coronavirus and COVID-19?
|
119 |
+
4181750,What should I consider when evaluating the credibility of experts quoted or cited in health articles?
|
120 |
+
4181750,How can I identify if a source is trying to make me feel a certain way rather than providing factual information?
|
121 |
+
4181750,What is the role of social media in obtaining reliable health information and what cautions should I take?
|
122 |
+
4181750,Where can I learn more about digital and media literacy and thinking critically around health claims?
|
123 |
+
2554141,Why does having a plan help manage fear and stress during a pandemic?
|
124 |
+
2554141,What are some tasks I can include in my daily schedule for managing during a pandemic?
|
125 |
+
2554141,Where can I find resources on problem-solving to help me manage during a pandemic?
|
126 |
+
2554141,How can I practice problem-solving to manage uncertain situations during a pandemic?
|
127 |
+
2554141,What are some ways I can manage feelings of being overwhelmed or hopeless during a pandemic?
|
128 |
+
9100298,What are some ways I can maintain social connections while physically separated from loved ones?
|
129 |
+
9100298,What should I do if I'm feeling lonely during this time?
|
130 |
+
9100298,Where can I find local community support groups and mutual aid groups online?
|
131 |
+
2884887,How does taking care of my physical health impact my mental health?
|
132 |
+
2884887,What are some tips for maintaining a balanced diet while spending more time at home?
|
133 |
+
2884887,What are some ways to stay active and exercise while staying safe at home?
|
134 |
+
2884887,How can I practice healthy sleep habits if stress and anxiety are affecting my sleep?
|
135 |
+
2884887,What should I do if I have a chronic illness and need to take additional precautions during this time?
|
136 |
+
9250044,What are some low-effort distractions I can try when I'm feeling overwhelmed or isolated?
|
137 |
+
9250044,What are some ways I can keep myself engaged and focused if I have more energy?
|
138 |
+
9250044,How can I use online resources to learn new things and stay entertained during social distancing?
|
139 |
+
9250044,What are some ways I can maintain healthier habits and avoid unhelpful ones when my schedule is disrupted?
|
140 |
+
9250044,How can I get involved in helping my community while practicing social distancing and good hygiene?
|
141 |
+
3597720,How does the way I think about a situation impact my feelings and behaviors?
|
142 |
+
3597720,What can challenging negative thoughts do to improve my mood and help me see new options?
|
143 |
+
3597720,Can you give me an example of how to reframe a negative thought to a more positive or productive one?
|
144 |
+
3597720,How can I better understand the situation more realistically and see the parts that I can control right now?
|
145 |
+
3597720,"What can I do to focus on the things I can do, and make everything feel more manageable?"
|
146 |
+
7535002,What strategies can I use to challenge common thinking traps?
|
147 |
+
7535002,How can I identify if I'm falling into distorted thinking patterns?
|
148 |
+
7535002,What is a helpful way to break a thinking trap by looking at the thoughts?
|
149 |
+
4134858,What are some common causes of grief outside of losing a person or pet?
|
150 |
+
4134858,How can I healthily express my feelings of grief?
|
151 |
+
4134858,Where can I find help from a mental health professional if I'm struggling with grief?
|
152 |
+
9676742,How can I find a family doctor using the College of Physicians and Surgeons of BC's Find a Physician tool?
|
153 |
+
9676742,Are walk-in clinics a good option for finding a regular doctor if I have ongoing care needs?
|
154 |
+
9676742,How can I obtain a referral to see a psychiatrist?
|
155 |
+
9676742,Where can I find a registered psychologist in BC?
|
156 |
+
9676742,How can I visit the BC Association of Clinical Counsellors to find a clinical counsellor?
|
157 |
+
2612846,Can I make an appointment with a psychiatrist directly or do I need a referral from a doctor?
|
158 |
+
2612846,What is the process for self-referring to a mental health program in BC?
|
159 |
+
2612846,How can I find my local mental health center in BC?
|
160 |
+
2612846,What services are available at a mental health center besides access to a psychiatrist?
|
161 |
+
2612846,How can I get help from HealthlinkBC if I need assistance finding a mental health service?
|
162 |
+
3166337,Where can I find a Registered Psychologist?
|
163 |
+
3166337,Do I need a doctor's referral to see a psychologist?
|
164 |
+
3166337,How can I find out about lower-cost options for counselling in my community?
|
165 |
+
3166337,Are the costs of seeing a Registered Psychologist covered by MSP?
|
166 |
+
3166337,Can I ask for a sliding scale based on my income when making an appointment with a psychologist?
|
167 |
+
7009409,Where can I find directories of counsellors?
|
168 |
+
7009409,Do I need a doctor's referral to see a counsellor?
|
169 |
+
7009409,How can I find out about lower-cost options to access counselling in my community?
|
170 |
+
7009409,Are counselling services at public mental health centers covered by MSP?
|
171 |
+
7009409,How can Indigenous community members access counselling services locally or through the First Nations Health Authority?
|
172 |
+
9630578,Where can I look for support groups specific to mental illnesses like mood disorders or post-traumatic stress disorder?
|
173 |
+
9630578,How can I find out about support groups offered by the Canadian Mental Health Association or the BC Schizophrenia Society?
|
174 |
+
9630578,Where can I find online support if I have trouble getting to an in-person support group?
|
175 |
+
1585622,Where can I encourage my child to talk about their mental health concerns?
|
176 |
+
1585622,Who can I talk to if I'm concerned about my child's mental health?
|
177 |
+
1585622,Where can I find specific child and youth mental health services and providers?
|
178 |
+
1585622,"Where can I get guidance, information, and support for youth and parent mental health?"
|
179 |
+
1585622,Where can young people find easy-to-access mental health care and support?
|
180 |
+
1833460,Where can I find information about local mental health services for older adults?
|
181 |
+
1833460,Can I get information about senior's mental health resources from the Canadian Coalition for Seniors' Mental Health?
|
182 |
+
1833460,Who can I contact if I'm concerned about a loved one's mental health?
|
183 |
+
6981545,Where can I find self-help resources for depression that are appropriate for teens?
|
184 |
+
6981545,Can you recommend some self-help materials for managing depression while pregnant or after delivery?
|
185 |
+
6981545,Are there any online self-help programs for depression that are based outside of BC but offer good information?
|
186 |
+
2115228,Where can I find self-help resources for anxiety if I'm not in British Columbia?
|
187 |
+
2115228,Can I use Anxiety Canada's resources if I'm an adult but not a teen or young adult?
|
188 |
+
2115228,What resources does the BC Reproductive Mental Health Program offer for anxiety during and after birth?
|
189 |
+
2009922,Where can I find free programs to help manage ongoing physical or mental health issues?
|
190 |
+
2009922,Are there any self-guided workbooks that discuss the links between physical health and mental health?
|
191 |
+
2009922,"What resources are available to help me cope with depression, low mood, or anxiety caused by a chronic health condition?"
|
192 |
+
2009922,Can I purchase any booklets that offer practical tips to cope with a chronic health problem?
|
193 |
+
2009922,Where can I find one-on-one support from a therapist or counselor if I'm having a hard time coping?
|
194 |
+
6167248,How can I determine if my substance use is causing problems?
|
195 |
+
6167248,Where can I find resources for helping someone else with their substance use?
|
196 |
+
6167248,What are some ways I can think about my relationship with substances?
|
197 |
+
6167248,What tips and resources are available for cutting back or quitting substance use?
|
198 |
+
6167248,How can I contact the Alcohol and Drug Information Referral Service for help in my area?
|
199 |
+
6779222,How can I find out if my BC Medical Services Plan covers mental health services like counselling or therapy?
|
200 |
+
6779222,Where can I find mental health clinics or hospitals that offer free or low-cost counselling services?
|
201 |
+
6779222,How can I find mental health services in my area using HealthLink BC’s Find Services tool and Locator app?
|
202 |
+
6779222,Where can I look for private mental health services that offer a sliding scale based on income?
|
203 |
+
6779222,How can mental health organizations like Anxiety Canada or the Canadian Mental Health Association help me find local mental health services or connections?
|
204 |
+
1546812,Is there a program to help me pay for my psychiatric medications?
|
205 |
+
1546812,How can I apply for the Psychiatric Medications Plan through BC PharmaCare?
|
206 |
+
1546812,How long does the coverage for Plan G typically last?
|
207 |
+
2176317,Are there any mental health services covered by MSP that I could access for free?
|
208 |
+
2176317,What are some ways I can offset the costs of mental health services not covered by MSP?
|
209 |
+
2176317,How can I find mental health providers that offer lower-cost services or a sliding scale based on income?
|
210 |
+
3284724,What are the different income levels for provincial income assistance?
|
211 |
+
3284724,How can mental illness be considered in PWD or PPMB income assistance applications?
|
212 |
+
3284724,Where can I find resources to help me navigate the application process for PWD and PPMB benefits?
|
213 |
+
5981663,What is the purpose of MSP in British Columbia?
|
214 |
+
5981663,How are MSP fees determined and paid?
|
215 |
+
5981663,Where can I get help with applying for or managing my MSP coverage?
|
216 |
+
6623577,What does it mean when someone recommends me to another service in healthcare?
|
217 |
+
6623577,How do I access a specialist like a psychiatrist for mental health in BC?
|
218 |
+
6623577,What is the process for getting an appointment with a specialist after a referral from my doctor?
|
219 |
+
6851366,"Are psychiatrists able to prescribe medications, while psychologists cannot?"
|
220 |
+
6851366,How are the education and training different between psychiatrists and registered psychologists?
|
221 |
+
6851366,How does payment for services differ between accessing a psychologist in the public system versus the private system?
|
222 |
+
1898078,What are the commonalities between psychotherapy and counseling?
|
223 |
+
1898078,Can you explain the role of a professional therapist or counselor in the healing process?
|
224 |
+
1898078,What are some examples of different psychotherapies that have been found effective for various problems or illnesses?
|
225 |
+
1706961,What is the main focus of CBT in contrast to DBT?
|
226 |
+
1706961,How does DBT deals with emotions and relationships differently than CBT?
|
227 |
+
1706961,In what kind of mental health issues have DBT been proven to be effective?
|
228 |
+
4925221,What are the different classes of antidepressant medications and how do they work?
|
229 |
+
4925221,What are some common medications for each class of antidepressants?
|
230 |
+
4925221,What factors might affect how a medication works for different people?
|
231 |
+
1043721,How can I bring up my concerns about my diagnosis with the professional who provided it?
|
232 |
+
1043721,What is the process for getting a second opinion from a different professional?
|
233 |
+
1043721,How can I discuss my options and get a referral to a different program or health professional for a second opinion?
|
234 |
+
8471978,What should I do if I don't think my prescribed antidepressant is working?
|
235 |
+
8471978,Who can I contact if I want to discuss the common side effects of my medication?
|
236 |
+
8471978,Is it safe to stop taking my psychiatric medication or change the dose without consulting a health care provider?
|
237 |
+
8471978,What should I do if I experience a serious allergic reaction to my medication?
|
238 |
+
8471978,How can I effectively communicate with my doctor about symptoms or side effects that I find embarrassing?
|
239 |
+
2746837,How can I help an adult in my life who is struggling with potential mental health issues?
|
240 |
+
2746837,"What are the risks of diagnosing a health condition, especially online, without professional input?"
|
241 |
+
2746837,What is the role of the person being treated in their own recovery and how can I support them in this process?
|
242 |
+
2746837,How can I effectively express my concerns and work together with the person to find a solution?
|
243 |
+
2746837,What should I know about the BC Mental Health Act in relation to getting help for someone who is at risk of harming themselves or others?
|
244 |
+
5640861,Where can I find a family doctor to talk about my concerns for my child or teenager?
|
245 |
+
5640861,What kind of services and support can I expect from a school counselor regarding my child's mental health?
|
246 |
+
5640861,What is the role of Kelty Mental Health Resource Centre and how can their Help Finder tool assist me in navigating the mental health system for my child?
|
247 |
+
5640861,Does the Canadian Mental Health Association’s BC Division offer any resources or programs for managing behavior problems in children ages 3 to 12?
|
248 |
+
5640861,Where can I find HeretoHelp resources on child and youth mental health and substance use?
|
249 |
+
3393534,Where can I find more information about mental health problems that may arise from a brain injury?
|
250 |
+
3393534,Are there service providers who are knowledgeable about both brain injuries and mental health?
|
251 |
+
3393534,How can I find local and regional groups in BC that support those with brain injuries?
|
252 |
+
3393534,What organizations provide information and support for those affected by brain injuries in BC?
|
253 |
+
3393534,Are mental health challenges related to brain injuries always treatable?
|
254 |
+
3839472,How can I recognize and empathize with my loved one's experience with depression?
|
255 |
+
3839472,Where can I learn more about depression to better understand it?
|
256 |
+
3839472,How can I create a safe space for my loved one to talk about their depression?
|
257 |
+
3839472,"What are some things I should avoid, like giving unsolicited advice?"
|
258 |
+
3839472,How can I support my loved one in their treatment and recovery?
|
259 |
+
3055896,What are some trustworthy resources where I can learn more about schizophrenia?
|
260 |
+
3055896,"How can I support my loved one during episodes of psychosis, especially when their hallucinations or delusions are distressing?"
|
261 |
+
3055896,What is the role of a family member in helping a loved one manage their treatment for schizophrenia?
|
262 |
+
3055896,What can I do if my loved one refuses treatment for schizophrenia and I believe they are at risk of harming themselves or others?
|
263 |
+
3055896,What should I do if my loved one expresses thoughts of ending their life?
|
264 |
+
4200873,How can learning about my parent's mental illness make it easier for me to understand their experiences?
|
265 |
+
4200873,What self-care activities can I do to take care of myself while my parent is unwell?
|
266 |
+
4200873,Where can I find programs specifically designed for young people in my situation?
|
267 |
+
1337085,What resources are available for someone experiencing thoughts of suicide?
|
268 |
+
1337085,How can I help someone I care about who is talking about suicide?
|
269 |
+
1337085,What should I do in a situation where there is immediate danger or risk of harm due to suicide thoughts?
|
270 |
+
2447683,What are the potential benefits and harms of using cannabis?
|
271 |
+
2447683,How can the timing of when a person starts using cannabis impact potential harms?
|
272 |
+
2447683,Are there certain groups of people who should avoid using cannabis due to increased risk of psychosis or schizophrenia?
|
273 |
+
2447683,How can mixing drugs like cannabis and alcohol increase the possibility of experiencing harms?
|
274 |
+
2447683,What is a simple way to gauge the use of psychoactive substances and prevent potential harms?
|
275 |
+
7995219,Can you explain more about what mental well-being entails?
|
276 |
+
7995219,How would you define a mental illness and how does it affect a person's life?
|
277 |
+
7995219,Can a person have good mental health even if they have been diagnosed with a mental illness?
|
278 |
+
7995219,"How does mental health exist on a continuum, similar to physical health?"
|
279 |
+
7995219,What supports and tools can help someone live well and find meaning despite mental health challenges?
|
280 |
+
2903196,Where can I find info sheets on mood disorders and bipolar disorder?
|
281 |
+
2903196,Do you have a self-test for depression that also screens for signs of bipolar disorder?
|
282 |
+
2903196,Can I find a series to help me deal with a diagnosis of depression and work with my doctor?
|
283 |
+
2903196,Are there any books or resources with personal stories about depression?
|
284 |
+
2903196,How can I access the What is Depression? booklet with audio in plain language for lower literacy readers?
|
285 |
+
4893447,How can I distinguish between normal anxiety and an anxiety disorder?
|
286 |
+
4893447,What are some examples of how anxiety disorders can impact someone's daily life?
|
287 |
+
4893447,What are the differences between the former and current classifications of some anxiety disorders?
|
288 |
+
8612349,What are the usual causes of stress?
|
289 |
+
8612349,How is anxiety different from stress in terms of what it focuses on?
|
290 |
+
8612349,Are the physical sensations of stress and anxiety always similar?
|
291 |
+
8612349,"Can anxiety be triggered by a specific threat, or is it always about vague worries?"
|
292 |
+
8612349,How can stress and anxiety impact well-being and daily life if they last for a long time?
|
293 |
+
6062232,How is sadness different from the illness of depression?
|
294 |
+
6062232,Can feelings of sadness impact daily life in a significant way like depression does?
|
295 |
+
6062232,Are there any physical symptoms associated with depression that don't occur with normal sadness?
|
296 |
+
9045344,How does persistent depressive disorder (PDD) differ from major depressive disorder in terms of symptoms and duration?
|
297 |
+
9045344,What are the symptoms of PDD?
|
298 |
+
9045344,Why is it a misconception that PDD is less severe than major depressive disorder?
|
299 |
+
9045344,How can PDD affect a person's ability to work and enjoy hobbies?
|
300 |
+
9045344,Why might someone with PDD think it is just part of their personality?
|
301 |
+
9020440,What is the relationship between cyclothymic disorder and bipolar disorder?
|
302 |
+
9020440,What are the symptoms of hypomania and depression associated with cyclothymic disorder?
|
303 |
+
9020440,How does the frequency of symptoms in cyclothymic disorder compare to bipolar disorder?
|
304 |
+
9020440,What wellness period are people with cyclothymic disorder likely to experience?
|
305 |
+
9020440,Who should I consult if I suspect I have cyclothymic disorder?
|
306 |
+
5819325,What does it mean when someone experiences four or more episodes of depression and/or mania in one year?
|
307 |
+
5819325,Who can experience rapid cycling and when does it typically occur?
|
308 |
+
5819325,Is rapid cycling a permanent condition for those diagnosed with bipolar disorder?
|
309 |
+
4816493,Where can I find more information about the five groups of symptoms for borderline personality disorder?
|
310 |
+
4816493,Do you know of any support groups or resources for borderline personality disorder in cities other than Vancouver and Victoria?
|
311 |
+
4816493,Can you recommend any helpful books for managing borderline personality disorder?
|
312 |
+
9178453,How does schizoid personality disorder affect social interactions and relationships?
|
313 |
+
9178453,What is the difference between schizoid personality disorder and schizophrenia?
|
314 |
+
9178453,How is schizoid personality disorder typically treated and managed?
|
315 |
+
9679704,How does antisocial personality disorder affect a person's thoughts and behaviors?
|
316 |
+
9679704,What is the relationship between conduct disorder and antisocial personality disorder?
|
317 |
+
9679704,How can treatment help someone with antisocial personality disorder?
|
318 |
+
9167296,"How does a personality disorder, such as obsessive-compulsive personality disorder, affect a person's daily life and thoughts?"
|
319 |
+
9167296,What are the key differences between obsessive-compulsive personality disorder and obsessive-compulsive disorder?
|
320 |
+
9167296,How is treatment typically approached for individuals with obsessive-compulsive personality disorder?
|
321 |
+
9167296,What kind of distress might a person with obsessive-compulsive personality disorder experience when they can't achieve control or perfectionism?
|
322 |
+
9167296,Where can someone seek help for obsessive-compulsive personality disorder in British Columbia?
|
323 |
+
9049618,What are the main symptoms of binge-eating disorder?
|
324 |
+
9049618,How can I recognize if someone has binge-eating disorder?
|
325 |
+
9049618,What makes binge-eating disorder different from just overeating?
|
326 |
+
9049618,How is binge-eating disorder treated?
|
327 |
+
9049618,Who should I consult if I think I have binge-eating disorder?
|
328 |
+
7984793,How does the 'split mind' in schizophrenia differ from the fragmented identity in dissociative identity disorder?
|
329 |
+
7984793,What is the significance of dissociation in dissociative identity disorder?
|
330 |
+
7984793,How does schizophrenia affect a person's perception of reality differently than dissociative identity disorder?
|
331 |
+
7984793,"What are some common misconceptions about dissociative identity disorder, such as its portrayal in media, and how does it contrast with the actual experience of those diagnosed with it?"
|
332 |
+
7984793,"How does schizophrenia impact an individual's thoughts, speech, and emotional expression as opposed to dissociative identity disorder?"
|
333 |
+
6085633,What is the difference between psychosis and schizophrenia in terms of their definitions?
|
334 |
+
6085633,"What are some common symptoms of psychosis, such as hallucinations and delusions?"
|
335 |
+
6085633,"What mental illnesses or factors, aside from schizophrenia, can cause psychosis?"
|
336 |
+
1896541,What do positive symptoms of schizophrenia involve?
|
337 |
+
1896541,Can you explain what negative symptoms of schizophrenia are?
|
338 |
+
1896541,What are cognitive symptoms and how do they relate to schizophrenia?
|
339 |
+
4962901,Can you explain what a prodrome is in simpler terms?
|
340 |
+
4962901,What are some early signs or symptoms of psychosis?
|
341 |
+
4962901,Why is it important to seek help early if you or a loved one is experiencing symptoms of a mental health problem?
|
342 |
+
6869967,How can I find a healthcare professional who specializes in assessing and treating ADHD in adults?
|
343 |
+
6869967,What resources and support are available for adults with ADHD in Canada?
|
344 |
+
6869967,Is there a support group for adults with ADHD in the Vancouver area?
|
345 |
+
4824231,What does it mean when someone says they are addicted to something like shopping?
|
346 |
+
4824231,How does the evidence suggest substance use and addiction differ?
|
347 |
+
4824231,Can you explain how substance dependence develops and what it involves?
|
348 |
+
4294616,What are some ways I can get help for an alcohol or drug use problem?
|
349 |
+
4294616,How does my health and social situation factor into finding the right help for me?
|
350 |
+
4294616,Can I talk to a nurse or doctor confidentially about drug use and what resources are available in my area?
|
351 |
+
4373204,How can I determine if I'm drinking too much considering my unique relationship with alcohol?
|
352 |
+
4373204,What are the signs of alcohol use becoming a problem in my life or in the lives of others?
|
353 |
+
4373204,Where can I get personalized feedback about my drinking pattern as compared to Canada's Low-Risk Alcohol Drinking Guidelines?
|
354 |
+
7807643,"If cannabis smoke contains harmful toxins, why is the risk of cancer less for cannabis smokers than tobacco smokers?"
|
355 |
+
7807643,How do the negative effects of cannabis on the brain compare to those of alcohol?
|
356 |
+
7807643,What are the benefits of legalizing cannabis in terms of minimizing potential harms?
|
357 |
+
4352464,How can I help my child develop skills to make good choices regarding drugs?
|
358 |
+
4352464,What are some ways to strengthen my relationship with my child through discussions about drugs?
|
359 |
+
4352464,How can I support my child in developing critical thinking skills about drug use?
|
360 |
+
6521784,What are the medical conditions that CBD has been used in the treatment of?
|
361 |
+
6521784,How does CBD produce therapeutic effects in the body?
|
362 |
+
6521784,Are there any recorded negative drug interactions with CBD?
|
363 |
+
6521784,What are some potential side effects of using CBD?
|
364 |
+
6521784,Is there any research on the use of CBD for Alzheimer's disease?
|
365 |
+
3221856,What are the potential harms of vaping?
|
366 |
+
3221856,How is nicotine delivered through vaping?
|
367 |
+
3221856,What is the impact of vaping marketing strategies on young people?
|
dataset/rag-eval-mistral.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
dataset/rag_eval_llama.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
docker-compose.yaml
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
services:
|
2 |
+
postgres:
|
3 |
+
image: postgres:13
|
4 |
+
environment:
|
5 |
+
POSTGRES_DB: ${DB_NAME}
|
6 |
+
POSTGRES_USER: ${DB_USER}
|
7 |
+
POSTGRES_PASSWORD: ${DB_PASSWORD}
|
8 |
+
ports:
|
9 |
+
- "5432:5432"
|
10 |
+
volumes:
|
11 |
+
- pgdata:/var/lib/postgresql/data # Using Docker's volume instead of bind mount
|
12 |
+
|
13 |
+
streamlit:
|
14 |
+
build:
|
15 |
+
context: .
|
16 |
+
dockerfile: Dockerfile
|
17 |
+
ports:
|
18 |
+
- "8501:8501"
|
19 |
+
depends_on:
|
20 |
+
- postgres
|
21 |
+
environment:
|
22 |
+
- DB_NAME=${DB_NAME}
|
23 |
+
- DB_USER=${DB_USER}
|
24 |
+
- DB_PASSWORD=${DB_PASSWORD}
|
25 |
+
- DB_HOST=postgres
|
26 |
+
- DB_PORT=5432
|
27 |
+
- GROQ_API_KEY=${GROQ_API_KEY}
|
28 |
+
- MISTRAL_API_KEY=${MISTRAL_API_KEY}
|
29 |
+
- DATA_PATH=/app/dataset/data.csv
|
30 |
+
volumes:
|
31 |
+
- ./dataset:/app/dataset
|
32 |
+
|
33 |
+
grafana:
|
34 |
+
image: grafana/grafana:latest
|
35 |
+
ports:
|
36 |
+
- "3000:3000"
|
37 |
+
depends_on:
|
38 |
+
- postgres
|
39 |
+
environment:
|
40 |
+
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_ADMIN_PASSWORD}
|
41 |
+
- GF_INSTALL_PLUGINS=grafana-clock-panel,grafana-simple-json-datasource
|
42 |
+
volumes:
|
43 |
+
- grafana-storage:/var/lib/grafana
|
44 |
+
|
45 |
+
volumes:
|
46 |
+
pgdata: # This is now a Docker-managed volume
|
47 |
+
grafana-storage:
|
48 |
+
driver: local
|
grafana/dashboard.json
ADDED
@@ -0,0 +1,952 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"annotations": {
|
3 |
+
"list": [
|
4 |
+
{
|
5 |
+
"builtIn": 1,
|
6 |
+
"datasource": {
|
7 |
+
"type": "grafana",
|
8 |
+
"uid": "-- Grafana --"
|
9 |
+
},
|
10 |
+
"enable": true,
|
11 |
+
"hide": true,
|
12 |
+
"iconColor": "rgba(0, 211, 255, 1)",
|
13 |
+
"name": "Annotations & Alerts",
|
14 |
+
"type": "dashboard"
|
15 |
+
}
|
16 |
+
]
|
17 |
+
},
|
18 |
+
"editable": true,
|
19 |
+
"fiscalYearStartMonth": 0,
|
20 |
+
"graphTooltip": 0,
|
21 |
+
"id": 1,
|
22 |
+
"links": [],
|
23 |
+
"panels": [
|
24 |
+
{
|
25 |
+
"datasource": {
|
26 |
+
"default": true,
|
27 |
+
"type": "grafana-postgresql-datasource",
|
28 |
+
"uid": "ae169klpan0g0e"
|
29 |
+
},
|
30 |
+
"fieldConfig": {
|
31 |
+
"defaults": {
|
32 |
+
"color": {
|
33 |
+
"mode": "thresholds"
|
34 |
+
},
|
35 |
+
"custom": {
|
36 |
+
"align": "auto",
|
37 |
+
"cellOptions": {
|
38 |
+
"type": "auto"
|
39 |
+
},
|
40 |
+
"inspect": false
|
41 |
+
},
|
42 |
+
"mappings": [],
|
43 |
+
"thresholds": {
|
44 |
+
"mode": "absolute",
|
45 |
+
"steps": [
|
46 |
+
{
|
47 |
+
"color": "green",
|
48 |
+
"value": null
|
49 |
+
},
|
50 |
+
{
|
51 |
+
"color": "red",
|
52 |
+
"value": 80
|
53 |
+
}
|
54 |
+
]
|
55 |
+
}
|
56 |
+
},
|
57 |
+
"overrides": []
|
58 |
+
},
|
59 |
+
"gridPos": {
|
60 |
+
"h": 8,
|
61 |
+
"w": 12,
|
62 |
+
"x": 0,
|
63 |
+
"y": 0
|
64 |
+
},
|
65 |
+
"id": 5,
|
66 |
+
"options": {
|
67 |
+
"cellHeight": "sm",
|
68 |
+
"footer": {
|
69 |
+
"countRows": false,
|
70 |
+
"fields": "",
|
71 |
+
"reducer": [
|
72 |
+
"sum"
|
73 |
+
],
|
74 |
+
"show": false
|
75 |
+
},
|
76 |
+
"showHeader": true
|
77 |
+
},
|
78 |
+
"pluginVersion": "11.2.0",
|
79 |
+
"targets": [
|
80 |
+
{
|
81 |
+
"datasource": {
|
82 |
+
"type": "grafana-postgresql-datasource",
|
83 |
+
"uid": "ae169klpan0g0e"
|
84 |
+
},
|
85 |
+
"editorMode": "code",
|
86 |
+
"format": "table",
|
87 |
+
"rawQuery": true,
|
88 |
+
"rawSql": "SELECT\r\n timestamp AS time,\r\n question,\r\n answer,\r\n relevance\r\nFROM conversations\r\nWHERE timestamp BETWEEN $__timeFrom() AND $__timeTo()\r\nORDER BY timestamp DESC\r\nLIMIT 5",
|
89 |
+
"refId": "A",
|
90 |
+
"sql": {
|
91 |
+
"columns": [
|
92 |
+
{
|
93 |
+
"parameters": [],
|
94 |
+
"type": "function"
|
95 |
+
}
|
96 |
+
],
|
97 |
+
"groupBy": [
|
98 |
+
{
|
99 |
+
"property": {
|
100 |
+
"type": "string"
|
101 |
+
},
|
102 |
+
"type": "groupBy"
|
103 |
+
}
|
104 |
+
],
|
105 |
+
"limit": 50
|
106 |
+
}
|
107 |
+
}
|
108 |
+
],
|
109 |
+
"title": "Recent Conversations",
|
110 |
+
"type": "table"
|
111 |
+
},
|
112 |
+
{
|
113 |
+
"datasource": {
|
114 |
+
"default": true,
|
115 |
+
"type": "grafana-postgresql-datasource",
|
116 |
+
"uid": "ae169klpan0g0e"
|
117 |
+
},
|
118 |
+
"fieldConfig": {
|
119 |
+
"defaults": {
|
120 |
+
"color": {
|
121 |
+
"mode": "palette-classic"
|
122 |
+
},
|
123 |
+
"custom": {
|
124 |
+
"axisBorderShow": false,
|
125 |
+
"axisCenteredZero": false,
|
126 |
+
"axisColorMode": "text",
|
127 |
+
"axisLabel": "",
|
128 |
+
"axisPlacement": "auto",
|
129 |
+
"fillOpacity": 80,
|
130 |
+
"gradientMode": "none",
|
131 |
+
"hideFrom": {
|
132 |
+
"legend": false,
|
133 |
+
"tooltip": false,
|
134 |
+
"viz": false
|
135 |
+
},
|
136 |
+
"lineWidth": 1,
|
137 |
+
"scaleDistribution": {
|
138 |
+
"type": "linear"
|
139 |
+
},
|
140 |
+
"thresholdsStyle": {
|
141 |
+
"mode": "off"
|
142 |
+
}
|
143 |
+
},
|
144 |
+
"mappings": [],
|
145 |
+
"thresholds": {
|
146 |
+
"mode": "absolute",
|
147 |
+
"steps": [
|
148 |
+
{
|
149 |
+
"color": "green",
|
150 |
+
"value": null
|
151 |
+
},
|
152 |
+
{
|
153 |
+
"color": "red",
|
154 |
+
"value": 80
|
155 |
+
}
|
156 |
+
]
|
157 |
+
},
|
158 |
+
"unit": "short"
|
159 |
+
},
|
160 |
+
"overrides": []
|
161 |
+
},
|
162 |
+
"gridPos": {
|
163 |
+
"h": 8,
|
164 |
+
"w": 12,
|
165 |
+
"x": 12,
|
166 |
+
"y": 0
|
167 |
+
},
|
168 |
+
"id": 3,
|
169 |
+
"options": {
|
170 |
+
"barRadius": 0,
|
171 |
+
"barWidth": 0.97,
|
172 |
+
"fullHighlight": false,
|
173 |
+
"groupWidth": 0.7,
|
174 |
+
"legend": {
|
175 |
+
"calcs": [],
|
176 |
+
"displayMode": "list",
|
177 |
+
"placement": "right",
|
178 |
+
"showLegend": true
|
179 |
+
},
|
180 |
+
"orientation": "horizontal",
|
181 |
+
"showValue": "never",
|
182 |
+
"stacking": "none",
|
183 |
+
"tooltip": {
|
184 |
+
"mode": "single",
|
185 |
+
"sort": "none"
|
186 |
+
},
|
187 |
+
"xTickLabelRotation": 0,
|
188 |
+
"xTickLabelSpacing": 0
|
189 |
+
},
|
190 |
+
"targets": [
|
191 |
+
{
|
192 |
+
"datasource": {
|
193 |
+
"type": "grafana-postgresql-datasource",
|
194 |
+
"uid": "ae169klpan0g0e"
|
195 |
+
},
|
196 |
+
"editorMode": "code",
|
197 |
+
"format": "table",
|
198 |
+
"rawQuery": true,
|
199 |
+
"rawSql": "SELECT\r\n model_used,\r\n COUNT(*) as count\r\nFROM conversations\r\nWHERE timestamp BETWEEN $__timeFrom() AND $__timeTo()\r\nGROUP BY model_used",
|
200 |
+
"refId": "A",
|
201 |
+
"sql": {
|
202 |
+
"columns": [
|
203 |
+
{
|
204 |
+
"parameters": [],
|
205 |
+
"type": "function"
|
206 |
+
}
|
207 |
+
],
|
208 |
+
"groupBy": [
|
209 |
+
{
|
210 |
+
"property": {
|
211 |
+
"type": "string"
|
212 |
+
},
|
213 |
+
"type": "groupBy"
|
214 |
+
}
|
215 |
+
],
|
216 |
+
"limit": 50
|
217 |
+
}
|
218 |
+
}
|
219 |
+
],
|
220 |
+
"title": "Model Usage Panel",
|
221 |
+
"type": "barchart"
|
222 |
+
},
|
223 |
+
{
|
224 |
+
"datasource": {
|
225 |
+
"default": true,
|
226 |
+
"type": "grafana-postgresql-datasource",
|
227 |
+
"uid": "ae169klpan0g0e"
|
228 |
+
},
|
229 |
+
"fieldConfig": {
|
230 |
+
"defaults": {
|
231 |
+
"mappings": [],
|
232 |
+
"thresholds": {
|
233 |
+
"mode": "percentage",
|
234 |
+
"steps": [
|
235 |
+
{
|
236 |
+
"color": "green",
|
237 |
+
"value": null
|
238 |
+
},
|
239 |
+
{
|
240 |
+
"color": "orange",
|
241 |
+
"value": 70
|
242 |
+
},
|
243 |
+
{
|
244 |
+
"color": "red",
|
245 |
+
"value": 85
|
246 |
+
}
|
247 |
+
]
|
248 |
+
}
|
249 |
+
},
|
250 |
+
"overrides": []
|
251 |
+
},
|
252 |
+
"gridPos": {
|
253 |
+
"h": 8,
|
254 |
+
"w": 12,
|
255 |
+
"x": 0,
|
256 |
+
"y": 8
|
257 |
+
},
|
258 |
+
"id": 6,
|
259 |
+
"options": {
|
260 |
+
"minVizHeight": 75,
|
261 |
+
"minVizWidth": 75,
|
262 |
+
"orientation": "auto",
|
263 |
+
"reduceOptions": {
|
264 |
+
"calcs": [
|
265 |
+
"lastNotNull"
|
266 |
+
],
|
267 |
+
"fields": "",
|
268 |
+
"values": false
|
269 |
+
},
|
270 |
+
"showThresholdLabels": false,
|
271 |
+
"showThresholdMarkers": true,
|
272 |
+
"sizing": "auto"
|
273 |
+
},
|
274 |
+
"pluginVersion": "11.2.0",
|
275 |
+
"targets": [
|
276 |
+
{
|
277 |
+
"datasource": {
|
278 |
+
"type": "grafana-postgresql-datasource",
|
279 |
+
"uid": "ae169klpan0g0e"
|
280 |
+
},
|
281 |
+
"editorMode": "code",
|
282 |
+
"format": "table",
|
283 |
+
"rawQuery": true,
|
284 |
+
"rawSql": "SELECT\r\n SUM(CASE WHEN feedback > 0 THEN 1 ELSE 0 END) as thumbs_up,\r\n SUM(CASE WHEN feedback < 0 THEN 1 ELSE 0 END) as thumbs_down\r\nFROM feedback\r\nWHERE timestamp BETWEEN $__timeFrom() AND $__timeTo()",
|
285 |
+
"refId": "A",
|
286 |
+
"sql": {
|
287 |
+
"columns": [
|
288 |
+
{
|
289 |
+
"parameters": [],
|
290 |
+
"type": "function"
|
291 |
+
}
|
292 |
+
],
|
293 |
+
"groupBy": [
|
294 |
+
{
|
295 |
+
"property": {
|
296 |
+
"type": "string"
|
297 |
+
},
|
298 |
+
"type": "groupBy"
|
299 |
+
}
|
300 |
+
],
|
301 |
+
"limit": 50
|
302 |
+
}
|
303 |
+
}
|
304 |
+
],
|
305 |
+
"title": "Feedback Stats",
|
306 |
+
"type": "gauge"
|
307 |
+
},
|
308 |
+
{
|
309 |
+
"datasource": {
|
310 |
+
"default": true,
|
311 |
+
"type": "grafana-postgresql-datasource",
|
312 |
+
"uid": "ae169klpan0g0e"
|
313 |
+
},
|
314 |
+
"fieldConfig": {
|
315 |
+
"defaults": {
|
316 |
+
"color": {
|
317 |
+
"mode": "palette-classic"
|
318 |
+
},
|
319 |
+
"custom": {
|
320 |
+
"hideFrom": {
|
321 |
+
"legend": false,
|
322 |
+
"tooltip": false,
|
323 |
+
"viz": false
|
324 |
+
}
|
325 |
+
},
|
326 |
+
"mappings": []
|
327 |
+
},
|
328 |
+
"overrides": []
|
329 |
+
},
|
330 |
+
"gridPos": {
|
331 |
+
"h": 8,
|
332 |
+
"w": 12,
|
333 |
+
"x": 12,
|
334 |
+
"y": 8
|
335 |
+
},
|
336 |
+
"id": 2,
|
337 |
+
"options": {
|
338 |
+
"displayLabels": [
|
339 |
+
"percent",
|
340 |
+
"name"
|
341 |
+
],
|
342 |
+
"legend": {
|
343 |
+
"calcs": [],
|
344 |
+
"displayMode": "hidden",
|
345 |
+
"placement": "right",
|
346 |
+
"showLegend": false,
|
347 |
+
"values": []
|
348 |
+
},
|
349 |
+
"pieType": "pie",
|
350 |
+
"reduceOptions": {
|
351 |
+
"calcs": [
|
352 |
+
"lastNotNull"
|
353 |
+
],
|
354 |
+
"fields": "",
|
355 |
+
"values": true
|
356 |
+
},
|
357 |
+
"tooltip": {
|
358 |
+
"mode": "single",
|
359 |
+
"sort": "none"
|
360 |
+
}
|
361 |
+
},
|
362 |
+
"targets": [
|
363 |
+
{
|
364 |
+
"datasource": {
|
365 |
+
"type": "grafana-postgresql-datasource",
|
366 |
+
"uid": "ae169klpan0g0e"
|
367 |
+
},
|
368 |
+
"editorMode": "code",
|
369 |
+
"format": "table",
|
370 |
+
"rawQuery": true,
|
371 |
+
"rawSql": "SELECT\r\n relevance,\r\n COUNT(*) as count\r\nFROM conversations\r\nWHERE timestamp BETWEEN $__timeFrom() AND $__timeTo()\r\nGROUP BY relevance",
|
372 |
+
"refId": "A",
|
373 |
+
"sql": {
|
374 |
+
"columns": [
|
375 |
+
{
|
376 |
+
"parameters": [],
|
377 |
+
"type": "function"
|
378 |
+
}
|
379 |
+
],
|
380 |
+
"groupBy": [
|
381 |
+
{
|
382 |
+
"property": {
|
383 |
+
"type": "string"
|
384 |
+
},
|
385 |
+
"type": "groupBy"
|
386 |
+
}
|
387 |
+
],
|
388 |
+
"limit": 50
|
389 |
+
}
|
390 |
+
}
|
391 |
+
],
|
392 |
+
"title": "Relevance Distribution",
|
393 |
+
"type": "piechart"
|
394 |
+
},
|
395 |
+
{
|
396 |
+
"datasource": {
|
397 |
+
"default": true,
|
398 |
+
"type": "grafana-postgresql-datasource",
|
399 |
+
"uid": "ae169klpan0g0e"
|
400 |
+
},
|
401 |
+
"fieldConfig": {
|
402 |
+
"defaults": {
|
403 |
+
"color": {
|
404 |
+
"mode": "palette-classic"
|
405 |
+
},
|
406 |
+
"custom": {
|
407 |
+
"axisBorderShow": false,
|
408 |
+
"axisCenteredZero": false,
|
409 |
+
"axisColorMode": "text",
|
410 |
+
"axisLabel": "",
|
411 |
+
"axisPlacement": "auto",
|
412 |
+
"barAlignment": 0,
|
413 |
+
"barWidthFactor": 0.6,
|
414 |
+
"drawStyle": "line",
|
415 |
+
"fillOpacity": 0,
|
416 |
+
"gradientMode": "none",
|
417 |
+
"hideFrom": {
|
418 |
+
"legend": false,
|
419 |
+
"tooltip": false,
|
420 |
+
"viz": false
|
421 |
+
},
|
422 |
+
"insertNulls": false,
|
423 |
+
"lineInterpolation": "linear",
|
424 |
+
"lineWidth": 1,
|
425 |
+
"pointSize": 5,
|
426 |
+
"scaleDistribution": {
|
427 |
+
"type": "linear"
|
428 |
+
},
|
429 |
+
"showPoints": "auto",
|
430 |
+
"spanNulls": false,
|
431 |
+
"stacking": {
|
432 |
+
"group": "A",
|
433 |
+
"mode": "none"
|
434 |
+
},
|
435 |
+
"thresholdsStyle": {
|
436 |
+
"mode": "off"
|
437 |
+
}
|
438 |
+
},
|
439 |
+
"mappings": [],
|
440 |
+
"thresholds": {
|
441 |
+
"mode": "absolute",
|
442 |
+
"steps": [
|
443 |
+
{
|
444 |
+
"color": "green",
|
445 |
+
"value": null
|
446 |
+
},
|
447 |
+
{
|
448 |
+
"color": "red",
|
449 |
+
"value": 80
|
450 |
+
}
|
451 |
+
]
|
452 |
+
}
|
453 |
+
},
|
454 |
+
"overrides": []
|
455 |
+
},
|
456 |
+
"gridPos": {
|
457 |
+
"h": 8,
|
458 |
+
"w": 12,
|
459 |
+
"x": 0,
|
460 |
+
"y": 16
|
461 |
+
},
|
462 |
+
"id": 8,
|
463 |
+
"options": {
|
464 |
+
"legend": {
|
465 |
+
"calcs": [],
|
466 |
+
"displayMode": "list",
|
467 |
+
"placement": "right",
|
468 |
+
"showLegend": true
|
469 |
+
},
|
470 |
+
"tooltip": {
|
471 |
+
"mode": "single",
|
472 |
+
"sort": "none"
|
473 |
+
}
|
474 |
+
},
|
475 |
+
"targets": [
|
476 |
+
{
|
477 |
+
"datasource": {
|
478 |
+
"type": "grafana-postgresql-datasource",
|
479 |
+
"uid": "ae169klpan0g0e"
|
480 |
+
},
|
481 |
+
"editorMode": "code",
|
482 |
+
"format": "table",
|
483 |
+
"rawQuery": true,
|
484 |
+
"rawSql": "SELECT\r\n date_trunc('hour', f.timestamp) AS time,\r\n SUM(CASE WHEN f.feedback > 0 THEN 1 ELSE 0 END) AS positive_feedback,\r\n SUM(CASE WHEN f.feedback < 0 THEN 1 ELSE 0 END) AS negative_feedback\r\nFROM feedback f\r\nWHERE f.timestamp >= $__timeFrom() AND f.timestamp < $__timeTo()\r\nGROUP BY 1\r\nORDER BY 1;\r\n",
|
485 |
+
"refId": "A",
|
486 |
+
"sql": {
|
487 |
+
"columns": [
|
488 |
+
{
|
489 |
+
"parameters": [],
|
490 |
+
"type": "function"
|
491 |
+
}
|
492 |
+
],
|
493 |
+
"groupBy": [
|
494 |
+
{
|
495 |
+
"property": {
|
496 |
+
"type": "string"
|
497 |
+
},
|
498 |
+
"type": "groupBy"
|
499 |
+
}
|
500 |
+
],
|
501 |
+
"limit": 50
|
502 |
+
}
|
503 |
+
}
|
504 |
+
],
|
505 |
+
"title": "Feedback Trends Over time",
|
506 |
+
"type": "timeseries"
|
507 |
+
},
|
508 |
+
{
|
509 |
+
"datasource": {
|
510 |
+
"default": true,
|
511 |
+
"type": "grafana-postgresql-datasource",
|
512 |
+
"uid": "ae169klpan0g0e"
|
513 |
+
},
|
514 |
+
"fieldConfig": {
|
515 |
+
"defaults": {
|
516 |
+
"color": {
|
517 |
+
"mode": "palette-classic"
|
518 |
+
},
|
519 |
+
"custom": {
|
520 |
+
"axisBorderShow": false,
|
521 |
+
"axisCenteredZero": false,
|
522 |
+
"axisColorMode": "text",
|
523 |
+
"axisLabel": "",
|
524 |
+
"axisPlacement": "auto",
|
525 |
+
"barAlignment": 0,
|
526 |
+
"barWidthFactor": 0.6,
|
527 |
+
"drawStyle": "line",
|
528 |
+
"fillOpacity": 0,
|
529 |
+
"gradientMode": "none",
|
530 |
+
"hideFrom": {
|
531 |
+
"legend": false,
|
532 |
+
"tooltip": false,
|
533 |
+
"viz": false
|
534 |
+
},
|
535 |
+
"insertNulls": false,
|
536 |
+
"lineInterpolation": "linear",
|
537 |
+
"lineWidth": 1,
|
538 |
+
"pointSize": 5,
|
539 |
+
"scaleDistribution": {
|
540 |
+
"type": "linear"
|
541 |
+
},
|
542 |
+
"showPoints": "auto",
|
543 |
+
"spanNulls": false,
|
544 |
+
"stacking": {
|
545 |
+
"group": "A",
|
546 |
+
"mode": "none"
|
547 |
+
},
|
548 |
+
"thresholdsStyle": {
|
549 |
+
"mode": "off"
|
550 |
+
}
|
551 |
+
},
|
552 |
+
"mappings": [],
|
553 |
+
"thresholds": {
|
554 |
+
"mode": "absolute",
|
555 |
+
"steps": [
|
556 |
+
{
|
557 |
+
"color": "green",
|
558 |
+
"value": null
|
559 |
+
},
|
560 |
+
{
|
561 |
+
"color": "red",
|
562 |
+
"value": 80
|
563 |
+
}
|
564 |
+
]
|
565 |
+
}
|
566 |
+
},
|
567 |
+
"overrides": []
|
568 |
+
},
|
569 |
+
"gridPos": {
|
570 |
+
"h": 8,
|
571 |
+
"w": 12,
|
572 |
+
"x": 12,
|
573 |
+
"y": 16
|
574 |
+
},
|
575 |
+
"id": 1,
|
576 |
+
"options": {
|
577 |
+
"legend": {
|
578 |
+
"calcs": [],
|
579 |
+
"displayMode": "list",
|
580 |
+
"placement": "bottom",
|
581 |
+
"showLegend": true
|
582 |
+
},
|
583 |
+
"tooltip": {
|
584 |
+
"mode": "single",
|
585 |
+
"sort": "none"
|
586 |
+
}
|
587 |
+
},
|
588 |
+
"targets": [
|
589 |
+
{
|
590 |
+
"datasource": {
|
591 |
+
"type": "grafana-postgresql-datasource",
|
592 |
+
"uid": "ae169klpan0g0e"
|
593 |
+
},
|
594 |
+
"editorMode": "code",
|
595 |
+
"format": "table",
|
596 |
+
"rawQuery": true,
|
597 |
+
"rawSql": "SELECT\r\n timestamp AS time,\r\n response_time\r\nFROM conversations\r\nWHERE timestamp BETWEEN $__timeFrom() AND $__timeTo()\r\nORDER BY timestamp",
|
598 |
+
"refId": "A",
|
599 |
+
"sql": {
|
600 |
+
"columns": [
|
601 |
+
{
|
602 |
+
"parameters": [],
|
603 |
+
"type": "function"
|
604 |
+
}
|
605 |
+
],
|
606 |
+
"groupBy": [
|
607 |
+
{
|
608 |
+
"property": {
|
609 |
+
"type": "string"
|
610 |
+
},
|
611 |
+
"type": "groupBy"
|
612 |
+
}
|
613 |
+
],
|
614 |
+
"limit": 50
|
615 |
+
}
|
616 |
+
}
|
617 |
+
],
|
618 |
+
"title": "Response Time",
|
619 |
+
"type": "timeseries"
|
620 |
+
},
|
621 |
+
{
|
622 |
+
"datasource": {
|
623 |
+
"default": true,
|
624 |
+
"type": "grafana-postgresql-datasource",
|
625 |
+
"uid": "ae169klpan0g0e"
|
626 |
+
},
|
627 |
+
"fieldConfig": {
|
628 |
+
"defaults": {
|
629 |
+
"color": {
|
630 |
+
"mode": "palette-classic"
|
631 |
+
},
|
632 |
+
"custom": {
|
633 |
+
"axisBorderShow": false,
|
634 |
+
"axisCenteredZero": false,
|
635 |
+
"axisColorMode": "text",
|
636 |
+
"axisLabel": "",
|
637 |
+
"axisPlacement": "auto",
|
638 |
+
"barAlignment": 0,
|
639 |
+
"barWidthFactor": 0.6,
|
640 |
+
"drawStyle": "line",
|
641 |
+
"fillOpacity": 0,
|
642 |
+
"gradientMode": "none",
|
643 |
+
"hideFrom": {
|
644 |
+
"legend": false,
|
645 |
+
"tooltip": false,
|
646 |
+
"viz": false
|
647 |
+
},
|
648 |
+
"insertNulls": false,
|
649 |
+
"lineInterpolation": "linear",
|
650 |
+
"lineWidth": 1,
|
651 |
+
"pointSize": 5,
|
652 |
+
"scaleDistribution": {
|
653 |
+
"type": "linear"
|
654 |
+
},
|
655 |
+
"showPoints": "auto",
|
656 |
+
"spanNulls": false,
|
657 |
+
"stacking": {
|
658 |
+
"group": "A",
|
659 |
+
"mode": "none"
|
660 |
+
},
|
661 |
+
"thresholdsStyle": {
|
662 |
+
"mode": "off"
|
663 |
+
}
|
664 |
+
},
|
665 |
+
"mappings": [],
|
666 |
+
"thresholds": {
|
667 |
+
"mode": "absolute",
|
668 |
+
"steps": [
|
669 |
+
{
|
670 |
+
"color": "green",
|
671 |
+
"value": null
|
672 |
+
},
|
673 |
+
{
|
674 |
+
"color": "red",
|
675 |
+
"value": 80
|
676 |
+
}
|
677 |
+
]
|
678 |
+
}
|
679 |
+
},
|
680 |
+
"overrides": []
|
681 |
+
},
|
682 |
+
"gridPos": {
|
683 |
+
"h": 8,
|
684 |
+
"w": 12,
|
685 |
+
"x": 0,
|
686 |
+
"y": 24
|
687 |
+
},
|
688 |
+
"id": 4,
|
689 |
+
"options": {
|
690 |
+
"legend": {
|
691 |
+
"calcs": [],
|
692 |
+
"displayMode": "list",
|
693 |
+
"placement": "right",
|
694 |
+
"showLegend": true
|
695 |
+
},
|
696 |
+
"tooltip": {
|
697 |
+
"mode": "single",
|
698 |
+
"sort": "none"
|
699 |
+
}
|
700 |
+
},
|
701 |
+
"targets": [
|
702 |
+
{
|
703 |
+
"datasource": {
|
704 |
+
"type": "grafana-postgresql-datasource",
|
705 |
+
"uid": "ae169klpan0g0e"
|
706 |
+
},
|
707 |
+
"editorMode": "code",
|
708 |
+
"format": "table",
|
709 |
+
"rawQuery": true,
|
710 |
+
"rawSql": "SELECT\r\n $__timeGroup(timestamp, $__interval) AS time,\r\n AVG(total_tokens) AS avg_tokens\r\nFROM conversations\r\nWHERE timestamp BETWEEN $__timeFrom() AND $__timeTo()\r\nGROUP BY 1\r\nORDER BY 1",
|
711 |
+
"refId": "A",
|
712 |
+
"sql": {
|
713 |
+
"columns": [
|
714 |
+
{
|
715 |
+
"parameters": [],
|
716 |
+
"type": "function"
|
717 |
+
}
|
718 |
+
],
|
719 |
+
"groupBy": [
|
720 |
+
{
|
721 |
+
"property": {
|
722 |
+
"type": "string"
|
723 |
+
},
|
724 |
+
"type": "groupBy"
|
725 |
+
}
|
726 |
+
],
|
727 |
+
"limit": 50
|
728 |
+
}
|
729 |
+
}
|
730 |
+
],
|
731 |
+
"title": "Token Usage Panel",
|
732 |
+
"type": "timeseries"
|
733 |
+
},
|
734 |
+
{
|
735 |
+
"datasource": {
|
736 |
+
"default": true,
|
737 |
+
"type": "grafana-postgresql-datasource",
|
738 |
+
"uid": "ae169klpan0g0e"
|
739 |
+
},
|
740 |
+
"fieldConfig": {
|
741 |
+
"defaults": {
|
742 |
+
"color": {
|
743 |
+
"mode": "thresholds"
|
744 |
+
},
|
745 |
+
"custom": {
|
746 |
+
"align": "auto",
|
747 |
+
"cellOptions": {
|
748 |
+
"type": "auto"
|
749 |
+
},
|
750 |
+
"inspect": false
|
751 |
+
},
|
752 |
+
"mappings": [],
|
753 |
+
"thresholds": {
|
754 |
+
"mode": "absolute",
|
755 |
+
"steps": [
|
756 |
+
{
|
757 |
+
"color": "green",
|
758 |
+
"value": null
|
759 |
+
},
|
760 |
+
{
|
761 |
+
"color": "red",
|
762 |
+
"value": 80
|
763 |
+
}
|
764 |
+
]
|
765 |
+
}
|
766 |
+
},
|
767 |
+
"overrides": []
|
768 |
+
},
|
769 |
+
"gridPos": {
|
770 |
+
"h": 8,
|
771 |
+
"w": 12,
|
772 |
+
"x": 12,
|
773 |
+
"y": 24
|
774 |
+
},
|
775 |
+
"id": 9,
|
776 |
+
"options": {
|
777 |
+
"cellHeight": "sm",
|
778 |
+
"footer": {
|
779 |
+
"countRows": false,
|
780 |
+
"fields": "",
|
781 |
+
"reducer": [
|
782 |
+
"sum"
|
783 |
+
],
|
784 |
+
"show": false
|
785 |
+
},
|
786 |
+
"showHeader": true
|
787 |
+
},
|
788 |
+
"pluginVersion": "11.2.0",
|
789 |
+
"targets": [
|
790 |
+
{
|
791 |
+
"datasource": {
|
792 |
+
"type": "grafana-postgresql-datasource",
|
793 |
+
"uid": "ae169klpan0g0e"
|
794 |
+
},
|
795 |
+
"editorMode": "code",
|
796 |
+
"format": "table",
|
797 |
+
"rawQuery": true,
|
798 |
+
"rawSql": "SELECT\r\n question,\r\n COUNT(*) AS frequency\r\nFROM conversations\r\nWHERE timestamp >= $__timeFrom() AND timestamp < $__timeTo()\r\nGROUP BY question\r\nORDER BY frequency DESC\r\nLIMIT 5;",
|
799 |
+
"refId": "A",
|
800 |
+
"sql": {
|
801 |
+
"columns": [
|
802 |
+
{
|
803 |
+
"parameters": [],
|
804 |
+
"type": "function"
|
805 |
+
}
|
806 |
+
],
|
807 |
+
"groupBy": [
|
808 |
+
{
|
809 |
+
"property": {
|
810 |
+
"type": "string"
|
811 |
+
},
|
812 |
+
"type": "groupBy"
|
813 |
+
}
|
814 |
+
],
|
815 |
+
"limit": 50
|
816 |
+
}
|
817 |
+
}
|
818 |
+
],
|
819 |
+
"title": "Most Frequent Questions",
|
820 |
+
"type": "table"
|
821 |
+
},
|
822 |
+
{
|
823 |
+
"datasource": {
|
824 |
+
"default": true,
|
825 |
+
"type": "grafana-postgresql-datasource",
|
826 |
+
"uid": "ae169klpan0g0e"
|
827 |
+
},
|
828 |
+
"fieldConfig": {
|
829 |
+
"defaults": {
|
830 |
+
"color": {
|
831 |
+
"mode": "palette-classic"
|
832 |
+
},
|
833 |
+
"custom": {
|
834 |
+
"axisBorderShow": false,
|
835 |
+
"axisCenteredZero": false,
|
836 |
+
"axisColorMode": "text",
|
837 |
+
"axisLabel": "",
|
838 |
+
"axisPlacement": "auto",
|
839 |
+
"barAlignment": 0,
|
840 |
+
"barWidthFactor": 0.6,
|
841 |
+
"drawStyle": "line",
|
842 |
+
"fillOpacity": 0,
|
843 |
+
"gradientMode": "none",
|
844 |
+
"hideFrom": {
|
845 |
+
"legend": false,
|
846 |
+
"tooltip": false,
|
847 |
+
"viz": false
|
848 |
+
},
|
849 |
+
"insertNulls": false,
|
850 |
+
"lineInterpolation": "linear",
|
851 |
+
"lineWidth": 1,
|
852 |
+
"pointSize": 5,
|
853 |
+
"scaleDistribution": {
|
854 |
+
"type": "linear"
|
855 |
+
},
|
856 |
+
"showPoints": "auto",
|
857 |
+
"spanNulls": false,
|
858 |
+
"stacking": {
|
859 |
+
"group": "A",
|
860 |
+
"mode": "none"
|
861 |
+
},
|
862 |
+
"thresholdsStyle": {
|
863 |
+
"mode": "off"
|
864 |
+
}
|
865 |
+
},
|
866 |
+
"mappings": [],
|
867 |
+
"thresholds": {
|
868 |
+
"mode": "absolute",
|
869 |
+
"steps": [
|
870 |
+
{
|
871 |
+
"color": "green",
|
872 |
+
"value": null
|
873 |
+
},
|
874 |
+
{
|
875 |
+
"color": "red",
|
876 |
+
"value": 80
|
877 |
+
}
|
878 |
+
]
|
879 |
+
}
|
880 |
+
},
|
881 |
+
"overrides": []
|
882 |
+
},
|
883 |
+
"gridPos": {
|
884 |
+
"h": 8,
|
885 |
+
"w": 12,
|
886 |
+
"x": 0,
|
887 |
+
"y": 32
|
888 |
+
},
|
889 |
+
"id": 7,
|
890 |
+
"options": {
|
891 |
+
"legend": {
|
892 |
+
"calcs": [],
|
893 |
+
"displayMode": "list",
|
894 |
+
"placement": "right",
|
895 |
+
"showLegend": true
|
896 |
+
},
|
897 |
+
"tooltip": {
|
898 |
+
"mode": "single",
|
899 |
+
"sort": "none"
|
900 |
+
}
|
901 |
+
},
|
902 |
+
"targets": [
|
903 |
+
{
|
904 |
+
"datasource": {
|
905 |
+
"type": "grafana-postgresql-datasource",
|
906 |
+
"uid": "ae169klpan0g0e"
|
907 |
+
},
|
908 |
+
"editorMode": "code",
|
909 |
+
"format": "table",
|
910 |
+
"rawQuery": true,
|
911 |
+
"rawSql": "SELECT\r\n date_trunc('hour', timestamp) AS time,\r\n COUNT(*) AS conversation_count\r\nFROM conversations\r\nWHERE timestamp >= $__timeFrom() AND timestamp < $__timeTo()\r\nGROUP BY 1\r\nORDER BY 1;",
|
912 |
+
"refId": "A",
|
913 |
+
"sql": {
|
914 |
+
"columns": [
|
915 |
+
{
|
916 |
+
"parameters": [],
|
917 |
+
"type": "function"
|
918 |
+
}
|
919 |
+
],
|
920 |
+
"groupBy": [
|
921 |
+
{
|
922 |
+
"property": {
|
923 |
+
"type": "string"
|
924 |
+
},
|
925 |
+
"type": "groupBy"
|
926 |
+
}
|
927 |
+
],
|
928 |
+
"limit": 50
|
929 |
+
}
|
930 |
+
}
|
931 |
+
],
|
932 |
+
"title": "Conversation count over time",
|
933 |
+
"type": "timeseries"
|
934 |
+
}
|
935 |
+
],
|
936 |
+
"refresh": "",
|
937 |
+
"schemaVersion": 39,
|
938 |
+
"tags": [],
|
939 |
+
"templating": {
|
940 |
+
"list": []
|
941 |
+
},
|
942 |
+
"time": {
|
943 |
+
"from": "now-6h",
|
944 |
+
"to": "now"
|
945 |
+
},
|
946 |
+
"timepicker": {},
|
947 |
+
"timezone": "browser",
|
948 |
+
"title": "Mental_Health",
|
949 |
+
"uid": "ce16auu7hu4n4f",
|
950 |
+
"version": 13,
|
951 |
+
"weekStart": ""
|
952 |
+
}
|
grafana/init.py
ADDED
@@ -0,0 +1,237 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import time
|
3 |
+
import requests
|
4 |
+
import json
|
5 |
+
import logging
|
6 |
+
from typing import Dict, Any
|
7 |
+
|
8 |
+
# Set up logging
|
9 |
+
logging.basicConfig(
|
10 |
+
level=logging.INFO,
|
11 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
12 |
+
)
|
13 |
+
logger = logging.getLogger(__name__)
|
14 |
+
|
15 |
+
class GrafanaInitializer:
|
16 |
+
def __init__(self):
|
17 |
+
self.grafana_url = os.getenv('GRAFANA_URL', 'http://localhost:3000')
|
18 |
+
self.grafana_user = os.getenv('GRAFANA_ADMIN_USER', 'admin')
|
19 |
+
self.grafana_password = os.getenv('GRAFANA_ADMIN_PASSWORD', 'admin')
|
20 |
+
self.postgres_host = os.getenv('POSTGRES_HOST', 'postgres')
|
21 |
+
self.postgres_port = os.getenv('POSTGRES_PORT', '5432')
|
22 |
+
self.postgres_db = os.getenv('POSTGRES_DB', 'mental_health')
|
23 |
+
self.postgres_user = os.getenv('POSTGRES_USER', 'newton')
|
24 |
+
self.postgres_password = os.getenv('POSTGRES_PASSWORD', 'Admin')
|
25 |
+
|
26 |
+
self.headers = {
|
27 |
+
'Content-Type': 'application/json',
|
28 |
+
'Accept': 'application/json',
|
29 |
+
}
|
30 |
+
self.session = requests.Session()
|
31 |
+
self.session.auth = (self.grafana_user, self.grafana_password)
|
32 |
+
|
33 |
+
def wait_for_grafana(self, max_retries: int = 30, delay: int = 5) -> bool:
|
34 |
+
"""Wait for Grafana to become available."""
|
35 |
+
for i in range(max_retries):
|
36 |
+
try:
|
37 |
+
response = self.session.get(f"{self.grafana_url}/api/health")
|
38 |
+
if response.status_code == 200:
|
39 |
+
logger.info("Grafana is available")
|
40 |
+
return True
|
41 |
+
except requests.exceptions.RequestException:
|
42 |
+
pass
|
43 |
+
logger.info(f"Waiting for Grafana to become available (attempt {i + 1}/{max_retries})")
|
44 |
+
time.sleep(delay)
|
45 |
+
return False
|
46 |
+
|
47 |
+
def setup_datasource(self) -> None:
|
48 |
+
"""Configure PostgreSQL as a data source."""
|
49 |
+
datasource_config = {
|
50 |
+
"name": "PostgreSQL",
|
51 |
+
"type": "postgres",
|
52 |
+
"url": f"{self.postgres_host}:{self.postgres_port}",
|
53 |
+
"access": "proxy",
|
54 |
+
"basicAuth": False,
|
55 |
+
"database": self.postgres_db,
|
56 |
+
"user": self.postgres_user,
|
57 |
+
"secureJsonData": {
|
58 |
+
"password": self.postgres_password
|
59 |
+
},
|
60 |
+
"jsonData": {
|
61 |
+
"sslmode": "disable",
|
62 |
+
"maxOpenConns": 100,
|
63 |
+
"maxIdleConns": 100,
|
64 |
+
"connMaxLifetime": 14400,
|
65 |
+
"postgresVersion": 1300,
|
66 |
+
"timescaledb": False
|
67 |
+
}
|
68 |
+
}
|
69 |
+
|
70 |
+
response = self.session.post(
|
71 |
+
f"{self.grafana_url}/api/datasources",
|
72 |
+
json=datasource_config
|
73 |
+
)
|
74 |
+
|
75 |
+
if response.status_code == 200:
|
76 |
+
logger.info("PostgreSQL datasource configured successfully")
|
77 |
+
else:
|
78 |
+
logger.error(f"Failed to configure datasource: {response.text}")
|
79 |
+
|
80 |
+
def create_dashboards(self) -> None:
|
81 |
+
"""Initialize Grafana dashboards for system monitoring."""
|
82 |
+
# System Performance Dashboard
|
83 |
+
performance_dashboard = {
|
84 |
+
"dashboard": {
|
85 |
+
"title": "Mental Health Assistant Performance",
|
86 |
+
"timezone": "browser",
|
87 |
+
"panels": [
|
88 |
+
# Response Time Panel
|
89 |
+
{
|
90 |
+
"title": "Average Response Time",
|
91 |
+
"type": "graph",
|
92 |
+
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 0},
|
93 |
+
"targets": [{
|
94 |
+
"rawSql": """
|
95 |
+
SELECT
|
96 |
+
timestamp as time,
|
97 |
+
avg(response_time) as "Response Time"
|
98 |
+
FROM conversations
|
99 |
+
WHERE $__timeFilter(timestamp)
|
100 |
+
GROUP BY timestamp
|
101 |
+
ORDER BY timestamp
|
102 |
+
""",
|
103 |
+
"format": "time_series"
|
104 |
+
}]
|
105 |
+
},
|
106 |
+
# Model Usage Panel
|
107 |
+
{
|
108 |
+
"title": "Model Usage Distribution",
|
109 |
+
"type": "piechart",
|
110 |
+
"gridPos": {"h": 8, "w": 12, "x": 12, "y": 0},
|
111 |
+
"targets": [{
|
112 |
+
"rawSql": """
|
113 |
+
SELECT
|
114 |
+
model_used as metric,
|
115 |
+
count(*) as value
|
116 |
+
FROM conversations
|
117 |
+
WHERE $__timeFilter(timestamp)
|
118 |
+
GROUP BY model_used
|
119 |
+
"""
|
120 |
+
}]
|
121 |
+
},
|
122 |
+
# Token Usage Panel
|
123 |
+
{
|
124 |
+
"title": "Average Token Usage",
|
125 |
+
"type": "graph",
|
126 |
+
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 8},
|
127 |
+
"targets": [{
|
128 |
+
"rawSql": """
|
129 |
+
SELECT
|
130 |
+
timestamp as time,
|
131 |
+
avg(total_tokens) as "Total Tokens",
|
132 |
+
avg(prompt_tokens) as "Prompt Tokens",
|
133 |
+
avg(completion_tokens) as "Completion Tokens"
|
134 |
+
FROM conversations
|
135 |
+
WHERE $__timeFilter(timestamp)
|
136 |
+
GROUP BY timestamp
|
137 |
+
ORDER BY timestamp
|
138 |
+
""",
|
139 |
+
"format": "time_series"
|
140 |
+
}]
|
141 |
+
}
|
142 |
+
],
|
143 |
+
"refresh": "5s"
|
144 |
+
}
|
145 |
+
}
|
146 |
+
|
147 |
+
# User Feedback Dashboard
|
148 |
+
feedback_dashboard = {
|
149 |
+
"dashboard": {
|
150 |
+
"title": "User Feedback Analysis",
|
151 |
+
"timezone": "browser",
|
152 |
+
"panels": [
|
153 |
+
# Feedback Distribution
|
154 |
+
{
|
155 |
+
"title": "Feedback Distribution",
|
156 |
+
"type": "stat",
|
157 |
+
"gridPos": {"h": 8, "w": 12, "x": 0, "y": 0},
|
158 |
+
"targets": [{
|
159 |
+
"rawSql": """
|
160 |
+
SELECT
|
161 |
+
sum(case when feedback > 0 then 1 else 0 end) as "Positive",
|
162 |
+
sum(case when feedback < 0 then 1 else 0 end) as "Negative"
|
163 |
+
FROM feedback
|
164 |
+
WHERE $__timeFilter(timestamp)
|
165 |
+
"""
|
166 |
+
}]
|
167 |
+
},
|
168 |
+
# Relevance Distribution
|
169 |
+
{
|
170 |
+
"title": "Answer Relevance Distribution",
|
171 |
+
"type": "piechart",
|
172 |
+
"gridPos": {"h": 8, "w": 12, "x": 12, "y": 0},
|
173 |
+
"targets": [{
|
174 |
+
"rawSql": """
|
175 |
+
SELECT
|
176 |
+
relevance as metric,
|
177 |
+
count(*) as value
|
178 |
+
FROM conversations
|
179 |
+
WHERE $__timeFilter(timestamp)
|
180 |
+
GROUP BY relevance
|
181 |
+
"""
|
182 |
+
}]
|
183 |
+
},
|
184 |
+
# Feedback Timeline
|
185 |
+
{
|
186 |
+
"title": "Feedback Timeline",
|
187 |
+
"type": "graph",
|
188 |
+
"gridPos": {"h": 8, "w": 24, "x": 0, "y": 8},
|
189 |
+
"targets": [{
|
190 |
+
"rawSql": """
|
191 |
+
SELECT
|
192 |
+
date_trunc('hour', timestamp) as time,
|
193 |
+
count(*) FILTER (WHERE feedback > 0) as "Positive",
|
194 |
+
count(*) FILTER (WHERE feedback < 0) as "Negative"
|
195 |
+
FROM feedback
|
196 |
+
WHERE $__timeFilter(timestamp)
|
197 |
+
GROUP BY date_trunc('hour', timestamp)
|
198 |
+
ORDER BY time
|
199 |
+
""",
|
200 |
+
"format": "time_series"
|
201 |
+
}]
|
202 |
+
}
|
203 |
+
],
|
204 |
+
"refresh": "5s"
|
205 |
+
}
|
206 |
+
}
|
207 |
+
|
208 |
+
# Create dashboards
|
209 |
+
for dashboard in [performance_dashboard, feedback_dashboard]:
|
210 |
+
response = self.session.post(
|
211 |
+
f"{self.grafana_url}/api/dashboards/db",
|
212 |
+
json=dashboard
|
213 |
+
)
|
214 |
+
|
215 |
+
if response.status_code == 200:
|
216 |
+
logger.info(f"Dashboard '{dashboard['dashboard']['title']}' created successfully")
|
217 |
+
else:
|
218 |
+
logger.error(f"Failed to create dashboard: {response.text}")
|
219 |
+
|
220 |
+
def main():
|
221 |
+
initializer = GrafanaInitializer()
|
222 |
+
|
223 |
+
# Wait for Grafana to become available
|
224 |
+
if not initializer.wait_for_grafana():
|
225 |
+
logger.error("Grafana is not available after maximum retries")
|
226 |
+
return
|
227 |
+
|
228 |
+
# Set up data source and dashboards
|
229 |
+
try:
|
230 |
+
initializer.setup_datasource()
|
231 |
+
initializer.create_dashboards()
|
232 |
+
logger.info("Grafana initialization completed successfully")
|
233 |
+
except Exception as e:
|
234 |
+
logger.error(f"Failed to initialize Grafana: {str(e)}")
|
235 |
+
|
236 |
+
if __name__ == "__main__":
|
237 |
+
main()
|
notebooks/.ipynb_checkpoints/data_generation-checkpoint.ipynb
ADDED
@@ -0,0 +1,542 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 2,
|
6 |
+
"id": "ae13d278-e1c5-496e-8871-3936ccb71b5d",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"from mistralai import Mistral\n",
|
11 |
+
"import pandas as pd\n",
|
12 |
+
"import minsearch\n",
|
13 |
+
"import os\n",
|
14 |
+
"from groq import Groq\n",
|
15 |
+
"from dotenv import load_dotenv\n",
|
16 |
+
"from tqdm.auto import tqdm\n",
|
17 |
+
"import pandas as pd\n",
|
18 |
+
"import minsearch\n",
|
19 |
+
"import os\n",
|
20 |
+
"from groq import Groq\n",
|
21 |
+
"from dotenv import load_dotenv\n",
|
22 |
+
"from tqdm.auto import tqdm\n"
|
23 |
+
]
|
24 |
+
},
|
25 |
+
{
|
26 |
+
"cell_type": "markdown",
|
27 |
+
"id": "048c2b93-82c0-4d5b-bcaa-47b8531506cf",
|
28 |
+
"metadata": {},
|
29 |
+
"source": [
|
30 |
+
"## Environment variables Loading"
|
31 |
+
]
|
32 |
+
},
|
33 |
+
{
|
34 |
+
"cell_type": "code",
|
35 |
+
"execution_count": 3,
|
36 |
+
"id": "7c5f1265-31da-4ad6-bd8c-bd912b39e5b1",
|
37 |
+
"metadata": {},
|
38 |
+
"outputs": [
|
39 |
+
{
|
40 |
+
"data": {
|
41 |
+
"text/plain": [
|
42 |
+
"True"
|
43 |
+
]
|
44 |
+
},
|
45 |
+
"execution_count": 3,
|
46 |
+
"metadata": {},
|
47 |
+
"output_type": "execute_result"
|
48 |
+
}
|
49 |
+
],
|
50 |
+
"source": [
|
51 |
+
"load_dotenv()\n"
|
52 |
+
]
|
53 |
+
},
|
54 |
+
{
|
55 |
+
"cell_type": "code",
|
56 |
+
"execution_count": 4,
|
57 |
+
"id": "4c4fa421-e6b2-48a3-9329-215c91c26ade",
|
58 |
+
"metadata": {},
|
59 |
+
"outputs": [],
|
60 |
+
"source": [
|
61 |
+
"# Access the API keys\n",
|
62 |
+
"mistral_api_key = os.getenv(\"MISTRAL_API_KEY\")\n",
|
63 |
+
"groq_api_key = os.getenv(\"GROQ_API_KEY\")"
|
64 |
+
]
|
65 |
+
},
|
66 |
+
{
|
67 |
+
"cell_type": "code",
|
68 |
+
"execution_count": 5,
|
69 |
+
"id": "722521c0-1558-430a-852f-a5afdd082a49",
|
70 |
+
"metadata": {},
|
71 |
+
"outputs": [
|
72 |
+
{
|
73 |
+
"name": "stdout",
|
74 |
+
"output_type": "stream",
|
75 |
+
"text": [
|
76 |
+
"Variable Type Data/Info\n",
|
77 |
+
"---------------------------------------\n",
|
78 |
+
"Groq type <class 'groq.Groq'>\n",
|
79 |
+
"Mistral type <class 'mistralai.sdk.Mistral'>\n",
|
80 |
+
"groq_api_key str gsk_32VwUDXWlbcss91AZEhIW<...>Yv5D56tMak8RwoyfSBXePPdht\n",
|
81 |
+
"load_dotenv function <function load_dotenv at 0x0000024D110E7430>\n",
|
82 |
+
"minsearch module <module 'minsearch' from <...>notebooks\\\\minsearch.py'>\n",
|
83 |
+
"mistral_api_key str 8liS0F7zb7zNgujwgo3dgTbr6HbfvmeI\n",
|
84 |
+
"os module <module 'os' from 'C:\\\\Us<...>n\\\\Python39\\\\lib\\\\os.py'>\n",
|
85 |
+
"pd module <module 'pandas' from 'C:<...>es\\\\pandas\\\\__init__.py'>\n",
|
86 |
+
"tqdm type <class 'tqdm.auto.tqdm'>\n"
|
87 |
+
]
|
88 |
+
}
|
89 |
+
],
|
90 |
+
"source": [
|
91 |
+
"%whos"
|
92 |
+
]
|
93 |
+
},
|
94 |
+
{
|
95 |
+
"cell_type": "code",
|
96 |
+
"execution_count": 6,
|
97 |
+
"id": "069f3cf6-4941-46f5-adeb-c56813c8db3f",
|
98 |
+
"metadata": {},
|
99 |
+
"outputs": [],
|
100 |
+
"source": [
|
101 |
+
"df=pd.read_csv(\"../dataset/Mental_Health_FAQ.csv\")"
|
102 |
+
]
|
103 |
+
},
|
104 |
+
{
|
105 |
+
"cell_type": "code",
|
106 |
+
"execution_count": 7,
|
107 |
+
"id": "a8e4b926-85a9-4130-8107-d416abd56a97",
|
108 |
+
"metadata": {},
|
109 |
+
"outputs": [
|
110 |
+
{
|
111 |
+
"data": {
|
112 |
+
"text/html": [
|
113 |
+
"<div>\n",
|
114 |
+
"<style scoped>\n",
|
115 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
116 |
+
" vertical-align: middle;\n",
|
117 |
+
" }\n",
|
118 |
+
"\n",
|
119 |
+
" .dataframe tbody tr th {\n",
|
120 |
+
" vertical-align: top;\n",
|
121 |
+
" }\n",
|
122 |
+
"\n",
|
123 |
+
" .dataframe thead th {\n",
|
124 |
+
" text-align: right;\n",
|
125 |
+
" }\n",
|
126 |
+
"</style>\n",
|
127 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
128 |
+
" <thead>\n",
|
129 |
+
" <tr style=\"text-align: right;\">\n",
|
130 |
+
" <th></th>\n",
|
131 |
+
" <th>Question_ID</th>\n",
|
132 |
+
" <th>Questions</th>\n",
|
133 |
+
" <th>Answers</th>\n",
|
134 |
+
" </tr>\n",
|
135 |
+
" </thead>\n",
|
136 |
+
" <tbody>\n",
|
137 |
+
" <tr>\n",
|
138 |
+
" <th>0</th>\n",
|
139 |
+
" <td>1590140</td>\n",
|
140 |
+
" <td>What does it mean to have a mental illness?</td>\n",
|
141 |
+
" <td>Mental illnesses are health conditions that di...</td>\n",
|
142 |
+
" </tr>\n",
|
143 |
+
" <tr>\n",
|
144 |
+
" <th>1</th>\n",
|
145 |
+
" <td>2110618</td>\n",
|
146 |
+
" <td>Who does mental illness affect?</td>\n",
|
147 |
+
" <td>It is estimated that mental illness affects 1 ...</td>\n",
|
148 |
+
" </tr>\n",
|
149 |
+
" <tr>\n",
|
150 |
+
" <th>2</th>\n",
|
151 |
+
" <td>6361820</td>\n",
|
152 |
+
" <td>What causes mental illness?</td>\n",
|
153 |
+
" <td>It is estimated that mental illness affects 1 ...</td>\n",
|
154 |
+
" </tr>\n",
|
155 |
+
" <tr>\n",
|
156 |
+
" <th>3</th>\n",
|
157 |
+
" <td>9434130</td>\n",
|
158 |
+
" <td>What are some of the warning signs of mental i...</td>\n",
|
159 |
+
" <td>Symptoms of mental health disorders vary depen...</td>\n",
|
160 |
+
" </tr>\n",
|
161 |
+
" <tr>\n",
|
162 |
+
" <th>4</th>\n",
|
163 |
+
" <td>7657263</td>\n",
|
164 |
+
" <td>Can people with mental illness recover?</td>\n",
|
165 |
+
" <td>When healing from mental illness, early identi...</td>\n",
|
166 |
+
" </tr>\n",
|
167 |
+
" </tbody>\n",
|
168 |
+
"</table>\n",
|
169 |
+
"</div>"
|
170 |
+
],
|
171 |
+
"text/plain": [
|
172 |
+
" Question_ID Questions \\\n",
|
173 |
+
"0 1590140 What does it mean to have a mental illness? \n",
|
174 |
+
"1 2110618 Who does mental illness affect? \n",
|
175 |
+
"2 6361820 What causes mental illness? \n",
|
176 |
+
"3 9434130 What are some of the warning signs of mental i... \n",
|
177 |
+
"4 7657263 Can people with mental illness recover? \n",
|
178 |
+
"\n",
|
179 |
+
" Answers \n",
|
180 |
+
"0 Mental illnesses are health conditions that di... \n",
|
181 |
+
"1 It is estimated that mental illness affects 1 ... \n",
|
182 |
+
"2 It is estimated that mental illness affects 1 ... \n",
|
183 |
+
"3 Symptoms of mental health disorders vary depen... \n",
|
184 |
+
"4 When healing from mental illness, early identi... "
|
185 |
+
]
|
186 |
+
},
|
187 |
+
"execution_count": 7,
|
188 |
+
"metadata": {},
|
189 |
+
"output_type": "execute_result"
|
190 |
+
}
|
191 |
+
],
|
192 |
+
"source": [
|
193 |
+
"df.head()"
|
194 |
+
]
|
195 |
+
},
|
196 |
+
{
|
197 |
+
"cell_type": "code",
|
198 |
+
"execution_count": 8,
|
199 |
+
"id": "5c69465d-0018-432f-b134-2fa929045e83",
|
200 |
+
"metadata": {},
|
201 |
+
"outputs": [],
|
202 |
+
"source": [
|
203 |
+
"documents=df.to_dict(orient='records')"
|
204 |
+
]
|
205 |
+
},
|
206 |
+
{
|
207 |
+
"cell_type": "code",
|
208 |
+
"execution_count": 9,
|
209 |
+
"id": "5297116d-cf4b-44ae-aaad-72079a906855",
|
210 |
+
"metadata": {},
|
211 |
+
"outputs": [
|
212 |
+
{
|
213 |
+
"data": {
|
214 |
+
"text/plain": [
|
215 |
+
"{'Question_ID': 6361820,\n",
|
216 |
+
" 'Questions': 'What causes mental illness?',\n",
|
217 |
+
" 'Answers': 'It is estimated that mental illness affects 1 in 5 adults in America, and that 1 in 24 adults have a serious mental illness. Mental illness does not discriminate; it can affect anyone, regardless of gender, age, income, social status, ethnicity, religion, sexual orientation, or background. Although mental illness can affect anyone, certain conditions may be more common in different populations. For instance, eating disorders tend to occur more often in females, while disorders such as attention deficit/hyperactivity disorder is more prevalent in children. Additionally, all ages are susceptible, but the young and the old are especially vulnerable. Mental illnesses usually strike individuals in the prime of their lives, with 75 percent of mental health conditions developing by the age of 24. This makes identification and treatment of mental disorders particularly difficult, because the normal personality and behavioral changes of adolescence may mask symptoms of a mental health condition. Parents and caretakers should be aware of this fact, and take notice of changes in their child’s mood, personality, personal habits, and social withdrawal. When these occur in children under 18, they are referred to as serious emotional disturbances (SEDs).'}"
|
218 |
+
]
|
219 |
+
},
|
220 |
+
"execution_count": 9,
|
221 |
+
"metadata": {},
|
222 |
+
"output_type": "execute_result"
|
223 |
+
}
|
224 |
+
],
|
225 |
+
"source": [
|
226 |
+
"documents[2]"
|
227 |
+
]
|
228 |
+
},
|
229 |
+
{
|
230 |
+
"cell_type": "code",
|
231 |
+
"execution_count": 10,
|
232 |
+
"id": "604c32fc-bf9b-465d-b2d6-e55e8947ef4d",
|
233 |
+
"metadata": {},
|
234 |
+
"outputs": [],
|
235 |
+
"source": [
|
236 |
+
"prompt_template=\"\"\"You are emulating a patient concerned about mental health. For each answer, \n",
|
237 |
+
"formulate 5 questions that this patient might ask. The questions should be complete, not too short, \n",
|
238 |
+
"and use as few words as possible from the original answer.\n",
|
239 |
+
"\n",
|
240 |
+
"The record:\n",
|
241 |
+
"Question_ID:{Question_ID}\n",
|
242 |
+
"Questions:{Questions}\n",
|
243 |
+
"Answer: {Answers}\n",
|
244 |
+
"\n",
|
245 |
+
"Provide the output in parsable JSON format without using code blocks. The output should be structured like this:\n",
|
246 |
+
"\"\"\".strip()"
|
247 |
+
]
|
248 |
+
},
|
249 |
+
{
|
250 |
+
"cell_type": "code",
|
251 |
+
"execution_count": 11,
|
252 |
+
"id": "dacc3ea2-df3b-4fad-b9cd-1cc3a88a6e1c",
|
253 |
+
"metadata": {},
|
254 |
+
"outputs": [],
|
255 |
+
"source": [
|
256 |
+
"prompt=prompt_template.format(**documents[0])"
|
257 |
+
]
|
258 |
+
},
|
259 |
+
{
|
260 |
+
"cell_type": "code",
|
261 |
+
"execution_count": 15,
|
262 |
+
"id": "53b634ad-dc6b-4848-b6b4-b882e90076cb",
|
263 |
+
"metadata": {},
|
264 |
+
"outputs": [],
|
265 |
+
"source": [
|
266 |
+
"client = Mistral(api_key=mistral_api_key)"
|
267 |
+
]
|
268 |
+
},
|
269 |
+
{
|
270 |
+
"cell_type": "code",
|
271 |
+
"execution_count": 23,
|
272 |
+
"id": "079bc5f5-2977-43da-8eca-c340dcb884d4",
|
273 |
+
"metadata": {},
|
274 |
+
"outputs": [],
|
275 |
+
"source": [
|
276 |
+
"def llm(prompt,model=\"mistral-large-latest\"):\n",
|
277 |
+
" response = client.chat.complete(\n",
|
278 |
+
" model=model,\n",
|
279 |
+
" messages=[{\"role\": \"user\", \"content\": prompt}])\n",
|
280 |
+
" return response.choices[0].message.content\n",
|
281 |
+
" "
|
282 |
+
]
|
283 |
+
},
|
284 |
+
{
|
285 |
+
"cell_type": "code",
|
286 |
+
"execution_count": 24,
|
287 |
+
"id": "d227d497-bc50-49d8-a141-8e8a182aecf4",
|
288 |
+
"metadata": {},
|
289 |
+
"outputs": [],
|
290 |
+
"source": [
|
291 |
+
"quiz=llm(prompt)"
|
292 |
+
]
|
293 |
+
},
|
294 |
+
{
|
295 |
+
"cell_type": "code",
|
296 |
+
"execution_count": 25,
|
297 |
+
"id": "e7a63537-5edd-475b-a032-e5bb7380e160",
|
298 |
+
"metadata": {},
|
299 |
+
"outputs": [
|
300 |
+
{
|
301 |
+
"name": "stdout",
|
302 |
+
"output_type": "stream",
|
303 |
+
"text": [
|
304 |
+
"```json\n",
|
305 |
+
"{\n",
|
306 |
+
" \"Question1\": \"What are the main aspects of life affected by mental illnesses?\",\n",
|
307 |
+
" \"Question2\": \"How do mental illnesses vary in terms of severity and impact?\",\n",
|
308 |
+
" \"Question3\": \"Are mental illnesses related to a person's character or intelligence?\",\n",
|
309 |
+
" \"Question4\": \"How is mental illness treated, and what is the success rate?\",\n",
|
310 |
+
" \"Question5\": \"Can someone with a mental illness lead an independent and successful life?\"\n",
|
311 |
+
"}\n",
|
312 |
+
"```\n"
|
313 |
+
]
|
314 |
+
}
|
315 |
+
],
|
316 |
+
"source": [
|
317 |
+
"print(quiz)"
|
318 |
+
]
|
319 |
+
},
|
320 |
+
{
|
321 |
+
"cell_type": "code",
|
322 |
+
"execution_count": 20,
|
323 |
+
"id": "a5f31769-9b1d-4ca2-a565-24298207bdb4",
|
324 |
+
"metadata": {},
|
325 |
+
"outputs": [
|
326 |
+
{
|
327 |
+
"name": "stdout",
|
328 |
+
"output_type": "stream",
|
329 |
+
"text": [
|
330 |
+
"{\n",
|
331 |
+
" \"question1\": \"What is the definition of mental illness?\",\n",
|
332 |
+
" \"question2\": \"How do mental illnesses affect a person's daily functioning?\",\n",
|
333 |
+
" \"question3\": \"What are the different types of mental illnesses?\",\n",
|
334 |
+
" \"question4\": \"What are the treatment options for mental illnesses?\",\n",
|
335 |
+
" \"question5\": \"What is the impact of proper treatment on a person's life with mental illness?\"\n",
|
336 |
+
"}\n"
|
337 |
+
]
|
338 |
+
}
|
339 |
+
],
|
340 |
+
"source": [
|
341 |
+
"print(quiz)"
|
342 |
+
]
|
343 |
+
},
|
344 |
+
{
|
345 |
+
"cell_type": "code",
|
346 |
+
"execution_count": 22,
|
347 |
+
"id": "a2286fdc-116b-44c5-af27-21fdab4e8099",
|
348 |
+
"metadata": {},
|
349 |
+
"outputs": [
|
350 |
+
{
|
351 |
+
"name": "stdout",
|
352 |
+
"output_type": "stream",
|
353 |
+
"text": [
|
354 |
+
"3\n",
|
355 |
+
"3\n",
|
356 |
+
"3\n",
|
357 |
+
"3\n",
|
358 |
+
"3\n",
|
359 |
+
"3\n",
|
360 |
+
"3\n",
|
361 |
+
"3\n",
|
362 |
+
"3\n",
|
363 |
+
"3\n",
|
364 |
+
"3\n",
|
365 |
+
"3\n",
|
366 |
+
"3\n",
|
367 |
+
"3\n",
|
368 |
+
"3\n",
|
369 |
+
"3\n",
|
370 |
+
"3\n",
|
371 |
+
"3\n",
|
372 |
+
"3\n",
|
373 |
+
"3\n",
|
374 |
+
"3\n",
|
375 |
+
"3\n",
|
376 |
+
"3\n",
|
377 |
+
"3\n",
|
378 |
+
"3\n",
|
379 |
+
"3\n",
|
380 |
+
"3\n",
|
381 |
+
"3\n",
|
382 |
+
"3\n",
|
383 |
+
"3\n",
|
384 |
+
"3\n",
|
385 |
+
"3\n",
|
386 |
+
"3\n",
|
387 |
+
"3\n",
|
388 |
+
"3\n",
|
389 |
+
"3\n",
|
390 |
+
"3\n",
|
391 |
+
"3\n",
|
392 |
+
"3\n",
|
393 |
+
"3\n",
|
394 |
+
"3\n",
|
395 |
+
"3\n",
|
396 |
+
"3\n",
|
397 |
+
"3\n",
|
398 |
+
"3\n",
|
399 |
+
"3\n",
|
400 |
+
"3\n",
|
401 |
+
"3\n",
|
402 |
+
"3\n",
|
403 |
+
"3\n",
|
404 |
+
"3\n",
|
405 |
+
"3\n",
|
406 |
+
"3\n",
|
407 |
+
"3\n",
|
408 |
+
"3\n",
|
409 |
+
"3\n",
|
410 |
+
"3\n",
|
411 |
+
"3\n",
|
412 |
+
"3\n",
|
413 |
+
"3\n",
|
414 |
+
"3\n",
|
415 |
+
"3\n",
|
416 |
+
"3\n",
|
417 |
+
"3\n",
|
418 |
+
"3\n",
|
419 |
+
"3\n",
|
420 |
+
"3\n",
|
421 |
+
"3\n",
|
422 |
+
"3\n",
|
423 |
+
"3\n",
|
424 |
+
"3\n",
|
425 |
+
"3\n",
|
426 |
+
"3\n",
|
427 |
+
"3\n",
|
428 |
+
"3\n",
|
429 |
+
"3\n",
|
430 |
+
"3\n",
|
431 |
+
"3\n",
|
432 |
+
"3\n",
|
433 |
+
"3\n",
|
434 |
+
"3\n",
|
435 |
+
"3\n",
|
436 |
+
"3\n",
|
437 |
+
"3\n",
|
438 |
+
"3\n",
|
439 |
+
"3\n",
|
440 |
+
"3\n",
|
441 |
+
"3\n",
|
442 |
+
"3\n",
|
443 |
+
"3\n",
|
444 |
+
"3\n",
|
445 |
+
"3\n",
|
446 |
+
"3\n",
|
447 |
+
"3\n",
|
448 |
+
"3\n",
|
449 |
+
"3\n",
|
450 |
+
"3\n",
|
451 |
+
"3\n"
|
452 |
+
]
|
453 |
+
}
|
454 |
+
],
|
455 |
+
"source": [
|
456 |
+
"for quiz in documents:\n",
|
457 |
+
" print(len(quiz))"
|
458 |
+
]
|
459 |
+
},
|
460 |
+
{
|
461 |
+
"cell_type": "code",
|
462 |
+
"execution_count": 21,
|
463 |
+
"id": "71dedb46-3b27-4aa0-a972-0907fae7a5b1",
|
464 |
+
"metadata": {},
|
465 |
+
"outputs": [
|
466 |
+
{
|
467 |
+
"data": {
|
468 |
+
"text/plain": [
|
469 |
+
"377"
|
470 |
+
]
|
471 |
+
},
|
472 |
+
"execution_count": 21,
|
473 |
+
"metadata": {},
|
474 |
+
"output_type": "execute_result"
|
475 |
+
}
|
476 |
+
],
|
477 |
+
"source": [
|
478 |
+
"len(quiz)"
|
479 |
+
]
|
480 |
+
},
|
481 |
+
{
|
482 |
+
"cell_type": "code",
|
483 |
+
"execution_count": null,
|
484 |
+
"id": "5fbc9707-e590-4c86-bcfd-4374e07b659f",
|
485 |
+
"metadata": {},
|
486 |
+
"outputs": [],
|
487 |
+
"source": [
|
488 |
+
"df.info()"
|
489 |
+
]
|
490 |
+
},
|
491 |
+
{
|
492 |
+
"cell_type": "code",
|
493 |
+
"execution_count": null,
|
494 |
+
"id": "b611ea3d-ff42-49b0-82c3-c1c970cedcf2",
|
495 |
+
"metadata": {},
|
496 |
+
"outputs": [],
|
497 |
+
"source": [
|
498 |
+
"import os\n",
|
499 |
+
"from mistralai import Mistral\n",
|
500 |
+
"\n",
|
501 |
+
"client = Mistral(api_key=mistral_api_key)\n",
|
502 |
+
"\n",
|
503 |
+
"model = \"codestral-latest\"\n",
|
504 |
+
"message = [{\"role\": \"user\", \"content\": \"Write a function for fibonacci\"}]\n",
|
505 |
+
"chat_response = client.chat.complete(\n",
|
506 |
+
" model = model,\n",
|
507 |
+
" messages = message\n",
|
508 |
+
")\n",
|
509 |
+
"print(chat_response.choices[0].message.content)"
|
510 |
+
]
|
511 |
+
},
|
512 |
+
{
|
513 |
+
"cell_type": "code",
|
514 |
+
"execution_count": null,
|
515 |
+
"id": "5b254557-6c35-4306-aada-bae7a264ba89",
|
516 |
+
"metadata": {},
|
517 |
+
"outputs": [],
|
518 |
+
"source": []
|
519 |
+
}
|
520 |
+
],
|
521 |
+
"metadata": {
|
522 |
+
"kernelspec": {
|
523 |
+
"display_name": "Python 3 (ipykernel)",
|
524 |
+
"language": "python",
|
525 |
+
"name": "python3"
|
526 |
+
},
|
527 |
+
"language_info": {
|
528 |
+
"codemirror_mode": {
|
529 |
+
"name": "ipython",
|
530 |
+
"version": 3
|
531 |
+
},
|
532 |
+
"file_extension": ".py",
|
533 |
+
"mimetype": "text/x-python",
|
534 |
+
"name": "python",
|
535 |
+
"nbconvert_exporter": "python",
|
536 |
+
"pygments_lexer": "ipython3",
|
537 |
+
"version": "3.9.13"
|
538 |
+
}
|
539 |
+
},
|
540 |
+
"nbformat": 4,
|
541 |
+
"nbformat_minor": 5
|
542 |
+
}
|
notebooks/.ipynb_checkpoints/rag_evaluation-checkpoint.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
notebooks/__pycache__/minsearch.cpython-39.pyc
ADDED
Binary file (4.18 kB). View file
|
|
notebooks/data_generation.ipynb
ADDED
@@ -0,0 +1,1336 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"id": "ae13d278-e1c5-496e-8871-3936ccb71b5d",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"from mistralai import Mistral\n",
|
11 |
+
"import pandas as pd\n",
|
12 |
+
"import minsearch\n",
|
13 |
+
"import os\n",
|
14 |
+
"from groq import Groq\n",
|
15 |
+
"from dotenv import load_dotenv\n",
|
16 |
+
"from tqdm.auto import tqdm\n",
|
17 |
+
"import pandas as pd\n",
|
18 |
+
"import minsearch\n",
|
19 |
+
"import os\n",
|
20 |
+
"from groq import Groq\n",
|
21 |
+
"from dotenv import load_dotenv\n",
|
22 |
+
"from tqdm.auto import tqdm\n"
|
23 |
+
]
|
24 |
+
},
|
25 |
+
{
|
26 |
+
"cell_type": "markdown",
|
27 |
+
"id": "048c2b93-82c0-4d5b-bcaa-47b8531506cf",
|
28 |
+
"metadata": {},
|
29 |
+
"source": [
|
30 |
+
"## Environment variables Loading"
|
31 |
+
]
|
32 |
+
},
|
33 |
+
{
|
34 |
+
"cell_type": "code",
|
35 |
+
"execution_count": 2,
|
36 |
+
"id": "7c5f1265-31da-4ad6-bd8c-bd912b39e5b1",
|
37 |
+
"metadata": {},
|
38 |
+
"outputs": [
|
39 |
+
{
|
40 |
+
"data": {
|
41 |
+
"text/plain": [
|
42 |
+
"True"
|
43 |
+
]
|
44 |
+
},
|
45 |
+
"execution_count": 2,
|
46 |
+
"metadata": {},
|
47 |
+
"output_type": "execute_result"
|
48 |
+
}
|
49 |
+
],
|
50 |
+
"source": [
|
51 |
+
"load_dotenv()\n"
|
52 |
+
]
|
53 |
+
},
|
54 |
+
{
|
55 |
+
"cell_type": "code",
|
56 |
+
"execution_count": 3,
|
57 |
+
"id": "4c4fa421-e6b2-48a3-9329-215c91c26ade",
|
58 |
+
"metadata": {},
|
59 |
+
"outputs": [],
|
60 |
+
"source": [
|
61 |
+
"# Access the API keys\n",
|
62 |
+
"mistral_api_key = os.getenv(\"MISTRAL_API_KEY\")\n",
|
63 |
+
"groq_api_key = os.getenv(\"GROQ_API_KEY\")"
|
64 |
+
]
|
65 |
+
},
|
66 |
+
{
|
67 |
+
"cell_type": "code",
|
68 |
+
"execution_count": 4,
|
69 |
+
"id": "722521c0-1558-430a-852f-a5afdd082a49",
|
70 |
+
"metadata": {},
|
71 |
+
"outputs": [
|
72 |
+
{
|
73 |
+
"name": "stdout",
|
74 |
+
"output_type": "stream",
|
75 |
+
"text": [
|
76 |
+
"Variable Type Data/Info\n",
|
77 |
+
"---------------------------------------\n",
|
78 |
+
"Groq type <class 'groq.Groq'>\n",
|
79 |
+
"Mistral type <class 'mistralai.sdk.Mistral'>\n",
|
80 |
+
"groq_api_key str gsk_32VwUDXWlbcss91AZEhIW<...>Yv5D56tMak8RwoyfSBXePPdht\n",
|
81 |
+
"load_dotenv function <function load_dotenv at 0x00000145257C5310>\n",
|
82 |
+
"minsearch module <module 'minsearch' from <...>notebooks\\\\minsearch.py'>\n",
|
83 |
+
"mistral_api_key str 8liS0F7zb7zNgujwgo3dgTbr6HbfvmeI\n",
|
84 |
+
"os module <module 'os' from 'C:\\\\Us<...>n\\\\Python39\\\\lib\\\\os.py'>\n",
|
85 |
+
"pd module <module 'pandas' from 'C:<...>es\\\\pandas\\\\__init__.py'>\n",
|
86 |
+
"tqdm type <class 'tqdm.auto.tqdm'>\n"
|
87 |
+
]
|
88 |
+
}
|
89 |
+
],
|
90 |
+
"source": [
|
91 |
+
"%whos"
|
92 |
+
]
|
93 |
+
},
|
94 |
+
{
|
95 |
+
"cell_type": "code",
|
96 |
+
"execution_count": 4,
|
97 |
+
"id": "069f3cf6-4941-46f5-adeb-c56813c8db3f",
|
98 |
+
"metadata": {},
|
99 |
+
"outputs": [],
|
100 |
+
"source": [
|
101 |
+
"df=pd.read_csv(\"../dataset/Mental_Health_FAQ.csv\")"
|
102 |
+
]
|
103 |
+
},
|
104 |
+
{
|
105 |
+
"cell_type": "code",
|
106 |
+
"execution_count": 5,
|
107 |
+
"id": "a8e4b926-85a9-4130-8107-d416abd56a97",
|
108 |
+
"metadata": {
|
109 |
+
"scrolled": true
|
110 |
+
},
|
111 |
+
"outputs": [
|
112 |
+
{
|
113 |
+
"data": {
|
114 |
+
"text/html": [
|
115 |
+
"<div>\n",
|
116 |
+
"<style scoped>\n",
|
117 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
118 |
+
" vertical-align: middle;\n",
|
119 |
+
" }\n",
|
120 |
+
"\n",
|
121 |
+
" .dataframe tbody tr th {\n",
|
122 |
+
" vertical-align: top;\n",
|
123 |
+
" }\n",
|
124 |
+
"\n",
|
125 |
+
" .dataframe thead th {\n",
|
126 |
+
" text-align: right;\n",
|
127 |
+
" }\n",
|
128 |
+
"</style>\n",
|
129 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
130 |
+
" <thead>\n",
|
131 |
+
" <tr style=\"text-align: right;\">\n",
|
132 |
+
" <th></th>\n",
|
133 |
+
" <th>Question_ID</th>\n",
|
134 |
+
" <th>Questions</th>\n",
|
135 |
+
" <th>Answers</th>\n",
|
136 |
+
" </tr>\n",
|
137 |
+
" </thead>\n",
|
138 |
+
" <tbody>\n",
|
139 |
+
" <tr>\n",
|
140 |
+
" <th>0</th>\n",
|
141 |
+
" <td>1590140</td>\n",
|
142 |
+
" <td>What does it mean to have a mental illness?</td>\n",
|
143 |
+
" <td>Mental illnesses are health conditions that di...</td>\n",
|
144 |
+
" </tr>\n",
|
145 |
+
" <tr>\n",
|
146 |
+
" <th>1</th>\n",
|
147 |
+
" <td>2110618</td>\n",
|
148 |
+
" <td>Who does mental illness affect?</td>\n",
|
149 |
+
" <td>It is estimated that mental illness affects 1 ...</td>\n",
|
150 |
+
" </tr>\n",
|
151 |
+
" <tr>\n",
|
152 |
+
" <th>2</th>\n",
|
153 |
+
" <td>6361820</td>\n",
|
154 |
+
" <td>What causes mental illness?</td>\n",
|
155 |
+
" <td>It is estimated that mental illness affects 1 ...</td>\n",
|
156 |
+
" </tr>\n",
|
157 |
+
" <tr>\n",
|
158 |
+
" <th>3</th>\n",
|
159 |
+
" <td>9434130</td>\n",
|
160 |
+
" <td>What are some of the warning signs of mental i...</td>\n",
|
161 |
+
" <td>Symptoms of mental health disorders vary depen...</td>\n",
|
162 |
+
" </tr>\n",
|
163 |
+
" <tr>\n",
|
164 |
+
" <th>4</th>\n",
|
165 |
+
" <td>7657263</td>\n",
|
166 |
+
" <td>Can people with mental illness recover?</td>\n",
|
167 |
+
" <td>When healing from mental illness, early identi...</td>\n",
|
168 |
+
" </tr>\n",
|
169 |
+
" </tbody>\n",
|
170 |
+
"</table>\n",
|
171 |
+
"</div>"
|
172 |
+
],
|
173 |
+
"text/plain": [
|
174 |
+
" Question_ID Questions \\\n",
|
175 |
+
"0 1590140 What does it mean to have a mental illness? \n",
|
176 |
+
"1 2110618 Who does mental illness affect? \n",
|
177 |
+
"2 6361820 What causes mental illness? \n",
|
178 |
+
"3 9434130 What are some of the warning signs of mental i... \n",
|
179 |
+
"4 7657263 Can people with mental illness recover? \n",
|
180 |
+
"\n",
|
181 |
+
" Answers \n",
|
182 |
+
"0 Mental illnesses are health conditions that di... \n",
|
183 |
+
"1 It is estimated that mental illness affects 1 ... \n",
|
184 |
+
"2 It is estimated that mental illness affects 1 ... \n",
|
185 |
+
"3 Symptoms of mental health disorders vary depen... \n",
|
186 |
+
"4 When healing from mental illness, early identi... "
|
187 |
+
]
|
188 |
+
},
|
189 |
+
"execution_count": 5,
|
190 |
+
"metadata": {},
|
191 |
+
"output_type": "execute_result"
|
192 |
+
}
|
193 |
+
],
|
194 |
+
"source": [
|
195 |
+
"df.head()"
|
196 |
+
]
|
197 |
+
},
|
198 |
+
{
|
199 |
+
"cell_type": "code",
|
200 |
+
"execution_count": 6,
|
201 |
+
"id": "5c69465d-0018-432f-b134-2fa929045e83",
|
202 |
+
"metadata": {},
|
203 |
+
"outputs": [],
|
204 |
+
"source": [
|
205 |
+
"documents=df.to_dict(orient='records')"
|
206 |
+
]
|
207 |
+
},
|
208 |
+
{
|
209 |
+
"cell_type": "code",
|
210 |
+
"execution_count": 7,
|
211 |
+
"id": "5297116d-cf4b-44ae-aaad-72079a906855",
|
212 |
+
"metadata": {},
|
213 |
+
"outputs": [
|
214 |
+
{
|
215 |
+
"data": {
|
216 |
+
"text/plain": [
|
217 |
+
"{'Question_ID': 1590140,\n",
|
218 |
+
" 'Questions': 'What does it mean to have a mental illness?',\n",
|
219 |
+
" 'Answers': 'Mental illnesses are health conditions that disrupt a person’s thoughts, emotions, relationships, and daily functioning. They are associated with distress and diminished capacity to engage in the ordinary activities of daily life.\\nMental illnesses fall along a continuum of severity: some are fairly mild and only interfere with some aspects of life, such as certain phobias. On the other end of the spectrum lie serious mental illnesses, which result in major functional impairment and interference with daily life. These include such disorders as major depression, schizophrenia, and bipolar disorder, and may require that the person receives care in a hospital.\\nIt is important to know that mental illnesses are medical conditions that have nothing to do with a person’s character, intelligence, or willpower. Just as diabetes is a disorder of the pancreas, mental illness is a medical condition due to the brain’s biology.\\nSimilarly to how one would treat diabetes with medication and insulin, mental illness is treatable with a combination of medication and social support. These treatments are highly effective, with 70-90 percent of individuals receiving treatment experiencing a reduction in symptoms and an improved quality of life. With the proper treatment, it is very possible for a person with mental illness to be independent and successful.'}"
|
220 |
+
]
|
221 |
+
},
|
222 |
+
"execution_count": 7,
|
223 |
+
"metadata": {},
|
224 |
+
"output_type": "execute_result"
|
225 |
+
}
|
226 |
+
],
|
227 |
+
"source": [
|
228 |
+
"documents[0]"
|
229 |
+
]
|
230 |
+
},
|
231 |
+
{
|
232 |
+
"cell_type": "code",
|
233 |
+
"execution_count": null,
|
234 |
+
"id": "604c32fc-bf9b-465d-b2d6-e55e8947ef4d",
|
235 |
+
"metadata": {},
|
236 |
+
"outputs": [],
|
237 |
+
"source": [
|
238 |
+
"prompt_template=\"\"\"You are emulating a patient who is concerned about mental health.\n",
|
239 |
+
"Based on the answer provided, formulate 3 questions that this patient might ask. \n",
|
240 |
+
"The questions should be complete, not too short, and use as few words as possible from the original answer.\n",
|
241 |
+
"\n",
|
242 |
+
"The record:\n",
|
243 |
+
"Question_ID:{Question_ID}\n",
|
244 |
+
"Questions: {Questions}\n",
|
245 |
+
"Answer: {Answers}\n",
|
246 |
+
"\n",
|
247 |
+
"Provide the output in parsable JSON format without using code blocks:\n",
|
248 |
+
"\n",
|
249 |
+
"{{[\"question1\", \"question2\",..., \"question5\"]}}\n",
|
250 |
+
"\n",
|
251 |
+
"\"\"\".strip()"
|
252 |
+
]
|
253 |
+
},
|
254 |
+
{
|
255 |
+
"cell_type": "code",
|
256 |
+
"execution_count": 80,
|
257 |
+
"id": "dacc3ea2-df3b-4fad-b9cd-1cc3a88a6e1c",
|
258 |
+
"metadata": {},
|
259 |
+
"outputs": [],
|
260 |
+
"source": [
|
261 |
+
"prompt=prompt_template.format(**documents[0])"
|
262 |
+
]
|
263 |
+
},
|
264 |
+
{
|
265 |
+
"cell_type": "code",
|
266 |
+
"execution_count": 120,
|
267 |
+
"id": "53b634ad-dc6b-4848-b6b4-b882e90076cb",
|
268 |
+
"metadata": {},
|
269 |
+
"outputs": [],
|
270 |
+
"source": [
|
271 |
+
"client = Groq(api_key=groq_api_key)"
|
272 |
+
]
|
273 |
+
},
|
274 |
+
{
|
275 |
+
"cell_type": "code",
|
276 |
+
"execution_count": 81,
|
277 |
+
"id": "079bc5f5-2977-43da-8eca-c340dcb884d4",
|
278 |
+
"metadata": {},
|
279 |
+
"outputs": [],
|
280 |
+
"source": [
|
281 |
+
"def llm(prompt,model=\"mixtral-8x7b-32768\"):\n",
|
282 |
+
" response = client.chat.completions.create(\n",
|
283 |
+
" model=model,\n",
|
284 |
+
" messages=[{\"role\": \"user\", \"content\": prompt}])\n",
|
285 |
+
" return response.choices[0].message.content\n",
|
286 |
+
" "
|
287 |
+
]
|
288 |
+
},
|
289 |
+
{
|
290 |
+
"cell_type": "code",
|
291 |
+
"execution_count": 61,
|
292 |
+
"id": "d227d497-bc50-49d8-a141-8e8a182aecf4",
|
293 |
+
"metadata": {},
|
294 |
+
"outputs": [],
|
295 |
+
"source": [
|
296 |
+
"quiz=llm(prompt)"
|
297 |
+
]
|
298 |
+
},
|
299 |
+
{
|
300 |
+
"cell_type": "code",
|
301 |
+
"execution_count": 62,
|
302 |
+
"id": "e7a63537-5edd-475b-a032-e5bb7380e160",
|
303 |
+
"metadata": {},
|
304 |
+
"outputs": [
|
305 |
+
{
|
306 |
+
"name": "stdout",
|
307 |
+
"output_type": "stream",
|
308 |
+
"text": [
|
309 |
+
"[\n",
|
310 |
+
"\"How do mental illnesses affect a person's daily life?\",\n",
|
311 |
+
"\"What are some examples of serious mental illnesses?\",\n",
|
312 |
+
"\"What should I understand about the cause of mental illness?\",\n",
|
313 |
+
"\"What are the common treatments for mental illness?\",\n",
|
314 |
+
"\"How effective are the treatments for mental illness and what is the quality of life people can expect after receiving treatment?\"\n",
|
315 |
+
"]\n"
|
316 |
+
]
|
317 |
+
}
|
318 |
+
],
|
319 |
+
"source": [
|
320 |
+
"print(quiz)"
|
321 |
+
]
|
322 |
+
},
|
323 |
+
{
|
324 |
+
"cell_type": "code",
|
325 |
+
"execution_count": 16,
|
326 |
+
"id": "71dedb46-3b27-4aa0-a972-0907fae7a5b1",
|
327 |
+
"metadata": {},
|
328 |
+
"outputs": [
|
329 |
+
{
|
330 |
+
"data": {
|
331 |
+
"text/plain": [
|
332 |
+
"666"
|
333 |
+
]
|
334 |
+
},
|
335 |
+
"execution_count": 16,
|
336 |
+
"metadata": {},
|
337 |
+
"output_type": "execute_result"
|
338 |
+
}
|
339 |
+
],
|
340 |
+
"source": [
|
341 |
+
"len(quiz)"
|
342 |
+
]
|
343 |
+
},
|
344 |
+
{
|
345 |
+
"cell_type": "code",
|
346 |
+
"execution_count": 121,
|
347 |
+
"id": "70bb6f1d-1bb8-49e8-8281-8476dc5d94f1",
|
348 |
+
"metadata": {},
|
349 |
+
"outputs": [],
|
350 |
+
"source": [
|
351 |
+
"import json\n",
|
352 |
+
"\n",
|
353 |
+
"prompt_template=\"\"\"You are emulating a patient who is concerned about mental health.\n",
|
354 |
+
"Based on the answer provided, formulate 3 questions that this patient might ask. \n",
|
355 |
+
"The questions should be complete, not too short, and use as few words as possible from the original answer.\n",
|
356 |
+
"\n",
|
357 |
+
"The record:\n",
|
358 |
+
"Question_ID:{Question_ID}\n",
|
359 |
+
"Questions: {Questions}\n",
|
360 |
+
"Answer: {Answers}\n",
|
361 |
+
"\n",
|
362 |
+
"Provide the output in parsable JSON without using code blocks:\n",
|
363 |
+
"\n",
|
364 |
+
"{{\"questions\": [\"question1\", \"question2\", ..., \"question5\"]}}\n",
|
365 |
+
"\n",
|
366 |
+
"\"\"\".strip()\n",
|
367 |
+
"def generate_data(doc):\n",
|
368 |
+
" prompt=prompt_template.format(**doc)\n",
|
369 |
+
" response = client.chat.completions.create(\n",
|
370 |
+
" model='mixtral-8x7b-32768',\n",
|
371 |
+
" messages=[{\"role\": \"user\", \"content\": prompt}])\n",
|
372 |
+
" return response.choices[0].message.content\n",
|
373 |
+
" "
|
374 |
+
]
|
375 |
+
},
|
376 |
+
{
|
377 |
+
"cell_type": "code",
|
378 |
+
"execution_count": 122,
|
379 |
+
"id": "338aa361-0f1d-4529-8598-10e5bab0f8b7",
|
380 |
+
"metadata": {},
|
381 |
+
"outputs": [
|
382 |
+
{
|
383 |
+
"data": {
|
384 |
+
"application/vnd.jupyter.widget-view+json": {
|
385 |
+
"model_id": "5e864b5bc273436caba87010785a2998",
|
386 |
+
"version_major": 2,
|
387 |
+
"version_minor": 0
|
388 |
+
},
|
389 |
+
"text/plain": [
|
390 |
+
" 0%| | 0/98 [00:00<?, ?it/s]"
|
391 |
+
]
|
392 |
+
},
|
393 |
+
"metadata": {},
|
394 |
+
"output_type": "display_data"
|
395 |
+
},
|
396 |
+
{
|
397 |
+
"name": "stdout",
|
398 |
+
"output_type": "stream",
|
399 |
+
"text": [
|
400 |
+
"Raw JSON data for doc_id 1590140: {\n",
|
401 |
+
"\"questions\": [\n",
|
402 |
+
"\"How do mental illnesses affect a person's daily functioning and relationships?\",\n",
|
403 |
+
"\"What are some examples of serious mental illnesses that can result in major functional impairment?\",\n",
|
404 |
+
"\"Why is it a misconception to associate mental illness with a person's character, intelligence, or willpower?\",\n",
|
405 |
+
"\"How are mental illnesses treated, and what is the success rate of these treatments?\",\n",
|
406 |
+
"\"Can a person with mental illness become independent and successful with proper treatment?\"\n",
|
407 |
+
"]\n",
|
408 |
+
"}\n",
|
409 |
+
"Raw JSON data for doc_id 2110618: {\n",
|
410 |
+
"\"questions\": [\n",
|
411 |
+
"\"Who are the groups most commonly affected by different mental illnesses?\",\n",
|
412 |
+
"\"How do mental illnesses affect children and the elderly?\",\n",
|
413 |
+
"\"What behaviors should parents and caretakers watch out for in children that may indicate a serious emotional disturbance?\"\n",
|
414 |
+
"]\n",
|
415 |
+
"}\n",
|
416 |
+
"Raw JSON data for doc_id 6361820: {\n",
|
417 |
+
"\"questions\": [\n",
|
418 |
+
"\"How does mental illness affect different populations?\",\n",
|
419 |
+
"\"At what age are individuals most susceptible to mental illness?\",\n",
|
420 |
+
"\"What signs should parents and caretakers look out for in children under 18 that may indicate a mental health condition?\"\n",
|
421 |
+
"]\n",
|
422 |
+
"}\n",
|
423 |
+
"Raw JSON data for doc_id 9434130: {\n",
|
424 |
+
"\"questions\": [\n",
|
425 |
+
"\"What are some general symptoms that may indicate a mental health disorder in adults?\",\n",
|
426 |
+
"\"Can you name some symptoms that could suggest a mental health issue in older children and pre-teens?\",\n",
|
427 |
+
"\"Are there any signs that might point to mental health problems in younger children?\",\n",
|
428 |
+
"\"What kind of behavior in children might suggest they are struggling with mental health?\",\n",
|
429 |
+
"\"What are some potential indicators of mental health issues related to mood or eating habits?\"\n",
|
430 |
+
"]\n",
|
431 |
+
"}\n",
|
432 |
+
"Raw JSON data for doc_id 7657263: {\n",
|
433 |
+
"\"questions\": [\n",
|
434 |
+
"\"Can early identification and treatment improve recovery from mental illness?\",\n",
|
435 |
+
"\"Are there effective treatments available for different types of mental illnesses?\",\n",
|
436 |
+
"\"What is the importance of a person's active engagement in their own recovery process from mental illness?\",\n",
|
437 |
+
"\"Is it common for some people with mental illness to experience a return of symptoms after treatment?\",\n",
|
438 |
+
"\"How can one live a fulfilled and productive life despite careful monitoring and management of mental illness?\"\n",
|
439 |
+
"]\n",
|
440 |
+
"}\n",
|
441 |
+
"Raw JSON data for doc_id 1619387: {\n",
|
442 |
+
"\"questions\": [\n",
|
443 |
+
"\"What should I do if I suspect someone I know has a mental disorder?\",\n",
|
444 |
+
"\"How can I help a friend or family member who might be experiencing symptoms of a mental health condition?\",\n",
|
445 |
+
"\"What are the benefits of speaking with a mental health professional if I think a loved one has symptoms of a mental disorder?\"\n",
|
446 |
+
"]\n",
|
447 |
+
"}\n",
|
448 |
+
"Raw JSON data for doc_id 1030153: {\n",
|
449 |
+
"\"questions\": [\n",
|
450 |
+
"\"How can I search for mental health providers in my area?\",\n",
|
451 |
+
"\"What should I consider when researching mental health professionals for myself or my child?\",\n",
|
452 |
+
"\"How can I ensure that I will feel comfortable with the mental health professional I choose?\"]\n",
|
453 |
+
"}\n",
|
454 |
+
"Raw JSON data for doc_id 8022026: {\n",
|
455 |
+
"\"questions\": [\n",
|
456 |
+
"\"What types of treatments are available for mental illness?\",\n",
|
457 |
+
"\"How do different treatment options work for different people?\",\n",
|
458 |
+
"\"How can I find the most effective treatment for myself or my child?\"]\n",
|
459 |
+
"}\n",
|
460 |
+
"Raw JSON data for doc_id 1155199: {\n",
|
461 |
+
"\"questions\": [\n",
|
462 |
+
"\"What can I expect in terms of the cause of my illness?\",\n",
|
463 |
+
"\"Are there other conditions that share my symptoms?\",\n",
|
464 |
+
"\"What kind of physical or neurological tests are usually involved?\",\n",
|
465 |
+
"\"What other specialists might be involved in my treatment and who will coordinate?\",\n",
|
466 |
+
"\"What is the typical role of the family in the treatment process?\"\n",
|
467 |
+
"]\n",
|
468 |
+
"}\n",
|
469 |
+
"Raw JSON data for doc_id 7760466: {\n",
|
470 |
+
"\"questions\": [\n",
|
471 |
+
"\"What are the differences in education and training among mental health professionals?\",\n",
|
472 |
+
"\"How do mental health professionals specialize in different areas?\",\n",
|
473 |
+
"\"How can I find a mental health professional that fits my specific needs?\"]\n",
|
474 |
+
"}\n",
|
475 |
+
"Raw JSON data for doc_id 2553795: {\n",
|
476 |
+
"\"questions\": [\n",
|
477 |
+
"\"What steps can I take to find a mental health professional who is a good fit for me or my child?\",\n",
|
478 |
+
"\"How can I ensure that my child or I will feel comfortable working with a mental health professional?\",\n",
|
479 |
+
"\"What resources are available to help me research and find the right mental health professional for my needs or my child's needs?\"\n",
|
480 |
+
"]\n",
|
481 |
+
"}\n",
|
482 |
+
"Raw JSON data for doc_id 1259439: {\n",
|
483 |
+
"\"questions\": [\n",
|
484 |
+
"\"What can you tell me about the cause of my illness?\",\n",
|
485 |
+
"\"Are there other conditions that share my symptoms?\",\n",
|
486 |
+
"\"What kinds of examinations do you usually conduct?\",\n",
|
487 |
+
"\"What is your recommended treatment program for my diagnosis?\",\n",
|
488 |
+
"\"What can I expect from the medications prescribed for my condition?\"\n",
|
489 |
+
"]\n",
|
490 |
+
"}\n",
|
491 |
+
"Raw JSON data for doc_id 4197817: {\n",
|
492 |
+
"\"questions\": [\n",
|
493 |
+
"\"Where can I find mental health resources in my area?\",\n",
|
494 |
+
"\"What kind of organizations offer support groups for consumers and their families?\",\n",
|
495 |
+
"\"Are support groups always led by mental health professionals or can they be peer led?\"]\n",
|
496 |
+
"}\n",
|
497 |
+
"Raw JSON data for doc_id 3388962: {\n",
|
498 |
+
"\"questions\": [\n",
|
499 |
+
"\"What is the primary purpose of the new medication?\",\n",
|
500 |
+
"\"How long does it typically take for the medication to take effect and how will I know when it is effective?\",\n",
|
501 |
+
"\"What are the proper directions for taking this medication, including any food, drinks, or activities to avoid?\",\n",
|
502 |
+
"\"What side effects should I be aware of and what should I do if they occur?\",\n",
|
503 |
+
"\"What is the procedure if I accidentally miss a dose of the medication?\"]\n",
|
504 |
+
"}\n",
|
505 |
+
"Raw JSON data for doc_id 5343181: {\n",
|
506 |
+
"\"questions\": [\n",
|
507 |
+
"\"If I feel better after taking medication, does that mean I can stop taking it without consulting my doctor?\",\n",
|
508 |
+
"\"What might happen if I stop taking my medication abruptly?\",\n",
|
509 |
+
"\"How can I address side effects that make me unwilling to continue treatment?\"]\n",
|
510 |
+
"}\n",
|
511 |
+
"Raw JSON data for doc_id 5778437: {\n",
|
512 |
+
"\"questions\": [\n",
|
513 |
+
"\"What organizations provide prescription assistance programs for individuals with financial needs?\",\n",
|
514 |
+
"\"Do I need a doctor's consent to apply for prescription assistance programs?\",\n",
|
515 |
+
"\"What kind of proof do I need to provide for these prescription assistance programs?\"\n",
|
516 |
+
"]\n",
|
517 |
+
"}\n",
|
518 |
+
"Raw JSON data for doc_id 9541219: {\n",
|
519 |
+
"\"questions\": [\n",
|
520 |
+
"\"Where can I find a therapist who specializes in my specific mental health condition?\",\n",
|
521 |
+
"\"Are there different types of therapy for children and adults?\",\n",
|
522 |
+
"\"What kind of therapy would be most effective for my symptoms?\"]\n",
|
523 |
+
"}\n",
|
524 |
+
"Raw JSON data for doc_id 3268009: {\n",
|
525 |
+
"\"questions\": [\n",
|
526 |
+
"\"What are some alternative types of mental health treatment?\",\n",
|
527 |
+
"\"Are there any self-help plans for mental health conditions?\",\n",
|
528 |
+
"\"What is the role of peer support in mental health treatment?\"\n",
|
529 |
+
"]\n",
|
530 |
+
"}\n",
|
531 |
+
"Raw JSON data for doc_id 3340726: {\n",
|
532 |
+
"\"questions\": [\n",
|
533 |
+
"\"What are the different kinds of mental health professionals that I can choose from?\",\n",
|
534 |
+
"\"How can I find the right mental health professional for my needs?\",\n",
|
535 |
+
"\"Can you give me more information about the various types of mental health professionals?\"]\n",
|
536 |
+
"}\n",
|
537 |
+
"Raw JSON data for doc_id 9539480: {\n",
|
538 |
+
"\"questions\": [\n",
|
539 |
+
"\"Where can I find peer support organizations?\",\n",
|
540 |
+
"\"Are there support groups led by mental health professionals?\",\n",
|
541 |
+
"\"How can I find support groups for my family and friends?\"]\n",
|
542 |
+
"}\n",
|
543 |
+
"Raw JSON data for doc_id 4211025: {\n",
|
544 |
+
"\"questions\": [\n",
|
545 |
+
"\"Where can I find help for a mental health crisis?\",\n",
|
546 |
+
"\"What kinds of services does inpatient care provide for people in crisis?\",\n",
|
547 |
+
"\"How can inpatient care assist with adjusting to new medications or symptoms?\"]\n",
|
548 |
+
"}\n",
|
549 |
+
"Raw JSON data for doc_id 4031860: {\n",
|
550 |
+
"\"questions\": [\n",
|
551 |
+
"\"Where can I find resources to help me locate mental health therapists in my area?\",\n",
|
552 |
+
"\"How can I learn about different mental health treatment options in my community?\",\n",
|
553 |
+
"\"Can you suggest any ways I can better understand the treatment process for mental health services?\"]\n",
|
554 |
+
"}\n",
|
555 |
+
"Raw JSON data for doc_id 5215843: {\n",
|
556 |
+
"\"questions\": [\n",
|
557 |
+
"\"What are the risks associated with clinical trials?\",\n",
|
558 |
+
"\"How can I find out about new treatment approaches being tested?\",\n",
|
559 |
+
"\"Where can I get more information about participating in research studies?\"]\n",
|
560 |
+
"}\n",
|
561 |
+
"Raw JSON data for doc_id 8927672: {\n",
|
562 |
+
"\"questions\": [\n",
|
563 |
+
"\"What is a psychiatric advance directive and how does it differ from a medical advance directive?\",\n",
|
564 |
+
"\"How can I create a psychiatric advance directive and who will it impact during a mental health crisis?\",\n",
|
565 |
+
"\"What kind of treatment instructions can I include in a psychiatric advance directive?\"\n",
|
566 |
+
"]\n",
|
567 |
+
"}\n",
|
568 |
+
"Raw JSON data for doc_id 7728364: {\n",
|
569 |
+
"\"questions\": [\n",
|
570 |
+
"\"What exactly makes up mental health?\",\n",
|
571 |
+
"\"Can you explain the components of mental health?\",\n",
|
572 |
+
"\"How are beliefs, thoughts, feelings, and behaviors related to mental health?\"]\n",
|
573 |
+
"}\n",
|
574 |
+
"Raw JSON data for doc_id 4194958: {\n",
|
575 |
+
"\"questions\": [\n",
|
576 |
+
"\"What can I do if the usual support methods don't work for me?\",\n",
|
577 |
+
"\"How can I stay hopeful while searching for the right help?\",\n",
|
578 |
+
"\"What are some other approaches I can try if the current ones don't help?\"]\n",
|
579 |
+
"}\n",
|
580 |
+
"Raw JSON data for doc_id 1667863: {\n",
|
581 |
+
"\"questions\": [\n",
|
582 |
+
"\"Is it possible to take steps to avoid mental health issues?\",\n",
|
583 |
+
"\"How does working on our wellbeing and resilience contribute to preventing mental health problems?\",\n",
|
584 |
+
"\"What role does seeking help early play in preventing mental health issues from becoming severe?\"]\n",
|
585 |
+
"}\n",
|
586 |
+
"Raw JSON data for doc_id 8904276: {\n",
|
587 |
+
"\"questions\": [\n",
|
588 |
+
"\"Are there any treatments that can help with mental health issues?\",\n",
|
589 |
+
"\"Is it possible to find relief from mental health problems through talking and counselling?\",\n",
|
590 |
+
"\"Can medication, friendships, exercise, sleep, and nutrition play a role in addressing mental health concerns?\"]\n",
|
591 |
+
"}\n",
|
592 |
+
"Raw JSON data for doc_id 4283807: {\n",
|
593 |
+
"\"questions\": [\"What are some psychological causes of mental health problems?\", \"What role does biology play in mental health issues?\", \"How can social factors contribute to mental health problems?\"]\n",
|
594 |
+
"}\n",
|
595 |
+
"Raw JSON data for doc_id 8690253: {\n",
|
596 |
+
"\"questions\": [\n",
|
597 |
+
"\"Who are some people I can talk to if I'm worried about my mental health?\",\n",
|
598 |
+
"\"What steps can I take to find out more information about what I'm experiencing with my mental health?\",\n",
|
599 |
+
"\"How can talking to someone about my mental health help me get perspective and start getting help?\",\n",
|
600 |
+
"\"What kind of help can I expect to receive after I talk to someone about my mental health?\",\n",
|
601 |
+
"\"What can I do to get started on the path of improving my mental health?\"]\n",
|
602 |
+
"}\n",
|
603 |
+
"Raw JSON data for doc_id 2973656: {\n",
|
604 |
+
"\"questions\": [\n",
|
605 |
+
"\"How can I tell if my beliefs and thoughts are affecting my daily functioning?\",\n",
|
606 |
+
"\"What are the signs that my feelings and behaviors are having a significant impact on my ability to function normally?\",\n",
|
607 |
+
"\"When is it important to seek help if my mental health is affecting my daily life?\"\n",
|
608 |
+
"]\n",
|
609 |
+
"}\n",
|
610 |
+
"Raw JSON data for doc_id 4759773: {\n",
|
611 |
+
"\"questions\": [\n",
|
612 |
+
"\"What actions can I take if I'm concerned about a loved one's mental health?\",\n",
|
613 |
+
"\"How can I approach a friend or relative about seeking mental health support?\",\n",
|
614 |
+
"\"What is the first step I should take when I notice a concern for someone's mental well-being?\"\n",
|
615 |
+
"]\n",
|
616 |
+
"}\n",
|
617 |
+
"Raw JSON data for doc_id 1511075: {\n",
|
618 |
+
"\"questions\": [\n",
|
619 |
+
"\"How should I handle people giving me advice based on evidence?\",\n",
|
620 |
+
"\"What is the best way to find out what works for me when people tell me what to do?\",\n",
|
621 |
+
"\"How can I balance following others' advice and doing what is best for my mental health?\"]\n",
|
622 |
+
"}\n",
|
623 |
+
"Raw JSON data for doc_id 7069853: {\n",
|
624 |
+
"\"questions\": [\n",
|
625 |
+
"\"Why is it important for my mental health to stay informed about the pandemic?\",\n",
|
626 |
+
"\"How can reliable and up-to-date information about the coronavirus help me feel more resilient?\",\n",
|
627 |
+
"\"What are the negative effects of following the news all day and how can I avoid them?\"]\n",
|
628 |
+
"}\n",
|
629 |
+
"Raw JSON data for doc_id 4181750: {\n",
|
630 |
+
"\"questions\": [\n",
|
631 |
+
"\"How can I determine if a source is reliable for information about the coronavirus and COVID-19?\",\n",
|
632 |
+
"\"What should I consider when evaluating the credibility of experts quoted or cited in health articles?\",\n",
|
633 |
+
"\"How can I identify if a source is trying to make me feel a certain way rather than providing factual information?\",\n",
|
634 |
+
"\"What is the role of social media in obtaining reliable health information and what cautions should I take?\",\n",
|
635 |
+
"\"Where can I learn more about digital and media literacy and thinking critically around health claims?\"\n",
|
636 |
+
"]\n",
|
637 |
+
"}\n",
|
638 |
+
"Raw JSON data for doc_id 2554141: {\n",
|
639 |
+
"\"questions\": [\n",
|
640 |
+
"\"Why does having a plan help manage fear and stress during a pandemic?\",\n",
|
641 |
+
"\"What are some tasks I can include in my daily schedule for managing during a pandemic?\",\n",
|
642 |
+
"\"Where can I find resources on problem-solving to help me manage during a pandemic?\",\n",
|
643 |
+
"\"How can I practice problem-solving to manage uncertain situations during a pandemic?\",\n",
|
644 |
+
"\"What are some ways I can manage feelings of being overwhelmed or hopeless during a pandemic?\"\n",
|
645 |
+
"]\n",
|
646 |
+
"}\n",
|
647 |
+
"Raw JSON data for doc_id 9100298: {\n",
|
648 |
+
"\"questions\": [\n",
|
649 |
+
"\"What are some ways I can maintain social connections while physically separated from loved ones?\",\n",
|
650 |
+
"\"What should I do if I'm feeling lonely during this time?\",\n",
|
651 |
+
"\"Where can I find local community support groups and mutual aid groups online?\"\n",
|
652 |
+
"]\n",
|
653 |
+
"}\n",
|
654 |
+
"Raw JSON data for doc_id 2884887: {\n",
|
655 |
+
"\"questions\": [\n",
|
656 |
+
"\"How does taking care of my physical health impact my mental health?\",\n",
|
657 |
+
"\"What are some tips for maintaining a balanced diet while spending more time at home?\",\n",
|
658 |
+
"\"What are some ways to stay active and exercise while staying safe at home?\",\n",
|
659 |
+
"\"How can I practice healthy sleep habits if stress and anxiety are affecting my sleep?\",\n",
|
660 |
+
"\"What should I do if I have a chronic illness and need to take additional precautions during this time?\"\n",
|
661 |
+
"]\n",
|
662 |
+
"}\n",
|
663 |
+
"Raw JSON data for doc_id 9250044: {\n",
|
664 |
+
"\"questions\": [\n",
|
665 |
+
"\"What are some low-effort distractions I can try when I'm feeling overwhelmed or isolated?\",\n",
|
666 |
+
"\"What are some ways I can keep myself engaged and focused if I have more energy?\",\n",
|
667 |
+
"\"How can I use online resources to learn new things and stay entertained during social distancing?\",\n",
|
668 |
+
"\"What are some ways I can maintain healthier habits and avoid unhelpful ones when my schedule is disrupted?\",\n",
|
669 |
+
"\"How can I get involved in helping my community while practicing social distancing and good hygiene?\"\n",
|
670 |
+
"]\n",
|
671 |
+
"}\n",
|
672 |
+
"Raw JSON data for doc_id 3597720: {\n",
|
673 |
+
"\"questions\": [\n",
|
674 |
+
"\"How does the way I think about a situation impact my feelings and behaviors?\",\n",
|
675 |
+
"\"What can challenging negative thoughts do to improve my mood and help me see new options?\",\n",
|
676 |
+
"\"Can you give me an example of how to reframe a negative thought to a more positive or productive one?\",\n",
|
677 |
+
"\"How can I better understand the situation more realistically and see the parts that I can control right now?\",\n",
|
678 |
+
"\"What can I do to focus on the things I can do, and make everything feel more manageable?\"\n",
|
679 |
+
"]\n",
|
680 |
+
"}\n",
|
681 |
+
"Raw JSON data for doc_id 7535002: {\n",
|
682 |
+
"\"questions\": [\n",
|
683 |
+
"\"What strategies can I use to challenge common thinking traps?\",\n",
|
684 |
+
"\"How can I identify if I'm falling into distorted thinking patterns?\",\n",
|
685 |
+
"\"What is a helpful way to break a thinking trap by looking at the thoughts?\"\n",
|
686 |
+
"]\n",
|
687 |
+
"}\n",
|
688 |
+
"Raw JSON data for doc_id 4134858: {\n",
|
689 |
+
"\"questions\": [\n",
|
690 |
+
"\"What are some common causes of grief outside of losing a person or pet?\",\n",
|
691 |
+
"\"How can I healthily express my feelings of grief?\",\n",
|
692 |
+
"\"Where can I find help from a mental health professional if I'm struggling with grief?\"\n",
|
693 |
+
"]\n",
|
694 |
+
"}\n",
|
695 |
+
"Raw JSON data for doc_id 9676742: {\n",
|
696 |
+
"\"questions\": [\n",
|
697 |
+
"\"How can I find a family doctor using the College of Physicians and Surgeons of BC's Find a Physician tool?\",\n",
|
698 |
+
"\"Are walk-in clinics a good option for finding a regular doctor if I have ongoing care needs?\",\n",
|
699 |
+
"\"How can I obtain a referral to see a psychiatrist?\",\n",
|
700 |
+
"\"Where can I find a registered psychologist in BC?\",\n",
|
701 |
+
"\"How can I visit the BC Association of Clinical Counsellors to find a clinical counsellor?\"]\n",
|
702 |
+
"}\n",
|
703 |
+
"Raw JSON data for doc_id 2612846: {\n",
|
704 |
+
"\"questions\": [\n",
|
705 |
+
"\"Can I make an appointment with a psychiatrist directly or do I need a referral from a doctor?\",\n",
|
706 |
+
"\"What is the process for self-referring to a mental health program in BC?\",\n",
|
707 |
+
"\"How can I find my local mental health center in BC?\",\n",
|
708 |
+
"\"What services are available at a mental health center besides access to a psychiatrist?\",\n",
|
709 |
+
"\"How can I get help from HealthlinkBC if I need assistance finding a mental health service?\"\n",
|
710 |
+
"]\n",
|
711 |
+
"}\n",
|
712 |
+
"Raw JSON data for doc_id 3166337: {\n",
|
713 |
+
"\"questions\": [\n",
|
714 |
+
"\"Where can I find a Registered Psychologist?\",\n",
|
715 |
+
"\"Do I need a doctor's referral to see a psychologist?\",\n",
|
716 |
+
"\"How can I find out about lower-cost options for counselling in my community?\",\n",
|
717 |
+
"\"Are the costs of seeing a Registered Psychologist covered by MSP?\",\n",
|
718 |
+
"\"Can I ask for a sliding scale based on my income when making an appointment with a psychologist?\"\n",
|
719 |
+
"]\n",
|
720 |
+
"}\n",
|
721 |
+
"Raw JSON data for doc_id 7009409: {\n",
|
722 |
+
"\"questions\": [\n",
|
723 |
+
"\"Where can I find directories of counsellors?\",\n",
|
724 |
+
"\"Do I need a doctor's referral to see a counsellor?\",\n",
|
725 |
+
"\"How can I find out about lower-cost options to access counselling in my community?\",\n",
|
726 |
+
"\"Are counselling services at public mental health centers covered by MSP?\",\n",
|
727 |
+
"\"How can Indigenous community members access counselling services locally or through the First Nations Health Authority?\"\n",
|
728 |
+
"]\n",
|
729 |
+
"}\n",
|
730 |
+
"Raw JSON data for doc_id 9630578: {\n",
|
731 |
+
"\"questions\": [\n",
|
732 |
+
"\"Where can I look for support groups specific to mental illnesses like mood disorders or post-traumatic stress disorder?\",\n",
|
733 |
+
"\"How can I find out about support groups offered by the Canadian Mental Health Association or the BC Schizophrenia Society?\",\n",
|
734 |
+
"\"Where can I find online support if I have trouble getting to an in-person support group?\"\n",
|
735 |
+
"]\n",
|
736 |
+
"}\n",
|
737 |
+
"Raw JSON data for doc_id 1585622: {\n",
|
738 |
+
"\"questions\": [\n",
|
739 |
+
"\"Where can I encourage my child to talk about their mental health concerns?\",\n",
|
740 |
+
"\"Who can I talk to if I'm concerned about my child's mental health?\",\n",
|
741 |
+
"\"Where can I find specific child and youth mental health services and providers?\",\n",
|
742 |
+
"\"Where can I get guidance, information, and support for youth and parent mental health?\",\n",
|
743 |
+
"\"Where can young people find easy-to-access mental health care and support?\"\n",
|
744 |
+
"]\n",
|
745 |
+
"}\n",
|
746 |
+
"Raw JSON data for doc_id 1833460: {\n",
|
747 |
+
"\"questions\": [\n",
|
748 |
+
"\"Where can I find information about local mental health services for older adults?\",\n",
|
749 |
+
"\"Can I get information about senior's mental health resources from the Canadian Coalition for Seniors' Mental Health?\",\n",
|
750 |
+
"\"Who can I contact if I'm concerned about a loved one's mental health?\"\n",
|
751 |
+
"]\n",
|
752 |
+
"}\n",
|
753 |
+
"Raw JSON data for doc_id 6981545: {\n",
|
754 |
+
"\"questions\": [\n",
|
755 |
+
"\"Where can I find self-help resources for depression that are appropriate for teens?\",\n",
|
756 |
+
"\"Can you recommend some self-help materials for managing depression while pregnant or after delivery?\",\n",
|
757 |
+
"\"Are there any online self-help programs for depression that are based outside of BC but offer good information?\"\n",
|
758 |
+
"]\n",
|
759 |
+
"}\n",
|
760 |
+
"Raw JSON data for doc_id 2115228: {\n",
|
761 |
+
"\"questions\": [\n",
|
762 |
+
"\"Where can I find self-help resources for anxiety if I'm not in British Columbia?\",\n",
|
763 |
+
"\"Can I use Anxiety Canada's resources if I'm an adult but not a teen or young adult?\",\n",
|
764 |
+
"\"What resources does the BC Reproductive Mental Health Program offer for anxiety during and after birth?\"\n",
|
765 |
+
"]\n",
|
766 |
+
"}\n",
|
767 |
+
"Raw JSON data for doc_id 2009922: {\n",
|
768 |
+
"\"questions\": [\n",
|
769 |
+
"\"Where can I find free programs to help manage ongoing physical or mental health issues?\",\n",
|
770 |
+
"\"Are there any self-guided workbooks that discuss the links between physical health and mental health?\",\n",
|
771 |
+
"\"What resources are available to help me cope with depression, low mood, or anxiety caused by a chronic health condition?\",\n",
|
772 |
+
"\"Can I purchase any booklets that offer practical tips to cope with a chronic health problem?\",\n",
|
773 |
+
"\"Where can I find one-on-one support from a therapist or counselor if I'm having a hard time coping?\"\n",
|
774 |
+
"]\n",
|
775 |
+
"}\n",
|
776 |
+
"Raw JSON data for doc_id 6167248: {\n",
|
777 |
+
"\"questions\": [\n",
|
778 |
+
"\"How can I determine if my substance use is causing problems?\",\n",
|
779 |
+
"\"Where can I find resources for helping someone else with their substance use?\",\n",
|
780 |
+
"\"What are some ways I can think about my relationship with substances?\",\n",
|
781 |
+
"\"What tips and resources are available for cutting back or quitting substance use?\",\n",
|
782 |
+
"\"How can I contact the Alcohol and Drug Information Referral Service for help in my area?\"\n",
|
783 |
+
"]\n",
|
784 |
+
"}\n",
|
785 |
+
"Raw JSON data for doc_id 6779222: {\n",
|
786 |
+
"\"questions\": [\n",
|
787 |
+
"\"How can I find out if my BC Medical Services Plan covers mental health services like counselling or therapy?\",\n",
|
788 |
+
"\"Where can I find mental health clinics or hospitals that offer free or low-cost counselling services?\",\n",
|
789 |
+
"\"How can I find mental health services in my area using HealthLink BC’s Find Services tool and Locator app?\",\n",
|
790 |
+
"\"Where can I look for private mental health services that offer a sliding scale based on income?\",\n",
|
791 |
+
"\"How can mental health organizations like Anxiety Canada or the Canadian Mental Health Association help me find local mental health services or connections?\"\n",
|
792 |
+
"]\n",
|
793 |
+
"}\n",
|
794 |
+
"Raw JSON data for doc_id 1546812: {\n",
|
795 |
+
"\"questions\": [\n",
|
796 |
+
"\"Is there a program to help me pay for my psychiatric medications?\",\n",
|
797 |
+
"\"How can I apply for the Psychiatric Medications Plan through BC PharmaCare?\",\n",
|
798 |
+
"\"How long does the coverage for Plan G typically last?\"\n",
|
799 |
+
"]\n",
|
800 |
+
"}\n",
|
801 |
+
"Raw JSON data for doc_id 2176317: {\n",
|
802 |
+
"\"questions\": [\n",
|
803 |
+
"\"Are there any mental health services covered by MSP that I could access for free?\",\n",
|
804 |
+
"\"What are some ways I can offset the costs of mental health services not covered by MSP?\",\n",
|
805 |
+
"\"How can I find mental health providers that offer lower-cost services or a sliding scale based on income?\"\n",
|
806 |
+
"]\n",
|
807 |
+
"}\n",
|
808 |
+
"Raw JSON data for doc_id 3284724: {\n",
|
809 |
+
"\"questions\": [\n",
|
810 |
+
"\"What are the different income levels for provincial income assistance?\",\n",
|
811 |
+
"\"How can mental illness be considered in PWD or PPMB income assistance applications?\",\n",
|
812 |
+
"\"Where can I find resources to help me navigate the application process for PWD and PPMB benefits?\"]\n",
|
813 |
+
"}\n",
|
814 |
+
"Raw JSON data for doc_id 5981663: {\n",
|
815 |
+
"\"questions\": [\n",
|
816 |
+
"\"What is the purpose of MSP in British Columbia?\",\n",
|
817 |
+
"\"How are MSP fees determined and paid?\",\n",
|
818 |
+
"\"Where can I get help with applying for or managing my MSP coverage?\"\n",
|
819 |
+
"]\n",
|
820 |
+
"}\n",
|
821 |
+
"Raw JSON data for doc_id 6623577: {\n",
|
822 |
+
"\"questions\": [\n",
|
823 |
+
"\"What does it mean when someone recommends me to another service in healthcare?\",\n",
|
824 |
+
"\"How do I access a specialist like a psychiatrist for mental health in BC?\",\n",
|
825 |
+
"\"What is the process for getting an appointment with a specialist after a referral from my doctor?\"]\n",
|
826 |
+
"}\n",
|
827 |
+
"Raw JSON data for doc_id 6851366: {\n",
|
828 |
+
"\"questions\": [\n",
|
829 |
+
"\"Are psychiatrists able to prescribe medications, while psychologists cannot?\",\n",
|
830 |
+
"\"How are the education and training different between psychiatrists and registered psychologists?\",\n",
|
831 |
+
"\"How does payment for services differ between accessing a psychologist in the public system versus the private system?\"\n",
|
832 |
+
"]\n",
|
833 |
+
"}\n",
|
834 |
+
"Raw JSON data for doc_id 1898078: {\n",
|
835 |
+
"\"questions\": [\n",
|
836 |
+
"\"What are the commonalities between psychotherapy and counseling?\",\n",
|
837 |
+
"\"Can you explain the role of a professional therapist or counselor in the healing process?\",\n",
|
838 |
+
"\"What are some examples of different psychotherapies that have been found effective for various problems or illnesses?\"]\n",
|
839 |
+
"}\n",
|
840 |
+
"Raw JSON data for doc_id 1706961: {\n",
|
841 |
+
"\"questions\": [\n",
|
842 |
+
"\"What is the main focus of CBT in contrast to DBT?\",\n",
|
843 |
+
"\"How does DBT deals with emotions and relationships differently than CBT?\",\n",
|
844 |
+
"\"In what kind of mental health issues have DBT been proven to be effective?\"\n",
|
845 |
+
"]\n",
|
846 |
+
"}\n",
|
847 |
+
"Raw JSON data for doc_id 4925221: {\n",
|
848 |
+
"\"questions\": [\n",
|
849 |
+
"\"What are the different classes of antidepressant medications and how do they work?\",\n",
|
850 |
+
"\"What are some common medications for each class of antidepressants?\",\n",
|
851 |
+
"\"What factors might affect how a medication works for different people?\"\n",
|
852 |
+
"]\n",
|
853 |
+
"}\n",
|
854 |
+
"Raw JSON data for doc_id 1043721: {\n",
|
855 |
+
"\"questions\": [\n",
|
856 |
+
"\"How can I bring up my concerns about my diagnosis with the professional who provided it?\",\n",
|
857 |
+
"\"What is the process for getting a second opinion from a different professional?\",\n",
|
858 |
+
"\"How can I discuss my options and get a referral to a different program or health professional for a second opinion?\"\n",
|
859 |
+
"]\n",
|
860 |
+
"}\n",
|
861 |
+
"Raw JSON data for doc_id 8471978: {\n",
|
862 |
+
"\"questions\": [\n",
|
863 |
+
"\"What should I do if I don't think my prescribed antidepressant is working?\",\n",
|
864 |
+
"\"Who can I contact if I want to discuss the common side effects of my medication?\",\n",
|
865 |
+
"\"Is it safe to stop taking my psychiatric medication or change the dose without consulting a health care provider?\",\n",
|
866 |
+
"\"What should I do if I experience a serious allergic reaction to my medication?\",\n",
|
867 |
+
"\"How can I effectively communicate with my doctor about symptoms or side effects that I find embarrassing?\"\n",
|
868 |
+
"]\n",
|
869 |
+
"}\n",
|
870 |
+
"Raw JSON data for doc_id 2746837: {\n",
|
871 |
+
"\"questions\": [\n",
|
872 |
+
"\"How can I help an adult in my life who is struggling with potential mental health issues?\",\n",
|
873 |
+
"\"What are the risks of diagnosing a health condition, especially online, without professional input?\",\n",
|
874 |
+
"\"What is the role of the person being treated in their own recovery and how can I support them in this process?\",\n",
|
875 |
+
"\"How can I effectively express my concerns and work together with the person to find a solution?\",\n",
|
876 |
+
"\"What should I know about the BC Mental Health Act in relation to getting help for someone who is at risk of harming themselves or others?\"\n",
|
877 |
+
"]\n",
|
878 |
+
"}\n",
|
879 |
+
"Raw JSON data for doc_id 5640861: {\n",
|
880 |
+
"\"questions\": [\n",
|
881 |
+
"\"Where can I find a family doctor to talk about my concerns for my child or teenager?\",\n",
|
882 |
+
"\"What kind of services and support can I expect from a school counselor regarding my child's mental health?\",\n",
|
883 |
+
"\"What is the role of Kelty Mental Health Resource Centre and how can their Help Finder tool assist me in navigating the mental health system for my child?\",\n",
|
884 |
+
"\"Does the Canadian Mental Health Association’s BC Division offer any resources or programs for managing behavior problems in children ages 3 to 12?\",\n",
|
885 |
+
"\"Where can I find HeretoHelp resources on child and youth mental health and substance use?\"\n",
|
886 |
+
"]\n",
|
887 |
+
"}\n",
|
888 |
+
"Raw JSON data for doc_id 3393534: {\n",
|
889 |
+
"\"questions\": [\n",
|
890 |
+
"\"Where can I find more information about mental health problems that may arise from a brain injury?\",\n",
|
891 |
+
"\"Are there service providers who are knowledgeable about both brain injuries and mental health?\",\n",
|
892 |
+
"\"How can I find local and regional groups in BC that support those with brain injuries?\",\n",
|
893 |
+
"\"What organizations provide information and support for those affected by brain injuries in BC?\",\n",
|
894 |
+
"\"Are mental health challenges related to brain injuries always treatable?\"]\n",
|
895 |
+
"}\n",
|
896 |
+
"Raw JSON data for doc_id 3839472: {\n",
|
897 |
+
"\"questions\": [\n",
|
898 |
+
"\"How can I recognize and empathize with my loved one's experience with depression?\",\n",
|
899 |
+
"\"Where can I learn more about depression to better understand it?\",\n",
|
900 |
+
"\"How can I create a safe space for my loved one to talk about their depression?\",\n",
|
901 |
+
"\"What are some things I should avoid, like giving unsolicited advice?\",\n",
|
902 |
+
"\"How can I support my loved one in their treatment and recovery?\"\n",
|
903 |
+
"]\n",
|
904 |
+
"}\n",
|
905 |
+
"Raw JSON data for doc_id 3055896: {\n",
|
906 |
+
"\"questions\": [\n",
|
907 |
+
"\"What are some trustworthy resources where I can learn more about schizophrenia?\",\n",
|
908 |
+
"\"How can I support my loved one during episodes of psychosis, especially when their hallucinations or delusions are distressing?\",\n",
|
909 |
+
"\"What is the role of a family member in helping a loved one manage their treatment for schizophrenia?\",\n",
|
910 |
+
"\"What can I do if my loved one refuses treatment for schizophrenia and I believe they are at risk of harming themselves or others?\",\n",
|
911 |
+
"\"What should I do if my loved one expresses thoughts of ending their life?\"\n",
|
912 |
+
"]\n",
|
913 |
+
"}\n",
|
914 |
+
"Raw JSON data for doc_id 4200873: {\n",
|
915 |
+
"\"questions\": [\n",
|
916 |
+
"\"How can learning about my parent's mental illness make it easier for me to understand their experiences?\",\n",
|
917 |
+
"\"What self-care activities can I do to take care of myself while my parent is unwell?\",\n",
|
918 |
+
"\"Where can I find programs specifically designed for young people in my situation?\"\n",
|
919 |
+
"]\n",
|
920 |
+
"}\n",
|
921 |
+
"Raw JSON data for doc_id 1337085: {\n",
|
922 |
+
"\"questions\": [\n",
|
923 |
+
"\"What resources are available for someone experiencing thoughts of suicide?\",\n",
|
924 |
+
"\"How can I help someone I care about who is talking about suicide?\",\n",
|
925 |
+
"\"What should I do in a situation where there is immediate danger or risk of harm due to suicide thoughts?\"\n",
|
926 |
+
"]\n",
|
927 |
+
"}\n",
|
928 |
+
"Raw JSON data for doc_id 2447683: {\n",
|
929 |
+
"\"questions\": [\n",
|
930 |
+
"\"What are the potential benefits and harms of using cannabis?\",\n",
|
931 |
+
"\"How can the timing of when a person starts using cannabis impact potential harms?\",\n",
|
932 |
+
"\"Are there certain groups of people who should avoid using cannabis due to increased risk of psychosis or schizophrenia?\",\n",
|
933 |
+
"\"How can mixing drugs like cannabis and alcohol increase the possibility of experiencing harms?\",\n",
|
934 |
+
"\"What is a simple way to gauge the use of psychoactive substances and prevent potential harms?\"\n",
|
935 |
+
"]\n",
|
936 |
+
"}\n",
|
937 |
+
"Raw JSON data for doc_id 7995219: {\n",
|
938 |
+
"\"questions\": [\n",
|
939 |
+
"\"Can you explain more about what mental well-being entails?\",\n",
|
940 |
+
"\"How would you define a mental illness and how does it affect a person's life?\",\n",
|
941 |
+
"\"Can a person have good mental health even if they have been diagnosed with a mental illness?\",\n",
|
942 |
+
"\"How does mental health exist on a continuum, similar to physical health?\",\n",
|
943 |
+
"\"What supports and tools can help someone live well and find meaning despite mental health challenges?\"\n",
|
944 |
+
"]\n",
|
945 |
+
"}\n",
|
946 |
+
"Raw JSON data for doc_id 2903196: {\n",
|
947 |
+
"\"questions\": [\n",
|
948 |
+
"\"Where can I find info sheets on mood disorders and bipolar disorder?\",\n",
|
949 |
+
"\"Do you have a self-test for depression that also screens for signs of bipolar disorder?\",\n",
|
950 |
+
"\"Can I find a series to help me deal with a diagnosis of depression and work with my doctor?\",\n",
|
951 |
+
"\"Are there any books or resources with personal stories about depression?\",\n",
|
952 |
+
"\"How can I access the What is Depression? booklet with audio in plain language for lower literacy readers?\"\n",
|
953 |
+
"]\n",
|
954 |
+
"}\n",
|
955 |
+
"Raw JSON data for doc_id 4893447: {\n",
|
956 |
+
"\"questions\": [\n",
|
957 |
+
"\"How can I distinguish between normal anxiety and an anxiety disorder?\",\n",
|
958 |
+
"\"What are some examples of how anxiety disorders can impact someone's daily life?\",\n",
|
959 |
+
"\"What are the differences between the former and current classifications of some anxiety disorders?\"\n",
|
960 |
+
"]\n",
|
961 |
+
"}\n",
|
962 |
+
"Raw JSON data for doc_id 8612349: {\n",
|
963 |
+
"\"questions\": [\n",
|
964 |
+
"\"What are the usual causes of stress?\",\n",
|
965 |
+
"\"How is anxiety different from stress in terms of what it focuses on?\",\n",
|
966 |
+
"\"Are the physical sensations of stress and anxiety always similar?\",\n",
|
967 |
+
"\"Can anxiety be triggered by a specific threat, or is it always about vague worries?\",\n",
|
968 |
+
"\"How can stress and anxiety impact well-being and daily life if they last for a long time?\"]\n",
|
969 |
+
"}\n",
|
970 |
+
"Raw JSON data for doc_id 6062232: {\n",
|
971 |
+
"\"questions\": [\n",
|
972 |
+
"\"How is sadness different from the illness of depression?\",\n",
|
973 |
+
"\"Can feelings of sadness impact daily life in a significant way like depression does?\",\n",
|
974 |
+
"\"Are there any physical symptoms associated with depression that don't occur with normal sadness?\"\n",
|
975 |
+
"]\n",
|
976 |
+
"}\n",
|
977 |
+
"Raw JSON data for doc_id 9045344: {\n",
|
978 |
+
"\"questions\": [\n",
|
979 |
+
"\"How does persistent depressive disorder (PDD) differ from major depressive disorder in terms of symptoms and duration?\",\n",
|
980 |
+
"\"What are the symptoms of PDD?\",\n",
|
981 |
+
"\"Why is it a misconception that PDD is less severe than major depressive disorder?\",\n",
|
982 |
+
"\"How can PDD affect a person's ability to work and enjoy hobbies?\",\n",
|
983 |
+
"\"Why might someone with PDD think it is just part of their personality?\"]\n",
|
984 |
+
"}\n",
|
985 |
+
"Raw JSON data for doc_id 9020440: {\n",
|
986 |
+
"\"questions\": [\n",
|
987 |
+
"\"What is the relationship between cyclothymic disorder and bipolar disorder?\",\n",
|
988 |
+
"\"What are the symptoms of hypomania and depression associated with cyclothymic disorder?\",\n",
|
989 |
+
"\"How does the frequency of symptoms in cyclothymic disorder compare to bipolar disorder?\",\n",
|
990 |
+
"\"What wellness period are people with cyclothymic disorder likely to experience?\",\n",
|
991 |
+
"\"Who should I consult if I suspect I have cyclothymic disorder?\"]\n",
|
992 |
+
"}\n",
|
993 |
+
"Raw JSON data for doc_id 5819325: {\n",
|
994 |
+
"\"questions\": [\n",
|
995 |
+
"\"What does it mean when someone experiences four or more episodes of depression and/or mania in one year?\",\n",
|
996 |
+
"\"Who can experience rapid cycling and when does it typically occur?\",\n",
|
997 |
+
"\"Is rapid cycling a permanent condition for those diagnosed with bipolar disorder?\"\n",
|
998 |
+
"]\n",
|
999 |
+
"}\n",
|
1000 |
+
"Raw JSON data for doc_id 4816493: {\n",
|
1001 |
+
"\"questions\": [\n",
|
1002 |
+
"\"Where can I find more information about the five groups of symptoms for borderline personality disorder?\",\n",
|
1003 |
+
"\"Do you know of any support groups or resources for borderline personality disorder in cities other than Vancouver and Victoria?\",\n",
|
1004 |
+
"\"Can you recommend any helpful books for managing borderline personality disorder?\"\n",
|
1005 |
+
"]\n",
|
1006 |
+
"}\n",
|
1007 |
+
"Raw JSON data for doc_id 9178453: {\n",
|
1008 |
+
"\"questions\": [\n",
|
1009 |
+
"\"How does schizoid personality disorder affect social interactions and relationships?\",\n",
|
1010 |
+
"\"What is the difference between schizoid personality disorder and schizophrenia?\",\n",
|
1011 |
+
"\"How is schizoid personality disorder typically treated and managed?\"\n",
|
1012 |
+
"]\n",
|
1013 |
+
"}\n",
|
1014 |
+
"Raw JSON data for doc_id 9679704: {\n",
|
1015 |
+
"\"questions\": [\n",
|
1016 |
+
"\"How does antisocial personality disorder affect a person's thoughts and behaviors?\",\n",
|
1017 |
+
"\"What is the relationship between conduct disorder and antisocial personality disorder?\",\n",
|
1018 |
+
"\"How can treatment help someone with antisocial personality disorder?\"]\n",
|
1019 |
+
"}\n",
|
1020 |
+
"Raw JSON data for doc_id 9167296: {\n",
|
1021 |
+
"\"questions\": [\n",
|
1022 |
+
"\"How does a personality disorder, such as obsessive-compulsive personality disorder, affect a person's daily life and thoughts?\",\n",
|
1023 |
+
"\"What are the key differences between obsessive-compulsive personality disorder and obsessive-compulsive disorder?\",\n",
|
1024 |
+
"\"How is treatment typically approached for individuals with obsessive-compulsive personality disorder?\",\n",
|
1025 |
+
"\"What kind of distress might a person with obsessive-compulsive personality disorder experience when they can't achieve control or perfectionism?\",\n",
|
1026 |
+
"\"Where can someone seek help for obsessive-compulsive personality disorder in British Columbia?\"\n",
|
1027 |
+
"]\n",
|
1028 |
+
"}\n",
|
1029 |
+
"Raw JSON data for doc_id 9049618: {\n",
|
1030 |
+
"\"questions\": [\n",
|
1031 |
+
"\"What are the main symptoms of binge-eating disorder?\",\n",
|
1032 |
+
"\"How can I recognize if someone has binge-eating disorder?\",\n",
|
1033 |
+
"\"What makes binge-eating disorder different from just overeating?\",\n",
|
1034 |
+
"\"How is binge-eating disorder treated?\",\n",
|
1035 |
+
"\"Who should I consult if I think I have binge-eating disorder?\"]\n",
|
1036 |
+
"}\n",
|
1037 |
+
"Raw JSON data for doc_id 7984793: {\n",
|
1038 |
+
"\"questions\": [\n",
|
1039 |
+
"\"How does the 'split mind' in schizophrenia differ from the fragmented identity in dissociative identity disorder?\",\n",
|
1040 |
+
"\"What is the significance of dissociation in dissociative identity disorder?\",\n",
|
1041 |
+
"\"How does schizophrenia affect a person's perception of reality differently than dissociative identity disorder?\",\n",
|
1042 |
+
"\"What are some common misconceptions about dissociative identity disorder, such as its portrayal in media, and how does it contrast with the actual experience of those diagnosed with it?\",\n",
|
1043 |
+
"\"How does schizophrenia impact an individual's thoughts, speech, and emotional expression as opposed to dissociative identity disorder?\"\n",
|
1044 |
+
"]\n",
|
1045 |
+
"}\n",
|
1046 |
+
"Raw JSON data for doc_id 6085633: {\n",
|
1047 |
+
"\"questions\": [\n",
|
1048 |
+
"\"What is the difference between psychosis and schizophrenia in terms of their definitions?\",\n",
|
1049 |
+
"\"What are some common symptoms of psychosis, such as hallucinations and delusions?\",\n",
|
1050 |
+
"\"What mental illnesses or factors, aside from schizophrenia, can cause psychosis?\"\n",
|
1051 |
+
"]\n",
|
1052 |
+
"}\n",
|
1053 |
+
"Raw JSON data for doc_id 1896541: {\n",
|
1054 |
+
"\"questions\": [\n",
|
1055 |
+
"\"What do positive symptoms of schizophrenia involve?\",\n",
|
1056 |
+
"\"Can you explain what negative symptoms of schizophrenia are?\",\n",
|
1057 |
+
"\"What are cognitive symptoms and how do they relate to schizophrenia?\"\n",
|
1058 |
+
"]\n",
|
1059 |
+
"}\n",
|
1060 |
+
"Raw JSON data for doc_id 4962901: {\n",
|
1061 |
+
"\"questions\": [\n",
|
1062 |
+
"\"Can you explain what a prodrome is in simpler terms?\",\n",
|
1063 |
+
"\"What are some early signs or symptoms of psychosis?\",\n",
|
1064 |
+
"\"Why is it important to seek help early if you or a loved one is experiencing symptoms of a mental health problem?\"\n",
|
1065 |
+
"]\n",
|
1066 |
+
"}\n",
|
1067 |
+
"Raw JSON data for doc_id 6869967: {\n",
|
1068 |
+
"\"questions\": [\n",
|
1069 |
+
"\"How can I find a healthcare professional who specializes in assessing and treating ADHD in adults?\",\n",
|
1070 |
+
"\"What resources and support are available for adults with ADHD in Canada?\",\n",
|
1071 |
+
"\"Is there a support group for adults with ADHD in the Vancouver area?\"\n",
|
1072 |
+
"]\n",
|
1073 |
+
"}\n",
|
1074 |
+
"Raw JSON data for doc_id 4824231: {\n",
|
1075 |
+
"\"questions\": [\n",
|
1076 |
+
"\"What does it mean when someone says they are addicted to something like shopping?\",\n",
|
1077 |
+
"\"How does the evidence suggest substance use and addiction differ?\",\n",
|
1078 |
+
"\"Can you explain how substance dependence develops and what it involves?\"\n",
|
1079 |
+
"]\n",
|
1080 |
+
"}\n",
|
1081 |
+
"Raw JSON data for doc_id 4294616: {\n",
|
1082 |
+
"\"questions\": [\n",
|
1083 |
+
"\"What are some ways I can get help for an alcohol or drug use problem?\",\n",
|
1084 |
+
"\"How does my health and social situation factor into finding the right help for me?\",\n",
|
1085 |
+
"\"Can I talk to a nurse or doctor confidentially about drug use and what resources are available in my area?\"\n",
|
1086 |
+
"]\n",
|
1087 |
+
"}\n",
|
1088 |
+
"Raw JSON data for doc_id 4373204: {\n",
|
1089 |
+
"\"questions\": [\n",
|
1090 |
+
"\"How can I determine if I'm drinking too much considering my unique relationship with alcohol?\",\n",
|
1091 |
+
"\"What are the signs of alcohol use becoming a problem in my life or in the lives of others?\",\n",
|
1092 |
+
"\"Where can I get personalized feedback about my drinking pattern as compared to Canada's Low-Risk Alcohol Drinking Guidelines?\"\n",
|
1093 |
+
"]\n",
|
1094 |
+
"}\n",
|
1095 |
+
"Raw JSON data for doc_id 7807643: {\n",
|
1096 |
+
"\"questions\": [\n",
|
1097 |
+
"\"If cannabis smoke contains harmful toxins, why is the risk of cancer less for cannabis smokers than tobacco smokers?\",\n",
|
1098 |
+
"\"How do the negative effects of cannabis on the brain compare to those of alcohol?\",\n",
|
1099 |
+
"\"What are the benefits of legalizing cannabis in terms of minimizing potential harms?\"\n",
|
1100 |
+
"]\n",
|
1101 |
+
"}\n",
|
1102 |
+
"Raw JSON data for doc_id 4352464: {\n",
|
1103 |
+
"\"questions\": [\n",
|
1104 |
+
"\"How can I help my child develop skills to make good choices regarding drugs?\",\n",
|
1105 |
+
"\"What are some ways to strengthen my relationship with my child through discussions about drugs?\",\n",
|
1106 |
+
"\"How can I support my child in developing critical thinking skills about drug use?\"\n",
|
1107 |
+
"]\n",
|
1108 |
+
"}\n",
|
1109 |
+
"Raw JSON data for doc_id 6521784: {\n",
|
1110 |
+
"\"questions\": [\n",
|
1111 |
+
"\"What are the medical conditions that CBD has been used in the treatment of?\",\n",
|
1112 |
+
"\"How does CBD produce therapeutic effects in the body?\",\n",
|
1113 |
+
"\"Are there any recorded negative drug interactions with CBD?\",\n",
|
1114 |
+
"\"What are some potential side effects of using CBD?\",\n",
|
1115 |
+
"\"Is there any research on the use of CBD for Alzheimer's disease?\"\n",
|
1116 |
+
"]\n",
|
1117 |
+
"}\n",
|
1118 |
+
"Raw JSON data for doc_id 3221856: {\n",
|
1119 |
+
"\"questions\": [\n",
|
1120 |
+
"\"What are the potential harms of vaping?\",\n",
|
1121 |
+
"\"How is nicotine delivered through vaping?\",\n",
|
1122 |
+
"\"What is the impact of vaping marketing strategies on young people?\"\n",
|
1123 |
+
"]\n",
|
1124 |
+
"}\n"
|
1125 |
+
]
|
1126 |
+
}
|
1127 |
+
],
|
1128 |
+
"source": [
|
1129 |
+
"results={}\n",
|
1130 |
+
"for doc in tqdm(documents):\n",
|
1131 |
+
" doc_id=doc['Question_ID']\n",
|
1132 |
+
" if doc_id in results:\n",
|
1133 |
+
" continue\n",
|
1134 |
+
" questions_raw = generate_data(doc)\n",
|
1135 |
+
" print(f\"Raw JSON data for doc_id {doc_id}: {questions_raw}\")\n",
|
1136 |
+
" \n",
|
1137 |
+
" # Check if it's empty\n",
|
1138 |
+
" if not questions_raw:\n",
|
1139 |
+
" print(f\"Error: Empty response for doc_id {doc_id}\")\n",
|
1140 |
+
" else:\n",
|
1141 |
+
" # Try parsing it\n",
|
1142 |
+
" try:\n",
|
1143 |
+
" questions = json.loads(questions_raw)\n",
|
1144 |
+
" results[doc_id] = questions['questions']\n",
|
1145 |
+
" except json.JSONDecodeError as e:\n",
|
1146 |
+
" print(f\"JSON decoding failed for doc_id {doc_id}: {e}\")\n"
|
1147 |
+
]
|
1148 |
+
},
|
1149 |
+
{
|
1150 |
+
"cell_type": "code",
|
1151 |
+
"execution_count": 123,
|
1152 |
+
"id": "4bbea76c-e98f-42a9-b2e0-8296828a5e24",
|
1153 |
+
"metadata": {},
|
1154 |
+
"outputs": [],
|
1155 |
+
"source": [
|
1156 |
+
"final_results = []\n",
|
1157 |
+
"\n",
|
1158 |
+
"for doc_id, questions in results.items():\n",
|
1159 |
+
" for q in questions:\n",
|
1160 |
+
" final_results.append((doc_id, q))\n"
|
1161 |
+
]
|
1162 |
+
},
|
1163 |
+
{
|
1164 |
+
"cell_type": "code",
|
1165 |
+
"execution_count": 128,
|
1166 |
+
"id": "2b72649f-4b4b-402a-8d83-310009aaa294",
|
1167 |
+
"metadata": {},
|
1168 |
+
"outputs": [
|
1169 |
+
{
|
1170 |
+
"data": {
|
1171 |
+
"text/plain": [
|
1172 |
+
"(6361820,\n",
|
1173 |
+
" 'What signs should parents and caretakers look out for in children under 18 that may indicate a mental health condition?')"
|
1174 |
+
]
|
1175 |
+
},
|
1176 |
+
"execution_count": 128,
|
1177 |
+
"metadata": {},
|
1178 |
+
"output_type": "execute_result"
|
1179 |
+
}
|
1180 |
+
],
|
1181 |
+
"source": [
|
1182 |
+
"final_results[10]\n"
|
1183 |
+
]
|
1184 |
+
},
|
1185 |
+
{
|
1186 |
+
"cell_type": "code",
|
1187 |
+
"execution_count": 129,
|
1188 |
+
"id": "20b5f107-951d-4842-895e-f1100e16e2a2",
|
1189 |
+
"metadata": {},
|
1190 |
+
"outputs": [],
|
1191 |
+
"source": [
|
1192 |
+
"df_results = pd.DataFrame(final_results, columns=['id', 'question'])\n"
|
1193 |
+
]
|
1194 |
+
},
|
1195 |
+
{
|
1196 |
+
"cell_type": "code",
|
1197 |
+
"execution_count": 131,
|
1198 |
+
"id": "c72c8a72-db39-4019-91ea-9444d7f20523",
|
1199 |
+
"metadata": {},
|
1200 |
+
"outputs": [
|
1201 |
+
{
|
1202 |
+
"data": {
|
1203 |
+
"text/html": [
|
1204 |
+
"<div>\n",
|
1205 |
+
"<style scoped>\n",
|
1206 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
1207 |
+
" vertical-align: middle;\n",
|
1208 |
+
" }\n",
|
1209 |
+
"\n",
|
1210 |
+
" .dataframe tbody tr th {\n",
|
1211 |
+
" vertical-align: top;\n",
|
1212 |
+
" }\n",
|
1213 |
+
"\n",
|
1214 |
+
" .dataframe thead th {\n",
|
1215 |
+
" text-align: right;\n",
|
1216 |
+
" }\n",
|
1217 |
+
"</style>\n",
|
1218 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
1219 |
+
" <thead>\n",
|
1220 |
+
" <tr style=\"text-align: right;\">\n",
|
1221 |
+
" <th></th>\n",
|
1222 |
+
" <th>id</th>\n",
|
1223 |
+
" <th>question</th>\n",
|
1224 |
+
" </tr>\n",
|
1225 |
+
" </thead>\n",
|
1226 |
+
" <tbody>\n",
|
1227 |
+
" <tr>\n",
|
1228 |
+
" <th>0</th>\n",
|
1229 |
+
" <td>1590140</td>\n",
|
1230 |
+
" <td>How do mental illnesses affect a person's dail...</td>\n",
|
1231 |
+
" </tr>\n",
|
1232 |
+
" <tr>\n",
|
1233 |
+
" <th>1</th>\n",
|
1234 |
+
" <td>1590140</td>\n",
|
1235 |
+
" <td>What are some examples of serious mental illne...</td>\n",
|
1236 |
+
" </tr>\n",
|
1237 |
+
" <tr>\n",
|
1238 |
+
" <th>2</th>\n",
|
1239 |
+
" <td>1590140</td>\n",
|
1240 |
+
" <td>Why is it a misconception to associate mental ...</td>\n",
|
1241 |
+
" </tr>\n",
|
1242 |
+
" <tr>\n",
|
1243 |
+
" <th>3</th>\n",
|
1244 |
+
" <td>1590140</td>\n",
|
1245 |
+
" <td>How are mental illnesses treated, and what is ...</td>\n",
|
1246 |
+
" </tr>\n",
|
1247 |
+
" <tr>\n",
|
1248 |
+
" <th>4</th>\n",
|
1249 |
+
" <td>1590140</td>\n",
|
1250 |
+
" <td>Can a person with mental illness become indepe...</td>\n",
|
1251 |
+
" </tr>\n",
|
1252 |
+
" <tr>\n",
|
1253 |
+
" <th>5</th>\n",
|
1254 |
+
" <td>2110618</td>\n",
|
1255 |
+
" <td>Who are the groups most commonly affected by d...</td>\n",
|
1256 |
+
" </tr>\n",
|
1257 |
+
" <tr>\n",
|
1258 |
+
" <th>6</th>\n",
|
1259 |
+
" <td>2110618</td>\n",
|
1260 |
+
" <td>How do mental illnesses affect children and th...</td>\n",
|
1261 |
+
" </tr>\n",
|
1262 |
+
" <tr>\n",
|
1263 |
+
" <th>7</th>\n",
|
1264 |
+
" <td>2110618</td>\n",
|
1265 |
+
" <td>What behaviors should parents and caretakers w...</td>\n",
|
1266 |
+
" </tr>\n",
|
1267 |
+
" <tr>\n",
|
1268 |
+
" <th>8</th>\n",
|
1269 |
+
" <td>6361820</td>\n",
|
1270 |
+
" <td>How does mental illness affect different popul...</td>\n",
|
1271 |
+
" </tr>\n",
|
1272 |
+
" <tr>\n",
|
1273 |
+
" <th>9</th>\n",
|
1274 |
+
" <td>6361820</td>\n",
|
1275 |
+
" <td>At what age are individuals most susceptible t...</td>\n",
|
1276 |
+
" </tr>\n",
|
1277 |
+
" </tbody>\n",
|
1278 |
+
"</table>\n",
|
1279 |
+
"</div>"
|
1280 |
+
],
|
1281 |
+
"text/plain": [
|
1282 |
+
" id question\n",
|
1283 |
+
"0 1590140 How do mental illnesses affect a person's dail...\n",
|
1284 |
+
"1 1590140 What are some examples of serious mental illne...\n",
|
1285 |
+
"2 1590140 Why is it a misconception to associate mental ...\n",
|
1286 |
+
"3 1590140 How are mental illnesses treated, and what is ...\n",
|
1287 |
+
"4 1590140 Can a person with mental illness become indepe...\n",
|
1288 |
+
"5 2110618 Who are the groups most commonly affected by d...\n",
|
1289 |
+
"6 2110618 How do mental illnesses affect children and th...\n",
|
1290 |
+
"7 2110618 What behaviors should parents and caretakers w...\n",
|
1291 |
+
"8 6361820 How does mental illness affect different popul...\n",
|
1292 |
+
"9 6361820 At what age are individuals most susceptible t..."
|
1293 |
+
]
|
1294 |
+
},
|
1295 |
+
"execution_count": 131,
|
1296 |
+
"metadata": {},
|
1297 |
+
"output_type": "execute_result"
|
1298 |
+
}
|
1299 |
+
],
|
1300 |
+
"source": [
|
1301 |
+
"df_results.head(10)"
|
1302 |
+
]
|
1303 |
+
},
|
1304 |
+
{
|
1305 |
+
"cell_type": "code",
|
1306 |
+
"execution_count": 133,
|
1307 |
+
"id": "e2cb78c2-6186-4aa9-93f3-cd501b9dcd24",
|
1308 |
+
"metadata": {},
|
1309 |
+
"outputs": [],
|
1310 |
+
"source": [
|
1311 |
+
"df_results.to_csv('../dataset/ground_truth_data.csv', index=False)\n"
|
1312 |
+
]
|
1313 |
+
}
|
1314 |
+
],
|
1315 |
+
"metadata": {
|
1316 |
+
"kernelspec": {
|
1317 |
+
"display_name": "Python 3 (ipykernel)",
|
1318 |
+
"language": "python",
|
1319 |
+
"name": "python3"
|
1320 |
+
},
|
1321 |
+
"language_info": {
|
1322 |
+
"codemirror_mode": {
|
1323 |
+
"name": "ipython",
|
1324 |
+
"version": 3
|
1325 |
+
},
|
1326 |
+
"file_extension": ".py",
|
1327 |
+
"mimetype": "text/x-python",
|
1328 |
+
"name": "python",
|
1329 |
+
"nbconvert_exporter": "python",
|
1330 |
+
"pygments_lexer": "ipython3",
|
1331 |
+
"version": "3.9.13"
|
1332 |
+
}
|
1333 |
+
},
|
1334 |
+
"nbformat": 4,
|
1335 |
+
"nbformat_minor": 5
|
1336 |
+
}
|
notebooks/minsearch.py
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
|
3 |
+
from sklearn.feature_extraction.text import TfidfVectorizer
|
4 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
5 |
+
|
6 |
+
import numpy as np
|
7 |
+
|
8 |
+
|
9 |
+
class Index:
|
10 |
+
"""
|
11 |
+
A simple search index using TF-IDF and cosine similarity for text fields and exact matching for keyword fields.
|
12 |
+
|
13 |
+
Attributes:
|
14 |
+
text_fields (list): List of text field names to index.
|
15 |
+
keyword_fields (list): List of keyword field names to index.
|
16 |
+
vectorizers (dict): Dictionary of TfidfVectorizer instances for each text field.
|
17 |
+
keyword_df (pd.DataFrame): DataFrame containing keyword field data.
|
18 |
+
text_matrices (dict): Dictionary of TF-IDF matrices for each text field.
|
19 |
+
docs (list): List of documents indexed.
|
20 |
+
"""
|
21 |
+
|
22 |
+
def __init__(self, text_fields, keyword_fields, vectorizer_params={}):
|
23 |
+
"""
|
24 |
+
Initializes the Index with specified text and keyword fields.
|
25 |
+
|
26 |
+
Args:
|
27 |
+
text_fields (list): List of text field names to index.
|
28 |
+
keyword_fields (list): List of keyword field names to index.
|
29 |
+
vectorizer_params (dict): Optional parameters to pass to TfidfVectorizer.
|
30 |
+
"""
|
31 |
+
self.text_fields = text_fields
|
32 |
+
self.keyword_fields = keyword_fields
|
33 |
+
|
34 |
+
self.vectorizers = {field: TfidfVectorizer(**vectorizer_params) for field in text_fields}
|
35 |
+
self.keyword_df = None
|
36 |
+
self.text_matrices = {}
|
37 |
+
self.docs = []
|
38 |
+
|
39 |
+
def fit(self, docs):
|
40 |
+
"""
|
41 |
+
Fits the index with the provided documents.
|
42 |
+
|
43 |
+
Args:
|
44 |
+
docs (list of dict): List of documents to index. Each document is a dictionary.
|
45 |
+
"""
|
46 |
+
self.docs = docs
|
47 |
+
keyword_data = {field: [] for field in self.keyword_fields}
|
48 |
+
|
49 |
+
for field in self.text_fields:
|
50 |
+
texts = [doc.get(field, '') for doc in docs]
|
51 |
+
self.text_matrices[field] = self.vectorizers[field].fit_transform(texts)
|
52 |
+
|
53 |
+
for doc in docs:
|
54 |
+
for field in self.keyword_fields:
|
55 |
+
keyword_data[field].append(doc.get(field, ''))
|
56 |
+
|
57 |
+
self.keyword_df = pd.DataFrame(keyword_data)
|
58 |
+
|
59 |
+
return self
|
60 |
+
|
61 |
+
def search(self, query, filter_dict={}, boost_dict={}, num_results=10):
|
62 |
+
"""
|
63 |
+
Searches the index with the given query, filters, and boost parameters.
|
64 |
+
|
65 |
+
Args:
|
66 |
+
query (str): The search query string.
|
67 |
+
filter_dict (dict): Dictionary of keyword fields to filter by. Keys are field names and values are the values to filter by.
|
68 |
+
boost_dict (dict): Dictionary of boost scores for text fields. Keys are field names and values are the boost scores.
|
69 |
+
num_results (int): The number of top results to return. Defaults to 10.
|
70 |
+
|
71 |
+
Returns:
|
72 |
+
list of dict: List of documents matching the search criteria, ranked by relevance.
|
73 |
+
"""
|
74 |
+
query_vecs = {field: self.vectorizers[field].transform([query]) for field in self.text_fields}
|
75 |
+
scores = np.zeros(len(self.docs))
|
76 |
+
|
77 |
+
# Compute cosine similarity for each text field and apply boost
|
78 |
+
for field, query_vec in query_vecs.items():
|
79 |
+
sim = cosine_similarity(query_vec, self.text_matrices[field]).flatten()
|
80 |
+
boost = boost_dict.get(field, 1)
|
81 |
+
scores += sim * boost
|
82 |
+
|
83 |
+
# Apply keyword filters
|
84 |
+
for field, value in filter_dict.items():
|
85 |
+
if field in self.keyword_fields:
|
86 |
+
mask = self.keyword_df[field] == value
|
87 |
+
scores = scores * mask.to_numpy()
|
88 |
+
|
89 |
+
# Use argpartition to get top num_results indices
|
90 |
+
top_indices = np.argpartition(scores, -num_results)[-num_results:]
|
91 |
+
top_indices = top_indices[np.argsort(-scores[top_indices])]
|
92 |
+
|
93 |
+
# Filter out zero-score results
|
94 |
+
top_docs = [self.docs[i] for i in top_indices if scores[i] > 0]
|
95 |
+
|
96 |
+
return top_docs
|
notebooks/rag_evaluation.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
src/__pycache__/ingest.cpython-39.pyc
ADDED
Binary file (631 Bytes). View file
|
|
src/__pycache__/minsearch.cpython-39.pyc
ADDED
Binary file (4.17 kB). View file
|
|
src/app.py
ADDED
@@ -0,0 +1,230 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import time
|
3 |
+
import uuid
|
4 |
+
from datetime import datetime
|
5 |
+
from zoneinfo import ZoneInfo
|
6 |
+
import pandas as pd
|
7 |
+
|
8 |
+
import rag
|
9 |
+
from db import (
|
10 |
+
save_conversation,
|
11 |
+
save_feedback,
|
12 |
+
get_recent_conversations,
|
13 |
+
get_feedback_stats,
|
14 |
+
init_db,
|
15 |
+
verify_conversation_saved
|
16 |
+
)
|
17 |
+
import logging
|
18 |
+
|
19 |
+
# Set up logging
|
20 |
+
logging.basicConfig(level=logging.INFO)
|
21 |
+
logger = logging.getLogger(__name__)
|
22 |
+
|
23 |
+
tz = ZoneInfo("Europe/Berlin")
|
24 |
+
|
25 |
+
def print_log(message):
|
26 |
+
print(message, flush=True)
|
27 |
+
|
28 |
+
def main():
|
29 |
+
print_log("Starting the Mental Health Assistant application")
|
30 |
+
st.title("Mental Health Assistant")
|
31 |
+
|
32 |
+
# Initialize the database
|
33 |
+
init_db()
|
34 |
+
|
35 |
+
# Session state initialization
|
36 |
+
if "conversation_id" not in st.session_state:
|
37 |
+
st.session_state.conversation_id = str(uuid.uuid4())
|
38 |
+
print_log(f"New conversation started with ID: {st.session_state.conversation_id}")
|
39 |
+
if "count" not in st.session_state:
|
40 |
+
st.session_state.count = 0
|
41 |
+
print_log("Feedback count initialized to 0")
|
42 |
+
if "feedback_given" not in st.session_state:
|
43 |
+
st.session_state.feedback_given = False
|
44 |
+
if "past_questions" not in st.session_state:
|
45 |
+
st.session_state.past_questions = []
|
46 |
+
if "chat_history" not in st.session_state:
|
47 |
+
st.session_state.chat_history = [] # Stores the questions and answers for display
|
48 |
+
if "clear_chat" not in st.session_state:
|
49 |
+
st.session_state.clear_chat = False
|
50 |
+
|
51 |
+
# Session state for user input
|
52 |
+
if "user_input" not in st.session_state:
|
53 |
+
st.session_state.user_input = "" # This will control the text input field value
|
54 |
+
|
55 |
+
# Check if we need to clear the chat
|
56 |
+
if st.session_state.clear_chat:
|
57 |
+
st.session_state.chat_history = []
|
58 |
+
st.session_state.clear_chat = False
|
59 |
+
|
60 |
+
# Model selection
|
61 |
+
model_choice = st.selectbox(
|
62 |
+
"Select a model:",
|
63 |
+
["gemma2-9b-it", "llama-3.1-70b-versatile", "llama3-70b-8192", "mixtral-8x7b-32768"],
|
64 |
+
)
|
65 |
+
print_log(f"User selected model: {model_choice}")
|
66 |
+
|
67 |
+
# User input text box
|
68 |
+
user_input = st.text_input("Ask a question about mental health:", value=st.session_state.user_input)
|
69 |
+
|
70 |
+
if "last_conversation_id" not in st.session_state:
|
71 |
+
st.session_state.last_conversation_id = None
|
72 |
+
|
73 |
+
if st.button("Ask"):
|
74 |
+
logger.debug(f"Ask button pressed. User input: {user_input}")
|
75 |
+
|
76 |
+
# Check if input is valid
|
77 |
+
if user_input.strip() == "":
|
78 |
+
st.warning("Please enter a question before asking.")
|
79 |
+
elif user_input in st.session_state.past_questions:
|
80 |
+
st.warning("You've already asked this question.")
|
81 |
+
else:
|
82 |
+
# Proceed with getting an answer from the assistant
|
83 |
+
print_log(f"User asked: '{user_input}'")
|
84 |
+
with st.spinner("Processing..."):
|
85 |
+
print_log(f"Getting answer from assistant using {model_choice} model")
|
86 |
+
start_time = time.time()
|
87 |
+
answer_data = rag.rag(user_input, model=model_choice)
|
88 |
+
end_time = time.time()
|
89 |
+
print_log(f"Answer received in {end_time - start_time:.2f} seconds")
|
90 |
+
st.success("Completed!")
|
91 |
+
st.write(answer_data["answer"])
|
92 |
+
|
93 |
+
# Store the conversation in chat history
|
94 |
+
st.session_state.chat_history.append({
|
95 |
+
"question": user_input,
|
96 |
+
"answer": answer_data["answer"],
|
97 |
+
"relevance": answer_data["relevance"],
|
98 |
+
"model": answer_data["model_used"]})
|
99 |
+
|
100 |
+
# Display monitoring information
|
101 |
+
st.write(f"Response time: {answer_data['response_time']:.2f} seconds")
|
102 |
+
st.write(f"Relevance: {answer_data['relevance']}")
|
103 |
+
st.write(f"Model used: {answer_data['model_used']}")
|
104 |
+
st.write(f"Total tokens: {answer_data['total_tokens']}")
|
105 |
+
|
106 |
+
# Save conversation to database
|
107 |
+
logger.debug(f"Attempting to save conversation: {st.session_state.conversation_id}")
|
108 |
+
save_conversation(st.session_state.conversation_id, user_input, answer_data)
|
109 |
+
logger.debug(f"Conversation saved. Verifying...")
|
110 |
+
verify_conversation_saved(st.session_state.conversation_id)
|
111 |
+
|
112 |
+
|
113 |
+
|
114 |
+
# Update the last_conversation_id and reset feedback
|
115 |
+
st.session_state.last_conversation_id = st.session_state.conversation_id
|
116 |
+
st.session_state.conversation_id = str(uuid.uuid4()) # New conversation ID for the next question
|
117 |
+
st.session_state.feedback_given = False # Reset feedback state
|
118 |
+
st.session_state.past_questions.append(user_input) # Add the question to past questions
|
119 |
+
|
120 |
+
# Clear the input field by resetting session state variable
|
121 |
+
st.session_state.user_input = "" # Reset input for next question
|
122 |
+
|
123 |
+
# Feedback buttons
|
124 |
+
col1, col2 = st.columns(2)
|
125 |
+
with col1:
|
126 |
+
if st.button("+1"):
|
127 |
+
if st.session_state.last_conversation_id and not st.session_state.feedback_given:
|
128 |
+
save_feedback(st.session_state.last_conversation_id, 1)
|
129 |
+
st.success("Positive feedback saved!")
|
130 |
+
st.session_state.feedback_given = True # Mark feedback as given
|
131 |
+
st.session_state.last_conversation_id = None # Clear last conversation
|
132 |
+
st.session_state.clear_chat = True # Set flag to clear chat on next rerun
|
133 |
+
st.rerun() # Rerun the app to refresh the UI
|
134 |
+
elif st.session_state.feedback_given:
|
135 |
+
st.warning("Feedback has already been provided for this conversation.")
|
136 |
+
else:
|
137 |
+
st.warning("No conversation to provide feedback for.")
|
138 |
+
with col2:
|
139 |
+
if st.button("-1"):
|
140 |
+
if st.session_state.last_conversation_id and not st.session_state.feedback_given:
|
141 |
+
save_feedback(st.session_state.last_conversation_id, -1)
|
142 |
+
st.success("Negative feedback saved!")
|
143 |
+
st.session_state.feedback_given = True # Mark feedback as given
|
144 |
+
st.session_state.last_conversation_id = None # Clear last conversation
|
145 |
+
st.session_state.clear_chat = True # Set flag to clear chat on next rerun
|
146 |
+
st.rerun() # Rerun the app to refresh the UI
|
147 |
+
elif st.session_state.feedback_given:
|
148 |
+
st.warning("Feedback has already been provided for this conversation.")
|
149 |
+
else:
|
150 |
+
st.warning("No conversation to provide feedback for.")
|
151 |
+
|
152 |
+
# Display feedback status
|
153 |
+
if st.session_state.feedback_given:
|
154 |
+
st.info("Feedback has already been provided for this conversation.")
|
155 |
+
else:
|
156 |
+
st.info("You can provide feedback for the current conversation.")
|
157 |
+
|
158 |
+
# Display chat history
|
159 |
+
if st.session_state.chat_history:
|
160 |
+
st.subheader("Chat History")
|
161 |
+
for chat in st.session_state.chat_history:
|
162 |
+
st.write(f"**Q:** {chat['question']}")
|
163 |
+
st.write(f"**A:** {chat['answer']}")
|
164 |
+
st.write(f"*Relevance: {chat['relevance']}, Model: {chat['model']}*")
|
165 |
+
st.write("---")
|
166 |
+
|
167 |
+
# Display statistics dashboard
|
168 |
+
st.subheader("Statistics Dashboard")
|
169 |
+
|
170 |
+
# Calculate relevance stats
|
171 |
+
relevance_counts = {
|
172 |
+
"RELEVANT": 0,
|
173 |
+
"PARTLY_RELEVANT": 0,
|
174 |
+
"NON_RELEVANT": 0
|
175 |
+
}
|
176 |
+
recent_conversations = get_recent_conversations(limit=100) # Get more conversations for better stats
|
177 |
+
for conv in recent_conversations:
|
178 |
+
if conv['relevance'] in relevance_counts:
|
179 |
+
relevance_counts[conv['relevance']] += 1
|
180 |
+
|
181 |
+
# Display relevance stats
|
182 |
+
st.write("Response Relevance Distribution")
|
183 |
+
relevance_df = pd.DataFrame({
|
184 |
+
'Relevance': list(relevance_counts.keys()),
|
185 |
+
'Count': list(relevance_counts.values())
|
186 |
+
})
|
187 |
+
st.bar_chart(relevance_df.set_index('Relevance'))
|
188 |
+
|
189 |
+
# Display feedback stats
|
190 |
+
feedback_stats = get_feedback_stats()
|
191 |
+
st.write("User Feedback Distribution")
|
192 |
+
feedback_df = pd.DataFrame({
|
193 |
+
'Feedback': ['Positive', 'Negative'],
|
194 |
+
'Count': [feedback_stats['thumbs_up'], feedback_stats['thumbs_down']]
|
195 |
+
})
|
196 |
+
st.bar_chart(feedback_df.set_index('Feedback'))
|
197 |
+
|
198 |
+
|
199 |
+
|
200 |
+
# Display recent conversations
|
201 |
+
st.subheader("Recent Conversations")
|
202 |
+
relevance_filter = st.selectbox(
|
203 |
+
"Filter by relevance:",
|
204 |
+
["All", "RELEVANT", "PARTLY_RELEVANT", "NON_RELEVANT"]
|
205 |
+
)
|
206 |
+
recent_conversations = get_recent_conversations(
|
207 |
+
limit=3,
|
208 |
+
relevance=relevance_filter if relevance_filter != "All" else None
|
209 |
+
)
|
210 |
+
for conv in recent_conversations:
|
211 |
+
st.write(f"Q: {conv['question']}")
|
212 |
+
st.write(f"A: {conv['answer']}")
|
213 |
+
st.write(f"Relevance: {conv['relevance']}")
|
214 |
+
st.write(f"Model: {conv['model_used']}")
|
215 |
+
st.write("---")
|
216 |
+
|
217 |
+
# Display feedback stats
|
218 |
+
feedback_stats = get_feedback_stats()
|
219 |
+
st.subheader("Feedback Statistics")
|
220 |
+
st.write(f"Thumbs up: {feedback_stats['thumbs_up']}")
|
221 |
+
st.write(f"Thumbs down: {feedback_stats['thumbs_down']}")
|
222 |
+
|
223 |
+
# Generate a new conversation ID for the next question
|
224 |
+
st.session_state.conversation_id = str(uuid.uuid4())
|
225 |
+
|
226 |
+
print_log("Streamlit app loop completed")
|
227 |
+
|
228 |
+
if __name__ == "__main__":
|
229 |
+
print_log("Mental Health Assistant application started")
|
230 |
+
main()
|
src/db.py
ADDED
@@ -0,0 +1,322 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import psycopg2
|
3 |
+
from psycopg2.extras import DictCursor
|
4 |
+
from datetime import datetime, timezone
|
5 |
+
from zoneinfo import ZoneInfo
|
6 |
+
import logging
|
7 |
+
|
8 |
+
# Set up logging
|
9 |
+
logging.basicConfig(level=logging.INFO)
|
10 |
+
logger = logging.getLogger(__name__)
|
11 |
+
|
12 |
+
RUN_TIMEZONE_CHECK = os.getenv('RUN_TIMEZONE_CHECK', '1') == '1'
|
13 |
+
|
14 |
+
TZ_INFO = os.getenv("TZ", "Europe/Berlin")
|
15 |
+
tz = ZoneInfo(TZ_INFO)
|
16 |
+
|
17 |
+
|
18 |
+
def get_db_connection():
|
19 |
+
try:
|
20 |
+
conn = psycopg2.connect(
|
21 |
+
host=os.getenv("POSTGRES_HOST", "postgres"),
|
22 |
+
database=os.getenv("POSTGRES_DB", "mental_health"),
|
23 |
+
user=os.getenv("POSTGRES_USER", "newton"),
|
24 |
+
password=os.getenv("POSTGRES_PASSWORD", "Admin"),
|
25 |
+
)
|
26 |
+
logger.info("Successfully connected to the database")
|
27 |
+
return conn
|
28 |
+
except Exception as e:
|
29 |
+
logger.error(f"Error connecting to the database: {e}")
|
30 |
+
raise
|
31 |
+
|
32 |
+
|
33 |
+
def init_db():
|
34 |
+
conn = get_db_connection()
|
35 |
+
try:
|
36 |
+
with conn.cursor() as cur:
|
37 |
+
# Check if tables exist
|
38 |
+
cur.execute("SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_name = 'conversations')")
|
39 |
+
conversations_exists = cur.fetchone()[0]
|
40 |
+
cur.execute("SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_name = 'feedback')")
|
41 |
+
feedback_exists = cur.fetchone()[0]
|
42 |
+
|
43 |
+
if not conversations_exists:
|
44 |
+
logger.info("Creating conversations table")
|
45 |
+
cur.execute("""
|
46 |
+
CREATE TABLE conversations (
|
47 |
+
id TEXT PRIMARY KEY,
|
48 |
+
question TEXT NOT NULL,
|
49 |
+
answer TEXT NOT NULL,
|
50 |
+
model_used TEXT NOT NULL,
|
51 |
+
response_time FLOAT NOT NULL,
|
52 |
+
relevance TEXT NOT NULL,
|
53 |
+
relevance_explanation TEXT NOT NULL,
|
54 |
+
prompt_tokens INTEGER NOT NULL,
|
55 |
+
completion_tokens INTEGER NOT NULL,
|
56 |
+
total_tokens INTEGER NOT NULL,
|
57 |
+
eval_prompt_tokens INTEGER NOT NULL,
|
58 |
+
eval_completion_tokens INTEGER NOT NULL,
|
59 |
+
eval_total_tokens INTEGER NOT NULL,
|
60 |
+
timestamp TIMESTAMP WITH TIME ZONE NOT NULL
|
61 |
+
)
|
62 |
+
""")
|
63 |
+
|
64 |
+
if not feedback_exists:
|
65 |
+
logger.info("Creating feedback table")
|
66 |
+
cur.execute("""
|
67 |
+
CREATE TABLE feedback (
|
68 |
+
id SERIAL PRIMARY KEY,
|
69 |
+
conversation_id TEXT REFERENCES conversations(id),
|
70 |
+
feedback INTEGER NOT NULL,
|
71 |
+
timestamp TIMESTAMP WITH TIME ZONE NOT NULL
|
72 |
+
)
|
73 |
+
""")
|
74 |
+
# Add comments table
|
75 |
+
cur.execute("SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_name = 'comments')")
|
76 |
+
comments_exists = cur.fetchone()[0]
|
77 |
+
|
78 |
+
if not comments_exists:
|
79 |
+
logger.info("Creating comments table")
|
80 |
+
cur.execute("""
|
81 |
+
CREATE TABLE comments (
|
82 |
+
id SERIAL PRIMARY KEY,
|
83 |
+
conversation_id TEXT REFERENCES conversations(id),
|
84 |
+
comment TEXT NOT NULL,
|
85 |
+
timestamp TIMESTAMP WITH TIME ZONE NOT NULL
|
86 |
+
)
|
87 |
+
""")
|
88 |
+
|
89 |
+
conn.commit()
|
90 |
+
logger.info("Database tables initialized successfully")
|
91 |
+
except Exception as e:
|
92 |
+
logger.error(f"Error initializing database: {e}")
|
93 |
+
conn.rollback()
|
94 |
+
finally:
|
95 |
+
conn.close()
|
96 |
+
|
97 |
+
|
98 |
+
def save_conversation(conversation_id, question, answer_data, timestamp=None):
|
99 |
+
if timestamp is None:
|
100 |
+
timestamp = datetime.now(tz)
|
101 |
+
|
102 |
+
conn = get_db_connection()
|
103 |
+
try:
|
104 |
+
with conn.cursor() as cur:
|
105 |
+
logger.debug(f"Saving conversation: {conversation_id}")
|
106 |
+
logger.debug(f"Question: {question}")
|
107 |
+
logger.debug(f"Answer data: {answer_data}")
|
108 |
+
cur.execute(
|
109 |
+
"""
|
110 |
+
INSERT INTO conversations
|
111 |
+
(id, question, answer, model_used, response_time, relevance,
|
112 |
+
relevance_explanation, prompt_tokens, completion_tokens, total_tokens,
|
113 |
+
eval_prompt_tokens, eval_completion_tokens, eval_total_tokens, timestamp)
|
114 |
+
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
115 |
+
""",
|
116 |
+
(
|
117 |
+
conversation_id,
|
118 |
+
question,
|
119 |
+
answer_data["answer"],
|
120 |
+
answer_data["model_used"],
|
121 |
+
answer_data["response_time"],
|
122 |
+
answer_data["relevance"].upper(), # Ensure it's uppercase
|
123 |
+
answer_data["relevance_explanation"],
|
124 |
+
answer_data["prompt_tokens"],
|
125 |
+
answer_data["completion_tokens"],
|
126 |
+
answer_data["total_tokens"],
|
127 |
+
answer_data["eval_prompt_tokens"],
|
128 |
+
answer_data["eval_completion_tokens"],
|
129 |
+
answer_data["eval_total_tokens"],
|
130 |
+
timestamp
|
131 |
+
),
|
132 |
+
)
|
133 |
+
conn.commit()
|
134 |
+
logger.info(f"Successfully saved conversation: {conversation_id}")
|
135 |
+
except Exception as e:
|
136 |
+
logger.error(f"Error saving conversation: {e}")
|
137 |
+
conn.rollback()
|
138 |
+
finally:
|
139 |
+
conn.close()
|
140 |
+
|
141 |
+
|
142 |
+
def save_feedback(conversation_id, feedback, timestamp=None):
|
143 |
+
if timestamp is None:
|
144 |
+
timestamp = datetime.now(tz)
|
145 |
+
|
146 |
+
conn = get_db_connection()
|
147 |
+
try:
|
148 |
+
with conn.cursor() as cur:
|
149 |
+
# Check if the conversation exists
|
150 |
+
cur.execute("SELECT id FROM conversations WHERE id = %s", (conversation_id,))
|
151 |
+
if cur.fetchone() is None:
|
152 |
+
logger.warning(f"Attempted to save feedback for non-existent conversation: {conversation_id}")
|
153 |
+
return # Or handle this case as appropriate for your application
|
154 |
+
|
155 |
+
logger.info(f"Attempting to save feedback: conversation_id={conversation_id}, feedback={feedback}, timestamp={timestamp}")
|
156 |
+
cur.execute(
|
157 |
+
"INSERT INTO feedback (conversation_id, feedback, timestamp) VALUES (%s, %s, %s)",
|
158 |
+
(conversation_id, feedback, timestamp),
|
159 |
+
)
|
160 |
+
conn.commit()
|
161 |
+
logger.info(f"Feedback saved successfully for conversation {conversation_id}")
|
162 |
+
except Exception as e:
|
163 |
+
logger.error(f"Error saving feedback: {e}")
|
164 |
+
conn.rollback()
|
165 |
+
raise
|
166 |
+
finally:
|
167 |
+
conn.close()
|
168 |
+
|
169 |
+
def save_comment(conversation_id, comment, timestamp=None):
|
170 |
+
if timestamp is None:
|
171 |
+
timestamp = datetime.now(tz)
|
172 |
+
|
173 |
+
conn = get_db_connection()
|
174 |
+
try:
|
175 |
+
with conn.cursor() as cur:
|
176 |
+
cur.execute(
|
177 |
+
"INSERT INTO comments (conversation_id, comment, timestamp) VALUES (%s, %s, %s)",
|
178 |
+
(conversation_id, comment, timestamp)
|
179 |
+
)
|
180 |
+
conn.commit()
|
181 |
+
logger.info(f"Comment saved successfully for conversation {conversation_id}")
|
182 |
+
except Exception as e:
|
183 |
+
logger.error(f"Error saving comment: {e}")
|
184 |
+
conn.rollback()
|
185 |
+
finally:
|
186 |
+
conn.close()
|
187 |
+
|
188 |
+
def get_comments(conversation_id):
|
189 |
+
conn = get_db_connection()
|
190 |
+
try:
|
191 |
+
with conn.cursor(cursor_factory=DictCursor) as cur:
|
192 |
+
cur.execute(
|
193 |
+
"SELECT * FROM comments WHERE conversation_id = %s ORDER BY timestamp DESC",
|
194 |
+
(conversation_id,)
|
195 |
+
)
|
196 |
+
return cur.fetchall()
|
197 |
+
finally:
|
198 |
+
conn.close()
|
199 |
+
def get_recent_conversations(limit=5, relevance=None):
|
200 |
+
conn = get_db_connection()
|
201 |
+
try:
|
202 |
+
with conn.cursor(cursor_factory=DictCursor) as cur:
|
203 |
+
query = """
|
204 |
+
SELECT c.*, f.feedback
|
205 |
+
FROM conversations c
|
206 |
+
LEFT JOIN feedback f ON c.id = f.conversation_id
|
207 |
+
"""
|
208 |
+
params = []
|
209 |
+
if relevance:
|
210 |
+
if relevance in ["RELEVANT", "PARTLY_RELEVANT", "NON_RELEVANT"]:
|
211 |
+
query += " WHERE c.relevance = %s"
|
212 |
+
params.append(relevance)
|
213 |
+
else:
|
214 |
+
logger.warning(f"Invalid relevance filter: {relevance}")
|
215 |
+
query += " ORDER BY c.timestamp DESC LIMIT %s"
|
216 |
+
params.append(limit)
|
217 |
+
|
218 |
+
logger.debug(f"Executing query: {query}")
|
219 |
+
logger.debug(f"Query parameters: {params}")
|
220 |
+
cur.execute(query, tuple(params))
|
221 |
+
return cur.fetchall()
|
222 |
+
except Exception as e:
|
223 |
+
logger.error(f"Error in get_recent_conversations: {e}")
|
224 |
+
return []
|
225 |
+
finally:
|
226 |
+
conn.close()
|
227 |
+
|
228 |
+
|
229 |
+
def get_feedback_stats():
|
230 |
+
conn = get_db_connection()
|
231 |
+
try:
|
232 |
+
with conn.cursor(cursor_factory=DictCursor) as cur:
|
233 |
+
cur.execute("""
|
234 |
+
SELECT
|
235 |
+
SUM(CASE WHEN feedback > 0 THEN 1 ELSE 0 END) as thumbs_up,
|
236 |
+
SUM(CASE WHEN feedback < 0 THEN 1 ELSE 0 END) as thumbs_down
|
237 |
+
FROM feedback
|
238 |
+
""")
|
239 |
+
return cur.fetchone()
|
240 |
+
finally:
|
241 |
+
conn.close()
|
242 |
+
|
243 |
+
|
244 |
+
def check_timezone():
|
245 |
+
conn = get_db_connection()
|
246 |
+
try:
|
247 |
+
with conn.cursor() as cur:
|
248 |
+
cur.execute("SHOW timezone;")
|
249 |
+
db_timezone = cur.fetchone()[0]
|
250 |
+
print(f"Database timezone: {db_timezone}")
|
251 |
+
|
252 |
+
cur.execute("SELECT current_timestamp;")
|
253 |
+
db_time_utc = cur.fetchone()[0]
|
254 |
+
print(f"Database current time (UTC): {db_time_utc}")
|
255 |
+
|
256 |
+
db_time_local = db_time_utc.astimezone(tz)
|
257 |
+
print(f"Database current time ({TZ_INFO}): {db_time_local}")
|
258 |
+
|
259 |
+
py_time = datetime.now(tz)
|
260 |
+
print(f"Python current time: {py_time}")
|
261 |
+
|
262 |
+
# Use py_time instead of tz for insertion
|
263 |
+
cur.execute("""
|
264 |
+
INSERT INTO conversations
|
265 |
+
(id, question, answer, model_used, response_time, relevance,
|
266 |
+
relevance_explanation, prompt_tokens, completion_tokens, total_tokens,
|
267 |
+
eval_prompt_tokens, eval_completion_tokens, eval_total_tokens, timestamp)
|
268 |
+
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
269 |
+
RETURNING timestamp;
|
270 |
+
""",
|
271 |
+
('test', 'test question', 'test answer', 'test model', 0.0, 0.0,
|
272 |
+
'test explanation', 0, 0, 0, 0, 0, 0, 0.0, py_time))
|
273 |
+
|
274 |
+
inserted_time = cur.fetchone()[0]
|
275 |
+
print(f"Inserted time (UTC): {inserted_time}")
|
276 |
+
print(f"Inserted time ({TZ_INFO}): {inserted_time.astimezone(tz)}")
|
277 |
+
|
278 |
+
cur.execute("SELECT timestamp FROM conversations WHERE id = 'test';")
|
279 |
+
selected_time = cur.fetchone()[0]
|
280 |
+
print(f"Selected time (UTC): {selected_time}")
|
281 |
+
print(f"Selected time ({TZ_INFO}): {selected_time.astimezone(tz)}")
|
282 |
+
|
283 |
+
# Clean up the test entry
|
284 |
+
cur.execute("DELETE FROM conversations WHERE id = 'test';")
|
285 |
+
conn.commit()
|
286 |
+
except Exception as e:
|
287 |
+
print(f"An error occurred: {e}")
|
288 |
+
conn.rollback()
|
289 |
+
finally:
|
290 |
+
conn.close()
|
291 |
+
|
292 |
+
def verify_conversation_saved(conversation_id):
|
293 |
+
conn = get_db_connection()
|
294 |
+
try:
|
295 |
+
with conn.cursor() as cur:
|
296 |
+
cur.execute("SELECT * FROM conversations WHERE id = %s", (conversation_id,))
|
297 |
+
result = cur.fetchone()
|
298 |
+
if result:
|
299 |
+
logger.info(f"Verified conversation saved: {conversation_id}")
|
300 |
+
else:
|
301 |
+
logger.error(f"Failed to verify conversation saved: {conversation_id}")
|
302 |
+
except Exception as e:
|
303 |
+
logger.error(f"Error verifying conversation: {e}")
|
304 |
+
finally:
|
305 |
+
conn.close()
|
306 |
+
def verify_feedback_saved(conversation_id):
|
307 |
+
conn = get_db_connection()
|
308 |
+
try:
|
309 |
+
with conn.cursor() as cur:
|
310 |
+
cur.execute("SELECT * FROM feedback WHERE conversation_id = %s", (conversation_id,))
|
311 |
+
result = cur.fetchone()
|
312 |
+
if result:
|
313 |
+
logger.info(f"Verified feedback saved for conversation: {conversation_id}")
|
314 |
+
else:
|
315 |
+
logger.error(f"Failed to verify feedback saved for conversation: {conversation_id}")
|
316 |
+
except Exception as e:
|
317 |
+
logger.error(f"Error verifying feedback: {e}")
|
318 |
+
finally:
|
319 |
+
conn.close()
|
320 |
+
|
321 |
+
if RUN_TIMEZONE_CHECK:
|
322 |
+
check_timezone()
|
src/db_prep.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from dotenv import load_dotenv
|
3 |
+
|
4 |
+
os.environ['RUN_TIMEZONE_CHECK'] = '0'
|
5 |
+
|
6 |
+
from db_utils import init_db
|
7 |
+
|
8 |
+
load_dotenv()
|
9 |
+
|
10 |
+
if __name__ == "__main__":
|
11 |
+
print("Initializing database...")
|
12 |
+
init_db()
|
src/ingest.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import pandas as pd
|
3 |
+
import pickle
|
4 |
+
import minsearch
|
5 |
+
|
6 |
+
DATA_PATH = os.getenv("DATA_PATH", "../dataset/data.csv")
|
7 |
+
|
8 |
+
def load_index(data_path=DATA_PATH):
|
9 |
+
df = pd.read_csv(data_path)
|
10 |
+
documents = df.to_dict(orient="records")
|
11 |
+
print(documents[9])
|
12 |
+
|
13 |
+
index = minsearch.Index(
|
14 |
+
text_fields=['Questions', 'Answers'],
|
15 |
+
keyword_fields=["Question_ID"],
|
16 |
+
)
|
17 |
+
|
18 |
+
index.fit(documents)
|
19 |
+
return index
|
src/minsearch.py
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
|
3 |
+
from sklearn.feature_extraction.text import TfidfVectorizer
|
4 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
5 |
+
|
6 |
+
import numpy as np
|
7 |
+
|
8 |
+
|
9 |
+
class Index:
|
10 |
+
"""
|
11 |
+
A simple search index using TF-IDF and cosine similarity for text fields and exact matching for keyword fields.
|
12 |
+
|
13 |
+
Attributes:
|
14 |
+
text_fields (list): List of text field names to index.
|
15 |
+
keyword_fields (list): List of keyword field names to index.
|
16 |
+
vectorizers (dict): Dictionary of TfidfVectorizer instances for each text field.
|
17 |
+
keyword_df (pd.DataFrame): DataFrame containing keyword field data.
|
18 |
+
text_matrices (dict): Dictionary of TF-IDF matrices for each text field.
|
19 |
+
docs (list): List of documents indexed.
|
20 |
+
"""
|
21 |
+
|
22 |
+
def __init__(self, text_fields, keyword_fields, vectorizer_params={}):
|
23 |
+
"""
|
24 |
+
Initializes the Index with specified text and keyword fields.
|
25 |
+
|
26 |
+
Args:
|
27 |
+
text_fields (list): List of text field names to index.
|
28 |
+
keyword_fields (list): List of keyword field names to index.
|
29 |
+
vectorizer_params (dict): Optional parameters to pass to TfidfVectorizer.
|
30 |
+
"""
|
31 |
+
self.text_fields = text_fields
|
32 |
+
self.keyword_fields = keyword_fields
|
33 |
+
|
34 |
+
self.vectorizers = {field: TfidfVectorizer(**vectorizer_params) for field in text_fields}
|
35 |
+
self.keyword_df = None
|
36 |
+
self.text_matrices = {}
|
37 |
+
self.docs = []
|
38 |
+
|
39 |
+
def fit(self, docs):
|
40 |
+
"""
|
41 |
+
Fits the index with the provided documents.
|
42 |
+
|
43 |
+
Args:
|
44 |
+
docs (list of dict): List of documents to index. Each document is a dictionary.
|
45 |
+
"""
|
46 |
+
self.docs = docs
|
47 |
+
keyword_data = {field: [] for field in self.keyword_fields}
|
48 |
+
|
49 |
+
for field in self.text_fields:
|
50 |
+
texts = [doc.get(field, '') for doc in docs]
|
51 |
+
self.text_matrices[field] = self.vectorizers[field].fit_transform(texts)
|
52 |
+
|
53 |
+
for doc in docs:
|
54 |
+
for field in self.keyword_fields:
|
55 |
+
keyword_data[field].append(doc.get(field, ''))
|
56 |
+
|
57 |
+
self.keyword_df = pd.DataFrame(keyword_data)
|
58 |
+
|
59 |
+
return self
|
60 |
+
|
61 |
+
def search(self, query, filter_dict={}, boost_dict={}, num_results=10):
|
62 |
+
"""
|
63 |
+
Searches the index with the given query, filters, and boost parameters.
|
64 |
+
|
65 |
+
Args:
|
66 |
+
query (str): The search query string.
|
67 |
+
filter_dict (dict): Dictionary of keyword fields to filter by. Keys are field names and values are the values to filter by.
|
68 |
+
boost_dict (dict): Dictionary of boost scores for text fields. Keys are field names and values are the boost scores.
|
69 |
+
num_results (int): The number of top results to return. Defaults to 10.
|
70 |
+
|
71 |
+
Returns:
|
72 |
+
list of dict: List of documents matching the search criteria, ranked by relevance.
|
73 |
+
"""
|
74 |
+
query_vecs = {field: self.vectorizers[field].transform([query]) for field in self.text_fields}
|
75 |
+
scores = np.zeros(len(self.docs))
|
76 |
+
|
77 |
+
# Compute cosine similarity for each text field and apply boost
|
78 |
+
for field, query_vec in query_vecs.items():
|
79 |
+
sim = cosine_similarity(query_vec, self.text_matrices[field]).flatten()
|
80 |
+
boost = boost_dict.get(field, 1)
|
81 |
+
scores += sim * boost
|
82 |
+
|
83 |
+
# Apply keyword filters
|
84 |
+
for field, value in filter_dict.items():
|
85 |
+
if field in self.keyword_fields:
|
86 |
+
mask = self.keyword_df[field] == value
|
87 |
+
scores = scores * mask.to_numpy()
|
88 |
+
|
89 |
+
# Use argpartition to get top num_results indices
|
90 |
+
top_indices = np.argpartition(scores, -num_results)[-num_results:]
|
91 |
+
top_indices = top_indices[np.argsort(-scores[top_indices])]
|
92 |
+
|
93 |
+
# Filter out zero-score results
|
94 |
+
top_docs = [self.docs[i] for i in top_indices if scores[i] > 0]
|
95 |
+
|
96 |
+
return top_docs
|
src/rag.py
ADDED
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
from time import time
|
3 |
+
from groq import Groq
|
4 |
+
from dotenv import load_dotenv
|
5 |
+
import os
|
6 |
+
import ingest
|
7 |
+
import logging
|
8 |
+
|
9 |
+
# Set up logging
|
10 |
+
logging.basicConfig(level=logging.INFO)
|
11 |
+
logger = logging.getLogger(__name__)
|
12 |
+
|
13 |
+
load_dotenv()
|
14 |
+
|
15 |
+
groq_api_key = os.getenv("GROQ_API_KEY")
|
16 |
+
client = Groq(api_key=groq_api_key)
|
17 |
+
|
18 |
+
# Load the search index
|
19 |
+
try:
|
20 |
+
index = ingest.load_index()
|
21 |
+
except Exception as e:
|
22 |
+
logger.error(f"Failed to load index: {e}")
|
23 |
+
raise
|
24 |
+
|
25 |
+
if index is None:
|
26 |
+
raise ValueError("Search index could not be loaded")
|
27 |
+
|
28 |
+
def search(query):
|
29 |
+
try:
|
30 |
+
results = index.search(
|
31 |
+
query=query,
|
32 |
+
num_results=10
|
33 |
+
)
|
34 |
+
return results
|
35 |
+
except Exception as e:
|
36 |
+
logger.error(f"Error in search function: {e}")
|
37 |
+
return []
|
38 |
+
|
39 |
+
prompt_template = """
|
40 |
+
You are an expert mental health assistant specialized in providing detailed and accurate answers based on the given context. Answer the QUESTION based on the CONTEXT from our mental health database. Use only the facts from the CONTEXT when answering the QUESTION.
|
41 |
+
|
42 |
+
Here is the context:
|
43 |
+
|
44 |
+
Context: {context}
|
45 |
+
|
46 |
+
Please answer the following question based on the provided context:
|
47 |
+
|
48 |
+
Question: {question}
|
49 |
+
|
50 |
+
Provide a detailed and informative response. Ensure that your answer is clear, concise, and directly addresses the question while being relevant to the context provided.
|
51 |
+
|
52 |
+
Your response should be in plain text and should not include any code blocks or extra formatting.
|
53 |
+
|
54 |
+
Answer:
|
55 |
+
""".strip()
|
56 |
+
|
57 |
+
entry_template = """
|
58 |
+
questions={Questions}
|
59 |
+
answers={Answers}
|
60 |
+
""".strip()
|
61 |
+
|
62 |
+
def build_prompt(query, search_results):
|
63 |
+
context = ""
|
64 |
+
for doc in search_results:
|
65 |
+
context = context + entry_template.format(**doc) + "\n\n"
|
66 |
+
prompt = prompt_template.format(question=query, context=context).strip()
|
67 |
+
return prompt
|
68 |
+
|
69 |
+
def llm(prompt, model="mixtral-8x7b-32768"):
|
70 |
+
start_time = time()
|
71 |
+
response = client.chat.completions.create(
|
72 |
+
model=model, messages=[{"role": "user", "content": prompt}]
|
73 |
+
)
|
74 |
+
|
75 |
+
answer = response.choices[0].message.content
|
76 |
+
|
77 |
+
token_stats = {
|
78 |
+
"prompt_tokens": response.usage.prompt_tokens,
|
79 |
+
"completion_tokens": response.usage.completion_tokens,
|
80 |
+
"total_tokens": response.usage.total_tokens,
|
81 |
+
}
|
82 |
+
end_time = time()
|
83 |
+
response_time = end_time - start_time
|
84 |
+
|
85 |
+
return answer, token_stats, response_time
|
86 |
+
|
87 |
+
def evaluate_relevance(question, answer, model='mixtral-8x7b-32768'):
|
88 |
+
eval_prompt = f"""
|
89 |
+
You are an expert evaluator for a Retrieval-Augmented Generation (RAG) system.
|
90 |
+
Your task is to analyze the relevance of the generated answer to the given question.
|
91 |
+
Based on the relevance of the generated answer, you will classify it
|
92 |
+
as "NON_RELEVANT", "PARTLY_RELEVANT", or "RELEVANT".
|
93 |
+
|
94 |
+
Here is the data for evaluation:
|
95 |
+
Question: {question}
|
96 |
+
Answer: {answer}
|
97 |
+
|
98 |
+
Please analyze the content and context of the generated answer in relation to the question
|
99 |
+
and provide your evaluation in parsable JSON without using code blocks:
|
100 |
+
|
101 |
+
"Relevance": "NON_RELEVANT" | "PARTLY_RELEVANT" | "RELEVANT",
|
102 |
+
"Explanation": "[Provide a brief explanation for your evaluation]"
|
103 |
+
""".strip()
|
104 |
+
|
105 |
+
evaluation, tokens, _ = llm(eval_prompt, model)
|
106 |
+
|
107 |
+
try:
|
108 |
+
json_eval = json.loads(evaluation)
|
109 |
+
relevance = json_eval['Relevance'].upper() # Ensure it's uppercase
|
110 |
+
if relevance not in ["NON_RELEVANT", "PARTLY_RELEVANT", "RELEVANT"]:
|
111 |
+
logger.warning(f"Unexpected relevance value: {relevance}. Defaulting to PARTLY_RELEVANT.")
|
112 |
+
relevance = "PARTLY_RELEVANT"
|
113 |
+
return relevance, json_eval['Explanation'], tokens
|
114 |
+
except json.JSONDecodeError:
|
115 |
+
logger.error(f"Failed to parse evaluation JSON: {evaluation}")
|
116 |
+
return "PARTLY_RELEVANT", "Failed to parse evaluation", tokens
|
117 |
+
|
118 |
+
|
119 |
+
def rag(query, model="mixtral-8x7b-32768"):
|
120 |
+
t0 = time()
|
121 |
+
|
122 |
+
search_results = search(query)
|
123 |
+
prompt = build_prompt(query, search_results)
|
124 |
+
answer, tokens, response_time = llm(prompt, model=model)
|
125 |
+
|
126 |
+
relevance, explanation, eval_tokens = evaluate_relevance(query, answer, model=model)
|
127 |
+
|
128 |
+
t1 = time()
|
129 |
+
took = t1 - t0
|
130 |
+
|
131 |
+
answer_data = {
|
132 |
+
'answer': answer,
|
133 |
+
'model_used': model,
|
134 |
+
'response_time': response_time,
|
135 |
+
'relevance': relevance,
|
136 |
+
'relevance_explanation': explanation,
|
137 |
+
'prompt_tokens': tokens['prompt_tokens'],
|
138 |
+
'completion_tokens': tokens['completion_tokens'],
|
139 |
+
'total_tokens': tokens['total_tokens'],
|
140 |
+
'eval_prompt_tokens': eval_tokens['prompt_tokens'],
|
141 |
+
'eval_completion_tokens': eval_tokens['completion_tokens'],
|
142 |
+
'eval_total_tokens': eval_tokens['total_tokens'],
|
143 |
+
}
|
144 |
+
|
145 |
+
return answer_data
|
src/synthetic_data.py
ADDED
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import random
|
3 |
+
from datetime import datetime, timedelta
|
4 |
+
from zoneinfo import ZoneInfo
|
5 |
+
import time
|
6 |
+
import logging
|
7 |
+
from db import save_conversation, save_feedback, get_db_connection
|
8 |
+
import uuid
|
9 |
+
|
10 |
+
# Set up logging
|
11 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
12 |
+
logger = logging.getLogger(__name__)
|
13 |
+
|
14 |
+
# Use the same timezone as in the original code
|
15 |
+
TZ_INFO = os.getenv("TZ", "Europe/Berlin")
|
16 |
+
tz = ZoneInfo(TZ_INFO)
|
17 |
+
|
18 |
+
# Sample data for generating synthetic conversations
|
19 |
+
QUESTIONS = [
|
20 |
+
"How can I manage stress?",
|
21 |
+
"What are the symptoms of depression?",
|
22 |
+
"How to improve sleep quality?",
|
23 |
+
"What is cognitive behavioral therapy?",
|
24 |
+
"How to deal with anxiety attacks?",
|
25 |
+
]
|
26 |
+
|
27 |
+
MODELS = ["gemma2-9b-it", "llama-3.1-70b-versatile", "llama3-70b-8192", "mixtral-8x7b-32768"]
|
28 |
+
RELEVANCE_OPTIONS = ["NON_RELEVANT", "PARTLY_RELEVANT", "RELEVANT"]
|
29 |
+
|
30 |
+
def generate_answer(question):
|
31 |
+
return f"Here's some information about {question.lower()[:-1]}: ..."
|
32 |
+
|
33 |
+
def generate_conversation(timestamp):
|
34 |
+
question = random.choice(QUESTIONS)
|
35 |
+
model = random.choice(MODELS)
|
36 |
+
conversation_id = str(uuid.uuid4())
|
37 |
+
|
38 |
+
answer_data = {
|
39 |
+
"answer": generate_answer(question),
|
40 |
+
"model_used": model,
|
41 |
+
"response_time": round(random.uniform(0.5, 3.0), 2),
|
42 |
+
"relevance": random.choice(RELEVANCE_OPTIONS),
|
43 |
+
"relevance_explanation": "This is a synthetic relevance explanation.",
|
44 |
+
"prompt_tokens": random.randint(50, 200),
|
45 |
+
"completion_tokens": random.randint(100, 500),
|
46 |
+
"total_tokens": random.randint(150, 700),
|
47 |
+
"eval_prompt_tokens": random.randint(20, 100),
|
48 |
+
"eval_completion_tokens": random.randint(50, 200),
|
49 |
+
"eval_total_tokens": random.randint(70, 300),
|
50 |
+
}
|
51 |
+
|
52 |
+
return conversation_id, question, answer_data, timestamp
|
53 |
+
|
54 |
+
def generate_feedback(conversation_id, timestamp):
|
55 |
+
feedback = random.choice([-1, 1])
|
56 |
+
return conversation_id, feedback, timestamp
|
57 |
+
|
58 |
+
def populate_historical_data():
|
59 |
+
end_time = datetime.now(tz)
|
60 |
+
start_time = end_time - timedelta(days=7) # Generate a week's worth of data
|
61 |
+
current_time = start_time
|
62 |
+
|
63 |
+
while current_time <= end_time:
|
64 |
+
conversation_id, question, answer_data, timestamp = generate_conversation(current_time)
|
65 |
+
try:
|
66 |
+
save_conversation(conversation_id, question, answer_data, timestamp)
|
67 |
+
logger.info(f"Saved historical conversation: {conversation_id} at {timestamp}")
|
68 |
+
|
69 |
+
# Generate feedback for some conversations
|
70 |
+
if random.random() < 0.7: # 70% chance of feedback
|
71 |
+
feedback_timestamp = timestamp + timedelta(minutes=random.randint(1, 10))
|
72 |
+
save_feedback(*generate_feedback(conversation_id, feedback_timestamp))
|
73 |
+
logger.info(f"Saved historical feedback for conversation: {conversation_id}")
|
74 |
+
except Exception as e:
|
75 |
+
logger.error(f"Error saving historical data: {e}")
|
76 |
+
|
77 |
+
current_time += timedelta(minutes=random.randint(5, 60))
|
78 |
+
|
79 |
+
def generate_live_data():
|
80 |
+
while True:
|
81 |
+
timestamp = datetime.now(tz)
|
82 |
+
conversation_id, question, answer_data, _ = generate_conversation(timestamp)
|
83 |
+
try:
|
84 |
+
save_conversation(conversation_id, question, answer_data, timestamp)
|
85 |
+
logger.info(f"Generated live conversation: {conversation_id} at {timestamp}")
|
86 |
+
|
87 |
+
# Generate feedback for some conversations
|
88 |
+
if random.random() < 0.7: # 70% chance of feedback
|
89 |
+
feedback_timestamp = timestamp + timedelta(seconds=random.randint(30, 300))
|
90 |
+
save_feedback(*generate_feedback(conversation_id, feedback_timestamp))
|
91 |
+
logger.info(f"Generated live feedback for conversation: {conversation_id}")
|
92 |
+
except Exception as e:
|
93 |
+
logger.error(f"Error saving live data: {e}")
|
94 |
+
|
95 |
+
time.sleep(random.uniform(1, 5)) # Wait for 1-5 seconds before generating the next data point
|
96 |
+
|
97 |
+
if __name__ == "__main__":
|
98 |
+
logger.info("Starting synthetic data generation")
|
99 |
+
|
100 |
+
# Ensure database connection is working
|
101 |
+
try:
|
102 |
+
conn = get_db_connection()
|
103 |
+
conn.close()
|
104 |
+
logger.info("Database connection successful")
|
105 |
+
except Exception as e:
|
106 |
+
logger.error(f"Failed to connect to the database: {e}")
|
107 |
+
exit(1)
|
108 |
+
|
109 |
+
logger.info("Populating historical data...")
|
110 |
+
populate_historical_data()
|
111 |
+
logger.info("Historical data population complete")
|
112 |
+
|
113 |
+
logger.info("Starting live data generation...")
|
114 |
+
generate_live_data()
|