MBilal-72 commited on
Commit
7f31da2
·
verified ·
1 Parent(s): 4aade35

Update utils/optimizer.py

Browse files
Files changed (1) hide show
  1. utils/optimizer.py +33 -33
utils/optimizer.py CHANGED
@@ -138,47 +138,47 @@ class ContentOptimizer:
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),
162
- HumanMessagePromptTemplate.from_template(content[:6000])
163
- ])
164
 
165
- chain = prompt_template | self.llm
166
- result = chain.invoke({})
167
 
168
- result_content = result.content if hasattr(result, 'content') else str(result)
169
- parsed_result = self._parse_optimization_result(result_content)
170
 
171
- parsed_result.update({
172
- 'optimization_type': 'standard',
173
- 'analyze_only': analyze_only,
174
- 'original_length': len(content),
175
- 'original_word_count': len(content.split())
176
- })
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:
 
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),
162
+ HumanMessagePromptTemplate.from_template(content[:6000])
163
+ ])
164
 
165
+ chain = prompt_template | self.llm
166
+ result = chain.invoke({})
167
 
168
+ result_content = result.content if hasattr(result, 'content') else str(result)
169
+ parsed_result = self._parse_optimization_result(result_content)
170
 
171
+ parsed_result.update({
172
+ 'optimization_type': 'standard',
173
+ 'analyze_only': analyze_only,
174
+ 'original_length': len(content),
175
+ 'original_word_count': len(content.split())
176
+ })
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: