Spaces:
Sleeping
Sleeping
Update article_generator.py
Browse files- article_generator.py +11 -5
article_generator.py
CHANGED
|
@@ -247,16 +247,22 @@ def perform_initial_tavily_search(h2_texts, h3_texts):
|
|
| 247 |
for idx, h2_text in enumerate(h2_texts):
|
| 248 |
h3_for_this_h2 = [h3 for h3 in h3_texts if h3.startswith(f"{idx+1}-")]
|
| 249 |
if not h3_for_this_h2 and h2_text.strip() != "まとめ":
|
| 250 |
-
print(f"{h2_text}
|
| 251 |
continue
|
| 252 |
query = f"{h2_text} {' '.join(h3_for_this_h2)}"
|
| 253 |
queries.append(query)
|
| 254 |
-
|
| 255 |
-
print("Tavily
|
| 256 |
responses = tavily_search_tool.search(queries)
|
| 257 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
filtered_responses = filter_responses_by_domain(responses, allowed_domains)
|
| 259 |
-
response_dict = {query: (filtered_responses[i] if i < len(filtered_responses) else "
|
| 260 |
return response_dict
|
| 261 |
|
| 262 |
def save_preloaded_tavily_data(data):
|
|
|
|
| 247 |
for idx, h2_text in enumerate(h2_texts):
|
| 248 |
h3_for_this_h2 = [h3 for h3 in h3_texts if h3.startswith(f"{idx+1}-")]
|
| 249 |
if not h3_for_this_h2 and h2_text.strip() != "まとめ":
|
| 250 |
+
print(f"No matching h3 elements found for h2: {h2_text} at index {idx+1}")
|
| 251 |
continue
|
| 252 |
query = f"{h2_text} {' '.join(h3_for_this_h2)}"
|
| 253 |
queries.append(query)
|
| 254 |
+
|
| 255 |
+
print("Tavily search executing with queries:", queries)
|
| 256 |
responses = tavily_search_tool.search(queries)
|
| 257 |
+
|
| 258 |
+
# レスポンスの形式を確認
|
| 259 |
+
if not isinstance(responses, list):
|
| 260 |
+
print("Error: Response is not a list.")
|
| 261 |
+
return {}
|
| 262 |
+
|
| 263 |
+
# レスポンスをフィルタリング
|
| 264 |
filtered_responses = filter_responses_by_domain(responses, allowed_domains)
|
| 265 |
+
response_dict = {query: (filtered_responses[i] if i < len(filtered_responses) else "No response received") for i, query in enumerate(queries)}
|
| 266 |
return response_dict
|
| 267 |
|
| 268 |
def save_preloaded_tavily_data(data):
|