Spaces:
Running
Running
File size: 8,944 Bytes
92d2175 |
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
"""
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)) |