小智头像图片
AI教程 2025年01月15日
0 收藏 0 点赞 435 浏览 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

相关推荐

AI编程-Trae+Figma强强联手前端也能秒出高颜值页面!: 本篇文章介绍用Trae+ Figma MCP来对页面样…

小智头像图片
435

AI写作-网文写作7步法模板教程【步骤三】第一次摩擦​: 【步骤三】第一次摩擦​ ​ ​ ​ 具体怎么写要…

小智头像图片
36

AI写作-网文写作7步法模板教程【步骤二】制作信息差​: 【步骤二】制作信息差​ ​ ​ ​ 在实际写作过…

小智头像图片
435

AI写作-网文写作7步法模板教程【步骤一】展示优势: 【步骤一】展示优势​ ​ ​ ​ 核心套路在于首先…

小智头像图片
435

AI写作-网文写作7步法模板教程-七步故事模板: 七步故事模板​ 1.通过情节,展示主角的优势或潜力,…

小智头像图片
435

AI编程-用Cursor设计移动app原型新手教程: 本篇文章介绍用Cursor来做移动app原型设计的实践,对比…

小智头像图片
112

AI写作-AI写小说教程-创建个人小说智能体(4): 2.4 生成小说架构 1.滑到下方记忆模块中,长期记…

小智头像图片
435

AI写作-AI写小说教程-创建个人小说智能体(3): 2.3 添加插件​ 1.返回Bot主页后,我们点击插件中…

小智头像图片
435
发表评论
暂无评论

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

助力原创内容

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

扫描二维码

手机访问本站

二维码
vip弹窗图片