ammoncoder123 commited on
Commit
1dd0272
·
verified ·
1 Parent(s): 5906217

Update chatbot.py

Browse files
Files changed (1) hide show
  1. chatbot.py +27 -8
chatbot.py CHANGED
@@ -50,22 +50,41 @@ for message in st.session_state.messages:
50
  with st.chat_message(message["role"]):
51
  st.markdown(message["content"])
52
 
53
- if prompt := st.chat_input("Ask about Industrial Practical Training..."):
 
 
54
  st.session_state.messages.append({"role": "user", "content": prompt})
55
  with st.chat_message("user"):
56
  st.markdown(prompt)
57
 
58
  with st.chat_message("assistant"):
59
  with st.spinner("Thinking..."):
60
- chat_messages = [{"role": "user", "content": prompt}]
61
- outputs = pipe(chat_messages, max_new_tokens=300, temperature=0.7, do_sample=True, top_p=0.9)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  response = outputs[0]["generated_text"]
63
  if isinstance(response, str) and response.startswith(prompt):
64
  response = response[len(prompt):].strip()
65
- st.markdown(response)
66
 
67
- st.session_state.messages.append({"role": "assistant", "content": response})
68
 
69
- if st.button("Clear Chat"):
70
- st.session_state.messages = []
71
- st.rerun()
 
50
  with st.chat_message(message["role"]):
51
  st.markdown(message["content"])
52
 
53
+ # ... (model loading code above remains unchanged)
54
+
55
+ if prompt := st.chat_input("Ask about IPT, ICT, or anything..."):
56
  st.session_state.messages.append({"role": "user", "content": prompt})
57
  with st.chat_message("user"):
58
  st.markdown(prompt)
59
 
60
  with st.chat_message("assistant"):
61
  with st.spinner("Thinking..."):
62
+ # Define the system prompt here
63
+ system_prompt = """
64
+ You are a knowledgeable assistant for ICT and engineering students in Tanzania.
65
+ IPT means Industrial Practical Training (Industrial Attachment) — a mandatory work placement for students to gain real-world experience.
66
+ Always use this correct meaning unless the context clearly means something else.
67
+ If unsure, say: "In most educational contexts in Tanzania, IPT stands for Industrial Practical Training."
68
+ """
69
+
70
+ # Build messages with system prompt first
71
+ chat_messages = [
72
+ {"role": "system", "content": system_prompt},
73
+ {"role": "user", "content": prompt}
74
+ ]
75
+
76
+ outputs = pipe(
77
+ chat_messages,
78
+ max_new_tokens=300,
79
+ temperature=0.7,
80
+ do_sample=True,
81
+ top_p=0.9
82
+ )
83
+
84
  response = outputs[0]["generated_text"]
85
  if isinstance(response, str) and response.startswith(prompt):
86
  response = response[len(prompt):].strip()
 
87
 
88
+ st.markdown(response)
89
 
90
+ st.session_state.messages.append({"role": "assistant", "content": response})