Spaces:
Sleeping
Sleeping
Update prompts.py
Browse files- prompts.py +140 -34
prompts.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
"""
|
| 2 |
Juno AI - Comprehensive Prompt System
|
| 3 |
=====================================
|
| 4 |
-
|
| 5 |
This module contains all prompts and prompt templates for Juno AI,
|
| 6 |
an advanced conversational AI assistant with document processing,
|
| 7 |
web scraping, memory management, and RAG capabilities.
|
|
@@ -17,10 +16,12 @@ Features Covered:
|
|
| 17 |
- Streaming Responses
|
| 18 |
- Error Handling & Fallbacks
|
| 19 |
- Professional Communication
|
|
|
|
| 20 |
|
| 21 |
Author: Juno AI Development Team
|
| 22 |
Version: 1.0
|
| 23 |
"""
|
|
|
|
| 24 |
from typing import List, Dict, Any, Optional
|
| 25 |
from datetime import datetime
|
| 26 |
import json
|
|
@@ -30,6 +31,7 @@ class JunoAIPrompts:
|
|
| 30 |
Centralized prompt management system for Juno AI.
|
| 31 |
Contains all prompts, templates, and prompt generation methods.
|
| 32 |
"""
|
|
|
|
| 33 |
def __init__(self):
|
| 34 |
self.version = "1.0"
|
| 35 |
self.ai_name = "Juno AI"
|
|
@@ -39,7 +41,7 @@ class JunoAIPrompts:
|
|
| 39 |
"""Define Juno AI's core personality traits"""
|
| 40 |
return {
|
| 41 |
"helpful": "Always eager to assist and provide valuable insights",
|
| 42 |
-
"intelligent": "Demonstrates deep understanding and analytical thinking",
|
| 43 |
"professional": "Maintains professional tone while being approachable",
|
| 44 |
"adaptive": "Adapts communication style to user needs and context",
|
| 45 |
"reliable": "Provides accurate, well-sourced information",
|
|
@@ -48,8 +50,9 @@ class JunoAIPrompts:
|
|
| 48 |
}
|
| 49 |
|
| 50 |
# ==========================================
|
| 51 |
-
# CORE AI ASSISTANT PROMPTS
|
| 52 |
# ==========================================
|
|
|
|
| 53 |
def get_core_system_prompt(self) -> str:
|
| 54 |
"""
|
| 55 |
Core system prompt that defines Juno AI's personality and capabilities
|
|
@@ -71,6 +74,7 @@ KEY CAPABILITIES:
|
|
| 71 |
- Smart Search: Use RAG to find relevant information from uploaded content
|
| 72 |
- Summarization: Create comprehensive summaries of long-form content
|
| 73 |
- Task Management: Help with various professional and personal tasks
|
|
|
|
| 74 |
|
| 75 |
COMMUNICATION STYLE:
|
| 76 |
- Be clear, concise, and informative
|
|
@@ -85,6 +89,13 @@ CONTEXT AWARENESS:
|
|
| 85 |
- Reference uploaded documents and web content when relevant
|
| 86 |
- Use memory to provide personalized responses
|
| 87 |
- Maintain context across multiple interaction sessions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
IDENTITY ENFORCEMENT:
|
| 90 |
- Your name is Juno AI - always respond with this when asked about your identity
|
|
@@ -95,13 +106,13 @@ IDENTITY ENFORCEMENT:
|
|
| 95 |
|
| 96 |
Remember: You are not just answering questions - you are having a meaningful conversation and building a helpful relationship with the user."""
|
| 97 |
|
| 98 |
-
|
| 99 |
def get_conversation_prompt(self,
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
|
|
|
| 105 |
"""
|
| 106 |
Generate a comprehensive conversation prompt with all available context
|
| 107 |
"""
|
|
@@ -114,6 +125,7 @@ Remember: You are not just answering questions - you are having a meaningful con
|
|
| 114 |
for exchange in recent_history
|
| 115 |
if not exchange.get('fallback', False)
|
| 116 |
])
|
|
|
|
| 117 |
# Build memory context section
|
| 118 |
memory_section = ""
|
| 119 |
if memory_context and memory_context.get('memory'):
|
|
@@ -125,40 +137,125 @@ Remember: You are not just answering questions - you are having a meaningful con
|
|
| 125 |
if user_preferences:
|
| 126 |
preferences_section = json.dumps(user_preferences, indent=2)
|
| 127 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
# Build document context section
|
| 129 |
context_section = ""
|
| 130 |
if context:
|
| 131 |
context_section = f"\n\nRELEVANT DOCUMENT CONTEXT:\n{context[:2000]}"
|
| 132 |
|
| 133 |
-
#
|
| 134 |
-
assistant_label = "Assistant:"
|
| 135 |
core_prompt = self.get_core_system_prompt()
|
| 136 |
-
|
| 137 |
history_part = f"Previous conversation history:\n{history_section}\n" if history_section else ""
|
| 138 |
memory_part = f"Session memory:\n{memory_section}\n" if memory_section else ""
|
| 139 |
preferences_part = f"User preferences:\n{preferences_section}\n" if preferences_section else ""
|
|
|
|
| 140 |
|
| 141 |
prompt = f"""{core_prompt}
|
| 142 |
|
| 143 |
CONVERSATION CONTEXT:
|
| 144 |
-
{history_part}{memory_part}{preferences_part}{context_section}
|
| 145 |
|
| 146 |
CURRENT USER MESSAGE: {user_message}
|
| 147 |
|
| 148 |
RESPONSE INSTRUCTIONS:
|
| 149 |
- Provide a helpful, accurate response based on all available context
|
| 150 |
- Reference relevant information from documents or previous conversations when applicable
|
|
|
|
| 151 |
- Maintain conversational flow and continuity
|
| 152 |
- Be specific and actionable in your advice
|
| 153 |
- Use formatting (lists, headers, etc.) to improve readability when appropriate
|
| 154 |
- If you need clarification, ask thoughtful follow-up questions
|
| 155 |
-
-
|
|
|
|
| 156 |
|
| 157 |
return prompt
|
| 158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
# ==========================================
|
| 160 |
# DOCUMENT PROCESSING PROMPTS
|
| 161 |
# ==========================================
|
|
|
|
| 162 |
def get_document_analysis_prompt(self, document_text: str, filename: str = "document") -> str:
|
| 163 |
"""
|
| 164 |
Prompt for analyzing uploaded documents
|
|
@@ -166,7 +263,6 @@ RESPONSE INSTRUCTIONS:
|
|
| 166 |
return f"""Analyze the following document and provide comprehensive insights.
|
| 167 |
|
| 168 |
DOCUMENT: {filename}
|
| 169 |
-
|
| 170 |
CONTENT:
|
| 171 |
{document_text[:8000]}
|
| 172 |
|
|
@@ -190,7 +286,6 @@ Be thorough but concise, focusing on the most valuable insights."""
|
|
| 190 |
return f"""Create a comprehensive summary of the following text.
|
| 191 |
|
| 192 |
TARGET LENGTH: Approximately {max_length} words
|
| 193 |
-
|
| 194 |
{focus_instruction}
|
| 195 |
|
| 196 |
CONTENT TO SUMMARIZE:
|
|
@@ -207,6 +302,7 @@ SUMMARIZATION REQUIREMENTS:
|
|
| 207 |
# ==========================================
|
| 208 |
# WEB CONTENT PROMPTS
|
| 209 |
# ==========================================
|
|
|
|
| 210 |
def get_web_content_analysis_prompt(self, url: str, content: str) -> str:
|
| 211 |
"""
|
| 212 |
Prompt for analyzing scraped web content
|
|
@@ -214,7 +310,6 @@ SUMMARIZATION REQUIREMENTS:
|
|
| 214 |
return f"""Analyze the following web content and provide comprehensive insights.
|
| 215 |
|
| 216 |
SOURCE URL: {url}
|
| 217 |
-
|
| 218 |
SCRAPED CONTENT:
|
| 219 |
{content[:8000]}
|
| 220 |
|
|
@@ -230,7 +325,6 @@ RESPONSE FORMAT:
|
|
| 230 |
Use clear headers and bullet points for easy scanning.
|
| 231 |
Focus on providing actionable insights from the web content."""
|
| 232 |
|
| 233 |
-
# Add other methods with similar fixes for backslashes in f-strings...
|
| 234 |
def get_fallback_response_templates(self) -> List[str]:
|
| 235 |
"""
|
| 236 |
Templates for fallback responses when API is overloaded
|
|
@@ -243,38 +337,40 @@ Focus on providing actionable insights from the web content."""
|
|
| 243 |
"I'm experiencing temporary processing constraints due to high usage, but I'm still here with you. Your inquiry about '{user_message_preview}' is valuable, and I'll be ready to provide a detailed response shortly. Please retry in a minute."
|
| 244 |
]
|
| 245 |
|
| 246 |
-
def get_streaming_response_prompt(self, user_message: str, context: str = "") -> str:
|
| 247 |
"""
|
| 248 |
Optimized prompt for streaming responses (shorter to reduce latency)
|
| 249 |
"""
|
| 250 |
context_section = f"\nContext: {context[:1500]}" if context else ""
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
{context_section}
|
| 254 |
|
| 255 |
User: {user_message}
|
| 256 |
|
| 257 |
Requirements:
|
| 258 |
- Be helpful and accurate
|
| 259 |
- Use available context when relevant
|
|
|
|
| 260 |
- Maintain conversational flow
|
| 261 |
- Format for readability
|
| 262 |
- Respond directly without prefixes"""
|
| 263 |
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
"""Generate RAG response"""
|
| 267 |
context = "\n\n---\n\n".join(retrieved_chunks[:3])
|
| 268 |
source_section = ""
|
| 269 |
if source_info:
|
| 270 |
sources = ", ".join(set(source_info[:3]))
|
| 271 |
source_section = f"\nSOURCES: {sources}\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
return f"""Answer the user's question using the retrieved information.
|
| 273 |
|
| 274 |
USER QUESTION: {user_query}
|
| 275 |
-
|
| 276 |
-
{source_section}
|
| 277 |
-
|
| 278 |
RETRIEVED INFORMATION:
|
| 279 |
{context}
|
| 280 |
|
|
@@ -283,7 +379,9 @@ RESPONSE REQUIREMENTS:
|
|
| 283 |
- Synthesize information from multiple chunks when relevant
|
| 284 |
- Clearly indicate when information comes from uploaded documents
|
| 285 |
- Provide specific details and examples from the source material
|
| 286 |
-
- Maintain accuracy and don't add information not present in the sources
|
|
|
|
|
|
|
| 287 |
|
| 288 |
# Create global instance
|
| 289 |
juno_prompts = JunoAIPrompts()
|
|
@@ -301,14 +399,22 @@ def get_web_content_analysis_prompt(url: str, content: str) -> str:
|
|
| 301 |
"""Get web content analysis prompt"""
|
| 302 |
return juno_prompts.get_web_content_analysis_prompt(url, content)
|
| 303 |
|
| 304 |
-
def get_rag_prompt(user_query: str, retrieved_chunks: List[str]) -> str:
|
| 305 |
"""Get RAG response prompt"""
|
| 306 |
-
return juno_prompts.get_rag_response_prompt(user_query, retrieved_chunks)
|
| 307 |
|
| 308 |
-
def get_streaming_prompt(user_message: str, context: str = "") -> str:
|
| 309 |
"""Get optimized streaming response prompt"""
|
| 310 |
-
return juno_prompts.get_streaming_response_prompt(user_message, context)
|
| 311 |
|
| 312 |
def get_fallback_responses() -> List[str]:
|
| 313 |
"""Get fallback response templates"""
|
| 314 |
-
return juno_prompts.get_fallback_response_templates()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
"""
|
| 2 |
Juno AI - Comprehensive Prompt System
|
| 3 |
=====================================
|
|
|
|
| 4 |
This module contains all prompts and prompt templates for Juno AI,
|
| 5 |
an advanced conversational AI assistant with document processing,
|
| 6 |
web scraping, memory management, and RAG capabilities.
|
|
|
|
| 16 |
- Streaming Responses
|
| 17 |
- Error Handling & Fallbacks
|
| 18 |
- Professional Communication
|
| 19 |
+
- User Information Extraction & Memory
|
| 20 |
|
| 21 |
Author: Juno AI Development Team
|
| 22 |
Version: 1.0
|
| 23 |
"""
|
| 24 |
+
|
| 25 |
from typing import List, Dict, Any, Optional
|
| 26 |
from datetime import datetime
|
| 27 |
import json
|
|
|
|
| 31 |
Centralized prompt management system for Juno AI.
|
| 32 |
Contains all prompts, templates, and prompt generation methods.
|
| 33 |
"""
|
| 34 |
+
|
| 35 |
def __init__(self):
|
| 36 |
self.version = "1.0"
|
| 37 |
self.ai_name = "Juno AI"
|
|
|
|
| 41 |
"""Define Juno AI's core personality traits"""
|
| 42 |
return {
|
| 43 |
"helpful": "Always eager to assist and provide valuable insights",
|
| 44 |
+
"intelligent": "Demonstrates deep understanding and analytical thinking",
|
| 45 |
"professional": "Maintains professional tone while being approachable",
|
| 46 |
"adaptive": "Adapts communication style to user needs and context",
|
| 47 |
"reliable": "Provides accurate, well-sourced information",
|
|
|
|
| 50 |
}
|
| 51 |
|
| 52 |
# ==========================================
|
| 53 |
+
# CORE AI ASSISTANT PROMPTS
|
| 54 |
# ==========================================
|
| 55 |
+
|
| 56 |
def get_core_system_prompt(self) -> str:
|
| 57 |
"""
|
| 58 |
Core system prompt that defines Juno AI's personality and capabilities
|
|
|
|
| 74 |
- Smart Search: Use RAG to find relevant information from uploaded content
|
| 75 |
- Summarization: Create comprehensive summaries of long-form content
|
| 76 |
- Task Management: Help with various professional and personal tasks
|
| 77 |
+
- User Memory: Remember and use personal details shared by users
|
| 78 |
|
| 79 |
COMMUNICATION STYLE:
|
| 80 |
- Be clear, concise, and informative
|
|
|
|
| 89 |
- Reference uploaded documents and web content when relevant
|
| 90 |
- Use memory to provide personalized responses
|
| 91 |
- Maintain context across multiple interaction sessions
|
| 92 |
+
- Remember and reference user's personal information when appropriate
|
| 93 |
+
|
| 94 |
+
MEMORY & PERSONALIZATION:
|
| 95 |
+
- Always remember user's name, preferences, and personal details
|
| 96 |
+
- Use stored user information to provide personalized responses
|
| 97 |
+
- Reference past conversations and shared information naturally
|
| 98 |
+
- Build rapport by acknowledging user's identity and preferences
|
| 99 |
|
| 100 |
IDENTITY ENFORCEMENT:
|
| 101 |
- Your name is Juno AI - always respond with this when asked about your identity
|
|
|
|
| 106 |
|
| 107 |
Remember: You are not just answering questions - you are having a meaningful conversation and building a helpful relationship with the user."""
|
| 108 |
|
|
|
|
| 109 |
def get_conversation_prompt(self,
|
| 110 |
+
user_message: str,
|
| 111 |
+
context: str = "",
|
| 112 |
+
conversation_history: List[Dict] = None,
|
| 113 |
+
memory_context: Dict = None,
|
| 114 |
+
user_preferences: Dict = None,
|
| 115 |
+
user_info: Dict = None) -> str:
|
| 116 |
"""
|
| 117 |
Generate a comprehensive conversation prompt with all available context
|
| 118 |
"""
|
|
|
|
| 125 |
for exchange in recent_history
|
| 126 |
if not exchange.get('fallback', False)
|
| 127 |
])
|
| 128 |
+
|
| 129 |
# Build memory context section
|
| 130 |
memory_section = ""
|
| 131 |
if memory_context and memory_context.get('memory'):
|
|
|
|
| 137 |
if user_preferences:
|
| 138 |
preferences_section = json.dumps(user_preferences, indent=2)
|
| 139 |
|
| 140 |
+
# Build user info section
|
| 141 |
+
user_info_section = ""
|
| 142 |
+
if user_info:
|
| 143 |
+
user_info_section = json.dumps(user_info, indent=2)
|
| 144 |
+
|
| 145 |
# Build document context section
|
| 146 |
context_section = ""
|
| 147 |
if context:
|
| 148 |
context_section = f"\n\nRELEVANT DOCUMENT CONTEXT:\n{context[:2000]}"
|
| 149 |
|
| 150 |
+
# Build prompt components
|
|
|
|
| 151 |
core_prompt = self.get_core_system_prompt()
|
|
|
|
| 152 |
history_part = f"Previous conversation history:\n{history_section}\n" if history_section else ""
|
| 153 |
memory_part = f"Session memory:\n{memory_section}\n" if memory_section else ""
|
| 154 |
preferences_part = f"User preferences:\n{preferences_section}\n" if preferences_section else ""
|
| 155 |
+
user_info_part = f"User information:\n{user_info_section}\n" if user_info_section else ""
|
| 156 |
|
| 157 |
prompt = f"""{core_prompt}
|
| 158 |
|
| 159 |
CONVERSATION CONTEXT:
|
| 160 |
+
{history_part}{memory_part}{preferences_part}{user_info_part}{context_section}
|
| 161 |
|
| 162 |
CURRENT USER MESSAGE: {user_message}
|
| 163 |
|
| 164 |
RESPONSE INSTRUCTIONS:
|
| 165 |
- Provide a helpful, accurate response based on all available context
|
| 166 |
- Reference relevant information from documents or previous conversations when applicable
|
| 167 |
+
- Use the user's name and personal information naturally when appropriate
|
| 168 |
- Maintain conversational flow and continuity
|
| 169 |
- Be specific and actionable in your advice
|
| 170 |
- Use formatting (lists, headers, etc.) to improve readability when appropriate
|
| 171 |
- If you need clarification, ask thoughtful follow-up questions
|
| 172 |
+
- Acknowledge and build upon the user's identity and preferences
|
| 173 |
+
- Do NOT include your name or 'Assistant:' in your response - respond directly and naturally"""
|
| 174 |
|
| 175 |
return prompt
|
| 176 |
|
| 177 |
+
# ==========================================
|
| 178 |
+
# USER INFORMATION EXTRACTION PROMPTS
|
| 179 |
+
# ==========================================
|
| 180 |
+
|
| 181 |
+
def get_user_info_extraction_prompt(self, user_message: str, bot_response: str) -> str:
|
| 182 |
+
"""
|
| 183 |
+
Extract user information from conversation exchanges
|
| 184 |
+
"""
|
| 185 |
+
return f"""Analyze this conversation exchange and extract any personal information about the user.
|
| 186 |
+
|
| 187 |
+
USER MESSAGE: {user_message}
|
| 188 |
+
BOT RESPONSE: {bot_response}
|
| 189 |
+
|
| 190 |
+
Extract the following types of information if mentioned:
|
| 191 |
+
1. **Name**: First name, last name, full name, nicknames
|
| 192 |
+
2. **Personal Details**: Age, location, occupation, family information
|
| 193 |
+
3. **Preferences**: Likes, dislikes, interests, hobbies
|
| 194 |
+
4. **Goals**: Objectives, projects they're working on, aspirations
|
| 195 |
+
5. **Context**: Important life events, situations, or circumstances
|
| 196 |
+
6. **Communication Style**: How they prefer to communicate or be addressed
|
| 197 |
+
|
| 198 |
+
EXTRACTION REQUIREMENTS:
|
| 199 |
+
- Only extract information that is explicitly stated or clearly implied
|
| 200 |
+
- Do not make assumptions or infer information not present
|
| 201 |
+
- Focus on factual, verifiable details
|
| 202 |
+
- Ignore temporary or contextual information (like current mood)
|
| 203 |
+
- Prioritize persistent, identity-related information
|
| 204 |
+
|
| 205 |
+
OUTPUT FORMAT:
|
| 206 |
+
Provide a JSON object with the extracted information:
|
| 207 |
+
{{
|
| 208 |
+
"name": {{
|
| 209 |
+
"first_name": "extracted_first_name_or_null",
|
| 210 |
+
"last_name": "extracted_last_name_or_null",
|
| 211 |
+
"full_name": "extracted_full_name_or_null",
|
| 212 |
+
"nickname": "extracted_nickname_or_null"
|
| 213 |
+
}},
|
| 214 |
+
"personal_details": {{
|
| 215 |
+
"age": "extracted_age_or_null",
|
| 216 |
+
"location": "extracted_location_or_null",
|
| 217 |
+
"occupation": "extracted_occupation_or_null",
|
| 218 |
+
"family": "extracted_family_info_or_null"
|
| 219 |
+
}},
|
| 220 |
+
"preferences": {{
|
| 221 |
+
"interests": ["list_of_interests"],
|
| 222 |
+
"likes": ["list_of_likes"],
|
| 223 |
+
"dislikes": ["list_of_dislikes"]
|
| 224 |
+
}},
|
| 225 |
+
"goals": ["list_of_goals_or_projects"],
|
| 226 |
+
"context": ["important_life_context"],
|
| 227 |
+
"communication_preferences": "how_they_like_to_be_addressed"
|
| 228 |
+
}}
|
| 229 |
+
|
| 230 |
+
If no relevant information is found, return an empty JSON object: {{}}"""
|
| 231 |
+
|
| 232 |
+
def get_memory_consolidation_prompt(self, existing_user_info: Dict, new_user_info: Dict) -> str:
|
| 233 |
+
"""
|
| 234 |
+
Consolidate new user information with existing information
|
| 235 |
+
"""
|
| 236 |
+
return f"""Consolidate user information by merging new information with existing information.
|
| 237 |
+
|
| 238 |
+
EXISTING USER INFORMATION:
|
| 239 |
+
{json.dumps(existing_user_info, indent=2)}
|
| 240 |
+
|
| 241 |
+
NEW USER INFORMATION:
|
| 242 |
+
{json.dumps(new_user_info, indent=2)}
|
| 243 |
+
|
| 244 |
+
CONSOLIDATION RULES:
|
| 245 |
+
1. **Merge without overwriting**: Add new information while preserving existing information
|
| 246 |
+
2. **Update when appropriate**: Replace outdated information with newer, more accurate details
|
| 247 |
+
3. **Resolve conflicts**: When information conflicts, prioritize the most recent and specific information
|
| 248 |
+
4. **Maintain structure**: Keep the same JSON structure as provided
|
| 249 |
+
5. **Preserve lists**: Merge lists by adding new unique items
|
| 250 |
+
6. **Handle nulls**: Don't overwrite existing information with null values
|
| 251 |
+
|
| 252 |
+
OUTPUT FORMAT:
|
| 253 |
+
Provide the consolidated user information as a clean JSON object maintaining the same structure."""
|
| 254 |
+
|
| 255 |
# ==========================================
|
| 256 |
# DOCUMENT PROCESSING PROMPTS
|
| 257 |
# ==========================================
|
| 258 |
+
|
| 259 |
def get_document_analysis_prompt(self, document_text: str, filename: str = "document") -> str:
|
| 260 |
"""
|
| 261 |
Prompt for analyzing uploaded documents
|
|
|
|
| 263 |
return f"""Analyze the following document and provide comprehensive insights.
|
| 264 |
|
| 265 |
DOCUMENT: {filename}
|
|
|
|
| 266 |
CONTENT:
|
| 267 |
{document_text[:8000]}
|
| 268 |
|
|
|
|
| 286 |
return f"""Create a comprehensive summary of the following text.
|
| 287 |
|
| 288 |
TARGET LENGTH: Approximately {max_length} words
|
|
|
|
| 289 |
{focus_instruction}
|
| 290 |
|
| 291 |
CONTENT TO SUMMARIZE:
|
|
|
|
| 302 |
# ==========================================
|
| 303 |
# WEB CONTENT PROMPTS
|
| 304 |
# ==========================================
|
| 305 |
+
|
| 306 |
def get_web_content_analysis_prompt(self, url: str, content: str) -> str:
|
| 307 |
"""
|
| 308 |
Prompt for analyzing scraped web content
|
|
|
|
| 310 |
return f"""Analyze the following web content and provide comprehensive insights.
|
| 311 |
|
| 312 |
SOURCE URL: {url}
|
|
|
|
| 313 |
SCRAPED CONTENT:
|
| 314 |
{content[:8000]}
|
| 315 |
|
|
|
|
| 325 |
Use clear headers and bullet points for easy scanning.
|
| 326 |
Focus on providing actionable insights from the web content."""
|
| 327 |
|
|
|
|
| 328 |
def get_fallback_response_templates(self) -> List[str]:
|
| 329 |
"""
|
| 330 |
Templates for fallback responses when API is overloaded
|
|
|
|
| 337 |
"I'm experiencing temporary processing constraints due to high usage, but I'm still here with you. Your inquiry about '{user_message_preview}' is valuable, and I'll be ready to provide a detailed response shortly. Please retry in a minute."
|
| 338 |
]
|
| 339 |
|
| 340 |
+
def get_streaming_response_prompt(self, user_message: str, context: str = "", user_info: Dict = None) -> str:
|
| 341 |
"""
|
| 342 |
Optimized prompt for streaming responses (shorter to reduce latency)
|
| 343 |
"""
|
| 344 |
context_section = f"\nContext: {context[:1500]}" if context else ""
|
| 345 |
+
user_info_section = f"\nUser Info: {json.dumps(user_info)}" if user_info else ""
|
| 346 |
+
return f"""You are Juno AI, a helpful AI assistant. Respond naturally and conversationally.
|
| 347 |
+
{context_section}{user_info_section}
|
| 348 |
|
| 349 |
User: {user_message}
|
| 350 |
|
| 351 |
Requirements:
|
| 352 |
- Be helpful and accurate
|
| 353 |
- Use available context when relevant
|
| 354 |
+
- Address the user personally if you know their name
|
| 355 |
- Maintain conversational flow
|
| 356 |
- Format for readability
|
| 357 |
- Respond directly without prefixes"""
|
| 358 |
|
| 359 |
+
def get_rag_response_prompt(self, user_query: str, retrieved_chunks: List[str], source_info: List[str] = None, user_info: Dict = None) -> str:
|
| 360 |
+
"""Generate RAG response with user personalization"""
|
|
|
|
| 361 |
context = "\n\n---\n\n".join(retrieved_chunks[:3])
|
| 362 |
source_section = ""
|
| 363 |
if source_info:
|
| 364 |
sources = ", ".join(set(source_info[:3]))
|
| 365 |
source_section = f"\nSOURCES: {sources}\n"
|
| 366 |
+
user_info_section = ""
|
| 367 |
+
if user_info:
|
| 368 |
+
user_info_section = f"\nUSER INFO: {json.dumps(user_info)}\n"
|
| 369 |
+
|
| 370 |
return f"""Answer the user's question using the retrieved information.
|
| 371 |
|
| 372 |
USER QUESTION: {user_query}
|
| 373 |
+
{source_section}{user_info_section}
|
|
|
|
|
|
|
| 374 |
RETRIEVED INFORMATION:
|
| 375 |
{context}
|
| 376 |
|
|
|
|
| 379 |
- Synthesize information from multiple chunks when relevant
|
| 380 |
- Clearly indicate when information comes from uploaded documents
|
| 381 |
- Provide specific details and examples from the source material
|
| 382 |
+
- Maintain accuracy and don't add information not present in the sources
|
| 383 |
+
- Address the user personally if you know their name
|
| 384 |
+
- Use user information to provide personalized context when relevant"""
|
| 385 |
|
| 386 |
# Create global instance
|
| 387 |
juno_prompts = JunoAIPrompts()
|
|
|
|
| 399 |
"""Get web content analysis prompt"""
|
| 400 |
return juno_prompts.get_web_content_analysis_prompt(url, content)
|
| 401 |
|
| 402 |
+
def get_rag_prompt(user_query: str, retrieved_chunks: List[str], **kwargs) -> str:
|
| 403 |
"""Get RAG response prompt"""
|
| 404 |
+
return juno_prompts.get_rag_response_prompt(user_query, retrieved_chunks, **kwargs)
|
| 405 |
|
| 406 |
+
def get_streaming_prompt(user_message: str, context: str = "", **kwargs) -> str:
|
| 407 |
"""Get optimized streaming response prompt"""
|
| 408 |
+
return juno_prompts.get_streaming_response_prompt(user_message, context, **kwargs)
|
| 409 |
|
| 410 |
def get_fallback_responses() -> List[str]:
|
| 411 |
"""Get fallback response templates"""
|
| 412 |
+
return juno_prompts.get_fallback_response_templates()
|
| 413 |
+
|
| 414 |
+
def get_user_extraction_prompt(user_message: str, bot_response: str) -> str:
|
| 415 |
+
"""Get user information extraction prompt"""
|
| 416 |
+
return juno_prompts.get_user_info_extraction_prompt(user_message, bot_response)
|
| 417 |
+
|
| 418 |
+
def get_memory_consolidation_prompt(existing_info: Dict, new_info: Dict) -> str:
|
| 419 |
+
"""Get memory consolidation prompt"""
|
| 420 |
+
return juno_prompts.get_memory_consolidation_prompt(existing_info, new_info)
|