Donne120 commited on
Commit
c621fd2
·
1 Parent(s): 26b81e7

Add working conversational model with distilgpt2

Browse files
Files changed (2) hide show
  1. enhanced_capabilities/capability_router.py +17 -13
  2. main.py +12 -0
enhanced_capabilities/capability_router.py CHANGED
@@ -96,29 +96,33 @@ def is_school_related(question: str) -> bool:
96
 
97
  return False
98
 
99
- def handle_question(query: str) -> Dict[str, Any]:
100
- """Route questions to appropriate capability"""
 
101
 
102
- # Check for greetings/farewells FIRST before other processing
 
 
 
103
  query_lower = query.lower().strip()
104
 
105
- # Detect greetings
106
- if any(greeting in query_lower for greeting in ["hello", "hi", "hey", "greetings"]):
 
107
  return {
108
  "capability": "greeting",
109
- "answer": "Hello! I'm the ALU Assistant. How can I help with your questions today?",
110
  "source": "conversation"
111
  }
112
 
113
- # Detect farewells
114
- if any(farewell in query_lower for farewell in ["bye", "goodbye", "see you", "farewell"]):
 
115
  return {
116
  "capability": "farewell",
117
  "answer": "Goodbye! Feel free to return if you have more questions about ALU. Wishing you success in your studies!",
118
  "source": "conversation"
119
  }
120
-
121
- # Rest of your existing routing logic...
122
 
123
  print(f"Routing question: '{query}'")
124
 
@@ -202,10 +206,10 @@ def handle_question(query: str) -> Dict[str, Any]:
202
  except Exception as e:
203
  print(f"Web search error: {e}")
204
 
205
- # 6. If we got here, use the provided search function if available
206
- if None:
207
  try:
208
- docs = None(query)
209
  # Process docs here if needed
210
  return {
211
  "answer": "I found some information in our knowledge base that might help.",
 
96
 
97
  return False
98
 
99
+ # Update the function signature to accept the context retriever function
100
+ def handle_question(query: str, context_retriever=None) -> Dict[str, Any]:
101
+ """Route questions to appropriate capability
102
 
103
+ Args:
104
+ query: The user's question
105
+ context_retriever: Optional function to retrieve context documents
106
+ """
107
  query_lower = query.lower().strip()
108
 
109
+ # Check for simple greetings first
110
+ greeting_phrases = ["hello", "hi", "hey", "greetings", "good morning", "good afternoon", "good evening"]
111
+ if any(query_lower == phrase or query_lower.startswith(phrase) for phrase in greeting_phrases):
112
  return {
113
  "capability": "greeting",
114
+ "answer": "Hello! I'm the ALU student companion Assistant. How can I help with your questions today?",
115
  "source": "conversation"
116
  }
117
 
118
+ # Check for farewells
119
+ farewell_phrases = ["bye", "goodbye", "see you", "farewell", "thanks", "thank you"]
120
+ if any(query_lower == phrase or query_lower.startswith(phrase) for phrase in farewell_phrases):
121
  return {
122
  "capability": "farewell",
123
  "answer": "Goodbye! Feel free to return if you have more questions about ALU. Wishing you success in your studies!",
124
  "source": "conversation"
125
  }
 
 
126
 
127
  print(f"Routing question: '{query}'")
128
 
 
206
  except Exception as e:
207
  print(f"Web search error: {e}")
208
 
209
+ # 6. Use context_retriever if provided for document search
210
+ if context_retriever:
211
  try:
212
+ docs = context_retriever(query)
213
  # Process docs here if needed
214
  return {
215
  "answer": "I found some information in our knowledge base that might help.",
main.py CHANGED
@@ -315,6 +315,18 @@ def process_chat_internal(request: ChatRequest):
315
 
316
  print(f"Selected capability: {result['source']}")
317
 
 
 
 
 
 
 
 
 
 
 
 
 
318
  # Format the response based on which capability handled it
319
  if result["source"] == "math_solver":
320
  steps = "\n".join(result["additional_info"]) if result["additional_info"] else ""
 
315
 
316
  print(f"Selected capability: {result['source']}")
317
 
318
+ # If response came from document search but was very short or low confidence
319
+ if result["source"] == "document_search" and (len(result["answer"]) < 50 or "confidence" in result and result["confidence"] < 0.7):
320
+ # Try using conversation model instead for common phrases
321
+ if conversation_handler:
322
+ try:
323
+ conv_response = conversation_handler.get_response(user_message, conversation.get_formatted_history())
324
+ if len(conv_response) > len(result["answer"]):
325
+ result["answer"] = conv_response
326
+ result["source"] = "conversation"
327
+ except Exception as e:
328
+ print(f"Error using conversation fallback: {e}")
329
+
330
  # Format the response based on which capability handled it
331
  if result["source"] == "math_solver":
332
  steps = "\n".join(result["additional_info"]) if result["additional_info"] else ""