Spaces:
Sleeping
Sleeping
Update third.py
Browse files
third.py
CHANGED
|
@@ -2,7 +2,6 @@
|
|
| 2 |
|
| 3 |
import os
|
| 4 |
import openai
|
| 5 |
-
import json
|
| 6 |
from langchain.chat_models import ChatOpenAI
|
| 7 |
from langchain.experimental.plan_and_execute import PlanAndExecute, load_agent_executor, load_chat_planner
|
| 8 |
from langchain.llms import OpenAI
|
|
@@ -58,13 +57,10 @@ async def main(editable_output2, keyword_id):
|
|
| 58 |
|
| 59 |
# Specify the type of information you want to research.
|
| 60 |
if "人物" in h1_text or any("人物" in h2_text for h2_text in h2_texts) or any("人物" in h3_text for h3_text in h3_texts):
|
| 61 |
-
# If the topic is about a person, specify that you want to research their name and career.
|
| 62 |
purpose += " including the person's name and career"
|
| 63 |
elif "商品" in h1_text or any("商品" in h2_text for h2_text in h2_texts) or any("商品" in h3_text for h3_text in h3_texts):
|
| 64 |
-
# If the topic is about a product, specify that you want to research the brand name, product name, and price.
|
| 65 |
purpose += " including the brand name, product name, and price"
|
| 66 |
elif "イベント" in h1_text or any("イベント" in h2_text for h2_text in h2_texts) or any("イベント" in h3_text for h3_text in h3_texts):
|
| 67 |
-
# If the topic is about an event, specify that you want to research the event's content, schedule, and venue.
|
| 68 |
purpose += " including the event's content, schedule, and venue"
|
| 69 |
|
| 70 |
# Convert the purpose into an instruction in the form of a question.
|
|
@@ -74,23 +70,7 @@ async def main(editable_output2, keyword_id):
|
|
| 74 |
if instruction not in executed_instructions:
|
| 75 |
raw_output = agent.run(instruction)
|
| 76 |
executed_instructions.append(instruction)
|
| 77 |
-
|
| 78 |
-
# raw_outputの内容を確認
|
| 79 |
-
print(f"Raw Output: {raw_output}")
|
| 80 |
-
|
| 81 |
-
try:
|
| 82 |
-
# エージェントの出力をJSONとして解析
|
| 83 |
-
agent_output = json.loads(raw_output)
|
| 84 |
-
|
| 85 |
-
# 'action_input'を取得
|
| 86 |
-
response_content = agent_output['action']['action_input']
|
| 87 |
-
except json.JSONDecodeError:
|
| 88 |
-
# JSON形式でない場合は、raw_outputを直接使用する
|
| 89 |
-
response_content = raw_output
|
| 90 |
-
except Exception as e:
|
| 91 |
-
print(f"Error: {e}")
|
| 92 |
-
return
|
| 93 |
-
|
| 94 |
research_results.append(response_content)
|
| 95 |
else:
|
| 96 |
response_content = "This instruction has already been executed."
|
|
@@ -102,10 +82,10 @@ async def main(editable_output2, keyword_id):
|
|
| 102 |
}
|
| 103 |
|
| 104 |
# Prepare the user message
|
| 105 |
-
research_summary = "\n".join(research_results)
|
| 106 |
user_message = {
|
| 107 |
"role": "user",
|
| 108 |
-
"content": f'"{h1_text}"という記事タイトルに沿った導入文を日本語で作成し、各見出し"{", ".join(h2_texts)}"についての導入文を作成してください。導入文はそれぞれの見出しの直下にある"{", ".join(h3_texts)}"の内容を考慮に入れて作成してください。その後、"{", ".join(h3_texts)}"
|
| 109 |
}
|
| 110 |
|
| 111 |
# Generate a new text using the ChatCompletion API
|
|
@@ -115,10 +95,10 @@ async def main(editable_output2, keyword_id):
|
|
| 115 |
temperature=0.7,
|
| 116 |
)
|
| 117 |
result = response.choices[0]["message"]["content"]
|
| 118 |
-
|
| 119 |
# Save the generated message to output3.txt
|
| 120 |
with open('output3.txt', 'w', encoding='utf-8') as f:
|
| 121 |
f.write(result)
|
| 122 |
-
|
| 123 |
# Print the generated message
|
| 124 |
print(result)
|
|
|
|
| 2 |
|
| 3 |
import os
|
| 4 |
import openai
|
|
|
|
| 5 |
from langchain.chat_models import ChatOpenAI
|
| 6 |
from langchain.experimental.plan_and_execute import PlanAndExecute, load_agent_executor, load_chat_planner
|
| 7 |
from langchain.llms import OpenAI
|
|
|
|
| 57 |
|
| 58 |
# Specify the type of information you want to research.
|
| 59 |
if "人物" in h1_text or any("人物" in h2_text for h2_text in h2_texts) or any("人物" in h3_text for h3_text in h3_texts):
|
|
|
|
| 60 |
purpose += " including the person's name and career"
|
| 61 |
elif "商品" in h1_text or any("商品" in h2_text for h2_text in h2_texts) or any("商品" in h3_text for h3_text in h3_texts):
|
|
|
|
| 62 |
purpose += " including the brand name, product name, and price"
|
| 63 |
elif "イベント" in h1_text or any("イベント" in h2_text for h2_text in h2_texts) or any("イベント" in h3_text for h3_text in h3_texts):
|
|
|
|
| 64 |
purpose += " including the event's content, schedule, and venue"
|
| 65 |
|
| 66 |
# Convert the purpose into an instruction in the form of a question.
|
|
|
|
| 70 |
if instruction not in executed_instructions:
|
| 71 |
raw_output = agent.run(instruction)
|
| 72 |
executed_instructions.append(instruction)
|
| 73 |
+
response_content = raw_output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
research_results.append(response_content)
|
| 75 |
else:
|
| 76 |
response_content = "This instruction has already been executed."
|
|
|
|
| 82 |
}
|
| 83 |
|
| 84 |
# Prepare the user message
|
| 85 |
+
research_summary = "\n".join(research_results)
|
| 86 |
user_message = {
|
| 87 |
"role": "user",
|
| 88 |
+
"content": f'"{h1_text}"という記事タイトルに沿った導入文を日本語で作成し、各見出し"{", ".join(h2_texts)}"についての導入文を作成してください。導入文はそれぞれの見出しの直下にある"{", ".join(h3_texts)}"の内容を考慮に入れて作成してください。その後、"{", ".join(h3_texts)}"のセクションで本文を作成してください。各セクションは、読者の興味を引き、記事の主題を明確に示すものであるべきです。最後に、記事全体のまとめ、<h2>まとめ</h2>としてクローズしてください。以下に取得した情報を示します:{research_summary}'
|
| 89 |
}
|
| 90 |
|
| 91 |
# Generate a new text using the ChatCompletion API
|
|
|
|
| 95 |
temperature=0.7,
|
| 96 |
)
|
| 97 |
result = response.choices[0]["message"]["content"]
|
| 98 |
+
|
| 99 |
# Save the generated message to output3.txt
|
| 100 |
with open('output3.txt', 'w', encoding='utf-8') as f:
|
| 101 |
f.write(result)
|
| 102 |
+
|
| 103 |
# Print the generated message
|
| 104 |
print(result)
|