Update app.py
Browse files
app.py
CHANGED
@@ -23,8 +23,6 @@ def system_instructions(context):
|
|
23 |
def generate_quiz(context):
|
24 |
formatted_prompt = system_instructions(context)
|
25 |
|
26 |
-
pre_prompt = [{"role": "system", "content": formatted_prompt}]
|
27 |
-
|
28 |
generate_kwargs = dict(
|
29 |
temperature=0.1,
|
30 |
max_new_tokens=2048,
|
@@ -33,14 +31,31 @@ def generate_quiz(context):
|
|
33 |
do_sample=True,
|
34 |
seed=42,)
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
@app.route("/", methods=["GET", "POST"])
|
46 |
def generate_quiz_page():
|
|
|
23 |
def generate_quiz(context):
|
24 |
formatted_prompt = system_instructions(context)
|
25 |
|
|
|
|
|
26 |
generate_kwargs = dict(
|
27 |
temperature=0.1,
|
28 |
max_new_tokens=2048,
|
|
|
31 |
do_sample=True,
|
32 |
seed=42,)
|
33 |
|
34 |
+
retries = 0
|
35 |
+
response = None
|
36 |
+
|
37 |
+
while retries < MAX_RETRIES:
|
38 |
+
retries += 1
|
39 |
+
try:
|
40 |
+
response = client.text_generation(
|
41 |
+
formatted_prompt,
|
42 |
+
**generate_kwargs,
|
43 |
+
stream=False,
|
44 |
+
details=False,
|
45 |
+
return_full_text=False,
|
46 |
+
)
|
47 |
+
break
|
48 |
|
49 |
+
except (RequestException, SystemExit) as e:
|
50 |
+
if retries == MAX_RETRIES:
|
51 |
+
return {"error": f"Failed after {MAX_RETRIES} retries. Error: {str(e)}"}
|
52 |
+
|
53 |
+
time.sleep(retries)
|
54 |
+
|
55 |
+
if response is None:
|
56 |
+
return {"error": "Max retries exceeded without success."}
|
57 |
+
|
58 |
+
return response
|
59 |
|
60 |
@app.route("/", methods=["GET", "POST"])
|
61 |
def generate_quiz_page():
|