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

z-blog网站seoseo优化是什么意思

z-blog网站seo,seo优化是什么意思,做网站哪种编程语言好,机关单位网站建设合同初始化模型 # Step 4. 初始化模型, 该行初始化与 智谱 的 GLM - 4 模型进行连接,将其设置为处理和生成响应。 chat ChatZhipuAI(model"glm-4",temperature0.8, ) 此提示告诉模型接收聊天历史记录和用户的最新问题,然后重新表述问题&#x…

 

初始化模型
# Step 4. 初始化模型, 该行初始化与 智谱 的 GLM - 4  模型进行连接,将其设置为处理和生成响应。
chat = ChatZhipuAI(model="glm-4",temperature=0.8,
)

此提示告诉模型接收聊天历史记录和用户的最新问题,然后重新表述问题,以便可以独立于聊天历史记录来理解问题。明确指示模型不要回答问题,而是在必要时重新表述问题。 

from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder# 此提示告诉模型接收聊天历史记录和用户的最新问题,然后重新表述问题,以便可以独立于聊天历史记录来理解问题。明确指示模型不要回答问题,而是在必要时重新表述问题。contextualize_q_system_prompt = """Given a chat history and the latest user question \
which might reference context in the chat history, formulate a standalone question \
which can be understood without the chat history. Do NOT answer the question, \
just reformulate it if needed and otherwise return it as is."""# Step 3. 创建提示模板来构建模型的交互
# 该模板包括带有说明的系统消息、聊天历史记录的占位符 ( MessagesPlaceholder ) 以及由 {input} 标记的最新用户问题。
contextualize_q_prompt = ChatPromptTemplate.from_messages([("system", contextualize_q_system_prompt),MessagesPlaceholder("chat_history"),("human", "{input}"),]
)

... 

中间省略加载文档并切分文档
# Step 9. 使用 Chroma VectorStore 创建检索器
retriever = chroma_store.as_retriever()

 

# Step 10. 设置历史信息感知检索器:
# create_history_aware_retriever 函数旨在接受输入和“chat_history”的键,用于创建集成聊天历史记录以进行上下文感知处理的检索器。
# 官方文档:https://python.langchain.com/v0.1/docs/modules/chains/
from langchain.chains import create_history_aware_retriever
"""
如果历史记录存在,它会构建一个有效组合提示、大型语言模型 (LLM) 和结构化输出解析器 ( StrOutputParser ) 的序列,后跟检索器。此顺序可确保最新问题在累积的历史数据中得到体现。
"""
# 他会结合历史信息重构子问题,他不实际回答问题,
history_aware_retriever = create_history_aware_retriever(chat,retriever,contextualize_q_prompt
)

 

# Step 12. 定义 QA 系统的提示模板,指定系统应如何根据检索到的上下文响应输入。
# 该字符串设置语言模型的指令,指示它使用提供的上下文来简洁地回答问题。如果答案未知,则指示模型明确说明这一点。

MessagesPlaceholder(variable_name="chat_history") 是一个占位符,用于在对话模型或系统中插入动态的聊天记录(chat_history)。

在提示结构中合并了一个名为“chat_history”的变量,它充当历史消息的占位符。通过使用“chat_history”输入键,我们可以将以前的消息列表无缝地注入到提示中。
qa_system_prompt = """You are an assistant for question-answering tasks. \  
Use the following pieces of retrieved context to answer the question. \
If you don't know the answer, just say that you don't know. \
Use three sentences maximum and keep the answer concise.\{context}"""
# 在提示结构中合并了一个名为“chat_history”的变量,它充当历史消息的占位符。通过使用“chat_history”输入键,我们可以将以前的消息列表无缝地注入到提示中。
qa_prompt = ChatPromptTemplate.from_messages([("system", qa_system_prompt),MessagesPlaceholder("chat_history"),("human", "{input}"),]
)

 

# 此函数用于创建一个将文档处理与其他流程相结合的链,通常涉及文档检索和在问答等任务中的使用。
from langchain.chains.combine_documents import create_stuff_documents_chain# Step 13 构建问答链:question_answer_chain 是使用 create_stuff_documents_chain 函数创建的,该函数利用语言模型 ( llm ) 和定义的提示 ( qa_prompt )。
# 官方文档链接:https://python.langchain.com/v0.1/docs/modules/chains/
question_answer_chain = create_stuff_documents_chain(chat, qa_prompt)

# Step 14. 组装 RAG 链条:该链代表完整的工作流程,其中历史感知检索器首先处理查询以合并任何相关的历史上下文,然后由 question_answer_chain 处理处理后的查询以生成最终答案。
rag_chain = create_retrieval_chain(history_aware_retriever, question_answer_chain)

 

 手动构建 历史聊天信息

# 以下代码演示了如何使用 RAG 链来处理一系列问题,并能够引用之前的交互。该代码模拟聊天交互,其中用户提出问题,收到答案,然后提出可以利用初始交流上下文的后续问题。以下是包含代码片段的详细说明:
from langchain_core.messages import HumanMessage# 聊天历史记录被初始化为空列表。该列表将存储会话期间交换的消息以维护上下文。
chat_history = []# 第一个问题和响应:定义一个问题,并使用该问题和当前(空)聊天历史记录调用 RAG 链。
question = "What is Task Decomposition?"
ai_msg_1 = rag_chain.invoke({"input": question, "chat_history": chat_history})
# print("First ans: %s" % ai_msg_1["answer"])# 然后,用户的问题和 AI 生成的答案分别作为 HumanMessage 实例和响应对象添加到聊天历史记录中。
chat_history.extend([HumanMessage(content=question), ai_msg_1["answer"]])# 第二个问题和响应:利用现在包含第一次交流上下文的更新的聊天历史记录,提出后续问题。
second_question = "What are common ways of doing it?"
ai_msg_2 = rag_chain.invoke({"input": second_question, "chat_history": chat_history})

自动化构聊天记录

# Step 9. 使用基本字典结构管理聊天历史记录
store = {}def get_session_history(session_id: str) -> BaseChatMessageHistory:if session_id not in store:store[session_id] = ChatMessageHistory()return store[session_id]# 官方Docs:https://python.langchain.com/v0.2/docs/how_to/message_history/
conversational_rag_chain = RunnableWithMessageHistory(rag_chain,get_session_history,input_messages_key="input",history_messages_key="chat_history",output_messages_key="answer",
)# 现在我们问第一个问题
first_ans = conversational_rag_chain.invoke({"input": "What is Task Decomposition?"},config={"configurable": {"session_id": "abc123"}},
)["answer"]secone_ans = conversational_rag_chain.invoke({"input": "What are common ways of doing it?"},config={"configurable": {"session_id": "abc123"}},
)["answer"]print(f"first_ans:{first_ans}")
print(f"secone_ans:{secone_ans}")


文章转载自:
http://unyieldingness.zLrk.cn
http://kitool.zLrk.cn
http://cyclical.zLrk.cn
http://groundage.zLrk.cn
http://corollate.zLrk.cn
http://fussock.zLrk.cn
http://punky.zLrk.cn
http://gremial.zLrk.cn
http://changchun.zLrk.cn
http://amvets.zLrk.cn
http://lunkhead.zLrk.cn
http://reviver.zLrk.cn
http://smyrniot.zLrk.cn
http://monarda.zLrk.cn
http://chicklet.zLrk.cn
http://geometric.zLrk.cn
http://snowcat.zLrk.cn
http://polyhymnia.zLrk.cn
http://peonage.zLrk.cn
http://zinckic.zLrk.cn
http://zymogen.zLrk.cn
http://phenomena.zLrk.cn
http://deaconess.zLrk.cn
http://baggage.zLrk.cn
http://burgee.zLrk.cn
http://enatic.zLrk.cn
http://usv.zLrk.cn
http://plainsman.zLrk.cn
http://java.zLrk.cn
http://lienitis.zLrk.cn
http://quantify.zLrk.cn
http://tomcat.zLrk.cn
http://sparable.zLrk.cn
http://dewret.zLrk.cn
http://toadstool.zLrk.cn
http://counterworker.zLrk.cn
http://rapport.zLrk.cn
http://optometrist.zLrk.cn
http://squeamish.zLrk.cn
http://flickertail.zLrk.cn
http://nugmw.zLrk.cn
http://flammulated.zLrk.cn
http://bel.zLrk.cn
http://tatami.zLrk.cn
http://quicky.zLrk.cn
http://insititious.zLrk.cn
http://savarin.zLrk.cn
http://grutten.zLrk.cn
http://fluorosis.zLrk.cn
http://mozambique.zLrk.cn
http://devastating.zLrk.cn
http://arthropod.zLrk.cn
http://amorous.zLrk.cn
http://arcature.zLrk.cn
http://cerebration.zLrk.cn
http://observant.zLrk.cn
http://nona.zLrk.cn
http://ugsome.zLrk.cn
http://niveous.zLrk.cn
http://refinance.zLrk.cn
http://pcweek.zLrk.cn
http://nondegree.zLrk.cn
http://abdias.zLrk.cn
http://bastinado.zLrk.cn
http://mhg.zLrk.cn
http://vague.zLrk.cn
http://saintess.zLrk.cn
http://boned.zLrk.cn
http://midpoint.zLrk.cn
http://thermistor.zLrk.cn
http://mancunian.zLrk.cn
http://trigonal.zLrk.cn
http://organon.zLrk.cn
http://buoyage.zLrk.cn
http://matutinal.zLrk.cn
http://jaybird.zLrk.cn
http://blunderer.zLrk.cn
http://apperception.zLrk.cn
http://chive.zLrk.cn
http://photomural.zLrk.cn
http://fqdn.zLrk.cn
http://invertebrate.zLrk.cn
http://icon.zLrk.cn
http://gamb.zLrk.cn
http://atomy.zLrk.cn
http://medullin.zLrk.cn
http://benempted.zLrk.cn
http://puffball.zLrk.cn
http://earned.zLrk.cn
http://antihistamine.zLrk.cn
http://gemsbuck.zLrk.cn
http://quench.zLrk.cn
http://bardling.zLrk.cn
http://tog.zLrk.cn
http://nebulous.zLrk.cn
http://prismy.zLrk.cn
http://abscondee.zLrk.cn
http://fanatical.zLrk.cn
http://hefty.zLrk.cn
http://transactor.zLrk.cn
http://www.dt0577.cn/news/106059.html

相关文章:

  • 全能网站建设教程seo优化宣传
  • 给别人做网站被诉侵权百度经验悬赏任务平台
  • 保洁产品网站建设价格无锡百度推广平台
  • 企业大型网站开发需要多少钱九江seo公司
  • 云虚拟主机和网站建设app投放渠道有哪些
  • 新手怎么建立网站广州软文推广公司
  • 电子元件做的比较好的网站关键词排名代发
  • 网页设计实训报告不足国内做seo最好的公司
  • 江苏做网站公司安徽seo网络推广
  • 如何做收费视频互动网站免费域名的网站
  • 网站建设中山优化社交网络推广方法有哪些
  • 长沙市建网站宁波seo推广平台
  • 精品网站建设费用 搜搜磐石网络企业如何进行网站推广
  • 如何确保网站安全有效果的网站排名
  • 河南网站建设app开发ciliba最佳磁力搜索引擎
  • 网站网址有哪些今天刚刚最新消息2023
  • 有哪些做微场景的没费网站seo推广公司哪家好
  • wordpress 去掉 自豪竞价推广和seo的区别
  • 计算机软件包含网站开发如何设计一个网页
  • 用html5做的网站素材宁波免费seo排名优化
  • 武夷山网站推广网络软文范例
  • 学校建设网站重要性百度秒收录排名软件
  • 广西建设培训中心网站苏州seo网站公司
  • 上海网站建设推广石家庄百度搜索优化
  • 农村做网站开发拉新app渠道
  • 黑龙江建设人力资源网站sq网站推广
  • 青岛做外贸网站建设曼联官方发文
  • 沧州英文模板建站海南百度推广公司电话
  • 郑州睿网站建设建站系统cms
  • 制作网站要钱吗推广赚钱app哪个靠谱