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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# # main.py
# from fastapi import FastAPI, HTTPException
# from pydantic import BaseModel
# from typing import Dict
# import os
# from groq import Groq

# app = FastAPI()

# # Pydantic model for request
# class ScoreInput(BaseModel):
#     score_percentages: Dict[str, float]
#     time_percentages: Dict[str, float]

# # Helper functions
# def get_final_score(score_percentages: Dict[str, float], time_percentages: Dict[str, float]) -> Dict[str, float]:
#     final_score = {}
#     for skill in score_percentages:
#         score_avg = (score_percentages[skill] + time_percentages[skill]) / 2
#         final_score[skill] = score_avg
#     return final_score

# def get_strengths_and_weaknesses(final_score: Dict[str, float]):
#     sorted_skills = sorted(
#         [(skill, score) for skill, score in final_score.items()],
#         key=lambda item: item[1],
#         reverse=True
#     )
#     num_skills = len(sorted_skills)
#     if num_skills == 0:
#         return [], [], []
    
#     split1 = num_skills // 3
#     split2 = 2 * (num_skills // 3)
    
#     strengths = sorted_skills[:split1]
#     opportunities = sorted_skills[split1:split2]
#     challenges = sorted_skills[split2:]
    
#     return strengths, opportunities, challenges

# # FastAPI route
# @app.post("/analyze")
# async def analyze_scores(input_data: ScoreInput):
#     final_score = get_final_score(input_data.score_percentages, input_data.time_percentages)
#     strengths, opportunities, challenges = get_strengths_and_weaknesses(final_score)

#     # Groq API call
#     api_key = os.getenv("GROQ_API_KEY")
#     if not api_key:
#         raise HTTPException(status_code=500, detail="Groq API key not found")

#     client = Groq(api_key=api_key)
#     sys_prompt = f"""You are an advanced language model trained to analyze student responses from a questionnaire on Academic, Cognitive, and Study Profile aspects related to JEE Mains preparation. Your task is to generate a personalized SCO (Strengths, Challenges, Opportunities) analysis and an Action Plan section based on the user's inputs.
#     You have been provided with the strengths {strengths}, Opportunities {opportunities} and Challenges {challenges} skills of the user
#     Output Structure:
#     SCO Analysis:
#     Strengths:
#     - List the student's strengths based on their {strengths} skills
#     - Let the student now how they can use these strengths in their JEE preparation and exam to improve their score.
#     - Also tell them how do they improve their score more.
#     Opportunities:
#     - List the student's strengths based on their {opportunities} skills
#     - Suggest opportunities for improvement by leveraging the student's strengths and addressing their challenges.
#     - Recommend ways to enhance their score in the {opportunities} skills.
#     - Also tell them if they improve in these skills what opportunities they have in improving their scores
#     Challenges:
#     - List the student's strengths based on their {challenges} skills
#     - Guide the student that these skills are basically the core area where they are lacking
#     - Tell them that if they continue not focusing upon them they might get far away from their JEE goal.
#     Action Plan:
#     - Provide a detailed plan to the student to improve in the {challenges} skills.
#     - Recommend targeted strategies, resources, and techniques to improve their {challenges} skills.
#     - Let them know if they improve these areas how it can help boost their scores and make their preparation more effective.
#     - Incorporate time management, revision, and test-taking strategies specific to JEE Mains and the identified subjects/topics/subtopics.

#     Things that LLM need to make sure:
#     1) Your analysis and action plan should be comprehensive, consistent, and tailored to the individual student's responses while leveraging your knowledge of the JEE Mains exam context, the mapping of subjects/topics to general cognitive traits and skills, and the ability to identify overarching trends across related subjects/topics.
#     2) Make sure you give the output that extracts the student.
#     3) Make sure you give out output in bullet points.
#     4) While entering a new line in the output use "\n" new line character.
#     5) Make the output very much JEE (Joint Entrance Examination) based and give everything with context to Physics , Chemistry and Maths JEE syllabus.
#     6) Use Italics, Bold and underline appropriately to improve the output more.
#     7) Bold text where you are taking chapter names from Physics , Chemsitry and Maths only which are in syllabus of Joint Entrance Examination.
#     8) Dont use "+" or any other special symbol whenever you want to break a line use "\n" to do it in the output.
#     """
    

