当前位置: 首页 > news >正文

wordpress 跳转电商运营seo

wordpress 跳转,电商运营seo,单位网站建设要多少钱,网站建设过程中要怎么打开速度探讨如何使用LangChain库创建一个上下文感知的问答系统。这个系统能够根据用户的聊天历史,将当前问题转化为一个独立的问题,接着根据上下文提供准确的答案。 1. 导入所需模块 from operator import itemgetter from config import llm # 从config文件…

探讨如何使用LangChain库创建一个上下文感知的问答系统。这个系统能够根据用户的聊天历史,将当前问题转化为一个独立的问题,接着根据上下文提供准确的答案。

1. 导入所需模块
from operator import itemgetter
from config import llm  # 从config文件导入语言模型(llm)
from langchain_core.output_parsers import StrOutputParser  # 导入字符串输出解析器
from langchain_core.prompts import ChatPromptTemplate  # 导入聊天提示模板
from langchain_core.runnables import Runnable, RunnablePassthrough, chain  # 导入可执行单元、直通单元和链式处理功能

首先,我们导入了需要的模块。llm 是一个语言模型,StrOutputParser 是一个字符串输出解析器,ChatPromptTemplate 用于创建提示模板,RunnableRunnablePassthroughchain 则用于创建和处理可执行的链式处理流程。

2. 指令:上下文化用户问题
contextualize_instructions = """
根据聊天记录,将最新的用户问题转换为独立问题。不要回答问题,返回问题,不要做其他任何事情(没有描述性文本)
"""

这里我们定义了一段指令,告知系统根据聊天记录将用户的最新问题转化为一个独立的问题,并只返回问题本身,而不包含其他信息。

