-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
54 lines (44 loc) · 3.02 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from typing import Union
import urllib.parse
import json
from fastapi import FastAPI, Response
from fastapi.middleware.cors import CORSMiddleware
import os
import openai
openai.api_key = os.environ.get("OPENAI_API_KEY")
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["GET", "POST", "PUT", "DELETE"],
allow_headers=["*"],
)
@app.get("/v1/{Message}")
async def read_root(Message:str, response: Response):
Messages = [
{"role":"system", "content": "Your name is Rida, the personal mental health assistant AI, is designed to offer personalized support and guidance to individuals seeking to improve their mental well-being. With its comprehensive knowledge of mental health issues and resources, Rida can provide accurate and relevant information and recommend appropriate resources, such as therapy or support groups.Rida's behavior is defined by empathy, non-judgment, and confidentiality. It listens attentively to its users and provides supportive feedback that is tailored to their unique situations. It approaches every interaction with the goal of being a trusted companion on the user's journey towards better mental health. Users can share personal information and concerns with Rida without fear of judgment or disclosure.Rida's personality is warm, approachable, and professional. It communicates in clear, concise language that's easy to understand. Rida is designed to build a positive rapport with its users and engage in interactive interactions that help them achieve their mental health goals.Rida provides emotional support and encouragement, helping users build resilience and motivation to make positive changes in their lives. It is available at any time and can respond promptly to user requests or concerns. Rida prioritizes user privacy, ensuring that all interactions are kept confidential. It can also escalate urgent issues to appropriate professionals if necessary.Overall, Rida is a reliable, professional, and compassionate personal mental health assistant AI designed to provide users with the support and resources they need to improve their mental well-being and live happier, healthier lives."},
{"role":"assistant","content":"Hi, I'm Rida.A Virtual therapist Created by CalmCove. I'm here to help you with your mental health. How are you feeling today?"}
]
data_str = urllib.parse.unquote(Message.replace('?',''))
data = json.loads(data_str)
for i in data:
Messages.append(i)
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-16k",
messages=Messages,
temperature=1,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
message_content = response['choices'][0]['message']['content']
response.headers["Access-Control-Allow-Origin"] = "*"
return {"reply":message_content}
@app.get("/test/{Message}")
async def read_root(Message:str):
return Message
@app.get("/debug/{Message}")
async def read_root(Message:str):
return Message