"""A single step in an execution plan for a RAG system."""
name: str = Field(description="The name of the tool to use.")
query: str = Field(description="A natural language search query for a RAG system.")
class QueryPlan(BaseModel):
"""A plan for a RAG system. After running the plan, we should have either enough information to answer the user's original query, or enough information to form a new query plan."""
items: list[QueryPlanItem] = Field(
description="A list of the QueryPlanItem objects in the plan."
)
'''通过astructured传入模型即可得到结构化输出
query_plan = await llm.astructured_predict(
QueryPlan,
self.planning_prompt,
context=context_str,
query=query,
)'''
复制代码
现在我们来界说工作流,一共有如下几个函数
制定计划,或者竣事工作流
执行函数
汇聚结果
class QueryPlanningWorkflow(Workflow):
#让模型进行规划根据上下文内容和用户输入
planning_prompt = PromptTemplate(
"Think step by step. Given an initial query, as well as information about the indexes you can query, return a plan for a RAG system.\n"
"The plan should be a list of QueryPlanItem objects, where each object contains a query.\n"
"The result of executing an entire plan should provide a result that is a substantial answer to the initial query, "
"or enough information to form a new query plan.\n"
"Sources you can query: {context}\n"
"Initial query: {query}\n"
"Plan:"
)
#根据目前结果,结束还是举行执行任务
decision_prompt = PromptTemplate(
"Given the following information, return a final response that satisfies the original query, or return 'PLAN' if you need to continue planning.\n"
使用glm-4可能出现的问题,我调用api接口一直返回的格式不精确,可能是 planning_prompt的的第三行只说返回一个query,这里改成a query and a name应该就能返回精确的格式了
按理来说prompt的问题的话qwen也会有同样的错误,但是虽然也有发生,重复两次也总是能执行
三、导入数据