Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -32,24 +32,26 @@ generator = pipeline(
|
|
32 |
def format_prompt(chat_history, user_message, system_message, response_style):
|
33 |
# Start with system message
|
34 |
prompt = system_message + "\n\n"
|
35 |
-
|
36 |
-
#
|
37 |
for turn in chat_history:
|
38 |
-
|
39 |
-
|
40 |
-
# Append the new user message
|
41 |
-
prompt += user_message
|
42 |
|
43 |
-
#
|
|
|
|
|
|
|
44 |
if response_style == "No explanation":
|
45 |
-
prompt += "
|
46 |
elif response_style == "Short explanation":
|
47 |
-
prompt += "
|
48 |
elif response_style == "Detailed explanation":
|
49 |
-
prompt += "
|
50 |
|
51 |
return prompt
|
52 |
|
|
|
53 |
# ---------------- CHAT FUNCTION ----------------
|
54 |
def chat(user_message, chat_history, system_message, max_tokens, temperature, top_p, response_style):
|
55 |
chat_history = chat_history or []
|
|
|
32 |
def format_prompt(chat_history, user_message, system_message, response_style):
|
33 |
# Start with system message
|
34 |
prompt = system_message + "\n\n"
|
35 |
+
|
36 |
+
# Add only user messages (optional: you can also add last assistant reply if needed)
|
37 |
for turn in chat_history:
|
38 |
+
if turn['role'] == 'user':
|
39 |
+
prompt += f"{turn['content']}\n"
|
|
|
|
|
40 |
|
41 |
+
# Add the new user message
|
42 |
+
prompt += f"{user_message}\n"
|
43 |
+
|
44 |
+
# Optionally instruct for explanation style
|
45 |
if response_style == "No explanation":
|
46 |
+
prompt += " Answer concisely with no explanation."
|
47 |
elif response_style == "Short explanation":
|
48 |
+
prompt += " Answer briefly with a one-sentence explanation."
|
49 |
elif response_style == "Detailed explanation":
|
50 |
+
prompt += " Answer in detail with reasoning and examples."
|
51 |
|
52 |
return prompt
|
53 |
|
54 |
+
|
55 |
# ---------------- CHAT FUNCTION ----------------
|
56 |
def chat(user_message, chat_history, system_message, max_tokens, temperature, top_p, response_style):
|
57 |
chat_history = chat_history or []
|