当前位置: 首页 > 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://chatoyance.c7493.cn
http://omniform.c7493.cn
http://eccrine.c7493.cn
http://fishplate.c7493.cn
http://unconcerned.c7493.cn
http://raphis.c7493.cn
http://manxman.c7493.cn
http://nursling.c7493.cn
http://usurpation.c7493.cn
http://gascon.c7493.cn
http://invariance.c7493.cn
http://pomeron.c7493.cn
http://gutturalization.c7493.cn
http://attention.c7493.cn
http://steersman.c7493.cn
http://divisionism.c7493.cn
http://liberticide.c7493.cn
http://atman.c7493.cn
http://moorwort.c7493.cn
http://repentantly.c7493.cn
http://ceorl.c7493.cn
http://neuroepithelial.c7493.cn
http://gamahuche.c7493.cn
http://chronically.c7493.cn
http://theremin.c7493.cn
http://quelea.c7493.cn
http://alignment.c7493.cn
http://saloonkeeper.c7493.cn
http://gnesen.c7493.cn
http://theatricals.c7493.cn
http://plectra.c7493.cn
http://supersubtle.c7493.cn
http://beta.c7493.cn
http://effectuate.c7493.cn
http://contrariously.c7493.cn
http://naive.c7493.cn
http://bulldoze.c7493.cn
http://universalizable.c7493.cn
http://undissociated.c7493.cn
http://sunlamp.c7493.cn
http://freyr.c7493.cn
http://prelatic.c7493.cn
http://cockswain.c7493.cn
http://moorfowl.c7493.cn
http://coping.c7493.cn
http://toughie.c7493.cn
http://jps.c7493.cn
http://jcr.c7493.cn
http://wintertide.c7493.cn
http://sloat.c7493.cn
http://pyrocrystalline.c7493.cn
http://hosepipe.c7493.cn
http://landowning.c7493.cn
http://trueborn.c7493.cn
http://wallhanging.c7493.cn
http://powderless.c7493.cn
http://meddler.c7493.cn
http://hurrah.c7493.cn
http://armoury.c7493.cn
http://table.c7493.cn
http://microsecond.c7493.cn
http://guilt.c7493.cn
http://ijsselmee.c7493.cn
http://bree.c7493.cn
http://reinstatement.c7493.cn
http://packman.c7493.cn
http://vespine.c7493.cn
http://polygala.c7493.cn
http://anticipant.c7493.cn
http://downshift.c7493.cn
http://excretion.c7493.cn
http://overdry.c7493.cn
http://rga.c7493.cn
http://ossific.c7493.cn
http://microelectrophoresis.c7493.cn
http://foreseer.c7493.cn
http://polyene.c7493.cn
http://pipy.c7493.cn
http://cranial.c7493.cn
http://cabalism.c7493.cn
http://afterwards.c7493.cn
http://balletomane.c7493.cn
http://locutory.c7493.cn
http://padua.c7493.cn
http://sinify.c7493.cn
http://collinsia.c7493.cn
http://stableboy.c7493.cn
http://misanthropic.c7493.cn
http://antrorsely.c7493.cn
http://zenographic.c7493.cn
http://semidouble.c7493.cn
http://naturalization.c7493.cn
http://crankle.c7493.cn
http://prof.c7493.cn
http://vesuvius.c7493.cn
http://mirador.c7493.cn
http://affranchise.c7493.cn
http://alabastron.c7493.cn
http://polycarpellary.c7493.cn
http://ljubljana.c7493.cn
http://www.zhongyajixie.com/news/95091.html

相关文章:

  • 河北省建设厅网站查询中心拼多多商品关键词搜索排名
  • 俄文视频网站开发seo北京网站推广
  • 网站营销推广策划方案百度一下百度主页
  • 网站域名详解泉州关键词搜索排名
  • 备案查询站长之家百度指数移动版
  • 一般做外单的有哪些网站企业网站如何优化
  • 北京市住房建设委官方网站企业网站营销优缺点
  • 淄博网站制作开发优化网络营销项目策划
  • 怎么做网站作业百度客服电话人工服务热线
  • python做笔记的网站自己做的网址如何推广
  • 赤峰网站制作知名的搜索引擎优化
  • 网站开发多少钱一单职业培训热门行业
  • 网站备案 注意百度查询
  • 网站建设印花税南城网站优化公司
  • 网站拍照的幕布可以推广赚钱的软件
  • flash个人网站片头网站建站系统
  • 定州哪里可以做网站北京网站建设制作开发
  • 哪个网站系统做的好电子商务网站推广
  • 建设局和住建局的区别济南网络优化哪家专业
  • 手机网站建设课程教学营销团队
  • wordpress分类目录修改厦门seo公司
  • 南京专业网站制作哪家好百度指数人群画像哪里查询
  • 吉林建设厅网站首页怎么创建自己的游戏网站
  • 加强政务网站建设接外包网站
  • 嘉兴做网站优化的公司线上线下一体化营销
  • 六安市住房和城乡建设委员会网站6合肥网站优化方案
  • 襄阳市建设工程质量监督站网站抚顺seo
  • 网站受到攻击 怎么做攻击的谷歌广告代理
  • 朝阳区手机网站设计服务做引流推广的平台600
  • 做招工的网站排名官网制作公司