chatbot fix4 sherika
Browse files
phase/Student_view/chatbot.py
CHANGED
|
@@ -64,19 +64,20 @@ def _reply_with_hf():
|
|
| 64 |
prompt = f"{TUTOR_PROMPT}\n\n{convo}\n\nTutor:"
|
| 65 |
|
| 66 |
try:
|
|
|
|
| 67 |
response = client.text_generation(
|
| 68 |
prompt,
|
| 69 |
max_new_tokens=220,
|
| 70 |
temperature=0.2,
|
| 71 |
-
return_full_text=False
|
| 72 |
-
stream=False, # 👈 force non-streaming
|
| 73 |
)
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
| 80 |
except Exception as e:
|
| 81 |
err_text = ''.join(traceback.format_exception_only(type(e), e)).strip()
|
| 82 |
raise RuntimeError(f"Hugging Face API Error: {err_text}")
|
|
|
|
| 64 |
prompt = f"{TUTOR_PROMPT}\n\n{convo}\n\nTutor:"
|
| 65 |
|
| 66 |
try:
|
| 67 |
+
# This should return a plain string
|
| 68 |
response = client.text_generation(
|
| 69 |
prompt,
|
| 70 |
max_new_tokens=220,
|
| 71 |
temperature=0.2,
|
| 72 |
+
return_full_text=False
|
|
|
|
| 73 |
)
|
| 74 |
+
|
| 75 |
+
# ✅ ensure it's text
|
| 76 |
+
if not isinstance(response, str):
|
| 77 |
+
response = str(response)
|
| 78 |
+
|
| 79 |
+
return response.strip()
|
| 80 |
+
|
| 81 |
except Exception as e:
|
| 82 |
err_text = ''.join(traceback.format_exception_only(type(e), e)).strip()
|
| 83 |
raise RuntimeError(f"Hugging Face API Error: {err_text}")
|