Rakshitjan commited on
Commit
a364f09
·
verified ·
1 Parent(s): e6096a7

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +1 -222
main.py CHANGED
@@ -1,225 +1,3 @@
1
- # from fastapi import FastAPI, HTTPException
2
- # from pydantic import BaseModel
3
- # import json
4
- # import openai
5
- # from typing import List, Dict, Any, Optional
6
- # import os
7
-
8
- # app = FastAPI()
9
-
10
- # class RoadmapInput(BaseModel):
11
- # overall_study_pattern: str
12
- # memorization_study_pattern: str
13
- # problem_solving_study_pattern: str
14
- # visualization_study_pattern: str
15
- # obstacle_study_pattern: str
16
- # new_topic_approach: str
17
- # old_topic_approach: str
18
- # topic_ratio: str
19
- # hours_of_study: str
20
- # hours_of_study_weekends: str
21
- # revision_days: str
22
- # test_days: str
23
- # completed_phy_chapters: List[str]
24
- # completed_chem_chapters: List[str]
25
- # completed_maths_chapters: List[str]
26
- # startphyRoadmapFrom: str
27
- # startchemRoadmapFrom: str
28
- # startmathRoadmapFrom: str
29
- # userleft_topic_phy: List[dict]
30
- # userleft_topic_chem: List[dict]
31
- # userleft_topic_maths: List[dict]
32
-
33
- # output_structure = """
34
- # {
35
- # "schedule": [
36
- # "days": [
37
- # {
38
- # "dayNumber": int,
39
- # "subjects": [
40
- # {
41
- # "name": "string",
42
- # "tasks": [
43
- # {
44
- # "type": "string",
45
- # "topic": "string",
46
- # "time": "string"
47
- # }
48
- # ]
49
- # }
50
- # ]
51
- # }
52
- # ]
53
- # ]
54
- # }
55
- # """
56
-
57
- # # Function to remove completed chapters from each subject
58
- # def remove_completed_chapters(subject_data, completed_chapters):
59
- # subject_data["chapters"] = [chapter for chapter in subject_data["chapters"]
60
- # if chapter["chapter"] not in completed_chapters]
61
- # return subject_data
62
-
63
- # # Function to get topics within timeframe
64
- # def get_topics_within_timeframe(subject, allowed_time, start_subtopic):
65
- # collected_subtopics = []
66
- # time_spent = 0
67
- # start_collecting = False
68
-
69
- # if 'chapters' not in subject:
70
- # print(f"Error: 'chapters' key not found in the subject: {subject}")
71
- # return collected_subtopics
72
-
73
- # for chapter in subject["chapters"]:
74
- # if 'subtopics' not in chapter:
75
- # print(f"Error: 'subtopics' key not found in the chapter: {chapter}")
76
- # continue
77
-
78
- # for subtopic in chapter["subtopics"]:
79
- # if (subtopic["subtopic"] == start_subtopic):
80
- # start_collecting = True
81
- # continue
82
-
83
- # if start_collecting and subtopic["subtopic_hours"]:
84
- # time_spent += float(subtopic["subtopic_hours"])
85
- # if time_spent <= allowed_time:
86
- # collected_subtopics.append({
87
- # "chapter": chapter["chapter"],
88
- # "subtopic": subtopic["subtopic"],
89
- # "subtopic_hours": subtopic["subtopic_hours"]
90
- # })
91
- # else:
92
- # break
93
- # if time_spent > allowed_time:
94
- # break
95
-
96
- # return collected_subtopics
97
-
98
-
99
- # @app.post("/generate_roadmap")
100
- # async def generate_roadmap(input_data: RoadmapInput):
101
- # try:
102
- # # Load JSON data for each subject
103
- # with open('Physics.json', 'r', encoding='utf-8') as file:
104
- # phy = json.load(file)
105
-
106
- # with open('Chemistry.json', 'r', encoding='utf-8') as file:
107
- # chem = json.load(file)
108
-
109
- # with open('Maths.json', 'r', encoding='utf-8') as file:
110
- # maths = json.load(file)
111
-
112
-
113
-
114
- # # Remove completed chapters
115
- # phy = remove_completed_chapters(phy, input_data.completed_phy_chapters)
116
- # chem = remove_completed_chapters(chem, input_data.completed_chem_chapters)
117
- # maths = remove_completed_chapters(maths, input_data.completed_maths_chapters)
118
- # total_time=10;
119
- # # Get topics within timeframe
120
- # physics_topics = get_topics_within_timeframe(phy, total_time, input_data.startphyRoadmapFrom)
121
- # chemistry_topics = get_topics_within_timeframe(chem, total_time, input_data.startchemRoadmapFrom)
122
- # mathematics_topics = get_topics_within_timeframe(maths, total_time, input_data.startmathRoadmapFrom)
123
-
124
- # for topic in reversed(input_data.userleft_topic_phy):
125
- # physics_topics.insert(0, topic)
126
- # for topic in reversed(input_data.userleft_topic_chem):
127
- # chemistry_topics.insert(0, topic)
128
- # for topic in reversed(input_data.userleft_topic_maths):
129
- # mathematics_topics.insert(0, topic)
130
-
131
- # print(physics_topics)
132
- # print(chemistry_topics)
133
- # print(mathematics_topics)
134
-
135
- # # User persona string
136
- # userPersona = f"""
137
- # You are required to generate a highly personalized roadmap for a student studying Physics, Chemistry, and Mathematics for the JEE Main exam.
138
- # The roadmap should be tailored based on the following student-specific details:
139
-
140
- # 1. *Study Preferences:*
141
- # - Study Pattern: {input_data.overall_study_pattern}
142
- # - Memorization Approach: {input_data.memorization_study_pattern}
143
- # - Problem-Solving Approach: {input_data.problem_solving_study_pattern}
144
- # - Visualization Approach: {input_data.visualization_study_pattern}
145
-
146
- # 2. *Handling Challenges:*
147
- # - If unable to understand a topic: {input_data.obstacle_study_pattern}
148
- # - Approach to New Topics: {input_data.new_topic_approach}
149
- # - Approach to Previously Encountered Topics: {input_data.old_topic_approach}
150
-
151
- # 3. *Study Hours:*
152
- # - Weekdays: {input_data.hours_of_study} hours/day
153
- # - Weekends: {input_data.hours_of_study_weekends} hours/day
154
- # - Time Allocation Ratio (Physics:Chemistry:Mathematics): {input_data.topic_ratio}
155
- # - By weekdays I mean day 1, day 2 , day 3 , day 4 , day 5
156
- # - By weekends I mean day 6 , day 7
157
- # """
158
-
159
- # # System prompt
160
- # sys_prompt = f"""
161
- # You are required to generate a highly personalized roadmap for a student studying Physics, Chemistry, and Mathematics for the JEE Main exam.
162
- # The roadmap should be tailored based on the following student-specific details:
163
-
164
- # The roadmap must be provided in the following format:
165
- # {output_structure}
166
-
167
- # Do not include anything other than the roadmap, and ensure the focus remains strictly on the subjects {physics_topics}, {chemistry_topics}, and {mathematics_topics} and associated chapters.
168
- # MAKE SURE THAT YOU MAKE THE ROADMAP FOR ALL THE THREE CHAPTERS EACH OF PHYSICS , CHEMISTRY AND MATHS TO COMPLETE THOSE CHAPTERS WITH 4 ASPECTS i.e "CONCEPT UNDERSTANDING","QUESTION PRACTICE","REVISION","TEST". ALSO INCLUDE TIME FOR EACH TASK THAT YOU GENERATE
169
- # MAKE SURE THAT WE FIRST COMPLETE 1) CONCEPT UNDERSTANDING , 2) QUESTION PRACTICE FOR EVERY SUBTOPIC AND THEN REVISION AND TEST FOR WHOLE CHAPTER TOGETHER.
170
- # MAKE SURE THAT WE INCLUDE EACH SUBTOPIC OF EACH CHAPTER FROM {physics_topics},{chemistry_topics} and {mathematics_topics} IS FINISHED
171
- # YOU ARE NOT CONSTRAINED TO CREATE A ROADMAP FOR ONLY 'X' NUMBER OF DAYS , YOU CAN EXTEND TILL THE TOPICS ARE FINISHED BUT ONLY STICK TO THE TIMEFRAME ALLOTED FOR EACH SUBJECT AND DO NOT GO ABOVE OR BELOW THAT TIME FRAME.
172
- # """
173
- # openai.api_key=os.getenv("KEY")
174
- # # First LLM call
175
- # response = openai.ChatCompletion.create(
176
- # model="gpt-4o-mini",
177
- # messages=[
178
- # {
179
- # "role": "system",
180
- # "content": sys_prompt + "MAKE SURE YOU VERY VERY STRICTLY FOLLOW THE JSON STRUCTURE BECAUSE I WILL PARSE YOUR OUTPUT TO JSON"
181
- # },
182
- # {
183
- # "role": "user",
184
- # "content": userPersona
185
- # }
186
- # ]
187
- # )
188
-
189
- # answer = response['choices'][0]['message']['content'].strip()
190
-
191
- # # Calculate provided subtopics
192
- # provided_subtopics = physics_topics + chemistry_topics + mathematics_topics
193
-
194
- # # Second LLM call
195
- # response = openai.ChatCompletion.create(
196
- # model="gpt-4o-mini",
197
- # messages=[
198
- # {
199
- # "role": "system",
200
- # "content": f'''
201
- # you created a very good roadmap {answer} but you make sure that you dont forget any subtopics from {provided_subtopics}. ensure that the style is same as the previous roadmap.
202
- # MAKE SURE YOU VERY VERY STRICTLY FOLLOW THE JSON STRUCTURE BECAUSE I WILL PARSE YOUR OUTPUT TO JSON.
203
- # DO not include json at the top of the answer
204
- # '''
205
- # },
206
- # {
207
- # "role": "user",
208
- # "content": "Generate"
209
- # }
210
- # ]
211
- # )
212
-
213
- # answer = response['choices'][0]['message']['content'].strip()
214
- # parsed_json = json.loads(answer)
215
-
216
- # return parsed_json
217
- # except Exception as e:
218
- # raise HTTPException(status_code=500, detail=str(e))
219
-
220
- # if __name__ == "__main__":
221
- # import uvicorn
222
- # uvicorn.run(app, host="0.0.0.0", port=8000)
223
  import json
