Spaces:
Sleeping
Sleeping
Update third.py
Browse files
third.py
CHANGED
|
@@ -11,12 +11,22 @@ from langchain.agents.tools import Tool
|
|
| 11 |
from bs4 import BeautifulSoup
|
| 12 |
import asyncio
|
| 13 |
from datetime import timedelta
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# APIキーと検索エンジンIDの設定
|
| 16 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 17 |
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
| 18 |
CUSTOM_SEARCH_ENGINE_ID = os.getenv("CUSTOM_SEARCH_ENGINE_ID")
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
# 追加: 実行された指示を追跡するリスト
|
| 21 |
executed_instructions = []
|
| 22 |
|
|
@@ -71,10 +81,14 @@ async def main(editable_output2, keyword_id):
|
|
| 71 |
# Convert the purpose into an instruction in the form of a question.
|
| 72 |
instruction = f"Can you research {purpose} and include specific details such as names, ages, careers, product names, service names, store names, locations, times, and any relevant numerical data or statistics in your response?"
|
| 73 |
|
| 74 |
-
# Run the instruction
|
| 75 |
if instruction not in executed_instructions:
|
| 76 |
-
|
| 77 |
executed_instructions.append(instruction)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
research_results.append(output_text)
|
| 79 |
else:
|
| 80 |
output_text = "This instruction has already been executed."
|
|
|
|
| 11 |
from bs4 import BeautifulSoup
|
| 12 |
import asyncio
|
| 13 |
from datetime import timedelta
|
| 14 |
+
from pydantic import BaseModel
|
| 15 |
+
from langchain.schema.output_parser import PydanticOutputParser
|
| 16 |
|
| 17 |
# APIキーと検索エンジンIDの設定
|
| 18 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 19 |
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
| 20 |
CUSTOM_SEARCH_ENGINE_ID = os.getenv("CUSTOM_SEARCH_ENGINE_ID")
|
| 21 |
|
| 22 |
+
# Pydanticのモデルを定義
|
| 23 |
+
class LLMOutput(BaseModel):
|
| 24 |
+
action: str
|
| 25 |
+
action_input: str
|
| 26 |
+
|
| 27 |
+
# PydanticOutputParserのインスタンスを作成
|
| 28 |
+
output_parser = PydanticOutputParser(LLMOutput)
|
| 29 |
+
|
| 30 |
# 追加: 実行された指示を追跡するリスト
|
| 31 |
executed_instructions = []
|
| 32 |
|
|
|
|
| 81 |
# Convert the purpose into an instruction in the form of a question.
|
| 82 |
instruction = f"Can you research {purpose} and include specific details such as names, ages, careers, product names, service names, store names, locations, times, and any relevant numerical data or statistics in your response?"
|
| 83 |
|
| 84 |
+
# Run the instruction with a clear expectation of the output format
|
| 85 |
if instruction not in executed_instructions:
|
| 86 |
+
raw_output = agent.run(instruction)
|
| 87 |
executed_instructions.append(instruction)
|
| 88 |
+
|
| 89 |
+
# Parse the LLM output using the PydanticOutputParser
|
| 90 |
+
parsed_output = output_parser.parse(raw_output)
|
| 91 |
+
output_text = parsed_output.action_input
|
| 92 |
research_results.append(output_text)
|
| 93 |
else:
|
| 94 |
output_text = "This instruction has already been executed."
|