Spaces:
Sleeping
Sleeping
Update article_generator.py
Browse files- article_generator.py +4 -4
article_generator.py
CHANGED
|
@@ -8,6 +8,7 @@ from langchain.chat_models import ChatOpenAI
|
|
| 8 |
from langchain_experimental.plan_and_execute import PlanAndExecute, load_agent_executor, load_chat_planner
|
| 9 |
from langchain.llms import OpenAI
|
| 10 |
from langchain.agents.tools import Tool
|
|
|
|
| 11 |
|
| 12 |
# APIキーの設定
|
| 13 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
|
@@ -76,7 +77,7 @@ def clear_state():
|
|
| 76 |
return "状態がクリアされました"
|
| 77 |
|
| 78 |
# 見出しを処理する関数
|
| 79 |
-
def process_heading(agent, h2_text, h3_for_this_h2,
|
| 80 |
query = f"{h2_text} {' '.join(h3_for_this_h2)}"
|
| 81 |
if query in cached_responses:
|
| 82 |
return (query, cached_responses[query])
|
|
@@ -149,7 +150,7 @@ def generate_article(editable_output2):
|
|
| 149 |
futures = []
|
| 150 |
for h2_text in h2_texts:
|
| 151 |
h3_for_this_h2 = [h3 for h3 in h3_texts if h3.startswith(f"{h2_texts.index(h2_text)+1}-")]
|
| 152 |
-
futures.append(executor.submit(process_heading, agent, h2_text, h3_for_this_h2,
|
| 153 |
|
| 154 |
for future in as_completed(futures):
|
| 155 |
purpose, response = future.result()
|
|
@@ -300,5 +301,4 @@ def continue_generate_article():
|
|
| 300 |
if os.path.exists("state.json"):
|
| 301 |
os.remove("state.json")
|
| 302 |
|
| 303 |
-
return final_result
|
| 304 |
-
|
|
|
|
| 8 |
from langchain_experimental.plan_and_execute import PlanAndExecute, load_agent_executor, load_chat_planner
|
| 9 |
from langchain.llms import OpenAI
|
| 10 |
from langchain.agents.tools import Tool
|
| 11 |
+
import gradio as gr
|
| 12 |
|
| 13 |
# APIキーの設定
|
| 14 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
|
|
|
| 77 |
return "状態がクリアされました"
|
| 78 |
|
| 79 |
# 見出しを処理する関数
|
| 80 |
+
def process_heading(agent, h2_text, h3_for_this_h2, cached_responses):
|
| 81 |
query = f"{h2_text} {' '.join(h3_for_this_h2)}"
|
| 82 |
if query in cached_responses:
|
| 83 |
return (query, cached_responses[query])
|
|
|
|
| 150 |
futures = []
|
| 151 |
for h2_text in h2_texts:
|
| 152 |
h3_for_this_h2 = [h3 for h3 in h3_texts if h3.startswith(f"{h2_texts.index(h2_text)+1}-")]
|
| 153 |
+
futures.append(executor.submit(process_heading, agent, h2_text, h3_for_this_h2, cached_responses))
|
| 154 |
|
| 155 |
for future in as_completed(futures):
|
| 156 |
purpose, response = future.result()
|
|
|
|
| 301 |
if os.path.exists("state.json"):
|
| 302 |
os.remove("state.json")
|
| 303 |
|
| 304 |
+
return final_result
|
|
|