224
  from fastapi import FastAPI, HTTPException
225
  from pydantic import BaseModel
@@ -342,6 +120,7 @@ async def generate_roadmap(study_input: StudyInput):
342
  MAKE SURE THAT WE FIRST COMPLETE 1) CONCEPT UNDERSTANDING , 2) QUESTION PRACTICE FOR EVERY SUBTOPIC AND THEN REVISION AND TEST FOR WHOLE CHAPTER TOGETHER.
343
  MAKE SURE THAT WE INCULDE EACH SUBTOPIC OF EACH CHAPTER FROM {phy},{chem} and {maths} IS FINISHED
344
  YOU ARE NOT CONSTRAINED TO CREATE A ROADMAP FOR ONLY 'X' NUMBER OF DAYS , YOU CAN EXTEND TILL THE TOPICS ARE FINISHED BUT ONLY STICK TO THE TIMEFRAME ALLOTED FOR EACH SUBJECT AND DO NOT GO ABOVE OR BELOW THAT TIME FRAME.
 
345
  """
346
 
347
  # Make OpenAI API call
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import json
2
  from fastapi import FastAPI, HTTPException
3
  from pydantic import BaseModel
 
120
  MAKE SURE THAT WE FIRST COMPLETE 1) CONCEPT UNDERSTANDING , 2) QUESTION PRACTICE FOR EVERY SUBTOPIC AND THEN REVISION AND TEST FOR WHOLE CHAPTER TOGETHER.
121
  MAKE SURE THAT WE INCULDE EACH SUBTOPIC OF EACH CHAPTER FROM {phy},{chem} and {maths} IS FINISHED
122
  YOU ARE NOT CONSTRAINED TO CREATE A ROADMAP FOR ONLY 'X' NUMBER OF DAYS , YOU CAN EXTEND TILL THE TOPICS ARE FINISHED BUT ONLY STICK TO THE TIMEFRAME ALLOTED FOR EACH SUBJECT AND DO NOT GO ABOVE OR BELOW THAT TIME FRAME.
123
+ Make sure you make the roadmap for 7-10 days only.
124
  """
125
 
126
  # Make OpenAI API call