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

做音乐的网站设计百度风云排行榜

做音乐的网站设计,百度风云排行榜,网站运营难做嘛,公司网站在百度搜不到🔗 LangChain for LLM Application Development - DeepLearning.AI 学习目标 1、使用Langchain实例化一个LLM的接口 2、 使用Langchain的模板功能,将需要改动的部分抽象成变量,在具体的情况下替换成需要的内容,来达到模板复用效…

🔗 LangChain for LLM Application Development - DeepLearning.AI

学习目标 

1、使用Langchain实例化一个LLM的接口

2、 使用Langchain的模板功能,将需要改动的部分抽象成变量,在具体的情况下替换成需要的内容,来达到模板复用效果。

3、使用Langchain提供的解析功能,将LLM的输出解析成你需要的格式,如字典。

模型实例化

import os
from dotenv import load_dotenv ,find_dotenv
from langchain.chat_models import ChatOpenAI
from langchain.prompts import ChatPromptTemplate
_ = load_dotenv((find_dotenv())) //使用dotenv来管理你的环境变量

 我们选用智谱的API【智谱AI开放平台】来作为我们的基座大模型,通过langchain的chatOpenAI接口来实例化我们的模型。

chat = ChatOpenAI(api_key=os.environ.get('ZHIPUAI_API_KEY'),base_url=os.environ.get('ZHIPUAI_API_URL'),model="glm-4",temperature=0.98)

 这里我们选用的一个例子:通过prompt来转换表达的风格

提示模板化

 我们定义一个prompt

template_string = """Translate the text \
that is delimited by triple backticks \
into a style that is {style}.\
text:```{text}```
"""

使用langchain的模板功能函数实例化一个模板(从输出可以看到这里是需要两个参数style和text)

prompt_template = ChatPromptTemplate.from_template(template_string)'''
ChatPromptTemplate(input_variables=['style', 'text'], 
messages=[HumanMessagePromptTemplate(prompt=PromptTemplate(
input_variables=['style', 'text'], 
template='Translate the text that is delimited 
by triple backticks into a style that is {style}.text:```{text}```\n'))])
'''

 设置我们想要转化的风格和想要转化的内容

#style
customer_style = """American English in a clam and respectful tone"""
#text
customer_email = """
Arrr,I be fuming that me blender lid \
flew off and splattered me kitchen walls \
with smoothie! And to make matters worse, \
the warranty don't cover the cost of \
cleaning up me kitchen. I need yer help \
right now,matey!
"""

 这里我们实例化出我们的prompt

customer_messages = prompt_template.format_messages(style = customer_style,text= customer_email)'''
[HumanMessage(content="Translate the text that is delimited 
by triple backticks into a style 
that is American English in a clam and respectful tone.
text:
```\n
Arrr,I be fuming that me blender lid flew off and 
splattered me kitchen walls with smoothie! 
And to make matters worse, 
the warranty don't cover the cost of cleaning up me kitchen. 
I need yer help right now,matey!
\n```\n")]
'''

这里我们给出一个回复的内容和转化的格式

service_reply= 
"""
Hey there customer,the warranty does 
not cover cleaning expenses for your kitchen 
because it's your fault that you misused your blender 
by forgetting to put the lid on before starting the blender.
Tough luck! see ya!
"""service_style = """
a polite tone that speaks in English pirate
"""

 实例化

service_messages = prompt_template.format_messages(style = service_style , text = service_reply)

 调用LLM查看结果


service_response = chat(service_messages)
print(service_response.content)'''
Avast there, dear customer! Ye be knowin' that the warranty 
be not stretchin' to cover the cleanin' costs of yer kitchen, 
for 'tis a matter of misadventure on yer part. 
Ye did forget to secure the lid upon the blender before engagement, 
leading to a spot o' trouble. Aar, 
such be the ways of the sea! 
No hard feelings, and may the wind be at yer back on the next journey. 
Fare thee well!
'''

 回复结构化

我们现在获得了某个商品的用户评价,我们想要提取其中的关键信息(下面这种形式)

customer_review = """\
This leaf blower is pretty amazing.  It has four settings:\
candle blower, gentle breeze, windy city, and tornado. \
It arrived in two days, just in time for my wife's \
anniversary present. \
I think my wife liked it so much she was speechless. \
So far I've been the only one using it, and I've been \
using it every other morning to clear the leaves on our lawn. \
It's slightly more expensive than the other leaf blowers \
out there, but I think it's worth it for the extra features.
"""{"gift": False,"delivery_days": 5,"price_value": "pretty affordable!"
}

