Spaces:
Build error
Build error
Update article_generator.py
Browse files- article_generator.py +10 -5
article_generator.py
CHANGED
|
@@ -70,9 +70,9 @@ def expand_h3_sections(soup, preloaded_data):
|
|
| 70 |
|
| 71 |
if key in preloaded_data:
|
| 72 |
context = preloaded_data[key]
|
| 73 |
-
prompt = f"「{h3_text}」に
|
| 74 |
else:
|
| 75 |
-
prompt = f"「{h3_text}」に
|
| 76 |
|
| 77 |
expanded_text = generate_text_with_gpt4(prompt)
|
| 78 |
new_paragraph = soup.new_tag('p')
|
|
@@ -202,7 +202,7 @@ def setup_plan_and_execute_agent():
|
|
| 202 |
# GPT-4を使用してテキストを生成するヘルパー関数
|
| 203 |
def generate_text_with_gpt4(prompt):
|
| 204 |
response = openai.ChatCompletion.create(
|
| 205 |
-
model="gpt-
|
| 206 |
messages=[{"role": "system", "content": "以下についての詳細な情報をまとめ、適宜箇所書き、もしくは表を使ってオリジナルの内容にしてください。"},
|
| 207 |
{"role": "user", "content": prompt}],
|
| 208 |
temperature=0.7,
|
|
@@ -215,12 +215,17 @@ def perform_initial_tavily_search(h2_texts, h3_texts):
|
|
| 215 |
tavily_search_tool = EnhancedTavilySearchTool()
|
| 216 |
queries = []
|
| 217 |
|
| 218 |
-
for idx, h2_text in enumerate(h2_texts):
|
|
|
|
| 219 |
h3_for_this_h2 = [h3 for h3 in h3_texts if h3.startswith(f"{idx+1}-")]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
query = f"{h2_text} {' '.join(h3_for_this_h2)}"
|
| 221 |
queries.append(query)
|
| 222 |
|
| 223 |
-
print("Performing Tavily search with queries:", queries)
|
| 224 |
response = tavily_search_tool.search(queries)
|
| 225 |
return {query: response[i] for i, query in enumerate(queries)}
|
| 226 |
|
|
|
|
| 70 |
|
| 71 |
if key in preloaded_data:
|
| 72 |
context = preloaded_data[key]
|
| 73 |
+
prompt = f"「{h3_text}」に続ける文章を生成してください。こちらが背景情報です:\n{context}"
|
| 74 |
else:
|
| 75 |
+
prompt = f"「{h3_text}」に続ける文章を生成してください。"
|
| 76 |
|
| 77 |
expanded_text = generate_text_with_gpt4(prompt)
|
| 78 |
new_paragraph = soup.new_tag('p')
|
|
|
|
| 202 |
# GPT-4を使用してテキストを生成するヘルパー関数
|
| 203 |
def generate_text_with_gpt4(prompt):
|
| 204 |
response = openai.ChatCompletion.create(
|
| 205 |
+
model="gpt-4o",
|
| 206 |
messages=[{"role": "system", "content": "以下についての詳細な情報をまとめ、適宜箇所書き、もしくは表を使ってオリジナルの内容にしてください。"},
|
| 207 |
{"role": "user", "content": prompt}],
|
| 208 |
temperature=0.7,
|
|
|
|
| 215 |
tavily_search_tool = EnhancedTavilySearchTool()
|
| 216 |
queries = []
|
| 217 |
|
| 218 |
+
for idx, h2_text in enumerate(h2_texts):
|
| 219 |
+
# プレフィックスにマッチする h3 を探します。
|
| 220 |
h3_for_this_h2 = [h3 for h3 in h3_texts if h3.startswith(f"{idx+1}-")]
|
| 221 |
+
if not h3_for_this_h2:
|
| 222 |
+
print(f"No matching h3 elements found for h2: {h2_text} at index {idx+1}")
|
| 223 |
+
continue # 該当する h3 がなければスキップ
|
| 224 |
+
|
| 225 |
query = f"{h2_text} {' '.join(h3_for_this_h2)}"
|
| 226 |
queries.append(query)
|
| 227 |
|
| 228 |
+
print("Performing Tavily search with queries:", queries)
|
| 229 |
response = tavily_search_tool.search(queries)
|
| 230 |
return {query: response[i] for i, query in enumerate(queries)}
|
| 231 |
|