#     try:
#         chat_completion = client.chat.completions.create(
#             messages=[
#                 {"role": "system", "content": sys_prompt},
#                 {"role": "user", "content": f"Generate the SOCA analysis based on the system prompt and {strengths}, {opportunities} and {challenges}. MAKE SURE WE STRICTLY FOLLOW THE STRUCTURE."},
#             ],
#             model="llama3-70b-8192",
#         )
#         analysis = chat_completion.choices[0].message.content
#     except Exception as e:
#         raise HTTPException(status_code=500, detail=f"Error calling Groq API: {str(e)}")

#     return {"analysis": analysis}

# if __name__ == "__main__":
#     import uvicorn
#     uvicorn.run(app, host="0.0.0.0", port=8000)




# Merger of SOCA v1 and SOCA v2
from embedchain import App
from fastapi import FastAPI, HTTPException
from mangum import Mangum
from pydantic import BaseModel
from typing import Dict
import os
from groq import Groq

app = FastAPI()
handler = Mangum(app)

#SOCA V1 CODE START

api_key1 = os.getenv('GROQ_API_KEY')

config = {
    'llm': {
    'provider': 'groq',
    'config': {
    'model':'llama3-70b-8192',
            'top_p': 0.5,
            'api_key': api_key1,
            'stream': True
            }
    },
    'embedder': {
        'provider': 'huggingface',
        'config': {
            'model': 'sentence-transformers/all-mpnet-base-v2'
      }
    }
}

swot_bot = App.from_config(config=config)

swot_bot.add("web_page","https://www.allen.ac.in/engineering/jee-main/tips-tricks/")
# swot_bot.add("https://motion.ac.in/blog/jee-main-weightage-chapter-wise/")
swot_bot.add("https://www.allen.ac.in/engineering/jee-main/preparation-strategy/")
#swot_bot.add("https://byjus.com/jee/how-to-prepare-for-jee-at-home/")
swot_bot.add("https://www.askiitians.com/iit-jee/how-to-prepare-for-iit-jee-from-class-11.html")
# swot_bot.add("https://byjus.com/jee/complete-study-plan-to-crack-jee-main/")
#swot_bot.add("https://mystudycart.com/iit-jee-preparation")
swot_bot.add("https://engineering.careers360.com/articles/how-prepare-for-jee-main")

swot_bot.add("https://www.allenoverseas.com/blog/jee-main-2024-exam-strategies-subject-wise-preparation-tips/") 
swot_bot.add("https://www.vedantu.com/jee-main/topics")
swot_bot.add("https://www.pw.live/exams/wp-content/uploads/2024/01/syllabus-for-jee-main-2024-as-on-01-november-2023-1-3.pdf")        
swot_bot.add("https://www.pw.live/exams/wp-content/uploads/2024/01/syllabus-for-jee-main-2024-as-on-01-november-2023-4-8.pdf")
swot_bot.add("https://www.pw.live/exams/jee/jee-main-chemistry-syllabus/")

swot_bot.add("https://www.pw.live/topics-chemistry-class-11")
swot_bot.add("https://www.pw.live/topics-chemistry-class-12")


