AI教程 2025年01月15日
0 收藏 0 点赞 361 浏览 8758 个字
摘要 :

面向开发者的LLM入门课程-模型提示和输出解释器英文版提示: 英文版提示 1.用美式英语表达海盗邮件 customer_email = “”” Arrr, I be fuming that me……

哈喽!伙伴们,我是小智,你们的AI向导。欢迎来到每日的AI学习时间。今天,我们将一起深入AI的奇妙世界,探索“面向开发者的LLM入门课程-模型提示和输出解释器英文版提示”,并学会本篇文章中所讲的全部知识点。还是那句话“不必远征未知,只需唤醒你的潜能!”跟着小智的步伐,我们终将学有所成,学以致用,并发现自身的更多可能性。话不多说,现在就让我们开始这场激发潜能的AI学习之旅吧。

面向开发者的LLM入门课程-模型提示和输出解释器英文版提示

面向开发者的LLM入门课程-模型提示和输出解释器英文版提示:

英文版提示

1.用美式英语表达海盗邮件

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!
“””
# 美式英语 + 平静、尊敬的语调
style = “””American English
in a calm and respectful tone
“””
# 要求模型根据给出的语调进行转化
prompt = f”””Translate the text
that is delimited by triple backticks
into a style that is {style}.
text: “`{customer_email}“`
“””
print(“提示:”, prompt)
response = get_completion(prompt)
print(“美式英语表达的海盗邮件: “, response)

提示:
Translate the text that is delimited by triple backticks
into a style that is American English in a calm and respectful tone
.
text: “`
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!
美式英语表达的海盗邮件:
I am quite frustrated that my blender lid flew off and made a mess of my kitchen walls with
smoothie! To add to my frustration, the warranty does not cover the cost of cleaning up my
kitchen. I kindly request your assistance at this moment, my friend.

2.用标准美式英语表达海盗邮件

from langchain.prompts import ChatPromptTemplate
template_string = “””Translate the text
that is delimited by triple backticks
into a style that is {style}.
text: “`{text}“`
“””
prompt_template = ChatPromptTemplate.from_template(template_string)
print(“提示模版中的第一个提示:”, prompt_template.messages[0].prompt)
customer_style = “””American English
in a calm and respectful tone
“””
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!
“””
customer_messages = prompt_template.format_messages(
style=customer_style,
text=customer_email)
print(“用提示模版中生成的第一条客户消息:”, customer_messages[0])

提示模版中的第一个提示:
input_variables=[‘style’, ‘text’] output_parser=None partial_variables={} template=’Translate
the text that is delimited by triple backticks into a style that is {style}. text:
“`{text}“`n’ template_format=’f-string’ validate_template=True
用提示模版中生成的第一条客户消息:
content=”Translate the text that is delimited by triple backticks into a style that is
American English in a calm and respectful tonen. text: “`nArrr, 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” additional_kwargs={} example=False

3.用海盗方言回复邮件

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_pirate = “””
a polite tone
that speaks in English Pirate
“””
service_messages = prompt_template.format_messages(
style=service_style_pirate,
text=service_reply)
print(“提示模版中的第一条客户消息内容:”, service_messages[0].content)
service_response = chat(service_messages)
print(“模型得到的回复邮件:”, service_response.content)

