sourize
commited on
Commit
·
7278faf
1
Parent(s):
55faf97
Commit
Browse files
app.py
CHANGED
|
@@ -22,7 +22,7 @@ SYSTEM = (
|
|
| 22 |
"fine-tuned by Sourish for domain support.\n"
|
| 23 |
"Answer **only** using the conversation context below.\n"
|
| 24 |
"Do NOT output any lines beginning with 'User:' or 'Assistant:'.\n"
|
| 25 |
-
"If you don
|
| 26 |
)
|
| 27 |
|
| 28 |
|
|
@@ -129,11 +129,18 @@ Assistant:"""
|
|
| 129 |
# generate reply
|
| 130 |
with st.spinner("Thinking…"):
|
| 131 |
try:
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
except Exception as e:
|
| 134 |
-
|
| 135 |
st.error(f"Generation error: {e}")
|
| 136 |
|
| 137 |
# show & store assistant turn
|
| 138 |
-
st.chat_message("assistant").write(
|
| 139 |
-
st.session_state.history.append(("Bot",
|
|
|
|
| 22 |
"fine-tuned by Sourish for domain support.\n"
|
| 23 |
"Answer **only** using the conversation context below.\n"
|
| 24 |
"Do NOT output any lines beginning with 'User:' or 'Assistant:'.\n"
|
| 25 |
+
"If you don't know, say 'I don't know.'\n"
|
| 26 |
)
|
| 27 |
|
| 28 |
|
|
|
|
| 129 |
# generate reply
|
| 130 |
with st.spinner("Thinking…"):
|
| 131 |
try:
|
| 132 |
+
# 1) raw generation
|
| 133 |
+
raw = generator(prompt)[0]["generated_text"]
|
| 134 |
+
# 2) Remove the prompt prefix (so you only see new content)
|
| 135 |
+
reply = raw[len(prompt):].strip()
|
| 136 |
+
# 3) If it ever slurps in "User:" or "Assistant:", cut there
|
| 137 |
+
for marker in ["User:", "Assistant:"]:
|
| 138 |
+
if marker in reply:
|
| 139 |
+
reply = reply.split(marker)[0].strip()
|
| 140 |
except Exception as e:
|
| 141 |
+
reply = "I'm sorry, something went wrong."
|
| 142 |
st.error(f"Generation error: {e}")
|
| 143 |
|
| 144 |
# show & store assistant turn
|
| 145 |
+
st.chat_message("assistant").write(reply)
|
| 146 |
+
st.session_state.history.append(("Bot", reply))
|