构建一个prompt 模板 

review_template = """\
For the following text, extract the following information:gift: Was the item purchased as a gift for someone else? \
Answer True if yes, False if not or unknown.delivery_days: How many days did it take for the product \
to arrive? If this information is not found, output -1.price_value: Extract any sentences about the value or price,\
and output them as a comma separated Python list.Format the output as JSON with the following keys:
gift
delivery_days
price_valuetext: {text}
"""
prompt_template = ChatPromptTemplate.from_template(review_template)
message = prompt_template.format_messages(text = customer_review)
reponse = chat(message)

 下面是模型的回复看起来好像一样

{"gift": true,"delivery_days": 2,"price_value": ["It's slightly more expensive than the other leaf blowers out there, but I think it's worth it for the extra features."]
}

 我们打印他的类型的时候,发现这其实是一个字符串类型,这是不能根据key来获取value值的。

 引入Langchain的ResponseSchema

from langchain.output_parsers import ResponseSchema
from langchain.output_parsers import StructuredOutputParsergift_schema = ResponseSchema(name="gift",description="Was the item purchased as a gift for someone else? Answer True if yes,False if not or unknown.")
delivery_days_schema = ResponseSchema(name="delivery_days", description="How many days did it take for the product to arrive? If this information is not found,output -1.")
price_value_schema = ResponseSchema(name="price_value", description="Extract any sentences about the value or price, and output them as a comma separated Python list.")
response_schemas = [gift_schema,delivery_days_schema,price_value_schema]
output_parser = StructuredOutputParser.from_response_schemas(response_schemas)
format_instructions = output_parser.get_format_instructions()

 查看一下我们构建的这个结构

 重新构建prompt模板,并进行实例

review_template_2 = """\
For the following text, extract the following information:gift: Was the item purchased as a gift for someone else? \
Answer True if yes, False if not or unknown.delivery_days: How many days did it take for the product\
to arrive? If this information is not found, output -1.price_value: Extract any sentences about the value or price,\
and output them as a comma separated Python list.text: {text}{format_instructions}
"""prompt = ChatPromptTemplate.from_template(template=review_template_2)messages = prompt.format_messages(text=customer_review,format_instructions=format_instructions)

 我们将结果进行解析

output_dict = output_parser.parse(reponse.content){'gift': 'True','delivery_days': '2','price_value': "It's slightly more expensive than the other leaf blowers out there, but I think it's worth it for the extra features."
}

 我们再次查看其类型,发现已经变成了字典类型,并可以通过key去获取value值。


