feat: Skip API call for short content and log to chat history for context
Browse files- utils/text_explainer.py +11 -0
utils/text_explainer.py
CHANGED
|
@@ -204,6 +204,17 @@ class TextExplainer:
|
|
| 204 |
}
|
| 205 |
]
|
| 206 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
# Add the current user message to chat history
|
| 208 |
self.chat_history.append({
|
| 209 |
"role": "user",
|
|
|
|
| 204 |
}
|
| 205 |
]
|
| 206 |
|
| 207 |
+
# Check if content is too small (less than 200 characters)
|
| 208 |
+
if len(content) < 200:
|
| 209 |
+
print(f"📋 Skipping API call for short content in '{heading}' ({len(content)} chars < 200)")
|
| 210 |
+
# Add the user prompt to chat history for context in subsequent queries
|
| 211 |
+
self.chat_history.append({
|
| 212 |
+
"role": "user",
|
| 213 |
+
"content": prompt
|
| 214 |
+
})
|
| 215 |
+
# Return a simple message indicating the content was too short
|
| 216 |
+
return f"This section contains minimal content ({len(content)} characters). The information has been noted for context in subsequent explanations."
|
| 217 |
+
|
| 218 |
# Add the current user message to chat history
|
| 219 |
self.chat_history.append({
|
| 220 |
"role": "user",
|