Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -225,17 +225,31 @@ Javobni faqat matn shaklida bering, kod yoki ortiqcha belgilar kiritmang."""
|
|
225 |
def process_response(self, response: str) -> str:
|
226 |
"""Clean up the response"""
|
227 |
try:
|
|
|
228 |
unwanted_tags = ["[INST]", "[/INST]", "<s>", "</s>"]
|
229 |
for tag in unwanted_tags:
|
230 |
response = response.replace(tag, "")
|
231 |
|
232 |
-
|
233 |
-
response = re.sub(r"
|
234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
return response.strip()
|
236 |
except Exception as e:
|
237 |
logging.error(f"Error processing response: {str(e)}")
|
238 |
-
return response
|
239 |
|
240 |
def chat(self, message: str, history: List[Tuple[str, str]]) -> str:
|
241 |
"""Process a single chat message"""
|
|
|
225 |
def process_response(self, response: str) -> str:
|
226 |
"""Clean up the response"""
|
227 |
try:
|
228 |
+
# Remove common model instruction tags
|
229 |
unwanted_tags = ["[INST]", "[/INST]", "<s>", "</s>"]
|
230 |
for tag in unwanted_tags:
|
231 |
response = response.replace(tag, "")
|
232 |
|
233 |
+
# Remove code blocks with language specifications
|
234 |
+
response = re.sub(r"```\w*\n.*?```", "", response, flags=re.DOTALL)
|
235 |
+
|
236 |
+
# Remove single line code blocks
|
237 |
+
response = re.sub(r"`.*?`", "", response)
|
238 |
+
|
239 |
+
# Remove any remaining code-like artifacts
|
240 |
+
response = re.sub(r"//.*?$", "", response, flags=re.MULTILINE) # Remove single line comments
|
241 |
+
response = re.sub(r"/\*.*?\*/", "", response, flags=re.DOTALL) # Remove multi-line comments
|
242 |
+
response = re.sub(r"[{}<>]", "", response) # Remove brackets
|
243 |
+
response = re.sub(r"\b(java|python|class|public|private|void)\b", "", response, flags=re.IGNORECASE) # Remove programming keywords
|
244 |
+
|
245 |
+
# Clean up multiple spaces and newlines
|
246 |
+
response = re.sub(r'\s+', ' ', response)
|
247 |
+
|
248 |
+
# Final cleanup
|
249 |
return response.strip()
|
250 |
except Exception as e:
|
251 |
logging.error(f"Error processing response: {str(e)}")
|
252 |
+
return response.strip()
|
253 |
|
254 |
def chat(self, message: str, history: List[Tuple[str, str]]) -> str:
|
255 |
"""Process a single chat message"""
|