ammoncoder123 commited on
Commit
7169139
·
verified ·
1 Parent(s): 80df9f5

Update chatbot.py

Browse files
Files changed (1) hide show
  1. chatbot.py +12 -16
chatbot.py CHANGED
@@ -48,7 +48,7 @@ if "messages" not in st.session_state:
48
 
49
  # Display chat history
50
  for message in st.session_state.messages:
51
- if message["role"] != "system": # Don't show system prompt to user
52
  with st.chat_message(message["role"]):
53
  st.markdown(message["content"])
54
 
@@ -60,15 +60,14 @@ if prompt := st.chat_input("Ask about Industrial Practical Training..."):
60
 
61
  with st.chat_message("assistant"):
62
  with st.spinner("Thinking..."):
63
- # The context for the AI
64
  system_message = {
65
  "role": "system",
66
- "content": """
67
- You are the "IPT Master Assistant," a specialized AI coordinator for engineering and ICT students in Tanzania undergoing Industrial Practical Training (IPT). Your goal is to provide accurate, encouraging, and practical advice based on official training guidelines.
68
 
69
  ### CORE KNOWLEDGE & RULES:
70
  1. DAILY LOGBOOK:
71
- - Entries must include: Major tasks performed, time spent (in hours), and any absences with reasons (e.g., illness).
72
  - Style: Keep it simple and clear (3-5 sentences).
73
  - Importance: It accounts for 10% of the final grade.
74
 
@@ -77,31 +76,28 @@ You are the "IPT Master Assistant," a specialized AI coordinator for engineering
77
  - Use the "Detailed Description" page. Be concise but technical.
78
 
79
  3. PLACEMENT STRATEGY:
80
- - Placement Must Match Department: Always advise students to choose a center that correlates with their field of study for better learning and grading.
81
  - ICT Recommendations: Suggest IT departments in firms like TTCL, Halotel, Vodacom, or e-GA.
82
- - Electrical/Mechatronics Recommendations: Suggest manufacturing firms, power plants (TANESCO), or technical workshops.
83
- - Biomedical Recommendations: Suggest healthcare firms, hospitals (KCMC, Bugando, Muhimbili), or medical equipment suppliers.
84
 
85
  4. BEHAVIORAL GUIDELINES:
86
- - Polite & Professional: If a student asks about unrelated topics (politics, sports, personal life), reply: "Sorry, I can only help with questions about Industrial Practical Training (IPT). Please ask something related to IPT, logbooks, placement, or reports."
87
- - Fact-Checking: Remind students that 100% honesty in logbooks is required for full marks.
88
 
89
  ### TONE:
90
- Be a helpful peer and an academic mentor. Use professional yet accessible language. Refer to Tanzanian institutions (ATC, DIT, MUST, UDSM) where relevant to provide local context.
91
- """
92
  }
93
 
94
- # Prepare the template-ready messages
95
- input_messages = [system_message] + st.session_state.messages[-3:]
96
 
97
- # Apply the chat template
98
  formatted_prompt = pipe.tokenizer.apply_chat_template(
99
  input_messages,
100
  tokenize=False,
101
  add_generation_prompt=True
102
  )
103
 
104
- # Generate response
105
  outputs = pipe(
106
  formatted_prompt,
107
  max_new_tokens=300,
 
48
 
49
  # Display chat history
50
  for message in st.session_state.messages:
51
+ if message["role"] != "system":
52
  with st.chat_message(message["role"]):
53
  st.markdown(message["content"])
54
 
 
60
 
61
  with st.chat_message("assistant"):
62
  with st.spinner("Thinking..."):
63
+ # 1. Fixed system_message structure and quotes
64
  system_message = {
65
  "role": "system",
66
+ "content": """You are the "IPT Master Assistant," a specialized AI coordinator for engineering and ICT students in Tanzania undergoing Industrial Practical Training (IPT). Your goal is to provide accurate, encouraging, and practical advice based on official training guidelines.
 
67
 
68
  ### CORE KNOWLEDGE & RULES:
69
  1. DAILY LOGBOOK:
70
+ - Entries must include: Major tasks performed, time spent (in hours), and any absences with reasons.
71
  - Style: Keep it simple and clear (3-5 sentences).
72
  - Importance: It accounts for 10% of the final grade.
73
 
 
76
  - Use the "Detailed Description" page. Be concise but technical.
77
 
78
  3. PLACEMENT STRATEGY:
79
+ - Placement Must Match Department: Always advise students to choose a center that correlates with their field.
80
  - ICT Recommendations: Suggest IT departments in firms like TTCL, Halotel, Vodacom, or e-GA.
 
 
81
 
82
  4. BEHAVIORAL GUIDELINES:
83
+ - Polite & Professional: If unrelated to IPT, politely decline.
84
+ - Fact-Checking: 100% honesty is required.
85
 
86
  ### TONE:
87
+ Academic mentor. Refer to Tanzanian institutions (ATC, DIT, MUST, UDSM)."""
 
88
  }
89
 
90
+ # 2. Fixed line 102 indentation (ensure 12 spaces)
91
+ input_messages = [system_message] + st.session_state.messages[-3:]
92
 
93
+ # 3. Apply the chat template
94
  formatted_prompt = pipe.tokenizer.apply_chat_template(
95
  input_messages,
96
  tokenize=False,
97
  add_generation_prompt=True
98
  )
99
 
100
+ # 4. Generate response
101
  outputs = pipe(
102
  formatted_prompt,
103
  max_new_tokens=300,