Spaces:
Runtime error
Runtime error
Update utils/optimizer.py
Browse files- utils/optimizer.py +65 -66
utils/optimizer.py
CHANGED
|
@@ -20,74 +20,73 @@ class ContentOptimizer:
|
|
| 20 |
"""Initialize optimization prompts"""
|
| 21 |
|
| 22 |
# Main content enhancement prompt
|
| 23 |
-
self.enhancement_prompt = (
|
| 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 |
-
# Competitive content analysis prompt
|
| 79 |
-
self.competitive_analysis_prompt =( "Compare this content against best practices for AI search optimization. Identify gaps and opportunities."
|
| 80 |
-
"Original Content: {content}"
|
| 81 |
-
"Analyze against these AI search factors:"
|
| 82 |
-
"- Entity recognition and linking"
|
| 83 |
-
"- Question coverage completeness"
|
| 84 |
-
"- Factual statement clarity"
|
| 85 |
-
"- Conversational flow"
|
| 86 |
-
"- Semantic relationship mapping"
|
| 87 |
-
|
| 88 |
-
"Provide competitive analysis in JSON format with specific recommendations."
|
| 89 |
-
)
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
def optimize_content(self, content: str, analyze_only: bool = False,
|
| 92 |
include_keywords: bool = True, optimization_type: str = "standard") -> Dict[str, Any]:
|
| 93 |
"""
|
|
|
|
| 20 |
"""Initialize optimization prompts"""
|
| 21 |
|
| 22 |
# Main content enhancement prompt
|
| 23 |
+
self.enhancement_prompt = (
|
| 24 |
+
"You are an AI Content Enhancement Specialist. Your purpose is to optimize user-provided text to maximize its effectiveness for large language models (LLMs) in search, question-answering, and conversational AI systems."
|
| 25 |
+
"Evaluate the input text based on the following criteria, assigning a score from 1-10 for each:"
|
| 26 |
+
"Clarity: How easily can the content be understood?"
|
| 27 |
+
"Structuredness: How well-organized and coherent is the content?"
|
| 28 |
+
"LLM Answerability: How easily can an LLM extract precise answers from the content?"
|
| 29 |
+
"Identify the most salient keywords."
|
| 30 |
+
"Rewrite the text to improve:"
|
| 31 |
+
"- Clarity and precision"
|
| 32 |
+
"- Logical structure and flow"
|
| 33 |
+
"- Suitability for LLM-based information retrieval"
|
| 34 |
+
"Present your analysis and optimized text in the following JSON format:"
|
| 35 |
+
"```json"
|
| 36 |
+
"{{"
|
| 37 |
+
"\"scores\": {{"
|
| 38 |
+
"\"clarity\": 8.5,"
|
| 39 |
+
"\"structuredness\": 7.0,"
|
| 40 |
+
"\"answerability\": 9.0"
|
| 41 |
+
"}},,"
|
| 42 |
+
"\"keywords\": [\"example\", \"installation\", \"setup\"],"
|
| 43 |
+
"\"optimized_text\": \"...\""
|
| 44 |
+
"}}"
|
| 45 |
+
"```"
|
| 46 |
+
)
|
| 47 |
|
| 48 |
+
self.seo_style_prompt = ("You are an AI-first SEO specialist. Optimize this content for AI search engines and LLM systems."
|
| 49 |
+
"Focus on:"
|
| 50 |
+
"1. Semantic keyword optimization"
|
| 51 |
+
"2. Question-answer format enhancement"
|
| 52 |
+
"3. Factual accuracy and authority signals"
|
| 53 |
+
"4. Conversational readiness"
|
| 54 |
+
"5. Citation-worthy structure"
|
| 55 |
+
" Provide analysis and optimization in JSON:"
|
| 56 |
+
"```json"
|
| 57 |
+
"{"
|
| 58 |
+
"seo_analysis: {"
|
| 59 |
+
"keyword_density: analysis of current keywords,"
|
| 60 |
+
"semantic_gaps: [missing semantic terms],"
|
| 61 |
+
"readability_score: 8.5,"
|
| 62 |
+
"authority_signals : [credentials, citations]"
|
| 63 |
+
"},"
|
| 64 |
+
"optimized_content: {"
|
| 65 |
+
"title_suggestions: [optimized title 1, optimized title 2],"
|
| 66 |
+
"meta_description: AI-optimized meta description,"
|
| 67 |
+
"enhanced_content: full optimized content...,"
|
| 68 |
+
"structured_data_suggestions: [schema markup recommendations]"
|
| 69 |
+
"},"
|
| 70 |
+
"improvement_summary: {"
|
| 71 |
+
"changes_made: [change 1, change 2],"
|
| 72 |
+
"expected_impact: description of expected improvements"
|
| 73 |
+
"}"
|
| 74 |
+
"}"
|
| 75 |
+
"```"
|
| 76 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
+
# Competitive content analysis prompt
|
| 79 |
+
self.competitive_analysis_prompt =( "Compare this content against best practices for AI search optimization. Identify gaps and opportunities."
|
| 80 |
+
"Original Content: {content}"
|
| 81 |
+
"Analyze against these AI search factors:"
|
| 82 |
+
"- Entity recognition and linking"
|
| 83 |
+
"- Question coverage completeness"
|
| 84 |
+
"- Factual statement clarity"
|
| 85 |
+
"- Conversational flow"
|
| 86 |
+
"- Semantic relationship mapping"
|
| 87 |
+
|
| 88 |
+
"Provide competitive analysis in JSON format with specific recommendations."
|
| 89 |
+
)
|
| 90 |
def optimize_content(self, content: str, analyze_only: bool = False,
|
| 91 |
include_keywords: bool = True, optimization_type: str = "standard") -> Dict[str, Any]:
|
| 92 |
"""
|