Soumyajit94298 commited on
Commit
224f779
·
1 Parent(s): 80d491a

prompt change

Browse files
Files changed (1) hide show
  1. server/utils/summarize.py +31 -5
server/utils/summarize.py CHANGED
@@ -33,11 +33,14 @@ def summarize(all_text: str):
33
 
34
 
35
  def summarize_week(all_text: str):
 
 
36
  MAX_WORDS = 90000 # Keep buffer for OpenAI token limit
37
  all_text = " ".join(all_text.split()[:MAX_WORDS])
38
- new_text=" ".join(all_text.split())
39
  print(len(new_text))
40
- if len(new_text)==0:
 
41
  return None
42
 
43
  model_name = "gpt-4o-mini"
@@ -45,19 +48,42 @@ def summarize_week(all_text: str):
45
  response = client.chat.completions.create(
46
  model=model_name,
47
  messages=[
48
- {"role": "system", "content": "You are an AI that summarizes long emails related to the topic and write an article"},
49
- {"role": "user", "content": f"The context is: {new_text} \n Summarize the above mentioned context and write a beautiful breife article understanding from the context"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  ],
51
  max_tokens=2000
52
  )
53
 
54
- # Extract structured JSON response
55
  final_summary = response.choices[0].message.content.strip()
56
  return final_summary
57
 
58
 
59
 
60
 
 
61
  if __name__=="__main__":
62
  text="""
63
  Hello City Council,
 
33
 
34
 
35
  def summarize_week(all_text: str):
36
+ import openai
37
+
38
  MAX_WORDS = 90000 # Keep buffer for OpenAI token limit
39
  all_text = " ".join(all_text.split()[:MAX_WORDS])
40
+ new_text = " ".join(all_text.split())
41
  print(len(new_text))
42
+
43
+ if len(new_text) == 0:
44
  return None
45
 
46
  model_name = "gpt-4o-mini"
 
48
  response = client.chat.completions.create(
49
  model=model_name,
50
  messages=[
51
+ {
52
+ "role": "system",
53
+ "content": (
54
+ "You are an AI designed to summarize long emails or documents "
55
+ "and format them into a **professional, beautiful article** written in **Markdown**. "
56
+ "Structure the article systematically with a clear title, sections, bullet points, and conclusion."
57
+ )
58
+ },
59
+ {
60
+ "role": "user",
61
+ "content": (
62
+ f"The context is: {new_text}\n\n"
63
+ "Please summarize the above content into a **well-structured Markdown article** with:\n"
64
+ "- A clear title\n"
65
+ "- Proper headings (##)\n"
66
+ "- Bullet points (where needed)\n"
67
+ "- Bold text (**text**)\n"
68
+ "- Italic (*text*)\n"
69
+ "- Unordered list (- Item 1) \n"
70
+ "- A conclusion\n"
71
+ "- Keep it engaging but concise.\n"
72
+ "- Use Markdown formatting properly.\n"
73
+ "- Avoid unnecessary repetition.\n"
74
+ )
75
+ }
76
  ],
77
  max_tokens=2000
78
  )
79
 
 
80
  final_summary = response.choices[0].message.content.strip()
81
  return final_summary
82
 
83
 
84
 
85
 
86
+
87
  if __name__=="__main__":
88
  text="""
89
  Hello City Council,