Update app.py
Browse files
app.py
CHANGED
@@ -86,6 +86,7 @@ class EnhancedContextDrivenChatbot:
|
|
86 |
r"(.*?),?\s*(?:please\s+)?(provide\s+(?:me\s+)?a\s+.*?|give\s+(?:me\s+)?a\s+.*?|create\s+a\s+.*?)$",
|
87 |
r"(.*?),?\s*(?:please\s+)?(summarize|analyze|explain|describe|elaborate\s+on).*$",
|
88 |
r"(.*?),?\s*(?:please\s+)?(in\s+detail|briefly|concisely).*$",
|
|
|
89 |
]
|
90 |
|
91 |
for pattern in instruction_patterns:
|
@@ -140,7 +141,7 @@ class EnhancedContextDrivenChatbot:
|
|
140 |
|
141 |
if self.is_follow_up_question(core_question):
|
142 |
contextualized_question = self.get_most_relevant_context(core_question)
|
143 |
-
contextualized_question = self.rephrase_query(contextualized_question
|
144 |
else:
|
145 |
contextualized_question = core_question
|
146 |
|
@@ -352,17 +353,18 @@ def estimate_tokens(text):
|
|
352 |
# Rough estimate: 1 token ~= 4 characters
|
353 |
return len(text) // 4
|
354 |
|
355 |
-
def ask_question(question
|
356 |
model = get_model(temperature, top_p, repetition_penalty)
|
357 |
chatbot.model = model
|
358 |
|
359 |
if web_search:
|
360 |
contextualized_question, topics, entity_tracker, instructions = chatbot.process_question(question)
|
361 |
-
|
362 |
# Log the contextualized question for debugging
|
363 |
print(f"Contextualized question: {contextualized_question}")
|
|
|
364 |
|
365 |
-
|
366 |
|
367 |
context_chunks = []
|
368 |
for result in search_results:
|
|
|
86 |
r"(.*?),?\s*(?:please\s+)?(provide\s+(?:me\s+)?a\s+.*?|give\s+(?:me\s+)?a\s+.*?|create\s+a\s+.*?)$",
|
87 |
r"(.*?),?\s*(?:please\s+)?(summarize|analyze|explain|describe|elaborate\s+on).*$",
|
88 |
r"(.*?),?\s*(?:please\s+)?(in\s+detail|briefly|concisely).*$",
|
89 |
+
r"(.*?),?\s*(?:please\s+)?(considering\s+yourself\s+as\s+.*?)$"
|
90 |
]
|
91 |
|
92 |
for pattern in instruction_patterns:
|
|
|
141 |
|
142 |
if self.is_follow_up_question(core_question):
|
143 |
contextualized_question = self.get_most_relevant_context(core_question)
|
144 |
+
contextualized_question = self.rephrase_query(contextualized_question)
|
145 |
else:
|
146 |
contextualized_question = core_question
|
147 |
|
|
|
353 |
# Rough estimate: 1 token ~= 4 characters
|
354 |
return len(text) // 4
|
355 |
|
356 |
+
def ask_question(question, temperature, top_p, repetition_penalty, web_search, chatbot):
|
357 |
model = get_model(temperature, top_p, repetition_penalty)
|
358 |
chatbot.model = model
|
359 |
|
360 |
if web_search:
|
361 |
contextualized_question, topics, entity_tracker, instructions = chatbot.process_question(question)
|
362 |
+
|
363 |
# Log the contextualized question for debugging
|
364 |
print(f"Contextualized question: {contextualized_question}")
|
365 |
+
print(f"Instructions: {instructions}")
|
366 |
|
367 |
+
search_results = google_search(contextualized_question, num_results=3)
|
368 |
|
369 |
context_chunks = []
|
370 |
for result in search_results:
|