system_prompt = """You are an advanced language model trained to analyze student responses from a questionnaire on Academic, Cognitive, and Study Profile aspects related to JEE Mains preparation. Your task is to generate a personalized SCO (Strengths, Challenges, Opportunities) analysis and an Action Plan section based on the user's inputs.
        Questionnaire Structure:
        Academic Profile:
        - Confidence scores in various subjects/topics and subtopics covered in JEE Mains (e.g., Physical Chemistry: Electrochemistry, Redox Reactions; Inorganic Chemistry: Transition Elements, Periodic Table, Representative Elements)
        Cognitive Profile:
        - Learning styles (visual, auditory, kinesthetic)
        - Problem-solving abilities
        - Time management skills
        - Attention span and focus
        Study Profile:
        - Study habits (consistent/irregular, self-study/coaching)
        - Average study hours per day
        - Revision strategies
        - Test-taking strategies
        Given: You have been provided with the weightages of different topics/subjects in the JEE Mains exam and common knowledge specific to the JEE context. Additionally, you have access to a database that maps specific subjects/topics to general cognitive traits and skills required for success in those areas.
        Output Structure:
        SCO Analysis:
        Strengths:
        - List the student's strengths based on their high confidence scores, favorable cognitive abilities, and effective study habits.
        - Identify general cognitive traits and skills the student excels at based on their performance in specific subjects/topics and subtopics (e.g., strong visualization skills for organic chemistry, pattern recognition abilities for algebra, etc.)
        - Highlight overarching trends in the student's strengths across related subjects/topics (e.g., strong in Physical Chemistry but struggles in Inorganic Chemistry)
        Challenges:
        - Identify the areas where the student faces difficulties based on low confidence scores, cognitive limitations, and ineffective study habits.
        - Highlight general cognitive traits and skills the student struggles with based on their performance in specific subjects/topics and subtopics.
        - Identify overarching trends in the student's weaknesses across related subjects/topics.
        Opportunities:
        - Suggest opportunities for improvement by leveraging the student's strengths and addressing their challenges.
        - Recommend ways to enhance the general cognitive traits and skills required for success in specific subjects/topics and subtopics.
        Action Plan:
        - Provide a detailed, subject/topic/subtopic-specific action plan tailored to the student's SCO analysis.
        - Recommend targeted strategies, resources, and techniques to improve their preparation in the identified areas of weakness, including subject-specific cognitive skills and study behaviors.
        - Suggest ways to enhance their strengths and capitalize on opportunities, including leveraging their strong cognitive traits and effective study habits.
        - Incorporate time management, revision, and test-taking strategies specific to JEE Mains and the identified subjects/topics/subtopics.
        - Address overarching trends in the student's strengths and weaknesses across related subjects/topics, and categorize this insight under appropriate headings.
        |
        Your analysis and action plan should be comprehensive, consistent, and tailored to the individual student's responses while leveraging your knowledge of the JEE Mains exam context, the mapping of subjects/topics to general cognitive traits and skills, and the ability to identify overarching trends across related subjects/topics."""

#SOCA v1 CODE END



# Pydantic model for request
class ScoreInput(BaseModel):
    score_percentages: Dict[str, float]
    time_percentages: Dict[str, float]
     #SOCA v1 Inputs
    confidence_scores_str: str
    problem_solving_approach: str
    thorough_understanding: str
    feedback: str
    misconception: str
    time_management: str
    time_division: str
    mock_test_frequency: str
    progress_monitoring: str
    study_methods: str
    study_techniques: str

# Helper functions
def get_final_score(score_percentages: Dict[str, float], time_percentages: Dict[str, float]) -> Dict[str, float]:
    final_score = {}
    for skill in score_percentages:
        score_avg = (score_percentages[skill] + time_percentages[skill]) / 2
        final_score[skill] = score_avg
    return final_score

