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

模版网站可以做排名嘛wordpress文章添加tag标签

模版网站可以做排名嘛,wordpress文章添加tag标签,湖南省建设信息网,服务平台名称大全LLM 所实现的最强大的应用之一是复杂的问答 (QA) 聊天机器人。这些应用程序可以回答有关特定源信息的问题。这些应用程序使用一种称为检索增强生成 (RAG) 的技术。 典型的 RAG 应用程序有两个主要组件 索引#xff1a;从源中提取数据并对其进行索引的管道。这通常在线下…LLM 所实现的最强大的应用之一是复杂的问答 (QA) 聊天机器人。这些应用程序可以回答有关特定源信息的问题。这些应用程序使用一种称为检索增强生成 (RAG) 的技术。 典型的 RAG 应用程序有两个主要组件 索引从源中提取数据并对其进行索引的管道。这通常在线下进行。检索和生成实际的 RAG 链它在运行时接受用户查询并从索引中检索相关数据然后将其传递给模型。 从原始数据到答案最常见的完整序列如下 加载首先我们需要加载数据。这是通过DocumentLoaders完成的。拆分文本拆分器将大块内容拆分Documents成小块内容。这对于索引数据和将数据传递到模型都很有用因为大块内容更难搜索并且不适合模型的有限上下文窗口。存储我们需要一个地方来存储和索引我们的分割以便以后可以搜索它们。这通常使用VectorStore和Embeddings模型来完成 检索和生成 4. 检索根据用户输入使用检索器从存储中检索相关分割。 5. 生成ChatModel / LLM使用包含问题和检索到的数据的提示生成答案 #创建embedding 模型 from langchain.embeddings import HuggingFaceEmbeddings from langchain_community.vectorstores import FAISS from langchain_community.vectorstores.utils import DistanceStrategy from config import EMBEDDING_PATH# init embedding model model_kwargs {device: cuda} encode_kwargs {batch_size: 64, normalize_embeddings: True}embed_model HuggingFaceEmbeddings(model_nameEMBEDDING_PATH,model_kwargsmodel_kwargs,encode_kwargsencode_kwargs)#导入相关库 from langchain_openai import ChatOpenAI import bs4 from langchain import hub from langchain_community.vectorstores import FAISS from langchain_community.document_loaders import WebBaseLoader from langchain_core.output_parsers import StrOutputParser from langchain_core.runnables import RunnablePassthrough from langchain_text_splitters import RecursiveCharacterTextSplitterchat ChatOpenAI()loader WebBaseLoader(web_paths(https://lilianweng.github.io/posts/2023-06-23-agent/,),bs_kwargsdict(parse_onlybs4.SoupStrainer(class_(post-content, post-title, post-header))), ) docs loader.load()documents RecursiveCharacterTextSplitter(chunk_size1000,chunk_overlap200).split_documents(docs)vetorstors FAISS.from_documents(documents,embed_model)retriever vetorstors.as_retriever()promt hub.pull(rlm/rag-prompt)promtdef format_docs(docs):return \n\n.join(doc.page_content for doc in docs)#创建链 chain ({context:retriever | format_docs ,question:RunnablePassthrough()}| promt| chat| StrOutputParser() )chain.invoke(What is Task Decomposition?)输出结果 ‘Task decomposition is the process of breaking down a problem into multiple thought steps to create a tree structure. It can be achieved through LLM with simple prompting, task-specific instructions, or human inputs. The goal is to transform big tasks into smaller and simpler steps to enhance model performance on complex tasks.’ 首先这些组件retriever、prompt、chat等中的每一个都是Runnable的实例。这意味着它们实现相同的方法——例如sync和async .invoke、、.stream或.batch——这使得它们更容易连接在一起。它们可以通过运算符|连接到RunnableSequence另一个 Runnable。 当遇到|操作符时LangChain 会自动将某些对象转换为 Runnable。这里format_docs转换为RunnableLambdacontext 带有和的字典question转换为RunnableParallel。细节并不重要重要的是每个对象都是一个 Runnable。 让我们追踪一下输入问题如何流经上述可运行程序。 正如我们在上面看到的输入prompt预计是一个带有键context和 的字典question。因此该链的第一个元素构建了可运行对象它将根据输入问题计算这两个值 retriever | format_docs 将文本传递给检索器生成Document对象然后将Document对象format_docs生成字符串 RunnablePassthrough()不变地通过输入问题。 内置Chain from langchain.chains import create_retrieval_chain from langchain.chains.combine_documents import create_stuff_documents_chain from langchain_core.prompts import ChatPromptTemplatesystem_prompt (You are an assistant for question-answering tasks. Use the following pieces of retrieved context to answer the question. If you dont know the answer, say that you dont know. Use three sentences maximum and keep the answer concise.\n\n{context} )prompt ChatPromptTemplate.from_messages([(system, system_prompt),(human, {input}),] )question_answer_chain create_stuff_documents_chain(chat, prompt) rag_chain create_retrieval_chain(retriever, question_answer_chain)response rag_chain.invoke({input:What is Task Decomposition?}) print(response)输出结果 {‘input’: ‘What is Task Decomposition?’, ‘context’: [Document(page_content‘Tree of Thoughts (Yao et al. 2023) extends CoT by exploring multiple reasoning possibilities at each step. It first decomposes the problem into multiple thought steps and generates multiple thoughts per step, creating a tree structure. The search process can be BFS (breadth-first search) or DFS (depth-first search) with each state evaluated by a classifier (via a prompt) or majority vote.\nTask decomposition can be done (1) by LLM with simple prompting like “Steps for XYZ.\n1.”, “What are the subgoals for achieving XYZ?”, (2) by using task-specific instructions; e.g. “Write a story outline.” for writing a novel, or (3) with human inputs.’, metadata{‘source’: ‘https://lilianweng.github.io/posts/2023-06-23-agent/’}), Document(page_content‘Fig. 1. Overview of a LLM-powered autonomous agent system.\nComponent One: Planning#\nA complicated task usually involves many steps. An agent needs to know what they are and plan ahead.\nTask Decomposition#\nChain of thought (CoT; Wei et al. 2022) has become a standard prompting technique for enhancing model performance on complex tasks. The model is instructed to “think step by step” to utilize more test-time computation to decompose hard tasks into smaller and simpler steps. CoT transforms big tasks into multiple manageable tasks and shed lights into an interpretation of the model’s thinking process.’, metadata{‘source’: ‘https://lilianweng.github.io/posts/2023-06-23-agent/’}), Document(page_content‘Fig. 2. Examples of reasoning trajectories for knowledge-intensive tasks (e.g. HotpotQA, FEVER) and decision-making tasks (e.g. AlfWorld Env, WebShop). (Image source: Yao et al. 2023).\nIn both experiments on knowledge-intensive tasks and decision-making tasks, ReAct works better than the Act-only baseline where Thought: … step is removed.\nReflexion (Shinn Labash 2023) is a framework to equips agents with dynamic memory and self-reflection capabilities to improve reasoning skills. Reflexion has a standard RL setup, in which the reward model provides a simple binary reward and the action space follows the setup in ReAct where the task-specific action space is augmented with language to enable complex reasoning steps. After each action a t a_t at​, the agent computes a heuristic h t h_t ht​ and optionally may decide to reset the environment to start a new trial depending on the self-reflection results.’, metadata{‘source’: ‘https://lilianweng.github.io/posts/2023-06-23-agent/’}), Document(page_content‘Here are a sample conversation for task clarification sent to OpenAI ChatCompletion endpoint used by GPT-Engineer. The user inputs are wrapped in {{user input text}}.\n[\n {\n “role”: “system”,\n “content”: “You will read instructions and not carry them out, only seek to clarify them.\nSpecifically you will first summarise a list of super short bullets of areas that need clarification.\nThen you will pick one clarifying question, and wait for an answer from the user.\n”\n },\n {\n “role”: “user”,\n “content”: “We are writing {{a Super Mario game in python. MVC components split in separate files. Keyboard control.}}\n”\n },\n {\n “role”: “assistant”,’, metadata{‘source’: ‘https://lilianweng.github.io/posts/2023-06-23-agent/’})], ‘answer’: ‘Task decomposition involves breaking down a complex task into smaller and simpler steps to make it more manageable. This technique allows models or agents to utilize more computational resources at test time by thinking step by step. By decomposing tasks, models can better understand and interpret the thinking process involved in solving difficult problems.’} create_stuff_documents_chain def create_stuff_documents_chain(llm: LanguageModelLike,prompt: BasePromptTemplate,*,output_parser: Optional[BaseOutputParser] None,document_prompt: Optional[BasePromptTemplate] None,document_separator: str DEFAULT_DOCUMENT_SEPARATOR, ) - Runnable[Dict[str, Any], Any]:_validate_prompt(prompt)_document_prompt document_prompt or DEFAULT_DOCUMENT_PROMPT_output_parser output_parser or StrOutputParser()def format_docs(inputs: dict) - str:return document_separator.join(format_document(doc, _document_prompt) for doc in inputs[DOCUMENTS_KEY])return (RunnablePassthrough.assign(**{DOCUMENTS_KEY: format_docs}).with_config(run_nameformat_inputs)| prompt| llm| _output_parser).with_config(run_namestuff_documents_chain)从源代码看出来就是chain create_retrieval_chain def create_retrieval_chain(retriever: Union[BaseRetriever, Runnable[dict, RetrieverOutput]],combine_docs_chain: Runnable[Dict[str, Any], str], ) - Runnable:if not isinstance(retriever, BaseRetriever):retrieval_docs: Runnable[dict, RetrieverOutput] retrieverelse:retrieval_docs (lambda x: x[input]) | retrieverretrieval_chain (RunnablePassthrough.assign(contextretrieval_docs.with_config(run_nameretrieve_documents),).assign(answercombine_docs_chain)).with_config(run_nameretrieval_chain)return retrieval_chaincreate_retrieval_chain调用过程就是先检索然后调用combine_docs_chain
http://www.hkea.cn/news/14425858/