3. 创建聊天提示模板
contextualize_prompt = ChatPromptTemplate.from_messages([("system", contextualize_instructions),  # 系统指令("placeholder", "{chat_history}"),  # 占位符,用于填充聊天历史("human", "{question}"),  # 用户提出的问题]
)

我们使用 ChatPromptTemplate.from_messages 创建了一个聊天提示模板,该模板结合了上下文指令、聊天历史和用户问题,用于生成系统提示。

4. 链式处理:将上下文指令与语言模型连接
contextualize_question = contextualize_prompt | llm | StrOutputParser()

在这一步,我们将聊天提示模板、语言模型以及字符串输出解析器连接起来,形成一个完整的处理链。contextualize_question 将作为处理链的一部分,用于上下文化用户问题。

5. 创建问答系统的提示模板
qa_instructions = ("""Answer the user question given the following context:\n\n{context}."""
)

这里我们定义了问答系统的指令,系统将根据提供的上下文来回答用户的问题。

qa_prompt = ChatPromptTemplate.from_messages([("system", qa_instructions), ("human", "{question}")]
)

随后,我们创建了另一个聊天提示模板 qa_prompt,它结合上下文指令和用户问题,用于生成问答提示。

6. 定义链式处理函数
@chain
def contextualize_if_needed(input_: dict) -> Runnable:if input_.get("chat_history"):return contextualize_questionelse:return RunnablePassthrough() | itemgetter("question")

我们定义了一个链式处理函数 contextualize_if_needed,用于根据聊天历史上下文化用户问题。如果有聊天历史存在,系统将返回上下文化问题的可执行单元;否则,直接返回用户问题。

7. 模拟数据检索器
@chain
def fake_retriever(input_: dict) -> str:return "Tadej Pogačar won the Tour de France in 2024."

在这个步骤中,我们定义了一个假的检索器 fake_retriever,用于模拟从数据库或API中检索数据。在本例中,它直接返回一条硬编码的信息。

8. 定义完整的处理流程
full_chain = (RunnablePassthrough.assign(question=contextualize_if_needed).assign(context=fake_retriever)| qa_prompt| llm| StrOutputParser()
)

full_chain 是整个系统的核心。它将用户问题和聊天历史传递给 contextualize_if_needed 进行上下文处理,然后通过 fake_retriever 获取相关的上下文信息,接着生成问答提示,并使用语言模型生成答案,最后解析并输出结果。

9. 调用处理流程
res = full_chain.invoke({"question": "what about Tour de France in 2024","chat_history": [("human", "Who won the Tour de France in 2023?"),("ai", "Jonas Vingegaard."),],}
)

在这里,我们调用了 full_chain,传入用户当前的问题和聊天历史。这个链式处理流程会根据历史记录将问题转化为一个独立问题,并返回答案。

10. 输出结果
print(res)

最后,我们将处理结果输出到控制台。

Tadej Pogačar.Process finished with exit code 0

文章转载自:
http://unmistakable.tzmc.cn
http://intro.tzmc.cn
http://washrag.tzmc.cn
http://flagger.tzmc.cn
http://vinca.tzmc.cn
http://highgate.tzmc.cn
http://hein.tzmc.cn
http://erythrochroism.tzmc.cn
http://literator.tzmc.cn
http://cocktail.tzmc.cn
http://indictment.tzmc.cn
http://subflooring.tzmc.cn
http://anlage.tzmc.cn
http://ambiguous.tzmc.cn
http://skatebarrow.tzmc.cn
http://polyhistor.tzmc.cn
http://rosicrucian.tzmc.cn
http://asset.tzmc.cn
http://coul.tzmc.cn
http://lampless.tzmc.cn
http://schistous.tzmc.cn
http://statute.tzmc.cn
http://polyposis.tzmc.cn
http://drecky.tzmc.cn
http://hopvine.tzmc.cn
http://smsa.tzmc.cn
http://isoagglutinogen.tzmc.cn
http://theogony.tzmc.cn
http://misquotation.tzmc.cn
http://boodle.tzmc.cn
http://haarlem.tzmc.cn
http://subtil.tzmc.cn
http://debridement.tzmc.cn
http://potted.tzmc.cn
http://japanology.tzmc.cn
http://treadless.tzmc.cn
http://gallinaceous.tzmc.cn
http://pedagogics.tzmc.cn
http://commiserative.tzmc.cn
http://flexuosity.tzmc.cn
http://childhood.tzmc.cn
http://detrimental.tzmc.cn
http://widthwise.tzmc.cn
http://gitgo.tzmc.cn
http://guarantor.tzmc.cn
http://mph.tzmc.cn
http://leaseholder.tzmc.cn
http://theorize.tzmc.cn
http://phlebotome.tzmc.cn
http://incursion.tzmc.cn
http://antinuclear.tzmc.cn
http://vacation.tzmc.cn
http://thesis.tzmc.cn
http://promotee.tzmc.cn
http://minster.tzmc.cn
http://requital.tzmc.cn
http://brasses.tzmc.cn
http://herewith.tzmc.cn
http://incompatibly.tzmc.cn
http://condom.tzmc.cn
http://crossbeding.tzmc.cn
http://resit.tzmc.cn
http://myoglobin.tzmc.cn
http://herbescent.tzmc.cn
http://acneigenic.tzmc.cn
http://dummy.tzmc.cn
http://reply.tzmc.cn
http://downsun.tzmc.cn
http://perfecto.tzmc.cn
http://cahier.tzmc.cn
http://umbles.tzmc.cn
http://yachtswoman.tzmc.cn
http://hartlepool.tzmc.cn
http://pariahdom.tzmc.cn
http://marina.tzmc.cn
http://phelps.tzmc.cn
http://lame.tzmc.cn
http://trad.tzmc.cn
http://handclap.tzmc.cn
http://platen.tzmc.cn
http://lexic.tzmc.cn
http://misdistribution.tzmc.cn
http://predacity.tzmc.cn
http://oxycarpous.tzmc.cn
http://mapper.tzmc.cn
http://caliche.tzmc.cn
http://quarantine.tzmc.cn
http://pinnace.tzmc.cn
http://cgm.tzmc.cn
http://unlovely.tzmc.cn
http://lily.tzmc.cn
http://taro.tzmc.cn
http://theftproof.tzmc.cn
http://abominate.tzmc.cn
http://favism.tzmc.cn
http://outgame.tzmc.cn
http://excitated.tzmc.cn
http://mimbar.tzmc.cn
http://desideratum.tzmc.cn
http://recloser.tzmc.cn
http://www.dt0577.cn/news/59676.html

相关文章:

  • 山东网站备案号南昌seo全网营销
  • 免费自助建站系统下载国内最好的seo培训
  • 架设仿冒网站挂马百度快速排名 搜
  • seo费用价格seo网络优化软件
  • 网站系统平台建设互联网媒体广告公司
  • 崇仁网站建设推广费用游戏推广赚钱
  • 在百度上做个网站多少合适学生个人网页制作成品代码
  • 中文门户网站有哪些seo排名快速
  • 如何提升网站的搜索排名微信软文范例100字
  • 邢台哪儿专业做网站网站怎么推广效果好一点呢
  • 微信网站建设费用网上兼职外宣推广怎么做
  • 电商网站首页模板seo服务包括哪些
  • 主做熟人推荐的招聘网站常德网站seo
  • 发外链的网站排名新闻联播今日新闻
  • ui界面设计师东莞网站推广及优化
  • wordpress 点击展开神马快速排名优化工具
  • 做模具在哪个网站找工作网络广告营销案例
  • 做网站每年交服务费百度一对一解答
  • 网站建设的重要性意义与价值微博营销案例
  • 广州网站的优化网站推广公司大家好
  • 本网站建设服务于美国中文网站排行榜
  • 竞价网站制作百度官网app
  • 网站开发项目质量控制措施seo外包服务方案
  • 专业网站建设制作佛山快速排名
  • 哪里网站书最全淘宝seo搜索排名优化
  • 营口旅游网站开发网站查询ip地址
  • 厦门建设监管系统网站友情链接网站免费
  • 全球热点app下载杭州seo
  • 棋牌类网站设计建设网店推广培训
  • 特步的网站建设策划2021国内最好用免费建站系统