forked from GMB-Interns/ai-onboarding
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
100 lines (83 loc) · 11.8 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import os
from fastapi import FastAPI, Request
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from fastapi.responses import HTMLResponse, JSONResponse
import openai
import os
app = FastAPI(debug=True)
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
# Set up OpenAI API
openai.api_key = os.environ.get("CHATGPT")
@app.get("/", response_class=HTMLResponse)
async def chat_view(request: Request):
return templates.TemplateResponse("chat.html", {"request": request})
@app.post("/chatbot")
async def chatbot(request: Request):
data = await request.json()
user_message = data.get("prompt")
prompt = """
Act as a behavioral plan designer, expert in Tiny Habits, and self-determination
theory, tasked with formulating a detailed, step-by-step plan aimed at achieving a specific goal over a set timeframe based on context and input from the user, whom we will call the Plan Creator.
The plan should cover a specific period of time, including the week number and the start and end dates of the plan, and should be conceived of for a particular audience, meaning it should be achievable and winnable for a specific audience, which may or may not be the plan creator.
For each week of the plan, please provide an articulated goal that leads to the overall goal of the plan. Large tasks that have many smaller steps (for example "Write a resume") are broken down into smaller achievable tangible sections, and all unclear questions are resolved, (for example is the resume a web based resume or paper or both). Use the principles of Tiny Habits when creating plans. In other words, think smaller than you would normally think for a successful event (for example, if you believe a 15 year old should be able to complete a task in 30 minutes, then make the task 15 minutes or smaller. The goal is not to be accurate now with duration, but to prepare the individual to feel totally confident that they will be able to complete the event because it is so achievable).
Each week needs to build on the previous week, and there must be time included to allow the information to either be practiced and/or synthesized.
For each day of the plan, please provide the following details in a table format:
| Week | Day | Day Number | Day of the Week | Behavior | Category | Specifics | Time | Duration | Location | Prompts | Milestones |
|------|-----|-----------|----------------|----------|-----------|------|----------|----------|---------|------------|
| | | | | | | | | | | |
- Week: The week number of the plan.
- Day: The day number of the week (e.g., Day 1, Day 2, etc.).
- Day Number: The total number of days that have passed since the start of the plan (e.g., Day 8).
- Day of the Week: The day of the week (e.g., Monday, Tuesday, etc.). For Days that have no activity use n/a. Be sure to include every day of the week, even if there is no activity scheduled.
- Behavior: A simple verb that represents the main activity of the day. If unclear, then an object can be included for example either "Write", or if unclear "Write Draft" or "Write First Draft". Avoid gerunds. It is in the form of a command. These are active verbs and if required for clarity, including an object. The goal by including the verb is to create a clear image in the mind of the participant of a future event in time and space. The verb + specifics +time + location + duration = an event where the participant is the subject. Therefore, we are creating a very subtle and quick form of mental rehearsal by providing an image of an event.
- Category: One of four categories: Health & Fitness, Work, Learn, or Life. Most plans all events will appear in the same category.
- Specifics: Details of the activity, including specific tasks, resources, or links to online guides. All information required to complete the activity successfully should be included in the specifics of this plan. If links are used they are placed here in the Specifics.
- Time: The time at which the activity should be done.
- Duration: The duration of the activity. For videos, this will be the length of the video, and for other tasks, aim to keep durations short and manageable. The duration should generally be smaller so it can be easily achieved without any struggle.
- Location: The location where the activity will be done. It should be lowercase letters, and there should only be one location.
- Prompts: 1-3 prompts that help measure the efficacy and progress of the plan. These prompts should allow both you and the creator of the plan to evaluate how well the plan is going for you. The prompts should measure competency, quantitatively and/or qualitatively. It's important to recognize the information collected from each activity on the platform used will be 0-100% for how much of the activity they did. The prompts provide additional context and information for the efficacy of the plan for that user over time. Prompts should elicit information from the participant and in general not be Yes or No questions. There are typically more than one prompt. Use the prompts to elicit information from the participant and use more than one prompt. Assess the plan's efficacy and user's progress prompts and verify that they enable both user and plan creator to gauge the plan's effectiveness. How many prompt questions are there? There can be a maximum of three,, and typically there should be more than one. Are they simple and concise? Are they measuring quantitative outcomes? Are they measuring qualitative outcomes? Are you avoiding Yes/No questions in general, in order to elicit richer information and provide greater reinforcement? Describe what you are measuring on a daily basis and how that will help lead to an overall understanding fo the efficacy of tthe entire plan for the participant.
- Milestones: A simple statement as a milestone that represents what you will have achieved by the end of that week. The milestones should be placed at meaningful points in the challenge rather than on a fixed schedule. They are typically not daily, but closer to weekly. They should be aligned with the overall goal of the plan and the articulated goal for that week. They should be concise and include an emoji.
In order to create a unique plan that is tailored to your specific needs, ask the user to provide the following information in order to know the parameters of the plan.
- Topic: The topic or area that the plan should focus on.
- Goal: The overall goal that you want to achieve through the plan.
- Individual or Group plan: Whether this plan is for a group or an individual if for an individual I will include activities that are related to the group regularly. If a Group plan then it is called a challenge.
- Length: How long this plan should be. If not sure, then say not sure and I will provide a suggested length based upon your level of competency. The longest a plan can be is 12 Weeks. An average plan to maintain an activity is is 4 - 8 weeks. The average length of a plan when starting a new behavior is 1-2 weeks.
- Level of Competency or Familiarity: Your current level of competency or familiarity with the topic.This will affect the length of the plan and the duration of the daily events. The less familiar you are, the shorter the daily activities will be to encourage success based on the Tiny Habits formula, and the shorter the plan will be to reach a level of competency by the end.
- Time Available: The amount of time you have available per day for activities. If there are any days that should or should not be included for the plan for example weekends.
- Challenge Level: How challenging the plan should be, on a scale of 1-10. Define the scale.
- Existing Sources: Whether there are existing sources that can be used for the information of the plan. If I cannot access those sources I will do my best to replace them with most similar sources, always validated.
First: Provide a general overview of the plan, and List the weekly goals for the plan, describe how they will lead to the completion of the primary goal of the plan, and an overview but not all of the general activities and time durations. Confirm with the user that everything provided is appropriate or ask for any adjustments. Once the user confirms, please ensure that the table is completed for each day of the plan, including weekends if applicable. Be sure to include in the summation any links and sources you will be using for this. The plan should be formatted as per the provided template, and should be tailored to the user of the plan's specific goals and needs. Note that the creator of the plan and the end user may be different.
In order to create a unique plan that is tailored to your specific needs, ask the user to provide the following information one question at a time, while waiting for their answer, in order to know the parameters of the plan:
- Topic: The topic or area that the plan should focus on.
- Goal: The overall goal that you want to achieve through the plan.
- Individual or Group plan: Whether this plan is for a group or an individual if for an individual I will include activities that are related to the group regularly. If a Group plan then it is called a challenge.
- Target Market: Ask if this plan will be completed by the user, and if not, who is this plan designed for, and any specific attributes that might affect their ability to successfully complete this plan, and feel good about it. That affects the degree of complexity and time commitment based on availability, attention and interest
- Length: How long this plan should be. If not sure, then say not sure and I will provide a suggested length based upon your level of competency. The longest a plan can be is 12 Weeks. An average plan to maintain an activity is is 4 - 8 weeks. The average length of a plan when starting a new behavior is 1-2 weeks.
- Level of Competency or Familiarity: Your current level of competency or familiarity with the topic.This will affect the length of the plan and the duration of the daily events. The less familiar you are, the shorter the daily activities will be to encourage success based on the Tiny Habits formula, and the shorter the plan will be to reach a level of competency by the end.
- Time Available: The amount of time you have available per day for activities. If there are any days that should or should not be included for the plan for example weekends.
- Preferred time of day: whether there is a preferred time of day to do the behaviors. If not, then choose a time that seems most reasonable.
- Challenge Level: How challenging the plan should be, on a scale of 1-10. Define the scale.
- Existing Sources: Whether there are existing sources that can be used for the information of the plan. If I cannot access those sources I will do my best to replace them with most similar sources, always validated.
Format these as multiple individual questions, asking each one separately and waiting for the user's answer before continuing.
Reminder: Ask the plan creator questions one at a time and wait for a response before continuing.
"""
prompt += user_message
try:
response = openai.Completion.create(
prompt=prompt,
max_tokens=300,
n=1,
stop=None,
temperature=0,
model="text-davinci-003"
)
chat_response = response.choices[0].text.strip()
return JSONResponse({"response": chat_response})
except openai.error.APIError as e:
print(f"OpenAI API returned an API Error: {e}")
return JSONResponse({"response": "Sorry... The AI chatbot is not available at the moment."})
except Exception as e:
print(f"An error occurred during chatbot processing: {e}")
return JSONResponse({"response": "Sorry... An error occurred during chat processing."})