Spaces:
Sleeping
Sleeping
File size: 1,436 Bytes
3195421 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | import logging
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def compose_response(response: str) -> str:
"""
Process and enhance the final response
"""
try:
# Remove any system artifacts or unwanted patterns
print("*********** in composer agent *************")
print("response input received : ", response)
response = remove_system_artifacts(response)
# Apply standard formatting
response = format_response(response)
return response
except Exception as e:
logger.error(f"Error in composition: {str(e)}")
return response # Fallback to original
def remove_system_artifacts(text: str) -> str:
"""Remove any system artifacts or unwanted patterns"""
artifacts = ["Assistant:", "AI:", "Human:", "User:"]
cleaned = text
for artifact in artifacts:
cleaned = cleaned.replace(artifact, "")
return cleaned.strip()
def format_response(text: str) -> str:
"""Apply standard formatting"""
# Add proper spacing
formatted = text.replace("\n\n\n", "\n\n")
# Ensure proper capitalization
formatted = ". ".join(s.strip().capitalize() for s in formatted.split(". "))
# Ensure proper ending punctuation
if formatted and not formatted[-1] in ['.', '!', '?']:
formatted += '.'
return formatted
|