提示模版中的第一条客户消息内容:
Translate the text that is delimited by triple backticks into a style that is a polite tone
that speaks in English Pirate. text: “`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!
模型得到的回复内容:
Ahoy there, matey! I regret to inform ye that the warranty be not coverin’ the costs o’
cleanin’ yer galley, as ’tis yer own fault fer misusin’ yer blender by forgettin’ to secure
the lid afore startin’ it. Aye, tough luck, me heartie! Fare thee well!

4.不使用输出解释器提取客户评价中的信息

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.
“””
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_value
text: {text}
“””
from langchain.prompts import ChatPromptTemplate
prompt_template = ChatPromptTemplate.from_template(review_template)
print(“提示模版:”,prompt_template)
messages = prompt_template.format_messages(text=customer_review)
chat = ChatOpenAI(temperature=0.0)
response = chat(messages)
print(“回复内容:”,response.content)

提示模版:
input_variables=[‘text’] output_parser=None partial_variables={} messages=
[HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=[‘text’],
output_parser=None, partial_variables={}, template=’For the following text, extract the
following information:nngift: Was the item purchased as a gift for someone else? Answer True
if yes, False if not or unknown.nndelivery_days: How many days did it take for the product
to arrive? If this information is not found, output -1.nnprice_value: Extract any sentences
about the value or price,and output them as a comma separated Python list.nnFormat the
output as JSON with the following keys:ngiftndelivery_daysnprice_valuenntext: {text}n’,
template_format=’f-string’, validate_template=True), additional_kwargs={})]
回复内容:
{
“gift”: false,
“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.”]
}

5.使用输出解析器提取客户评价中的信息

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)
from langchain.output_parsers import ResponseSchema
from langchain.output_parsers import StructuredOutputParser
gift_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()
print(format_instructions)
messages = prompt.format_messages(text=customer_review,
format_instructions=format_instructions)
print(“提示消息:”, messages[0].content)
response = chat(messages)
print(“回复内容:”,response.content)
output_dict = output_parser.parse(response.content)
print(“解析后的结果类型:”, type(output_dict))
print(“解析后的结果:”, output_dict)

The output should be a markdown code snippet formatted in the following schema, including the
leading and trailing ““`json” and ““`”:
“`json
{
“gift”: string // Was the item purchased as a gift for
someone else? Answer True if yes,
False if not or unknown.
“delivery_days”: string // How many days did it take
for the product to arrive? If this
information is not found, output -1.
“price_value”: string // Extract any sentences about
the value or price, and output them as a
comma separated Python list.
}
“`
提示消息:
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 productto 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: 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.
The output should be a markdown code snippet formatted in the following schema, including the
leading and trailing ““`json” and ““`”:
“`json
{
“gift”: string // Was the item purchased as a gift for
someone else? Answer True if yes,
False if not or unknown.
“delivery_days”: string // How many days did it take
for the product to arrive? If this
information is not found, output -1.
“price_value”: string // Extract any sentences about
the value or price, and output them as a
comma separated Python list.
}
“`
回复内容:
“`json
{
“gift”: false,
“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.”
}
“`
解析后的结果类型:

解析后的结果:
{‘gift’: False, ‘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.”}

面向开发者的LLM入门课程-对话缓存储存
面向开发者的LLM入门课程-对话缓存储存:对话缓存储存 1.初始化对话模型 让我们先来初始化对话模型。 from langchain.chains i...

嘿,伙伴们,今天我们的AI探索之旅已经圆满结束。关于“面向开发者的LLM入门课程-模型提示和输出解释器英文版提示”的内容已经分享给大家了。感谢你们的陪伴,希望这次旅程让你对AI能够更了解、更喜欢。谨记,精准提问是解锁AI潜能的钥匙哦!如果有小伙伴想要了解学习更多的AI知识,请关注我们的官网“AI智研社”,保证让你收获满满呦!

微信扫一扫

支付宝扫一扫

版权: 转载请注明出处:https://www.ai-blog.cn/2657.html

相关推荐
01-15

面向开发者的LLM入门课程-路由链: 路由链 到目前为止,我们已经学习了大语言模型链和顺序链。但是…

213
01-15

面向开发者的LLM入门课程-顺序链: 顺序链 当只有一个输入和一个输出时,简单顺序链(SimpleSequen…

361
01-15

面向开发者的LLM入门课程-简单顺序链: 简单顺序链 顺序链(SequentialChains)是按预定义顺序执行…

361
01-15

面向开发者的LLM入门课程-大语言模型链: 模型链 链(Chains)通常将大语言模型(LLM)与提示(Pro…

361
01-15

面向开发者的LLM入门课程-对话储存英文版提示: 英文版提示 1.对话缓存储存 from langchain.chains…

361
01-15

面向开发者的LLM入门课程-对话摘要缓存储存: 对话摘要缓存储存 对话摘要缓存储存,使用 LLM 对到…

361
01-15

面向开发者的LLM入门课程-对话字符缓存储存: 对话字符缓存储存 使用对话字符缓存记忆,内存将限制…

361
01-15

面向开发者的LLM入门课程-对话缓存窗口储存: 对话缓存窗口储存 随着对话变得越来越长,所需的内存…

361
发表评论
暂无评论

还没有评论呢,快来抢沙发~

助力原创内容

快速提升站内名气成为大牛

扫描二维码

手机访问本站