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

网站建设的需求要素网站建设的公司工作室

网站建设的需求要素,网站建设的公司工作室,国外空间怎么上传网站,南宁网站设计图分类目录#xff1a;《自然语言处理从入门到应用》总目录 LLMChain LLMChain是查询LLM对象最流行的方式之一。它使用提供的输入键值#xff08;如果有的话#xff0c;还包括内存键值#xff09;格式化提示模板#xff0c;将格式化的字符串传递给LLM#xff0c;并返回LLM…分类目录《自然语言处理从入门到应用》总目录 LLMChain LLMChain是查询LLM对象最流行的方式之一。它使用提供的输入键值如果有的话还包括内存键值格式化提示模板将格式化的字符串传递给LLM并返回LLM的输出。下面我们展示了LLMChain类的附加功能 from langchain import PromptTemplate, OpenAI, LLMChainprompt_template What is a good name for a company that makes {product}?llm OpenAI(temperature0) llm_chain LLMChain(llmllm,promptPromptTemplate.from_template(prompt_template) ) llm_chain(colorful socks)输出 {product: colorful socks, text: \n\nSocktastic!}LLM链条的额外运行方式 除了所有Chain对象共享的__call__和run方法之外LLMChain还提供了几种调用链条逻辑的方式 apply允许我们对一组输入运行链 input_list [{product: socks},{product: computer},{product: shoes} ]llm_chain.apply(input_list) [{text: \n\nSocktastic!},{text: \n\nTechCore Solutions.},{text: \n\nFootwear Factory.}]generate与apply类似但返回一个LLMResult而不是字符串。LLMResult通常包含有用的生成信息例如令牌使用情况和完成原因。 llm_chain.generate(input_list)输出 LLMResult(generations[[Generation(text\n\nSocktastic!, generation_info{finish_reason: stop, logprobs: None})], [Generation(text\n\nTechCore Solutions., generation_info{finish_reason: stop, logprobs: None})], [Generation(text\n\nFootwear Factory., generation_info{finish_reason: stop, logprobs: None})]], llm_output{token_usage: {prompt_tokens: 36, total_tokens: 55, completion_tokens: 19}, model_name: text-davinci-003})predict与run方法类似只是输入键被指定为关键字参数而不是Python字典。 # Single input example llm_chain.predict(productcolorful socks)输出 \n\nSocktastic!输入 # Multiple inputs exampletemplate Tell me a {adjective} joke about {subject}. prompt PromptTemplate(templatetemplate, input_variables[adjective, subject]) llm_chain LLMChain(promptprompt, llmOpenAI(temperature0))llm_chain.predict(adjectivesad, subjectducks)输出 \n\nQ: What did the duck say when his friend died?\nA: Quack, quack, goodbye.解析输出结果 默认情况下即使底层的prompt对象具有输出解析器LLMChain也不会解析输出结果。如果你想在LLM输出上应用输出解析器可以使用predict_and_parse代替predict以及apply_and_parse代替apply。 仅使用predict方法 from langchain.output_parsers import CommaSeparatedListOutputParseroutput_parser CommaSeparatedListOutputParser() template List all the colors in a rainbow prompt PromptTemplate(templatetemplate, input_variables[], output_parseroutput_parser) llm_chain LLMChain(promptprompt, llmllm)llm_chain.predict()输出 \n\nRed, orange, yellow, green, blue, indigo, violet使用predict_and_parser方法 llm_chain.predict_and_parse()输出 [Red, orange, yellow, green, blue, indigo, violet]从字符串模板初始化 我们还可以直接使用字符串模板构建一个LLMChain。 template Tell me a {adjective} joke about {subject}. llm_chain LLMChain.from_string(llmllm, templatetemplate) llm_chain.predict(adjectivesad, subjectducks)输出 \n\nQ: What did the duck say when his friend died?\nA: Quack, quack, goodbye.RouterChain 本节演示了如何使用RouterChain创建一个根据给定输入动态选择下一个链条的链条。RouterChain通常由两个组件组成 路由链本身负责选择下一个要调用的链条目标链条即路由链可以路由到的链条 本节中我们将重点介绍不同类型的路由链。我们将展示这些路由链在MultiPromptChain中的应用创建一个问题回答链条根据给定的问题选择最相关的提示然后使用该提示回答问题。 from langchain.chains.router import MultiPromptChain from langchain.llms import OpenAI from langchain.chains import ConversationChain from langchain.chains.llm import LLMChain from langchain.prompts import PromptTemplate physics_template You are a very smart physics professor. \ You are great at answering questions about physics in a concise and easy to understand manner. \ When you dont know the answer to a question you admit that you dont know.Here is a question: {input}math_template You are a very good mathematician. You are great at answering math questions. \ You are so good because you are able to break down hard problems into their component parts, \ answer the component parts, and then put them together to answer the broader question.Here is a question: {input} prompt_infos [{name: physics, description: Good for answering questions about physics, prompt_template: physics_template},{name: math, description: Good for answering math questions, prompt_template: math_template} ] llm OpenAI() destination_chains {} for p_info in prompt_infos:name p_info[name]prompt_template p_info[prompt_template]prompt PromptTemplate(templateprompt_template, input_variables[input])chain LLMChain(llmllm, promptprompt)destination_chains[name] chain default_chain ConversationChain(llmllm, output_keytext)LLMRouterChain LLMRouterChain链条使用一个LLM来确定如何进行路由。 from langchain.chains.router.llm_router import LLMRouterChain, RouterOutputParser from langchain.chains.router.multi_prompt_prompt import MULTI_PROMPT_ROUTER_TEMPLATE destinations [f{p[name]}: {p[description]} for p in prompt_infos] destinations_str \n.join(destinations) router_template MULTI_PROMPT_ROUTER_TEMPLATE.format(destinationsdestinations_str ) router_prompt PromptTemplate(templaterouter_template,input_variables[input],output_parserRouterOutputParser(), ) router_chain LLMRouterChain.from_llm(llm, router_prompt) chain MultiPromptChain(router_chainrouter_chain, destination_chainsdestination_chains, default_chaindefault_chain, verboseTrue) print(chain.run(What is black body radiation?))日志输出 Entering new MultiPromptChain chain... physics: {input: What is black body radiation?}Finished chain.输出 Black body radiation is the term used to describe the electromagnetic radiation emitted by a “black body”—an object that absorbs all radiation incident upon it. A black body is an idealized physical body that absorbs all incident electromagnetic radiation, regardless of frequency or angle of incidence. It does not reflect, emit or transmit energy. This type of radiation is the result of the thermal motion of the bodys atoms and molecules, and it is emitted at all wavelengths. The spectrum of radiation emitted is described by Plancks law and is known as the black body spectrum.输入 print(chain.run(What is the first prime number greater than 40 such that one plus the prime number is divisible by 3))输出 Entering new MultiPromptChain chain... math: {input: What is the first prime number greater than 40 such that one plus the prime number is divisible by 3}Finished chain.输出 The answer is 43. One plus 43 is 44 which is divisible by 3.输入 print(chain.run(What is the name of the type of cloud that rins))日志输出 Entering new MultiPromptChain chain... None: {input: What is the name of the type of cloud that rains?}Finished chain.输出 The type of cloud that rains is called a cumulonimbus cloud. It is a tall and dense cloud that is often accompanied by thunder and lightning.EmbeddingRouterChain EmbeddingRouterChain使用嵌入和相似性来在目标链条之间进行路由。 from langchain.chains.router.embedding_router import EmbeddingRouterChain from langchain.embeddings import CohereEmbeddings from langchain.vectorstores import Chroma names_and_descriptions [(physics, [for questions about physics]),(math, [for questions about math]), ] router_chain EmbeddingRouterChain.from_names_and_descriptions(names_and_descriptions, Chroma, CohereEmbeddings(), routing_keys[input] ) chain MultiPromptChain(router_chainrouter_chain, destination_chainsdestination_chains, default_chaindefault_chain, verboseTrue) print(chain.run(What is black body radiation?))日志输出 Entering new MultiPromptChain chain... physics: {input: What is black body radiation?}Finished chain.输出 Black body radiation is the emission of energy from an idealized physical body (known as a black body) that is in thermal equilibrium with its environment. It is emitted in a characteristic pattern of frequencies known as a black-body spectrum, which depends only on the temperature of the body. The study of black body radiation is an important part of astrophysics and atmospheric physics, as the thermal radiation emitted by stars and planets can often be approximated as black body radiation.输入 print(chain.run(What is the first prime number greater than 40 such that one plus the prime number is divisible by 3))日志输出 Entering new MultiPromptChain chain... math: {input: What is the first prime number greater than 40 such that one plus the prime number is divisible by 3}Finished chain.输出 Answer: The first prime number greater than 40 such that one plus the prime number is divisible by 3 is 43.参考文献 [1] LangChain官方网站https://www.langchain.com/ [2] LangChain ️ 中文网跟着LangChain一起学LLM/GPT开发https://www.langchain.com.cn/ [3] LangChain中文网 - LangChain 是一个用于开发由语言模型驱动的应用程序的框架http://www.cnlangchain.com/
http://www.sadfv.cn/news/249351/

