Guiyom commited on
Commit
2f1fe79
·
verified ·
1 Parent(s): 3ab26ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -28
app.py CHANGED
@@ -177,17 +177,22 @@ def fine_tune_report(adjustment_request: str, openai_api_key: str, serpapi_api_k
177
  logging.info("fine_tune_report: Starting fine-tuning process based on the adjustment request.")
178
 
179
  # Step 1: Get unique plain text string(s) (without HTML) that identify the targeted area.
180
- prompt_identify = (
181
- f"You are a meticulous technical editor. Below is the full report HTML and a "
182
- f"user adjustment request. Extract one or more unique plain-text string(s) (without any HTML tags or formatting) "
183
- f"that uniquely appear in the area(s) targeted by the adjustment request. Output them in a JSON object with the key "
184
- f"\"identified_unique_strings\" mapped to a list of strings. Ensure these strings exactly match the content in the report.\n\n"
185
- f"Full Report HTML:\n{report_html}\n\n"
186
- f"User Adjustment Request:\n{adjustment_request}\n\n"
187
- f"Only output valid JSON."
 
 
 
 
 
188
  )
189
 
190
- response_identify = openai_call(prompt=prompt_identify, model="o3-mini", max_tokens_param=1500, temperature=0)
191
  logging.info(f"fine_tune_report: Raw unique string identification response: {response_identify}")
192
 
193
  try:
@@ -1207,25 +1212,6 @@ Note: no need to add a reference table at the end of the focus box, all the refe
1207
  result = result.strip().strip("```").strip()
1208
  logging.info(f"The code produced for this focus placeholder:\n{placeholder_text}\n\n {result}\n\n")
1209
  return result
1210
-
1211
- def replace_focus_placeholders(report_html: str, context: str, initial_query: str, crumbs: str) -> str:
1212
- pattern = r"\[\[Focus Placeholder (\d+):(.*?)\]\]" # Capture placeholder number
1213
- replacements = []
1214
-
1215
- def placeholder_replacer(match):
1216
- placeholder_num = match.group(1)
1217
- instructions = match.group(2).strip()
1218
- logging.info(f"Generating focus box {placeholder_num}")
1219
-
1220
- try:
1221
- focus_html = generate_focus_snippet(instructions, context, initial_query, crumbs)
1222
- # Add error boundary and logging
1223
- return f'<!-- Focus {placeholder_num} Start -->\n{focus_html}\n<!-- Focus {placeholder_num} End -->'
1224
- except Exception as e:
1225
- logging.error(f"Focus {placeholder_num} failed: {str(e)}")
1226
- return f'<!-- ERROR GENERATING VISUAL {placeholder_num} -->'
1227
-
1228
- return re.sub(pattern, placeholder_replacer, report_html, flags=re.DOTALL)
1229
 
1230
  def get_random_header():
1231
  headers = [
 
177
  logging.info("fine_tune_report: Starting fine-tuning process based on the adjustment request.")
178
 
179
  # Step 1: Get unique plain text string(s) (without HTML) that identify the targeted area.
180
+ prompt_identify = (f"""
181
+ You are a meticulous technical editor. Below is the full report HTML and a user adjustment request.
182
+ Extract one or more unique plain-text string(s) (without any HTML tags or formatting) that uniquely appear in the area(s) targeted by the adjustment request.
183
+ Output them in a JSON object with the key "identified_unique_strings" mapped to a list of strings.
184
+ Ensure these strings exactly match the content in the report.
185
+
186
+ Full Report HTML:
187
+ {report_html}
188
+
189
+ User Adjustment Request:
190
+ {adjustment_request}
191
+
192
+ Only output valid JSON."""
193
  )
194
 
195
+ response_identify = openai_call(prompt=prompt_identify, model="o3-mini", max_tokens_param=5000, temperature=0)
196
  logging.info(f"fine_tune_report: Raw unique string identification response: {response_identify}")
197
 
198
  try:
 
1212
  result = result.strip().strip("```").strip()
1213
  logging.info(f"The code produced for this focus placeholder:\n{placeholder_text}\n\n {result}\n\n")
1214
  return result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1215
 
1216
  def get_random_header():
1217
  headers = [