amitashukla commited on
Commit
9f96a54
·
verified ·
1 Parent(s): 70473f2

remove old tagging system

Browse files
Files changed (1) hide show
  1. src/chat.py +7 -23
src/chat.py CHANGED
@@ -1,7 +1,6 @@
1
  from huggingface_hub import InferenceClient
2
  from src.config import BASE_MODEL, MY_MODEL, HF_TOKEN
3
  import os
4
- from src.utils.tags import tag_user_input
5
  from src.utils.profile import load_schema, create_empty_profile, extract_profile_updates, merge_profile, profile_to_summary
6
  from src.utils.resources import load_resources, filter_resources, score_resources, format_resources_for_context
7
 
@@ -73,9 +72,6 @@ class Chatbot:
73
  """
74
  model_id = MY_MODEL if MY_MODEL else BASE_MODEL # define MY_MODEL in config.py if you create a new model in the HuggingFace Hub
75
  self.client = InferenceClient(model=model_id, token="HF_TOKEN")
76
- # Initialize tag lists
77
- self.user_tags = []
78
- self.substance_tags = []
79
  # Initialize user profile
80
  current_dir = os.path.dirname(os.path.abspath(__file__))
81
  data_dir = os.path.join(current_dir, '..', 'data')
@@ -91,8 +87,6 @@ class Chatbot:
91
 
92
  def reset(self):
93
  """Reset conversation state for a new session without re-initializing the client or resources."""
94
- self.user_tags = []
95
- self.substance_tags = []
96
  self.user_profile = create_empty_profile()
97
 
98
  def update_profile(self, user_input):
@@ -109,16 +103,13 @@ class Chatbot:
109
  def format_prompt(self, user_input, turn_number=0):
110
  """
111
  Format the user's input into a list of chat messages with system context.
112
- Also tags the input with relevant keywords and substances that appear in the text,
113
- and updates the user profile with any new information detected.
114
 
115
  This method:
116
- 1. Loads system prompt from system_prompt.txt
117
- 2. Detects keywords from keywords.txt in user input (case-insensitive, partial matches)
118
- 3. Detects substances from substances.txt in user input (case-insensitive, partial matches)
119
- 4. Updates user profile from schema-based keyword matching
120
- 5. Injects profile summary into the system prompt so the model knows what's been gathered
121
- 6. Returns a list of message dicts for the chat completion API
122
 
123
  Args:
124
  user_input (str): The user's question
@@ -135,13 +126,6 @@ class Chatbot:
135
  with open(system_prompt_path, 'r', encoding='utf-8') as f:
136
  system_prompt = f.read().strip()
137
 
138
- # Tag user input with keywords and substances
139
- keywords_path = os.path.join(current_dir, '../data/keywords.txt')
140
- substances_path = os.path.join(current_dir, '../data/substances.txt')
141
-
142
- self.user_tags = tag_user_input(keywords_path, user_input)
143
- self.substance_tags = tag_user_input(substances_path, user_input)
144
-
145
  # Update user profile from this message
146
  self.update_profile(user_input)
147
 
@@ -199,12 +183,12 @@ class Chatbot:
199
  print("[Harbor] Crisis keywords detected — returning crisis response.")
200
  return CRISIS_RESPONSE
201
 
202
- # 1. Format messages (also updates profile and tags)
203
  turn_number = len(history) if history else 0
204
  messages = self.format_prompt(user_input, turn_number=turn_number)
205
 
206
  # 1b. After the user's first message, return a fixed follow-up instead of calling the LLM.
207
- # Profile and tags have already been updated above so the first message is not lost.
208
  if history and len(history) == 1:
209
  return (
210
  "Thank you for sharing that. Before I give you any recommendations, "
 
1
  from huggingface_hub import InferenceClient
2
  from src.config import BASE_MODEL, MY_MODEL, HF_TOKEN
3
  import os
 
4
  from src.utils.profile import load_schema, create_empty_profile, extract_profile_updates, merge_profile, profile_to_summary
5
  from src.utils.resources import load_resources, filter_resources, score_resources, format_resources_for_context
6
 
 
72
  """
73
  model_id = MY_MODEL if MY_MODEL else BASE_MODEL # define MY_MODEL in config.py if you create a new model in the HuggingFace Hub
74
  self.client = InferenceClient(model=model_id, token="HF_TOKEN")
 
 
 
75
  # Initialize user profile
76
  current_dir = os.path.dirname(os.path.abspath(__file__))
77
  data_dir = os.path.join(current_dir, '..', 'data')
 
87
 
88
  def reset(self):
89
  """Reset conversation state for a new session without re-initializing the client or resources."""
 
 
90
  self.user_profile = create_empty_profile()
91
 
92
  def update_profile(self, user_input):
 
103
  def format_prompt(self, user_input, turn_number=0):
104
  """
105
  Format the user's input into a list of chat messages with system context.
106
+ Updates the user profile with any new information detected from the message.
 
107
 
108
  This method:
109
+ 1. Loads system prompt from system_prompt.md
110
+ 2. Updates user profile from schema-based extraction
111
+ 3. Injects profile summary into the system prompt so the model knows what's been gathered
112
+ 4. Returns a list of message dicts for the chat completion API
 
 
113
 
114
  Args:
115
  user_input (str): The user's question
 
126
  with open(system_prompt_path, 'r', encoding='utf-8') as f:
127
  system_prompt = f.read().strip()
128
 
 
 
 
 
 
 
 
129
  # Update user profile from this message
130
  self.update_profile(user_input)
131
 
 
183
  print("[Harbor] Crisis keywords detected — returning crisis response.")
184
  return CRISIS_RESPONSE
185
 
186
+ # 1. Format messages (also updates profile)
187
  turn_number = len(history) if history else 0
188
  messages = self.format_prompt(user_input, turn_number=turn_number)
189
 
190
  # 1b. After the user's first message, return a fixed follow-up instead of calling the LLM.
191
+ # Profile has already been updated above so the first message is not lost.
192
  if history and len(history) == 1:
193
  return (
194
  "Thank you for sharing that. Before I give you any recommendations, "