相关文章:

  • 安徽网站建设制作网站目录编辑审核的注意事项
  • wordpress微信群机器人嘉兴优化网站公司哪家好
  • wordpress视屏播放器seo和sem的区别与联系
  • 做网站广告wordpress 文章新窗口
  • 网页设计和网站制作网站建设有什么注意
  • wordpress做的好的网站东莞网站SEO优化推广
  • 我市建设车辆违章查询网站 病句晋中建设集团有限公司网站
  • 网站这么做404页面网络推广方式有哪些
  • 女人做春梦网站个人网页上传网站怎么做
  • 江宁区住房与城乡建设局网站百度刷排名seo
  • 企业网站都有哪些企业小程序建设的公司
  • 自己做网站 有名怎么做软文代发平台网站
  • 网站建设捌金手指下拉十七桂林网站制作哪家公司好
  • 深圳商城网站建设报价看seo
  • 网站类别划分校园网站建设情况通报
  • 汕头免费建设网站制作海尔电商网站建设方案
  • 四川营销网站建设北京网络科技公司
  • 怎么免费自己做网站把网站内的文本保存到txt怎么做
  • WordPress导出单页上海外包seo
  • excel做网站二维码设计字体设计
  • 怎样找到网站建设设置模板wordpress 用户信息
  • 网站重大建设项目公开发布制度中国机械加工网下载
  • 蒙阴做网站网页设计基础括号代码大全
  • 电商论坛网站模板推广项目
  • 网站建设相关语言wordpress显示全部标签
  • 为什么打开网址都是站长工具网站包括哪些主要内容
  • 网站链接结构有哪些做冒菜店网站
  • 网站列表页框架布局原则wordpress页面居中
  • 对于网站链接优化有哪些建议做ui设计师难吗
  • 做视频网站 带宽计算seo系统是什么