Yasu777 commited on
Commit
8f9b005
·
1 Parent(s): e0c663e

Update third.py

Browse files
Files changed (1) hide show
  1. third.py +16 -6
third.py CHANGED
@@ -85,10 +85,12 @@ async def main(editable_output2, keyword_id):
85
  # Prepare the user message
86
  research_summary = "\n".join(research_results)
87
  instructions = []
 
88
 
89
  # 記事タイトルに関する指示
90
  instructions.append(f'1. "{h1_text}"に関する導入文を作成してください。')
91
-
 
92
  # research_summaryを文単位に分割
93
  sentences = research_summary.split('。')
94
 
@@ -96,6 +98,7 @@ async def main(editable_output2, keyword_id):
96
  for idx, h2_text in enumerate(h2_texts):
97
  h3_for_this_h2 = [h3 for h3 in h3_texts if h3.startswith(f"{idx+1}-")]
98
  instructions.append(f'{idx+2}. "{h2_text}"に関する導入文を作成してください。この導入文は、以下の小見出しの内容を考慮してください:{"、".join(h3_for_this_h2)}。')
 
99
  for h3 in h3_for_this_h2:
100
  # h3のテキストをキーワードとして使用し、関連する文を探す
101
  related_sentences = [sentence for sentence in sentences if h3 in sentence]
@@ -104,9 +107,11 @@ async def main(editable_output2, keyword_id):
104
  if related_sentences:
105
  content_for_h3 = "。".join(related_sentences) + "。"
106
  instructions.append(f'次に、"{h3}"に関する詳細な内容として、以下の情報を記述してください:{content_for_h3}')
 
107
  else:
108
  instructions.append(f'次に、"{h3}"に関する詳細な内容を記述してください。')
109
-
 
110
  user_message = {
111
  "role": "user",
112
  "content": "\n".join(instructions)
@@ -120,11 +125,16 @@ async def main(editable_output2, keyword_id):
120
  )
121
  result = response.choices[0]["message"]["content"]
122
 
 
 
 
 
 
 
 
123
  # Save the generated message to output3.txt
124
  with open('output3.txt', 'w', encoding='utf-8') as f:
125
- f.write(result)
126
 
127
  # Print the generated message
128
- print(result)
129
-
130
- # 以下、main関数の呼び出しやその他の処理を追加することができます。
 
85
  # Prepare the user message
86
  research_summary = "\n".join(research_results)
87
  instructions = []
88
+ formatted_text = []
89
 
90
  # 記事タイトルに関する指示
91
  instructions.append(f'1. "{h1_text}"に関する導入文を作成してください。')
92
+ formatted_text.append(f"<h1>{h1_text}</h1>")
93
+
94
  # research_summaryを文単位に分割
95
  sentences = research_summary.split('。')
96
 
 
98
  for idx, h2_text in enumerate(h2_texts):
99
  h3_for_this_h2 = [h3 for h3 in h3_texts if h3.startswith(f"{idx+1}-")]
100
  instructions.append(f'{idx+2}. "{h2_text}"に関する導入文を作成してください。この導入文は、以下の小見出しの内容を考慮してください:{"、".join(h3_for_this_h2)}。')
101
+ formatted_text.append(f"<h2>{h2_text}</h2>")
102
  for h3 in h3_for_this_h2:
103
  # h3のテキストをキーワードとして使用し、関連する文を探す
104
  related_sentences = [sentence for sentence in sentences if h3 in sentence]
 
107
  if related_sentences:
108
  content_for_h3 = "。".join(related_sentences) + "。"
109
  instructions.append(f'次に、"{h3}"に関する詳細な内容として、以下の情報を記述してください:{content_for_h3}')
110
+ formatted_text.append(f"<h3>{h3}</h3>")
111
  else:
112
  instructions.append(f'次に、"{h3}"に関する詳細な内容を記述してください。')
113
+ formatted_text.append(f"<h3>{h3}</h3>")
114
+
115
  user_message = {
116
  "role": "user",
117
  "content": "\n".join(instructions)
 
125
  )
126
  result = response.choices[0]["message"]["content"]
127
 
128
+ # Split the generated text into sections
129
+ sections = result.split("\n")
130
+
131
+ # Format the generated text with the HTML tags
132
+ for i, section in enumerate(sections):
133
+ formatted_text[i] += section
134
+
135
  # Save the generated message to output3.txt
136
  with open('output3.txt', 'w', encoding='utf-8') as f:
137
+ f.write("\n".join(formatted_text))
138
 
139
  # Print the generated message
140
+ print("\n".join(formatted_text))