Yasu777 commited on
Commit
ab7abf1
·
verified ·
1 Parent(s): 374c331

Update article_generator.py

Browse files
Files changed (1) hide show
  1. article_generator.py +9 -3
article_generator.py CHANGED
@@ -62,7 +62,10 @@ def expand_h3_sections(soup, preloaded_data):
62
  h3_elements = soup.find_all('h3')
63
  for h3 in h3_elements:
64
  h3_text = h3.get_text(strip=True)
65
- section_id = h3['id']
 
 
 
66
  key = f"{h3_text} {section_id}"
67
 
68
  if key in preloaded_data:
@@ -108,7 +111,10 @@ def expand_section_with_gpt4(h2_text, h3_texts, preloaded_data):
108
  with ThreadPoolExecutor(max_workers=max(1, len(prompts))) as executor:
109
  future_to_prompt = {executor.submit(generate_text_with_gpt4, prompt): h3_text for prompt, h3_text in zip(prompts, h3_texts)}
110
  for future in as_completed(future_to_prompt):
111
- h3_text = future_to_prompt[future]
 
 
 
112
  try:
113
  expanded_text = future.result()
114
  expanded_texts.append(expanded_text)
@@ -196,7 +202,7 @@ def setup_plan_and_execute_agent():
196
  # GPT-4を使用してテキストを生成するヘルパー関数
197
  def generate_text_with_gpt4(prompt):
198
  response = openai.ChatCompletion.create(
199
- model="gpt-4o",
200
  messages=[{"role": "system", "content": "以下についての詳細な情報をまとめ、適宜箇所書き、もしくは表を使ってオリジナルの内容にしてください。"},
201
  {"role": "user", "content": prompt}],
202
  temperature=0.7,
 
62
  h3_elements = soup.find_all('h3')
63
  for h3 in h3_elements:
64
  h3_text = h3.get_text(strip=True)
65
+ section_id = h3.get('id', None)
66
+ if section_id is None:
67
+ print(f"Warning: h3 element '{h3_text}' has no ID.")
68
+ continue
69
  key = f"{h3_text} {section_id}"
70
 
71
  if key in preloaded_data:
 
111
  with ThreadPoolExecutor(max_workers=max(1, len(prompts))) as executor:
112
  future_to_prompt = {executor.submit(generate_text_with_gpt4, prompt): h3_text for prompt, h3_text in zip(prompts, h3_texts)}
113
  for future in as_completed(future_to_prompt):
114
+ h3_text = future_to_prompt.get(future)
115
+ if h3_text is None:
116
+ print("Error: Future not found in future_to_prompt")
117
+ continue
118
  try:
119
  expanded_text = future.result()
120
  expanded_texts.append(expanded_text)
 
202
  # GPT-4を使用してテキストを生成するヘルパー関数
203
  def generate_text_with_gpt4(prompt):
204
  response = openai.ChatCompletion.create(
205
+ model="gpt-4-turbo",
206
  messages=[{"role": "system", "content": "以下についての詳細な情報をまとめ、適宜箇所書き、もしくは表を使ってオリジナルの内容にしてください。"},
207
  {"role": "user", "content": prompt}],
208
  temperature=0.7,