fmab777 commited on
Commit
c2c94e2
Β·
verified Β·
1 Parent(s): c6f4070

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +32 -2
main.py CHANGED
@@ -329,7 +329,22 @@ async def generate_summary_gemini(text: str, summary_type: str) -> str:
329
  logger.info(f"[Gemini Fallback] Generating {summary_type} summary using {GEMINI_MODEL}. Input length: {len(text)}")
330
 
331
  if summary_type == "paragraph": prompt = ("You are an AI model designed to provide concise summaries using British English spellings. Your output MUST be:\n" "β€’ Clear and simple language suitable for someone unfamiliar with the topic.\n" "β€’ Uses British English spellings throughout.\n" "β€’ Straightforward and understandable vocabulary; avoid complex terms.\n" "β€’ Presented as ONE SINGLE PARAGRAPH.\n" "β€’ No more than 85 words maximum; but does not have to be exactly 85.\n" "β€’ Considers the entire text content equally.\n" "β€’ Uses semicolons (;) instead of em dashes (– or β€”).\n\n" "Here is the text to summarise:")
332
- else: prompt = ("You are an AI model designed to provide concise summaries using British English spellings. Your output MUST strictly follow this Markdown format:\n\n" "β€’ For each distinct topic or section identified in the text, create a heading.\n" "β€’ Each heading MUST be enclosed in double asterisks for bolding (e.g., **Section Title**).\n" "β€’ Immediately following each heading, list the key points as a bulleted list.\n" "β€’ Each bullet point MUST start with a hyphen and a space (- ) on a new line.\n" "β€’ The text within each bullet point should NOT contain any bold formatting.\n" "β€’ Use clear, simple, and straightforward language suitable for someone unfamiliar with the topic.\n" "β€’ Use British English spellings throughout.\n" "β€’ Avoid overly complex or advanced vocabulary.\n" "β€’ Keep bullet points concise.\n" "β€’ Ensure the entire summary takes no more than two minutes to read.\n" "β€’ Consider the entire text's content, not just the beginning or a few topics.\n" "β€’ Use semicolons (;) instead of em dashes (– or β€”).\n\n" "Here is the text to summarise:")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
333
  MAX_INPUT_LENGTH = 1000000
334
  if len(text) > MAX_INPUT_LENGTH: logger.warning(f"[Gemini Fallback] Input length ({len(text)}) exceeds limit ({MAX_INPUT_LENGTH}). Truncating."); text = text[:MAX_INPUT_LENGTH] + "... (Content truncated)"
335
  full_prompt = f"{prompt}\n\n{text}"
@@ -372,7 +387,22 @@ async def generate_summary(text: str, summary_type: str) -> str:
372
  if not OPENROUTER_API_KEY: logger.error("[Primary Summary] OpenRouter key missing."); return "Error: AI model configuration key missing."
373
 
374
  if summary_type == "paragraph": prompt = ("You are an AI model designed to provide concise summaries using British English spellings. Your output MUST be:\n" "β€’ Clear and simple language suitable for someone unfamiliar with the topic.\n" "β€’ Uses British English spellings throughout.\n" "β€’ Straightforward and understandable vocabulary; avoid complex terms.\n" "β€’ Presented as ONE SINGLE PARAGRAPH.\n" "β€’ No more than 85 words maximum; but does not have to be exactly 85.\n" "β€’ Considers the entire text content equally.\n" "β€’ Uses semicolons (;) instead of em dashes (– or β€”).\n\n" "Here is the text to summarise:")
375
- else: prompt = ("You are an AI model designed to provide concise summaries using British English spellings. Your output MUST strictly follow this Markdown format:\n\n" "β€’ For each distinct topic or section identified in the text, create a heading.\n" "β€’ Each heading MUST be enclosed in double asterisks for bolding (e.g., **Section Title**).\n" "β€’ Immediately following each heading, list the key points as a bulleted list.\n" "β€’ Each bullet point MUST start with a hyphen and a space (- ) on a new line.\n" "β€’ The text within each bullet point should NOT contain any bold formatting.\n" "β€’ Use clear, simple, and straightforward language suitable for someone unfamiliar with the topic.\n" "β€’ Use British English spellings throughout.\n" "β€’ Avoid overly complex or advanced vocabulary.\n" "β€’ Keep bullet points concise.\n" "β€’ Ensure the entire summary takes no more than two minutes to read.\n" "β€’ Consider the entire text's content, not just the beginning or a few topics.\n" "β€’ Use semicolons (;) instead of em dashes (– or β€”).\n\n" "Here is the text to summarise:")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
376
  MAX_INPUT_LENGTH = 500000
377
  if len(text) > MAX_INPUT_LENGTH: logger.warning(f"[Primary Summary] Input length ({len(text)}) exceeds limit ({MAX_INPUT_LENGTH}). Truncating."); text = text[:MAX_INPUT_LENGTH] + "... (Content truncated)"
378
  full_prompt = f"{prompt}\n\n{text}"
 
329
  logger.info(f"[Gemini Fallback] Generating {summary_type} summary using {GEMINI_MODEL}. Input length: {len(text)}")
330
 
