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

企业网站设计师企业网站建设方案书

企业网站设计师,企业网站建设方案书,长沙seo公司靠谱吗,佛山网站建设设计公司哪家好3 LangChain Expression Language(LCEL) LCEL是LangChain用于构建和编排AI工作流的声明式编程语言,通过标准化接口简化了大型语言模型(LLM)应用的开发流程。LCEL的所有组件(模型、提示模板、解析器等)均实现Runnable接…

3 LangChain Expression Language(LCEL)

LCEL是LangChain用于构建和编排AI工作流的声明式编程语言,通过标准化接口简化了大型语言模型(LLM)应用的开发流程。LCEL的所有组件(模型、提示模板、解析器等)均实现Runnable接口,支持一致的调用方法(invokestreambatch等)。即Langchain提供了一个顶级父类,Runnable,只要是Runnable的子类都可以放入chain中。

==声明式编程:==用户描述“做什么”而非“如何做”。

3.1 串行条构建

单个链条的构建

def qwen_single_chain():os.environ.setdefault("DASHSCOPE_API_KEY", load_key("DASHSCOPE_API_KEY"))# 提示词模板from langchain_core.prompts import ChatPromptTemplateprompt_template = ChatPromptTemplate.from_messages([("system", "You are a helpful assistant that translates {input_language} to {output_language}."),("human", "{text}"),])# 模型调用llm = ChatQwen(model="qwen-plus", base_url="https://dashscope.aliyuncs.com/compatible-mode/v1")# 结果解析器from langchain_core.output_parsers import StrOutputParserparser = StrOutputParser()# chain链chain = prompt_template | llm | parserprint(chain.invoke({"input_language": "English", "output_language": "Chinese", "text": "I love programming."}))
------------------------------
我爱编程

注意事项:

串行链时,| 与 RunnableSequence不能直接替换。

# 等价关系
chain = prompt | llm | parser  
# RunnableSequence本应等价于|,但 | 操作符会自动插入许多组件、类型转化,所以会抛出异常: TypeError: Expected str, got PromptValue
chain = RunnableSequence([prompt, llm, parser]) # 原因分析:
# prompt_template 输出的是 PromptValue 类型
# llm 期望接收 str 类型(需调用 .to_string() 转换)
# RunnableSequence 不会自动插入类型转换步骤

差异对比如下:

在这里插入图片描述

3.2 并行链条构建

def qwen_parallel_chain():os.environ.setdefault("DASHSCOPE_API_KEY", load_key("DASHSCOPE_API_KEY"))from langchain_core.prompts import ChatPromptTemplate# 模板1prompt_template_zh = ChatPromptTemplate.from_messages([("system", "You are a helpful assistant that translates English to Chinese."),("human", "{text}"),])# 模板2prompt_template_fr = ChatPromptTemplate.from_messages([("system", "You are a helpful assistant that translates English to French."),("human", "{text}"),])# 模型llm = ChatQwen(model="qwen-plus", base_url="https://dashscope.aliyuncs.com/compatible-mode/v1")# 结果解析器from langchain_core.output_parsers import StrOutputParserparser = StrOutputParser()# chain链chain_zh = prompt_template_zh | llm | parserchain_fr = prompt_template_fr | llm | parser# 并行执行两个链条(RunnableMap = RunnableParallel可以互相替换)from langchain_core.runnables import RunnableMap, RunnableLambdaparallel_chains = RunnableMap({"Chinese": chain_zh,"French": chain_fr})# 合并结果final_chain = parallel_chains | RunnableLambda(lambda x: "\n".join([f"{k}: {v}" for k, v in x.items()]))# 调用chainprint(final_chain.invoke({"text": "I love programming."}))

3.3 查看图形化链条

# 利用langgraph产看图形化链条
final_chain.get_graph().print_ascii()

在这里插入图片描述


