Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -13,12 +13,13 @@ with open(file_path, "r") as file:
|
|
13 |
def home():
|
14 |
return jsonify({"message": "Welcome to the Recommendation API!"})
|
15 |
|
16 |
-
def format_prompt(message):
|
17 |
-
|
18 |
-
|
19 |
-
prompt += "
|
20 |
-
|
21 |
-
|
|
|
22 |
|
23 |
@app.route('/get_course', methods=['POST'])
|
24 |
def recommend():
|
@@ -26,6 +27,7 @@ def recommend():
|
|
26 |
max_new_tokens = 256
|
27 |
top_p = 0.95
|
28 |
repetition_penalty = 1.0
|
|
|
29 |
|
30 |
content = request.json
|
31 |
user_degree = content.get('degree')
|
@@ -49,7 +51,7 @@ def recommend():
|
|
49 |
Note: Output should be valid json format in below format:
|
50 |
{{"course1:course_name, course2:course_name, course3:course_name,...}}
|
51 |
"""
|
52 |
-
formatted_prompt = format_prompt(prompt)
|
53 |
|
54 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=False, details=True, return_full_text=True)
|
55 |
return jsonify({"ans": stream})
|
@@ -60,6 +62,7 @@ def mentor():
|
|
60 |
max_new_tokens = 256
|
61 |
top_p = 0.95
|
62 |
repetition_penalty = 1.0
|
|
|
63 |
|
64 |
content = request.json
|
65 |
user_degree = content.get('degree')
|
@@ -91,7 +94,7 @@ def mentor():
|
|
91 |
Note: Output should be valid json format in below format:
|
92 |
{{"mentor1:mentor_name,mentor2:mentor_name,mentor3:mentor_name,...}}
|
93 |
"""
|
94 |
-
formatted_prompt = format_prompt(prompt)
|
95 |
|
96 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=False, details=True, return_full_text=True)
|
97 |
return jsonify({"ans": stream})
|
|
|
13 |
def home():
|
14 |
return jsonify({"message": "Welcome to the Recommendation API!"})
|
15 |
|
16 |
+
def format_prompt(message, history):
|
17 |
+
prompt = "<s>"
|
18 |
+
for user_prompt, bot_response in history:
|
19 |
+
prompt += f"[INST] {user_prompt} [/INST]"
|
20 |
+
prompt += f" {bot_response}</s> "
|
21 |
+
prompt += f"[INST] {message} [/INST]"
|
22 |
+
return prompt
|
23 |
|
24 |
@app.route('/get_course', methods=['POST'])
|
25 |
def recommend():
|
|
|
27 |
max_new_tokens = 256
|
28 |
top_p = 0.95
|
29 |
repetition_penalty = 1.0
|
30 |
+
history=history
|
31 |
|
32 |
content = request.json
|
33 |
user_degree = content.get('degree')
|
|
|
51 |
Note: Output should be valid json format in below format:
|
52 |
{{"course1:course_name, course2:course_name, course3:course_name,...}}
|
53 |
"""
|
54 |
+
formatted_prompt = format_prompt(prompt,history)
|
55 |
|
56 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=False, details=True, return_full_text=True)
|
57 |
return jsonify({"ans": stream})
|
|
|
62 |
max_new_tokens = 256
|
63 |
top_p = 0.95
|
64 |
repetition_penalty = 1.0
|
65 |
+
history=history
|
66 |
|
67 |
content = request.json
|
68 |
user_degree = content.get('degree')
|
|
|
94 |
Note: Output should be valid json format in below format:
|
95 |
{{"mentor1:mentor_name,mentor2:mentor_name,mentor3:mentor_name,...}}
|
96 |
"""
|
97 |
+
formatted_prompt = format_prompt(prompt,history)
|
98 |
|
99 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=False, details=True, return_full_text=True)
|
100 |
return jsonify({"ans": stream})
|