autoMate/tests/test_langchain.py
2024-04-03 00:23:33 +08:00

30 lines
1.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from functions.open_application_tool import OpenApplicationInput, OpenApplicationTool
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from tools.search_engine_tool import SearchEngineTool
from utils.llm_util import LLM_Util
class TestLangChain:
def test_chain(self):
template = """根据用户输入,提取出搜索引擎的关键字,返回该关键字:
{input}"""
model = LLM_Util().llm()
prompt = ChatPromptTemplate.from_template(template)
chain = prompt | model | StrOutputParser() | SearchEngineTool()
search_datas = chain.invoke({"input": "谁是李一舟"})
info = "\n".join(f"{i + 1}. {data.title}" for i, data in enumerate(search_datas))
choice = input(f"下面是百度搜索结果请选择你觉得有用的信息以逗号分割如1,3,4直接回车代表all in\n{info}")
choice = list(map(int, choice.split(",")))
def test_chain(self):
a = OpenApplicationTool()
# a.invoke(r"C:\Users\yuruo\Desktop\HBuilder X.lnk")
b = OpenApplicationInput.model_fields
for c in b.keys():
print(c)
print(b[c].title)