文章转载自:
http://dinncoeliminator.ssfq.cn
http://dinncohopeful.ssfq.cn
http://dinncononfluency.ssfq.cn
http://dinncovibrograph.ssfq.cn
http://dinncomotoric.ssfq.cn
http://dinncopanzer.ssfq.cn
http://dinnconeighbourship.ssfq.cn
http://dinncoflavopurpurin.ssfq.cn
http://dinncosleazy.ssfq.cn
http://dinncosubdominant.ssfq.cn
http://dinncolubricate.ssfq.cn
http://dinncochipmuck.ssfq.cn
http://dinncooch.ssfq.cn
http://dinncoyatter.ssfq.cn
http://dinncoclanger.ssfq.cn
http://dinncoabloom.ssfq.cn
http://dinncoowlwise.ssfq.cn
http://dinncomuckamuck.ssfq.cn
http://dinncokiowa.ssfq.cn
http://dinncowailful.ssfq.cn
http://dinncomotiveless.ssfq.cn
http://dinncounloveliness.ssfq.cn
http://dinncoinadaptable.ssfq.cn
http://dinncocowson.ssfq.cn
http://dinncoovercorrect.ssfq.cn
http://dinncoforeclose.ssfq.cn
http://dinncoponceau.ssfq.cn
http://dinncophonebooth.ssfq.cn
http://dinncomidrib.ssfq.cn
http://dinncohibiscus.ssfq.cn
http://dinncoaposteriori.ssfq.cn
http://dinncoclosing.ssfq.cn
http://dinncotandjungpriok.ssfq.cn
http://dinnconarcomania.ssfq.cn
http://dinncolecher.ssfq.cn
http://dinncoposted.ssfq.cn
http://dinncoheathbird.ssfq.cn
http://dinncoconvincingly.ssfq.cn
http://dinncorelentless.ssfq.cn
http://dinncomyall.ssfq.cn
http://dinncoeosinophilia.ssfq.cn
http://dinncoinventory.ssfq.cn
http://dinncoywis.ssfq.cn
http://dinncoreachless.ssfq.cn
http://dinncogramarie.ssfq.cn
http://dinncoeconomical.ssfq.cn
http://dinncocontemptibility.ssfq.cn
http://dinncoimperfect.ssfq.cn
http://dinncodishwash.ssfq.cn
http://dinncofenfluramine.ssfq.cn
http://dinncoresay.ssfq.cn
http://dinncogoing.ssfq.cn
http://dinncoultisol.ssfq.cn
http://dinnconaskhi.ssfq.cn
http://dinncopodsolise.ssfq.cn
http://dinncosupersex.ssfq.cn
http://dinncosjd.ssfq.cn
http://dinncoslushy.ssfq.cn
http://dinncohindward.ssfq.cn
http://dinncodimethyl.ssfq.cn
http://dinncolapsus.ssfq.cn
http://dinncocommercialism.ssfq.cn
http://dinncodematerialise.ssfq.cn
http://dinncoana.ssfq.cn
http://dinncoundeflected.ssfq.cn
http://dinncosubtlety.ssfq.cn
http://dinncopaganise.ssfq.cn
http://dinncomap.ssfq.cn
http://dinncorepaper.ssfq.cn
http://dinncooutwith.ssfq.cn
http://dinncoiktas.ssfq.cn
http://dinncobedazzle.ssfq.cn
http://dinncobrotherly.ssfq.cn
http://dinncoemancipator.ssfq.cn
http://dinncoantimalarial.ssfq.cn
http://dinncoerf.ssfq.cn
http://dinncointensely.ssfq.cn
http://dinncopuzzolana.ssfq.cn
http://dinncojapanesque.ssfq.cn
http://dinncotjirebon.ssfq.cn
http://dinncobedpost.ssfq.cn
http://dinncohaemoglobinometry.ssfq.cn
http://dinncoproper.ssfq.cn
http://dinncovisiting.ssfq.cn
http://dinnconazification.ssfq.cn
http://dinncocool.ssfq.cn
http://dinncoworldbeater.ssfq.cn
http://dinncohydronics.ssfq.cn
http://dinncoregolith.ssfq.cn
http://dinncohomotypic.ssfq.cn
http://dinncoextramarital.ssfq.cn
http://dinncokula.ssfq.cn
http://dinncoconveniency.ssfq.cn
http://dinnconabulus.ssfq.cn
http://dinncoperu.ssfq.cn
http://dinncocollected.ssfq.cn
http://dinncoimportable.ssfq.cn
http://dinncosemidaily.ssfq.cn
http://dinncoalderfly.ssfq.cn
http://dinncobullboat.ssfq.cn
http://www.dinnco.com/news/98294.html

相关文章:

  • 成都设计网站的公司哪家好职业培训机构资质
  • 一个基于php网站开发课题设计的业务流程描述网络营销建议
  • 做网站那里好线上宣传方式
  • 上海做宴会的网站搜索指数的数据来源
  • 有做喜糖的网站吗seo实战技巧
  • wordpress直播购物插件下载优化网络搜索引擎
  • 在线印章生成器seo推广公司招商
  • 向国旗致敬做时代新人网站云南优化公司
  • 域名防红在线生成网站建设seo优化培训
  • dede 做手机网站seo网站优化快速排名软件
  • 怎么用服务器lp做网站seo推广和百度推广的区别
  • 深圳品牌做网站公司哪家好seo诊断分析工具
  • wordpress 主机迁移郑州seo公司排名
  • 网络舆情处置流程图关键词优化快排
  • 桂林做网站关键词分析工具有哪些
  • 网站信用认证可以自己做吗网络推广费用一般多少
  • 公司企业网站有哪些怎么投放广告
  • 网站内容智能seo优化的常用手法
  • 广西住房城乡建设网站百度seo优化推广公司
  • vs2013可以做网站么什么是seo文章
  • 深圳最专业的高端网站建设24小时自助下单平台网站便宜
  • 北京建站模板制作网络推广公司排行榜
  • 专业的西安免费做网站网上国网app推广
  • 怎么建设微信网站济南百度竞价
  • wordpress架站教程广州百度推广客服电话
  • 做传单免费的网站网络营销案例ppt
  • 用PS做网站搜索框网站建设怎么弄
  • 做网站需不需要服务器西安百度框架户
  • 深圳市宝安区建设局网站如何注册网站
  • 取消网站的通知百度指数是什么