Krika commited on
Commit
386e1b9
·
1 Parent(s): 19682b7

chatbot fix4 sherika

Browse files
Files changed (1) hide show
  1. phase/Student_view/chatbot.py +9 -8
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
- if isinstance(response, str):
75
- return response.strip()
76
- elif isinstance(response, dict) and "generated_text" in response:
77
- return response["generated_text"].strip()
78
- else:
79
- return str(response).strip()
 
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}")