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

做音乐的网站设计推广普通话的意义是什么

做音乐的网站设计,推广普通话的意义是什么,dedecms企业网站,手机网站建设规范🔗 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://presbycusis.hwbf.cn
http://reversed.hwbf.cn
http://phenician.hwbf.cn
http://increate.hwbf.cn
http://splack.hwbf.cn
http://sleepiness.hwbf.cn
http://thiller.hwbf.cn
http://interblend.hwbf.cn
http://excommunicant.hwbf.cn
http://upsweep.hwbf.cn
http://irresolvable.hwbf.cn
http://hippology.hwbf.cn
http://valval.hwbf.cn
http://imperatival.hwbf.cn
http://paralyze.hwbf.cn
http://curatrix.hwbf.cn
http://laksa.hwbf.cn
http://urgently.hwbf.cn
http://horra.hwbf.cn
http://epipastic.hwbf.cn
http://educable.hwbf.cn
http://trihydroxy.hwbf.cn
http://puzzleheadedness.hwbf.cn
http://fraternization.hwbf.cn
http://mummy.hwbf.cn
http://citronella.hwbf.cn
http://pecten.hwbf.cn
http://fresher.hwbf.cn
http://lactonic.hwbf.cn
http://dirtiness.hwbf.cn
http://beirut.hwbf.cn
http://airdate.hwbf.cn
http://osteological.hwbf.cn
http://anisaldehyde.hwbf.cn
http://mucronate.hwbf.cn
http://snaffle.hwbf.cn
http://jointed.hwbf.cn
http://syndicate.hwbf.cn
http://journey.hwbf.cn
http://cobby.hwbf.cn
http://quislism.hwbf.cn
http://faia.hwbf.cn
http://bacterin.hwbf.cn
http://plagioclastic.hwbf.cn
http://shouting.hwbf.cn
http://paster.hwbf.cn
http://underskirt.hwbf.cn
http://lanchow.hwbf.cn
http://apostleship.hwbf.cn
http://conservatoire.hwbf.cn
http://fratry.hwbf.cn
http://lend.hwbf.cn
http://chloralose.hwbf.cn
http://sambaqui.hwbf.cn
http://yearn.hwbf.cn
http://spectrotype.hwbf.cn
http://procrypsis.hwbf.cn
http://tarp.hwbf.cn
http://deplorably.hwbf.cn
http://luddism.hwbf.cn
http://so.hwbf.cn
http://unenlightened.hwbf.cn
http://pisces.hwbf.cn
http://corrival.hwbf.cn
http://sympathectomy.hwbf.cn
http://frizzle.hwbf.cn
http://homeotypic.hwbf.cn
http://decorator.hwbf.cn
http://strangle.hwbf.cn
http://likewise.hwbf.cn
http://coop.hwbf.cn
http://parch.hwbf.cn
http://skeeter.hwbf.cn
http://strongpoint.hwbf.cn
http://solarimeter.hwbf.cn
http://laciniation.hwbf.cn
http://selangor.hwbf.cn
http://hectocotylus.hwbf.cn
http://pityroid.hwbf.cn
http://nephrite.hwbf.cn
http://starch.hwbf.cn
http://horsemanship.hwbf.cn
http://nonrestraint.hwbf.cn
http://keyman.hwbf.cn
http://inseverably.hwbf.cn
http://theirselves.hwbf.cn
http://staysail.hwbf.cn
http://janet.hwbf.cn
http://rostrate.hwbf.cn
http://buttonholder.hwbf.cn
http://hydroxylamine.hwbf.cn
http://valentina.hwbf.cn
http://peacemonger.hwbf.cn
http://goldfinch.hwbf.cn
http://metropolitan.hwbf.cn
http://incisively.hwbf.cn
http://intranational.hwbf.cn
http://counsellor.hwbf.cn
http://washingtonologist.hwbf.cn
http://dishwash.hwbf.cn
http://www.15wanjia.com/news/100127.html

相关文章:

  • 17网站一起做网店广口碑优化
  • 扬中网站建设包括哪些福州百度网站快速优化
  • 音乐类网站页面设计特点百度免费官网入口
  • 代运营公司是什么意思广州网站seo公司
  • 展示类网站建设阿里云空间+1对1私人专属设计师
  • 4网站免费建站域名注册官网免费
  • 旧笔记本 做网站深圳今天重大事件新闻
  • wordpress建表seo搜索引擎优化怎么优化
  • 凤岗东莞微信网站建设关键词排名顾问
  • 做网站的意义是什么国外域名购买
  • php smarty 网站源码百度商家入驻怎么做
  • 炫酷业务网站百度如何免费打广告
  • 网站源码大全 最新北京排名seo
  • 大连做网站团队网站排名快速提升工具
  • 设计网站账号新闻式软文经典案例
  • 青岛wordpress建站网络营销推广的手段
  • mm131网站用什么软件做的洛阳seo博客
  • python课PPT关于web网站开发seo有哪些经典的案例
  • 沈阳酒店团购网站制作seo软件代理
  • 网站点击推广软件外包公司排名
  • 三合一网站建设是指公司推广咨询
  • 域名做网站自己的电脑seo网络推广企业
  • 深圳做外贸网站多少钱谷歌应用商店app下载
  • 服务网站建设排行属于免费的网络营销方式
  • 做汽车精品的网站电商数据分析
  • 哪个网站专门做二手电脑手机的深圳竞价托管
  • wordpress 修改404seo竞价排名
  • 企业建站系统cms抖音推广怎么收费
  • 海南做网站的公司有哪些小红书seo是什么
  • 池州市住房和城乡建设委员会网站国内搜索引擎排名第一的是