相关文章:

  • 湖南网站seo营销昭通做网站
  • 鹏达建设集团有限公司网站重庆市建设工程信息网电话
  • 电子商务网站的建设内容郑州企业如何建网站
  • 建设银行长沙招聘网站做网站教程流程
  • 中国市政建设局网站上海网站建设聚众网络
  • 顺德大良网站建设开发wordpress所见即所得编辑器
  • php做的网站怎么让外网访问凡客诚品 v官网
  • 跟我学做纸艺花网站宠物网站建设目标
  • 公司网站做的比较好wordpress评论区插件
  • 王者荣耀做网站网站建设怎样提升形象与品牌价值
  • 企业网站开发文献综述艺术家网站建设中企业网站建设的策划初期的一些误区
  • 江门城乡建设部网站首页wordpress demo数据
  • 网站源码文件discuz主题
  • 大理住房和城乡建设局网站取消网站备案制度
  • 网站能调用一些字体h5平台官网
  • 菏泽官方网站做360手机网站优化快
  • 设计模板素材网站医疗软件网站建设公司排名
  • 尚品本色木门网站是哪个公司做的wordpress 音乐主题
  • 绍兴网站制作方案在线观看免费网站网址
  • 网站建设硬件设计方案做网站的公司
  • 宁波市节约型机关建设考试网站澄迈网站建设
  • 中国科技成就作文800字长沙百度推广排名优化
  • 公司的帐如何做网站wordpress 源码下载主题
  • 哈密市建设局网站深圳短视频代运营公司
  • 平台网站建设方案标书seo高效优化
  • 制作网站常用软件wordpress impreza
  • 全球网站建设服务商如何打死网站
  • 怎么做网站内的搜索dedecms安装
  • 矿区网站建设百度的网址
  • 那家做网站好国内4大现货交易所