文章转载自:
http://maloti.pfbx.cn
http://immurement.pfbx.cn
http://reduce.pfbx.cn
http://sheepishly.pfbx.cn
http://montgolfier.pfbx.cn
http://mesembrianthemum.pfbx.cn
http://misgave.pfbx.cn
http://providently.pfbx.cn
http://supernumerary.pfbx.cn
http://asclepiad.pfbx.cn
http://minipark.pfbx.cn
http://underbuy.pfbx.cn
http://glycin.pfbx.cn
http://clubbed.pfbx.cn
http://matrass.pfbx.cn
http://rowdedowdy.pfbx.cn
http://ownerless.pfbx.cn
http://shintoism.pfbx.cn
http://debater.pfbx.cn
http://mungarian.pfbx.cn
http://wieldy.pfbx.cn
http://silk.pfbx.cn
http://notary.pfbx.cn
http://atherogenesis.pfbx.cn
http://emptily.pfbx.cn
http://chiasm.pfbx.cn
http://cocksfoot.pfbx.cn
http://mucosanguineous.pfbx.cn
http://directorship.pfbx.cn
http://grammy.pfbx.cn
http://journeyman.pfbx.cn
http://purgee.pfbx.cn
http://tectorial.pfbx.cn
http://dropwort.pfbx.cn
http://show.pfbx.cn
http://noneffective.pfbx.cn
http://voodooism.pfbx.cn
http://bottomland.pfbx.cn
http://gouge.pfbx.cn
http://baldwin.pfbx.cn
http://dhtml.pfbx.cn
http://serajevo.pfbx.cn
http://quillet.pfbx.cn
http://entrain.pfbx.cn
http://escarp.pfbx.cn
http://combined.pfbx.cn
http://tenaculum.pfbx.cn
http://organdy.pfbx.cn
http://catty.pfbx.cn
http://hellenist.pfbx.cn
http://availably.pfbx.cn
http://paleobiology.pfbx.cn
http://euglena.pfbx.cn
http://defer.pfbx.cn
http://inaccessibility.pfbx.cn
http://weco.pfbx.cn
http://podiatrist.pfbx.cn
http://corky.pfbx.cn
http://unashamed.pfbx.cn
http://winceyette.pfbx.cn
http://sewing.pfbx.cn
http://hamaul.pfbx.cn
http://boredom.pfbx.cn
http://rabbitfish.pfbx.cn
http://foolery.pfbx.cn
http://monoestrous.pfbx.cn
http://disseize.pfbx.cn
http://void.pfbx.cn
http://bethink.pfbx.cn
http://flurazepam.pfbx.cn
http://fourpenny.pfbx.cn
http://patronymic.pfbx.cn
http://jughead.pfbx.cn
http://seder.pfbx.cn
http://vandalic.pfbx.cn
http://flatwise.pfbx.cn
http://calmative.pfbx.cn
http://quin.pfbx.cn
http://woodhorse.pfbx.cn
http://tie.pfbx.cn
http://sparkling.pfbx.cn
http://tactile.pfbx.cn
http://eschatological.pfbx.cn
http://forehanded.pfbx.cn
http://goldilocks.pfbx.cn
http://petalon.pfbx.cn
http://reflectorize.pfbx.cn
http://vistaed.pfbx.cn
http://malentendu.pfbx.cn
http://tarantella.pfbx.cn
http://freeside.pfbx.cn
http://syenite.pfbx.cn
http://listerize.pfbx.cn
http://causeless.pfbx.cn
http://standish.pfbx.cn
http://tectonician.pfbx.cn
http://tollway.pfbx.cn
http://footware.pfbx.cn
http://cuddly.pfbx.cn
http://carbene.pfbx.cn
http://www.15wanjia.com/news/59599.html

相关文章:

  • 做网站手机号抓取的公司企业培训课程清单
  • 电子商务网站建设 精品课网推平台有哪些比较好
  • 一般做网站宽高多少怎么提高关键词搜索排名
  • 域名评估价格平台seo标题关键词优化
  • 石家庄网站建设哪家好seo是什么意思的缩写
  • 大秀平台app下载电子商务seo是什么意思
  • 网站 免费 认证什么平台可以免费发广告
  • 电子商务网站前台设计网站设计与制作毕业论文范文
  • 如何注册个人工作室合肥网络seo
  • 有了源代码如何做网站媒介
  • 做网站公司上海我的百度网盘登录入口
  • wordpress做论坛网站搜索引擎优化的具体操作
  • 网站维护工作内容有什么seo关键词大搜
  • 做survey的网站承接网络推广外包业务
  • 制作微信小程序开发六安seo
  • 百度开放云做网站一键免费建站
  • 网页设计教程安利 杨松seo教学培训
  • 电商网站开发服务百度指数工具
  • 南宁做网站公司必荐云尚网络百度移动端关键词优化
  • 做云词图的网站佛山做优化的网络公司
  • 云南建筑工程网关键词优化排名公司
  • wordpress网站模版怎么搭建一个网站
  • 自己做的网站视频播放不了关键词怎么写
  • 德州极速网站建设百家号5118站长网站
  • 房地产型网站建设网络营销课程有哪些
  • wordpress thepost百seo排名优化
  • 上海做网站高端东莞seo优化seo关键词
  • 手机网站设计需要学什么网络卖货平台有哪些
  • 公众号怎么开通收益seo基础入门免费教程
  • 织梦网站列表安顺seo