调试后整体可以使用的版本。
This commit is contained in:
@@ -3,7 +3,7 @@ from langchain_core.output_parsers import StrOutputParser
|
||||
from langchain_experimental.utilities import PythonREPL
|
||||
from langchain_core.tools import Tool
|
||||
from langchain_experimental.tools import PythonREPLTool
|
||||
from project import ProjectBuilder
|
||||
from project import ProjectBuilder, ProjectToolkit
|
||||
import sys
|
||||
import io
|
||||
import traceback
|
||||
@@ -43,6 +43,7 @@ class CodeExecutor:
|
||||
try:
|
||||
namespace = {
|
||||
"project": __import__("project"),
|
||||
"ProjectBuilder": ProjectBuilder,
|
||||
}
|
||||
|
||||
old_stdout = sys.stdout
|
||||
|
||||
+39
-47
@@ -112,12 +112,9 @@ class DialogManager:
|
||||
rewritten_list.append((rewritten, doc.page_content))
|
||||
return rewritten_list
|
||||
|
||||
async def run_async(self, pre_input: str = None, automated: bool = False):
|
||||
async def run_async(self, pre_input: str = None):
|
||||
logger.info("启动对话管理器,等待用户输入")
|
||||
if automated:
|
||||
print("自动化模式已启动。")
|
||||
else:
|
||||
print("欢迎使用博微造价工程数据访问系统,输入 exit 退出。")
|
||||
print("欢迎使用博微造价工程数据访问系统,输入 exit 退出。")
|
||||
|
||||
if pre_input:
|
||||
user_questions = [pre_input]
|
||||
@@ -127,16 +124,11 @@ class DialogManager:
|
||||
while True:
|
||||
if user_questions:
|
||||
user_question = user_questions.pop(0)
|
||||
if not automated:
|
||||
print(f"预输入问题:{user_question}")
|
||||
elif automated:
|
||||
if not user_questions:
|
||||
logger.info("自动化模式下没有更多问题,退出程序。")
|
||||
break
|
||||
print(f"预输入问题:{user_question}")
|
||||
else:
|
||||
user_question = input("请输入您的问题:")
|
||||
|
||||
if user_question.strip().lower() == "exit" and not automated:
|
||||
if user_question.strip().lower() == "exit":
|
||||
logger.info("用户退出程序")
|
||||
print("退出程序。")
|
||||
break
|
||||
@@ -147,38 +139,38 @@ class DialogManager:
|
||||
user_questions.clear()
|
||||
continue
|
||||
|
||||
if automated:
|
||||
# 自动化模式下选择第一个结果
|
||||
selected_rewritten, selected_knowledge = rewritten_results[0]
|
||||
logger.info(f"自动化模式选择第一个访问请求,内容:{selected_rewritten}")
|
||||
result = self.code_executor.generate_and_run_code(
|
||||
selected_rewritten,
|
||||
context=selected_knowledge,
|
||||
bowei_api_docs=self.bowei_api_docs
|
||||
)
|
||||
logger.info("代码执行完成,返回结果")
|
||||
print("\n访问结果:\n", result)
|
||||
print("-" * 50)
|
||||
else:
|
||||
InteractionHandler.display_rewritten_requests(rewritten_results)
|
||||
choice_index = InteractionHandler.get_user_choice(rewritten_results)
|
||||
if choice_index is not None:
|
||||
selected_rewritten, selected_knowledge = rewritten_results[choice_index]
|
||||
logger.info(f"用户选择访问请求编号 {choice_index + 1},内容:{selected_rewritten}")
|
||||
print(f"\n您选择的访问请求是:\n{selected_rewritten}\n")
|
||||
print(f"相关知识内容:\n{selected_knowledge}\n")
|
||||
#confirm = input("请确认是否继续执行该请求(输入n取消,其他继续):").strip().lower()
|
||||
confirm = ""
|
||||
if confirm == "n":
|
||||
#logger.info("用户取消执行访问请求")
|
||||
print("取消执行,您可以重新输入问题。\n" + "-"*50)
|
||||
else:
|
||||
#logger.info("用户确认执行访问请求")
|
||||
result = self.code_executor.generate_and_run_code(
|
||||
selected_rewritten,
|
||||
context=selected_knowledge,
|
||||
bowei_api_docs=self.bowei_api_docs
|
||||
)
|
||||
logger.info("代码执行完成,返回结果")
|
||||
print("\n访问结果:\n", result)
|
||||
print("-" * 50)
|
||||
InteractionHandler.display_rewritten_requests(rewritten_results)
|
||||
choice_index = InteractionHandler.get_user_choice(rewritten_results)
|
||||
if choice_index is not None:
|
||||
selected_rewritten, selected_knowledge = rewritten_results[choice_index]
|
||||
logger.info(f"用户选择访问请求编号 {choice_index + 1},内容:{selected_rewritten}")
|
||||
print(f"\n您选择的访问请求是:\n{selected_rewritten}\n")
|
||||
print(f"相关知识内容:\n{selected_knowledge}\n")
|
||||
#confirm = input("请确认是否继续执行该请求(输入n取消,其他继续):").strip().lower()
|
||||
confirm = ""
|
||||
if confirm == "n":
|
||||
#logger.info("用户取消执行访问请求")
|
||||
print("取消执行,您可以重新输入问题。\n" + "-"*50)
|
||||
else:
|
||||
#logger.info("用户确认执行访问请求")
|
||||
result = self.execute_generated_code(
|
||||
selected_rewritten,
|
||||
selected_knowledge
|
||||
)
|
||||
print("\n访问结果:\n", result)
|
||||
print("-" * 50)
|
||||
|
||||
def execute_generated_code(self, selected_rewritten, selected_knowledge):
|
||||
"""
|
||||
执行生成的代码并返回结果
|
||||
:param selected_rewritten: 选中的重写后的请求
|
||||
:param selected_knowledge: 选中的知识
|
||||
:return: 代码执行结果
|
||||
"""
|
||||
result = self.code_executor.generate_and_run_code(
|
||||
selected_rewritten,
|
||||
context=selected_knowledge,
|
||||
bowei_api_docs=self.bowei_api_docs
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
@@ -17,6 +17,9 @@ class Neo4jRawRetriever:
|
||||
def close(self):
|
||||
self.driver.close()
|
||||
|
||||
def driver(self):
|
||||
return self.driver
|
||||
|
||||
def get_relevant_documents(self, cypher_query: str) -> list[Document]:
|
||||
with self.driver.session() as session:
|
||||
result = session.run(cypher_query)
|
||||
|
||||
Reference in New Issue
Block a user