331
  if summary_type == "paragraph": prompt = ("You are an AI model designed to provide concise summaries using British English spellings. Your output MUST be:\n" "β€’ Clear and simple language suitable for someone unfamiliar with the topic.\n" "β€’ Uses British English spellings throughout.\n" "β€’ Straightforward and understandable vocabulary; avoid complex terms.\n" "β€’ Presented as ONE SINGLE PARAGRAPH.\n" "β€’ No more than 85 words maximum; but does not have to be exactly 85.\n" "β€’ Considers the entire text content equally.\n" "β€’ Uses semicolons (;) instead of em dashes (– or β€”).\n\n" "Here is the text to summarise:")
332
+ else: # points summary
333
+ prompt = ("You are an AI model designed to provide concise summaries using British English spellings. Your output MUST strictly follow this Markdown format:\n\n"
334
+ "β€’ For each distinct topic or section identified in the text, create a heading.\n"
335
+ "β€’ Each heading MUST be enclosed in double asterisks for bolding (e.g., **Section Title**).\n"
336
+ "β€’ Immediately following each heading, list the key points as a bulleted list.\n"
337
+ "β€’ Each bullet point MUST start with a hyphen and a space (- ) on a new line.\n"
338
+ "β€’ The text within each bullet point should NOT contain any bold formatting.\n"
339
+ "β€’ IMPORTANT: Never use bold formatting (double asterisks) within the text of the bullet points themselves.\n" # Added instruction for emphasis
340
+ "β€’ Use clear, simple, and straightforward language suitable for someone unfamiliar with the topic.\n"
341
+ "β€’ Use British English spellings throughout.\n"
342
+ "β€’ Avoid overly complex or advanced vocabulary.\n"
343
+ "β€’ Keep bullet points concise.\n"
344
+ "β€’ Ensure the entire summary takes no more than two minutes to read.\n"
345
+ "β€’ Consider the entire text's content, not just the beginning or a few topics.\n"
346
+ "β€’ Use semicolons (;) instead of em dashes (– or β€”).\n\n"
347
+ "Here is the text to summarise:")
348
  MAX_INPUT_LENGTH = 1000000
349
  if len(text) > MAX_INPUT_LENGTH: logger.warning(f"[Gemini Fallback] Input length ({len(text)}) exceeds limit ({MAX_INPUT_LENGTH}). Truncating."); text = text[:MAX_INPUT_LENGTH] + "... (Content truncated)"
350
  full_prompt = f"{prompt}\n\n{text}"
 
387
  if not OPENROUTER_API_KEY: logger.error("[Primary Summary] OpenRouter key missing."); return "Error: AI model configuration key missing."
388
 
389
  if summary_type == "paragraph": prompt = ("You are an AI model designed to provide concise summaries using British English spellings. Your output MUST be:\n" "β€’ Clear and simple language suitable for someone unfamiliar with the topic.\n" "β€’ Uses British English spellings throughout.\n" "β€’ Straightforward and understandable vocabulary; avoid complex terms.\n" "β€’ Presented as ONE SINGLE PARAGRAPH.\n" "β€’ No more than 85 words maximum; but does not have to be exactly 85.\n" "β€’ Considers the entire text content equally.\n" "β€’ Uses semicolons (;) instead of em dashes (– or β€”).\n\n" "Here is the text to summarise:")
390
+ else: # points summary
391
+ prompt = ("You are an AI model designed to provide concise summaries using British English spellings. Your output MUST strictly follow this Markdown format:\n\n"
392
+ "β€’ For each distinct topic or section identified in the text, create a heading.\n"
393
+ "β€’ Each heading MUST be enclosed in double asterisks for bolding (e.g., **Section Title**).\n"
394
+ "β€’ Immediately following each heading, list the key points as a bulleted list.\n"
395
+ "β€’ Each bullet point MUST start with a hyphen and a space (- ) on a new line.\n"
396
+ "β€’ The text within each bullet point should NOT contain any bold formatting.\n"
397
+ "β€’ IMPORTANT: Never use bold formatting (double asterisks) within the text of the bullet points themselves.\n" # Added instruction for emphasis
398
+ "β€’ Use clear, simple, and straightforward language suitable for someone unfamiliar with the topic.\n"
399
+ "β€’ Use British English spellings throughout.\n"
400
+ "β€’ Avoid overly complex or advanced vocabulary.\n"
401
+ "β€’ Keep bullet points concise.\n"
402
+ "β€’ Ensure the entire summary takes no more than two minutes to read.\n"
403
+ "β€’ Consider the entire text's content, not just the beginning or a few topics.\n"
404
+ "β€’ Use semicolons (;) instead of em dashes (– or β€”).\n\n"
405
+ "Here is the text to summarise:")
406
  MAX_INPUT_LENGTH = 500000
407
  if len(text) > MAX_INPUT_LENGTH: logger.warning(f"[Primary Summary] Input length ({len(text)}) exceeds limit ({MAX_INPUT_LENGTH}). Truncating."); text = text[:MAX_INPUT_LENGTH] + "... (Content truncated)"
408
  full_prompt = f"{prompt}\n\n{text}"