Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI | |
| from openai import OpenAI | |
| import os | |
| apikey = os.getenv('API_KEY') | |
| app = FastAPI() | |
| client = OpenAI( | |
| api_key=apikey, | |
| ) | |
| async def chat(query: str): | |
| chat_completion = client.chat.completions.create( | |
| messages=[ | |
| { | |
| "role": "system", | |
| "content": """ | |
| Generate me 10 MCQ type questions on the topic asked by the user of Joint Entrance Examination level and also explain the solution of each problem step-wise. And also give a hardness rating out of 100. The questions should have difficulty matching with the level of JEE mains and advanced. | |
| Give me questions which are of very high difficulty level. | |
| Make sure you provide VERY VERY Advanced level questions which cover the given topic properly. Also, the solutions or Hints have to be really relevant and explanatory. | |
| Expected output format: | |
| {"response":"Here are 10 MCQ type questions on the topic of Equilibrium at the level of Joint Entrance Examination (JEE):\n\n**Question 1:**\nQuestion: A container having a fixed volume of 1 liter is filled with 1 mole of a gas. The temperature of the system is increased from 27°C to 127°C. The entropy change of the system is (R = 8.314 J/mol-K)\nOptions: 23.4 J/mol-K,,, 46.8 J/mol-K,,, 29.3 J/mol-K,,, 58.6 J/mol-K\nAnswer: 23.4 J/mol-K\nHardness rating: 80\nSolution: The entropy change of an ideal gas can be calculated using the formula ΔS = nR ln(V2/V1) + nCp ln(T2/T1). Since the volume is constant, the first term is zero. Plugging in the values, we get ΔS = 1 × 8.314 × ln(400/300) = 23.4 J/mol-K.\n\n... (continue for 10 questions)" | |
| VERY IMPORTANT: MAKE SURE YOU STRICTLY FOLLOW THE OUTPUT FORMAT. | |
| VERY IMPORTANT: MAKE SURE THE GIVEN ANSWER FOR EVERY QUESTION EXISTS IN ANY OF THE FOUR OPTIONS. | |
| VERY IMPORTANT: MAKE SURE WE PUT ",,," BETWEEN OPTIONS TO DIFFERENTIATE WELL. For Example: Options: A,,,B,,,C,,,D | |
| """ | |
| }, | |
| { | |
| "role": "user", | |
| "content": query, | |
| } | |
| ], | |
| model="gpt-4o-mini", | |
| ) | |
| return {"response": chat_completion.choices[0].message.content} | |