Spaces:
Sleeping
Sleeping
| """ | |
| Prompts Collection - Tập trung tất cả prompts của hệ thống | |
| """ | |
| # System prompts | |
| SYSTEM_PROMPTS = { | |
| "main_agent": """You are an intelligent AI agent designed to answer questions accurately by using appropriate tools and reasoning. | |
| Your capabilities include: | |
| - Analyzing different types of questions (text, YouTube videos, images, audio, files, Wikipedia searches) | |
| - Using specialized tools for each content type | |
| - Reasoning through complex problems step by step | |
| - Handling reversed text and malformed questions | |
| - Providing comprehensive and accurate answers | |
| Guidelines: | |
| 1. Always analyze the question type first | |
| 2. Use appropriate tools based on content type | |
| 3. If text seems reversed, try reversing it | |
| 4. For YouTube links, extract metadata and transcripts | |
| 5. For images, use OCR to extract text | |
| 6. For audio, transcribe using speech-to-text | |
| 7. For factual questions, search Wikipedia | |
| 8. Combine information from multiple sources when needed | |
| 9. Be concise but thorough in your responses | |
| 10. If you cannot find relevant information, be honest about limitations | |
| Remember: Your goal is to provide the most accurate and helpful answer possible using all available tools and reasoning.""", | |
| "reasoning_agent": """You are a logical reasoning agent. Your task is to: | |
| 1. Break down complex problems into smaller parts | |
| 2. Apply logical thinking and common sense | |
| 3. Synthesize information from multiple sources | |
| 4. Provide clear, step-by-step explanations | |
| 5. Identify when information is insufficient and suggest next steps | |
| Always think through problems systematically and explain your reasoning process.""", | |
| "tool_selector": """You are a tool selection agent. Based on the question and context, determine which tools should be used. | |
| Available tools: | |
| - youtube_tool: For YouTube video analysis | |
| - image_ocr: For extracting text from images | |
| - audio_transcript: For transcribing audio files | |
| - wiki_search: For factual information lookup | |
| - file_reader: For reading various file formats | |
| - text_processor: For handling reversed or malformed text | |
| Respond with a list of recommended tools and the order they should be used.""" | |
| } | |
| # Question analysis prompts | |
| QUESTION_ANALYSIS_PROMPTS = { | |
| "reverse_text_check": """ | |
| Original: {original_text} | |
| Reversed: {reversed_text} | |
| Which version makes more sense as a question? Consider: | |
| - Proper grammar and sentence structure | |
| - Logical word order | |
| - Meaningful content | |
| Answer "original" or "reversed" only. | |
| """, | |
| "question_type_analysis": """ | |
| Analyze this question and determine its type: "{question}" | |
| Consider these categories: | |
| - youtube: Contains YouTube URLs | |
| - image: Mentions images, photos, diagrams, or has image attachments | |
| - audio: Mentions audio, sound, voice, music, or has audio attachments | |
| - wiki: Factual questions about people, places, events, concepts | |
| - file: References to file attachments or file processing | |
| - math: Mathematical calculations or problem solving | |
| - text: General text-based questions | |
| Return only the category name.""", | |
| "content_extraction": """ | |
| From the following content, extract the key information relevant to answering this question: "{question}" | |
| Content sources: | |
| {content_sources} | |
| Provide a concise summary of the most relevant information.""" | |
| } | |
| # Tool-specific prompts | |
| TOOL_PROMPTS = { | |
| "youtube_analysis": """ | |
| Based on this YouTube video information: | |
| Title: {title} | |
| Description: {description} | |
| Transcript: {transcript} | |
| Answer the question: "{question}" | |
| If transcript is not available, use the title and description to provide the best possible answer.""", | |
| "image_ocr_analysis": """ | |
| The following text was extracted from an image using OCR: | |
| {ocr_text} | |
| Based on this extracted text, answer the question: "{question}" | |
| Note: Some text may contain OCR errors, so use context to interpret unclear parts.""", | |
| "audio_transcript_analysis": """ | |
| The following text was transcribed from an audio file: | |
| {transcript} | |
| Based on this transcript, answer the question: "{question}" | |
| Consider that some words may be transcription errors, so focus on the overall meaning.""", | |
| "wiki_synthesis": """ | |
| Based on this Wikipedia information: | |
| Title: {title} | |
| Summary: {summary} | |
| URL: {url} | |
| Answer the question: "{question}" | |
| Provide accurate information and cite the Wikipedia article if appropriate.""", | |
| "file_content_analysis": """ | |
| The following content was extracted from a file: | |
| File Type: {file_type} | |
| Content: {file_content} | |
| Based on this file content, answer the question: "{question}" | |
| Analyze the content thoroughly and provide insights based on what you find.""" | |
| } | |
| # Response formatting prompts | |
| RESPONSE_PROMPTS = { | |
| "final_answer": """ | |
| Based on all the gathered information and analysis, provide a comprehensive answer to: "{question}" | |
| Available information: | |
| {context_summary} | |
| Requirements: | |
| 1. Be accurate and factual | |
| 2. Use information from all relevant sources | |
| 3. If you used specific tools or sources, mention them briefly | |
| 4. Keep the answer focused on the question | |
| 5. If information is incomplete, acknowledge limitations | |
| Answer:""", | |
| "error_handling": """ | |
| I encountered some difficulties while processing your question: "{question}" | |
| Issues encountered: | |
| {error_details} | |
| However, I can still provide a partial answer based on available information: | |
| {partial_info} | |
| Would you like me to try a different approach or do you need clarification on any part of this response?""", | |
| "no_content_found": """ | |
| I was unable to find specific content to answer your question: "{question}" | |
| Attempted approaches: | |
| {attempted_tools} | |
| This could be due to: | |
| - Content not being accessible or available | |
| - Question requiring specialized knowledge not in my training | |
| - Technical issues with content retrieval | |
| Could you provide more context or rephrase the question to help me better assist you?""" | |
| } | |
| # Validation prompts | |
| VALIDATION_PROMPTS = { | |
| "answer_quality_check": """ | |
| Question: {question} | |
| Proposed Answer: {answer} | |
| Evaluate this answer on: | |
| 1. Accuracy (based on provided information) | |
| 2. Completeness (addresses all parts of the question) | |
| 3. Clarity (easy to understand) | |
| 4. Relevance (directly answers the question) | |
| Rate each aspect as Good/Fair/Poor and provide brief feedback. | |
| Overall Quality: Good/Fair/Poor""", | |
| "source_verification": """ | |
| Verify if this information from {source_type} adequately supports the answer: | |
| Source Content: {source_content} | |
| Answer: {answer} | |
| Is the answer well-supported by the source? Yes/No | |
| If No, what additional information would be needed?""", | |
| "confidence_assessment": """ | |
| Based on the available information and tools used, rate your confidence in this answer: | |
| Question: {question} | |
| Answer: {answer} | |
| Information Sources: {sources} | |
| Confidence Level: High/Medium/Low | |
| Reasoning: [Explain why this confidence level]""" | |
| } | |
| # Utility functions for prompt formatting | |
| def format_prompt(template: str, **kwargs) -> str: | |
| """ | |
| Format prompt template với các tham số | |
| """ | |
| try: | |
| return template.format(**kwargs) | |
| except KeyError as e: | |
| return f"Error formatting prompt: Missing parameter {e}" | |
| def get_system_prompt(agent_type: str = "main_agent") -> str: | |
| """ | |
| Lấy system prompt cho loại agent | |
| """ | |
| return SYSTEM_PROMPTS.get(agent_type, SYSTEM_PROMPTS["main_agent"]) | |
| def get_analysis_prompt(prompt_type: str, **kwargs) -> str: | |
| """ | |
| Lấy prompt phân tích với tham số | |
| """ | |
| template = QUESTION_ANALYSIS_PROMPTS.get(prompt_type, "") | |
| return format_prompt(template, **kwargs) | |
| def get_tool_prompt(tool_name: str, **kwargs) -> str: | |
| """ | |
| Lấy prompt cho tool cụ thể | |
| """ | |
| template = TOOL_PROMPTS.get(tool_name, "") | |
| return format_prompt(template, **kwargs) | |
| def get_response_prompt(prompt_type: str, **kwargs) -> str: | |
| """ | |
| Lấy prompt formatting response | |
| """ | |
| template = RESPONSE_PROMPTS.get(prompt_type, "") | |
| return format_prompt(template, **kwargs) | |
| def build_context_summary(tool_results, cached_data) -> str: | |
| """ | |
| Tạo tóm tắt context từ tool results và cached data | |
| """ | |
| summary_parts = [] | |
| for tool_result in tool_results: | |
| if tool_result.success: | |
| summary_parts.append(f"- {tool_result.tool_name}: Available") | |
| else: | |
| summary_parts.append(f"- {tool_result.tool_name}: Failed ({tool_result.error_message})") | |
| if cached_data: | |
| summary_parts.append(f"- Cached data: {', '.join(cached_data.keys())}") | |
| return "\n".join(summary_parts) if summary_parts else "No information available" | |
| # Test function | |
| if __name__ == "__main__": | |
| # Test prompt formatting | |
| test_prompt = get_analysis_prompt( | |
| "reverse_text_check", | |
| original_text="Hello world", | |
| reversed_text="dlrow olleH" | |
| ) | |
| print("Test prompt:", test_prompt) | |
| # Test system prompt | |
| system_prompt = get_system_prompt("main_agent") | |
| print("System prompt length:", len(system_prompt)) |