| import logging
|
|
|
|
|
| logging.basicConfig(level=logging.INFO)
|
| logger = logging.getLogger(__name__)
|
|
|
| def compose_response(response: str) -> str:
|
| """
|
| Process and enhance the final response
|
| """
|
| try:
|
|
|
| print("*********** in composer agent *************")
|
| print("response input received : ", response)
|
| response = remove_system_artifacts(response)
|
|
|
|
|
| response = format_response(response)
|
|
|
| return response
|
|
|
| except Exception as e:
|
| logger.error(f"Error in composition: {str(e)}")
|
| return response
|
|
|
| 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"""
|
|
|
| formatted = text.replace("\n\n\n", "\n\n")
|
|
|
|
|
| formatted = ". ".join(s.strip().capitalize() for s in formatted.split(". "))
|
|
|
|
|
| if formatted and not formatted[-1] in ['.', '!', '?']:
|
| formatted += '.'
|
|
|
| return formatted
|
| |