Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from openai import OpenAI
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
client = OpenAI(api_key=OPENAI_API_KEY)
|
| 7 |
+
|
| 8 |
+
OPENAI_API_KEY = os.getenv("open_ai")
|
| 9 |
+
@app.post("/get_questions")
|
| 10 |
+
async def getQuestions(job_description: str, no_of_questions: int):
|
| 11 |
+
response = client.chat.completions.create(
|
| 12 |
+
model="gpt-3.5-turbo-1106",
|
| 13 |
+
response_format={"type": "json_object"}, # To ENABLE JSON MODE
|
| 14 |
+
messages=[
|
| 15 |
+
{"role": "system",
|
| 16 |
+
"content": "You are a helpful assistant designed to output JSON in this format [question-text as key and its value as answer-text]"},
|
| 17 |
+
{"role": "user",
|
| 18 |
+
"content": f"Given the job description [{job_description}] create {no_of_questions} "
|
| 19 |
+
f"interview questions and their corresponding answers"}
|
| 20 |
+
]
|
| 21 |
+
)
|
| 22 |
+
result = response.choices[0].message.content
|
| 23 |
+
# Parse the JSON data
|
| 24 |
+
parsed_data = json.loads(result)
|
| 25 |
+
|
| 26 |
+
return parsed_data
|