Rakshitjan commited on
Commit
c57cc4a
·
verified ·
1 Parent(s): 9a35242

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +116 -4
main.py CHANGED
@@ -1,11 +1,123 @@
1
- # main.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  from fastapi import FastAPI, HTTPException
 
3
  from pydantic import BaseModel
4
  from typing import Dict
5
  import os
6
  from groq import Groq
7
 
8
  app = FastAPI()
 
9
 
10
  # Pydantic model for request
11
  class ScoreInput(BaseModel):
@@ -46,11 +158,11 @@ async def analyze_scores(input_data: ScoreInput):
46
  strengths, opportunities, challenges = get_strengths_and_weaknesses(final_score)
47
 
48
  # Groq API call
49
- api_key = os.getenv("GROQ_API_KEY")
50
  if not api_key:
51
  raise HTTPException(status_code=500, detail="Groq API key not found")
52
 
53
- client = Groq(api_key=api_key)
54
  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.
55
  You have been provided with the strengths {strengths}, Opportunities {opportunities} and Challenges {challenges} skills of the user
56
  Output Structure:
@@ -87,7 +199,7 @@ async def analyze_scores(input_data: ScoreInput):
87
 
88
 
89
  try:
90
- chat_completion = client.chat.completions.create(
91
  messages=[
92
  {"role": "system", "content": sys_prompt},
93
  {"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."},
 
1
+ # # main.py
2
+ # from fastapi import FastAPI, HTTPException
3
+ # from pydantic import BaseModel
4
+ # from typing import Dict
5
+ # import os
6
+ # from groq import Groq
7
+
8
+ # app = FastAPI()
9
+
10
+ # # Pydantic model for request
11
+ # class ScoreInput(BaseModel):
12
+ # score_percentages: Dict[str, float]
13
+ # time_percentages: Dict[str, float]
14
+
15
+ # # Helper functions
16
+ # def get_final_score(score_percentages: Dict[str, float], time_percentages: Dict[str, float]) -> Dict[str, float]:
17
+ # final_score = {}
18
+ # for skill in score_percentages:
19
+ # score_avg = (score_percentages[skill] + time_percentages[skill]) / 2
20
+ # final_score[skill] = score_avg
21
+ # return final_score
22
+
23
+ # def get_strengths_and_weaknesses(final_score: Dict[str, float]):
24
+ # sorted_skills = sorted(
25
+ # [(skill, score) for skill, score in final_score.items()],
26
+ # key=lambda item: item[1],
27
+ # reverse=True
28
+ # )
29
+ # num_skills = len(sorted_skills)
30
+ # if num_skills == 0:
31
+ # return [], [], []
32
+
33
+ # split1 = num_skills // 3
34
+ # split2 = 2 * (num_skills // 3)
35
+
36
+ # strengths = sorted_skills[:split1]
37
+ # opportunities = sorted_skills[split1:split2]
38
+ # challenges = sorted_skills[split2:]
39
+
40
+ # return strengths, opportunities, challenges
41
+
42
+ # # FastAPI route
43
+ # @app.post("/analyze")
44
+ # async def analyze_scores(input_data: ScoreInput):
45
+ # final_score = get_final_score(input_data.score_percentages, input_data.time_percentages)
46
+ # strengths, opportunities, challenges = get_strengths_and_weaknesses(final_score)
47
+
48
+ # # Groq API call
49
+ # api_key = os.getenv("GROQ_API_KEY")
50
+ # if not api_key:
51
+ # raise HTTPException(status_code=500, detail="Groq API key not found")
52
+
53
+ # client = Groq(api_key=api_key)
54
+ # 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.
55
+ # You have been provided with the strengths {strengths}, Opportunities {opportunities} and Challenges {challenges} skills of the user
56
+ # Output Structure:
57
+ # SCO Analysis:
58
+ # Strengths:
59
+ # - List the student's strengths based on their {strengths} skills
60
+ # - Let the student now how they can use these strengths in their JEE preparation and exam to improve their score.
61
+ # - Also tell them how do they improve their score more.
62
+ # Opportunities:
63
+ # - List the student's strengths based on their {opportunities} skills
64
+ # - Suggest opportunities for improvement by leveraging the student's strengths and addressing their challenges.
65
+ # - Recommend ways to enhance their score in the {opportunities} skills.
66
+ # - Also tell them if they improve in these skills what opportunities they have in improving their scores
67
+ # Challenges:
68
+ # - List the student's strengths based on their {challenges} skills
69
+ # - Guide the student that these skills are basically the core area where they are lacking
70
+ # - Tell them that if they continue not focusing upon them they might get far away from their JEE goal.
71
+ # Action Plan:
72
+ # - Provide a detailed plan to the student to improve in the {challenges} skills.
73
+ # - Recommend targeted strategies, resources, and techniques to improve their {challenges} skills.
74
+ # - Let them know if they improve these areas how it can help boost their scores and make their preparation more effective.
75
+ # - Incorporate time management, revision, and test-taking strategies specific to JEE Mains and the identified subjects/topics/subtopics.
76
+
77
+ # Things that LLM need to make sure:
78
+ # 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.
79
+ # 2) Make sure you give the output that extracts the student.
80
+ # 3) Make sure you give out output in bullet points.
81
+ # 4) While entering a new line in the output use "\n" new line character.
82
+ # 5) Make the output very much JEE (Joint Entrance Examination) based and give everything with context to Physics , Chemistry and Maths JEE syllabus.
83
+ # 6) Use Italics, Bold and underline appropriately to improve the output more.
84
+ # 7) Bold text where you are taking chapter names from Physics , Chemsitry and Maths only which are in syllabus of Joint Entrance Examination.
85
+ # 8) Dont use "+" or any other special symbol whenever you want to break a line use "\n" to do it in the output.
86
+ # """
87
+
88
+
89
+ # try:
90
+ # chat_completion = client.chat.completions.create(
91
+ # messages=[
92
+ # {"role": "system", "content": sys_prompt},
93
+ # {"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."},
94
+ # ],
95
+ # model="llama3-70b-8192",
96
+ # )
97
+ # analysis = chat_completion.choices[0].message.content
98
+ # except Exception as e:
99
+ # raise HTTPException(status_code=500, detail=f"Error calling Groq API: {str(e)}")
100
+
101
+ # return {"analysis": analysis}
102
+
103
+ # if __name__ == "__main__":
104
+ # import uvicorn
105
+ # uvicorn.run(app, host="0.0.0.0", port=8000)
106
+
107
+
108
+
109
+
110
+ # Merger of SOCA v1 and SOCA v2
111
+ from embedchain import App
112
  from fastapi import FastAPI, HTTPException
113
+ from mangum import Mangum
114
  from pydantic import BaseModel
115
  from typing import Dict
116
  import os
117
  from groq import Groq
118
 
119
  app = FastAPI()
120
+ handler = Mangum(app)
121
 
122
  # Pydantic model for request
123
  class ScoreInput(BaseModel):
 
158
  strengths, opportunities, challenges = get_strengths_and_weaknesses(final_score)
159
 
160
  # Groq API call
161
+ api_key2 = os.getenv("GROQ_API_KEY")
162
  if not api_key:
163
  raise HTTPException(status_code=500, detail="Groq API key not found")
164
 
165
+ client2 = Groq(api_key=api_key2)
166
  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.
167
  You have been provided with the strengths {strengths}, Opportunities {opportunities} and Challenges {challenges} skills of the user
168
  Output Structure:
 
199
 
200
 
201
  try:
202
+ chat_completion = client2.chat.completions.create(
203
  messages=[
204
  {"role": "system", "content": sys_prompt},
205
  {"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."},