Spaces:
Runtime error
Runtime error
Update utils/optimizer.py
Browse files- utils/optimizer.py +19 -17
utils/optimizer.py
CHANGED
|
@@ -137,25 +137,25 @@ class ContentOptimizer:
|
|
| 137 |
return {'error': f"Optimization failed: {str(e)}"}
|
| 138 |
|
| 139 |
def _standard_optimization(self, content: str, analyze_only: bool, include_keywords: bool) -> Dict[str, Any]:
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
prompt_text = prompt_text.replace(
|
| 145 |
-
"
|
| 146 |
-
|
| 147 |
-
).replace(
|
| 148 |
-
'"optimized_text": "..."',
|
| 149 |
-
'"optimization_suggestions": ["suggestion 1", "suggestion 2"]'
|
| 150 |
)
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
''
|
| 155 |
-
)
|
| 156 |
-
else:
|
| 157 |
-
# Use dedicated rewrite prompt for optimization
|
| 158 |
-
prompt_text = self.optimization_rewrite_prompt
|
| 159 |
|
| 160 |
prompt_template = ChatPromptTemplate.from_messages([
|
| 161 |
SystemMessagePromptTemplate.from_template(prompt_text),
|
|
@@ -177,6 +177,8 @@ class ContentOptimizer:
|
|
| 177 |
|
| 178 |
return parsed_result
|
| 179 |
|
|
|
|
|
|
|
| 180 |
def _seo_style_optimization(self, content: str, analyze_only: bool) -> Dict[str, Any]:
|
| 181 |
"""SEO-focused optimization for AI search engines"""
|
| 182 |
try:
|
|
|
|
| 137 |
return {'error': f"Optimization failed: {str(e)}"}
|
| 138 |
|
| 139 |
def _standard_optimization(self, content: str, analyze_only: bool, include_keywords: bool) -> Dict[str, Any]:
|
| 140 |
+
"""Standard content optimization using enhancement prompt"""
|
| 141 |
+
try:
|
| 142 |
+
if analyze_only:
|
| 143 |
+
prompt_text = self.enhancement_prompt
|
| 144 |
+
prompt_text = prompt_text.replace(
|
| 145 |
+
"Rewrite the text to improve:",
|
| 146 |
+
"Analyze the text for potential improvements in:"
|
| 147 |
+
).replace(
|
| 148 |
+
'"optimized_text": "..."',
|
| 149 |
+
'"optimization_suggestions": ["suggestion 1", "suggestion 2"]'
|
| 150 |
+
)
|
| 151 |
+
if not include_keywords:
|
| 152 |
prompt_text = prompt_text.replace(
|
| 153 |
+
'"keywords": ["example", "installation", "setup"],',
|
| 154 |
+
''
|
|
|
|
|
|
|
|
|
|
| 155 |
)
|
| 156 |
+
else:
|
| 157 |
+
# Use dedicated rewrite prompt for optimization
|
| 158 |
+
prompt_text = self.optimization_rewrite_prompt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
prompt_template = ChatPromptTemplate.from_messages([
|
| 161 |
SystemMessagePromptTemplate.from_template(prompt_text),
|
|
|
|
| 177 |
|
| 178 |
return parsed_result
|
| 179 |
|
| 180 |
+
except Exception as e:
|
| 181 |
+
return {'error': f"Standard optimization failed: {str(e)}"}
|
| 182 |
def _seo_style_optimization(self, content: str, analyze_only: bool) -> Dict[str, Any]:
|
| 183 |
"""SEO-focused optimization for AI search engines"""
|
| 184 |
try:
|