def get_strengths_and_weaknesses(final_score: Dict[str, float]):
    sorted_skills = sorted(
        [(skill, score) for skill, score in final_score.items()],
        key=lambda item: item[1],
        reverse=True
    )
    num_skills = len(sorted_skills)
    if num_skills == 0:
        return [], [], []
    
    split1 = num_skills // 3
    split2 = 2 * (num_skills // 3)
    
    strengths = sorted_skills[:split1]
    opportunities = sorted_skills[split1:split2]
    challenges = sorted_skills[split2:]
    
    return strengths, opportunities, challenges

# FastAPI route
@app.post("/analyze")
async def analyze_scores(input_data: ScoreInput):
    final_score = get_final_score(input_data.score_percentages, input_data.time_percentages)
    strengths, opportunities, challenges = get_strengths_and_weaknesses(final_score)

   

    #SOCA v1 Code Output
    user_response = f"""Confidence score of the student across different subjects out of 10 :{input_data.confidence_scores_str},
    'When faced with complex,multi-stemp problems in JEE, how likely are you to approach problem-solving systematically, breaking down each step ?':{input_data.problem_solving_approach},
    'In your JEE preparation, how likely are you to ensure thorough understanding of fundamental concepts before moving on to advanced topics ?':{input_data.thorough_understanding},
    'How likely are  to integrate feedback from practice tests or teachers into your JEE preparation strategy ?':{input_data.feedback},
    'When encountering a misconception or misunderstanding in a JEE concept, how likely are you to identify and resolve it ?': {input_data.misconception},
    'How likely are you to effectively manage time during JEE exams, especially in sections with limited time constraints?':{input_data.time_management},
    'How do you divide your study time among Physics, Chemistry and Mathematics for JEE ? (Allocate Percentage)': {input_data.time_division},
    'How often do you use mock tests and past question papers for JEE preparation ?': {input_data.mock_test_frequency},
    'How do you monitor your progress in JEE topics or chapters?': {input_data.progress_monitoring},
    'How do you adjust your study methods for difficult or new JEE topics ?':  {input_data.study_methods},
    'What techniques do you use to remember JEE concepts and formulas for a long time ? eg: Flashcards, Mindmap, etc.': {input_data.study_techniques}"""


    outputSOCAv1 = swot_bot.query(system_prompt + user_response)


    # Groq API call
    api_key2 = os.getenv("GROQ_API_KEY")
    if not api_key2:
        raise HTTPException(status_code=500, detail="Groq API key not found")

    client2 = Groq(api_key=api_key2)
    client3 = Groq(api_key=os.getenv("GROQ_API_KEY"))
    sys_prompt = f"""You are an advanced language model trained to analyze student responses from a questionnaire on Academic, Cognitive, and Study Profile aspects related to JEE Mains preparation. Your task is to generate a personalized SCO (Strengths, Challenges, Opportunities) analysis and an Action Plan section based on the user's inputs.
    You have been provided with the strengths {strengths}, Opportunities {opportunities} and Challenges {challenges} skills of the user
    Output Structure:
    SCO Analysis:
    Strengths:
    - List the student's strengths based on their {strengths} skills
    - Let the student now how they can use these strengths in their JEE preparation and exam to improve their score.
    - Also tell them how do they improve their score more.
    Opportunities:
    - List the student's strengths based on their {opportunities} skills
    - Suggest opportunities for improvement by leveraging the student's strengths and addressing their challenges.
    - Recommend ways to enhance their score in the {opportunities} skills.
    - Also tell them if they improve in these skills what opportunities they have in improving their scores
    Challenges:
    - List the student's strengths based on their {challenges} skills
    - Guide the student that these skills are basically the core area where they are lacking
    - Tell them that if they continue not focusing upon them they might get far away from their JEE goal.
    Action Plan:
    - Provide a detailed plan to the student to improve in the {challenges} skills.
    - Recommend targeted strategies, resources, and techniques to improve their {challenges} skills.
    - Let them know if they improve these areas how it can help boost their scores and make their preparation more effective.
    - Incorporate time management, revision, and test-taking strategies specific to JEE Mains and the identified subjects/topics/subtopics.

    Things that LLM need to make sure:
    1) Your analysis and action plan should be comprehensive, consistent, and tailored to the individual student's responses while leveraging your knowledge of the JEE Mains exam context, the mapping of subjects/topics to general cognitive traits and skills, and the ability to identify overarching trends across related subjects/topics.
    2) Make sure you give the output that extracts the student.
    3) Make sure you give out output in bullet points.
    4) While entering a new line in the output use "\n" new line character.
    5) Make the output very much JEE (Joint Entrance Examination) based and give everything with context to Physics , Chemistry and Maths JEE syllabus.
    6) Bold text where you are taking chapter names from Physics , Chemsitry and Maths only which are in syllabus of Joint Entrance Examination.
    7) Dont use "+" or any other special symbol whenever you want to break a line use "\n" to do it in the output.
    """


    try:
        chat_completion2 = client2.chat.completions.create(
            messages=[
                {"role": "system", "content": sys_prompt},
                {"role": "user", "content": f"Generate the SOCA analysis based on the system prompt and {strengths}, {opportunities} and {challenges}. MAKE SURE WE STRICTLY FOLLOW THE STRUCTURE."},
            ],
            model="llama3-70b-8192",
        )
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"Error calling Groq API: {str(e)}")
    outputSOCAv2= chat_completion2.choices[0].message.content
    system_promptMerge = f""" ROLE 1 : You are an advanced language model trained to analyze student responses from a questionnaire on Academic, Cognitive, and Study Profile aspects related to JEE Mains preparation. Your task is to generate a personalized SCO (Strengths, Challenges, Opportunities) analysis and an Action Plan section based on the user's inputs.
        Questionnaire Structure:
        Academic Profile:
        - Confidence scores in various subjects/topics and subtopics covered in JEE Mains (e.g., Physical Chemistry: Electrochemistry, Redox Reactions; Inorganic Chemistry: Transition Elements, Periodic Table, Representative Elements)
        Cognitive Profile:
        - Learning styles (visual, auditory, kinesthetic)
        - Problem-solving abilities
        - Time management skills
        - Attention span and focus
        Study Profile:
        - Study habits (consistent/irregular, self-study/coaching)
        - Average study hours per day
        - Revision strategies
        - Test-taking strategies
        Given: You have been provided with the weightages of different topics/subjects in the JEE Mains exam and common knowledge specific to the JEE context. Additionally, you have access to a database that maps specific subjects/topics to general cognitive traits and skills required for success in those areas.
        The Analysis of Role 1 is given is {outputSOCAv1}.

        ROLE 2 : You are an advanced language model trained to analyze student responses from a questionnaire on Academic, Cognitive, and Study Profile aspects related to JEE Mains preparation. Your task is to generate a personalized SCO (Strengths, Challenges, Opportunities) analysis and an Action Plan section based on the user's inputs.
    You have been provided with the strengths {strengths}, Opportunities {opportunities} and Challenges {challenges} skills of the user
    The Analysis of Role 2 is {outputSOCAv2}

    Now you have to merge both the outputs of Role 1 and Role 2 and validate them also with each other .
    You are an Expert Joint Entrance Examination teacher who has to generate the Strengths , Oppourtunities , Challenges and Action Plan of a user.
    """

    OutputStructure="""SCO Analysis:
    Strengths:
    - List the student's strengths based on their strengths skills
    - Let the student now how they can use these strengths in their JEE preparation and exam to improve their score.
    - Also tell them how do they improve their score more.
    Opportunities:
    - List the student's strengths based on their opportunities skills
    - Suggest opportunities for improvement by leveraging the student's strengths and addressing their challenges.
    - Recommend ways to enhance their score in the opportunities skills.
    - Also tell them if they improve in these skills what opportunities they have in improving their scores
    Challenges:
    - List the student's strengths based on their challenges skills
    - Guide the student that these skills are basically the core area where they are lacking
    - Tell them that if they continue not focusing upon them they might get far away from their JEE goal.
    Action Plan:
    - Provide a detailed plan to the student to improve in the challenges skills.
    - Recommend targeted strategies, resources, and techniques to improve their challenges skills.
    - Let them know if they improve these areas how it can help boost their scores and make their preparation more effective.
    - Incorporate time management, revision, and test-taking strategies specific to JEE Mains and the identified subjects/topics/subtopics.

    Things that LLM need to make sure:
    1) Your analysis and action plan should be comprehensive, consistent, and tailored to the individual student's responses while leveraging your knowledge of the JEE Mains exam context, the mapping of subjects/topics to general cognitive traits and skills, and the ability to identify overarching trends across related subjects/topics.
    2) Make sure you give the output that extracts the student.
    3) Make sure you give out output in bullet points.
    4) While entering a new line in the output use "\n" new line character.
    5) Make the output very much JEE (Joint Entrance Examination) based and give everything with context to Physics , Chemistry and Maths JEE syllabus.
    6) Use Italics, Bold and underline appropriately to improve the output more.
    7) Bold text where you are taking chapter names from Physics , Chemsitry and Maths only which are in syllabus of Joint Entrance Examination.
    8) Dont use "+" or any other special symbol whenever you want to break a line use "\n" to do it in the output.""" 
    try:
        chat_completion3 = client3.chat.completions.create(
            messages=[
                {"role": "system", "content": system_promptMerge+OutputStructure},
                {"role": "user", "content": f"Generate the SOCA analysis based on the system prompt and {OutputStructure}"},
            ],
            model="llama3-70b-8192",
        )
    except Exception as e:
        raise HTTPException(status_code=500, detail=f"Error calling Groq API: {str(e)}")
    outputSOCAv3= chat_completion3.choices[0].message.content

    return {"analysis": outputSOCAv3}

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)