OpenAI官方吴达恩《ChatGPT Prompt Engineering 提示词工程师》(5)转换 / Transforming翻译

这篇具有很好参考价值的文章主要介绍了OpenAI官方吴达恩《ChatGPT Prompt Engineering 提示词工程师》(5)转换 / Transforming翻译。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

转换 / Transforming

输入一段文本,将其转换或翻译为另一种语言,或帮助拼写和语法纠正
转换格式,例如输入HTML并输出JSON

环境准备

和(①指南)一样需要搭建一个环境

import openai
import os

from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv()) # read local .env file

openai.api_key  = os.getenv('OPENAI_API_KEY')
def get_completion(prompt, model="gpt-3.5-turbo", temperature=0): 
    messages = [{"role": "user", "content": prompt}]
    response = openai.ChatCompletion.create(
        model=model,
        messages=messages,
        temperature=temperature, 
    )
    return response.choices[0].message["content"]

翻译

将以下英文文本翻译为西班牙文

prompt = f"""
Translate the following English text to Spanish: \ 
I would like to order a blender```
"""
response = get_completion(prompt)
print(response)
"""
Hola, me gustaría ordenar una licuadora.
"""

识别语言

prompt = f"""
Tell me which language this is: 
coûte le lampadaire?```
"""
response = get_completion(prompt)
print(response)
"""
This is French.
"""

同时进行多种翻译,翻译成法语、西班牙语、英语海盗语

prompt = f"""
Translate the following  text to French and Spanish
and English pirate: \
want to order a basketball```
"""
response = get_completion(prompt)
print(response)
"""
French pirate: ``Je veux commander un ballon de basket``
Spanish pirate: ``Quiero ordenar una pelota de baloncesto``
English pirate: ``I want to order a basketball``
"""

有正式和非正式之分。
正式场合是指当你和一个比你资历高的人说话或者在一个职业场合时,你需要使用正式语气;
而非正式则是当你和朋友群体交流时使用。

prompt = f"""
Translate the following text to Spanish in both the \
formal and informal forms: 
'Would you like to order a pillow?'
"""
response = get_completion(prompt)
print(response)
"""
Formal: ¿Le gustaría ordenar una almohada?
Informal: ¿Te gustaría ordenar una almohada?
"""

遍历翻译

粘贴一些不同语言的用户消息,然后我们将循环遍历每一个用户消息。
问模型告诉我们问题是用什么语言书写的。然后,我们将打印出原始消息的语言和问题,并要求模型将其翻译成英文和韩文。让我们运行它。

user_messages = [
  "La performance du système est plus lente que d'habitude.",  # System performance is slower than normal         
  "Mi monitor tiene píxeles que no se iluminan.",              # My monitor has pixels that are not lighting
  "Il mio mouse non funziona",                                 # My mouse is not working
  "Mój klawisz Ctrl jest zepsuty",                             # My keyboard has a broken control key
  "我的屏幕在闪烁"                                               # My screen is flashing
] 
for issue in user_messages:
    prompt = f"Tell me what language this is: ``{issue}``"
    lang = get_completion(prompt)
    print(f"Original message ({lang}): {issue}")

    prompt = f"""
    Translate the following  text to English \
    and Korean: ``{issue}``
    """
    response = get_completion(prompt)
    print(response, "\n")

"""
Original message (This is French.): La performance du système est plus lente que d'habitude.
English: The system performance is slower than usual.
Korean: 시스템 성능이 평소보다 느립니다. 

Original message (This is Spanish.): Mi monitor tiene píxeles que no se iluminan.
English: My monitor has pixels that don't light up.
Korean: 내 모니터에는 불이 켜지지 않는 픽셀이 있습니다. 

Original message (This is Italian.): Il mio mouse non funziona
English: My mouse is not working.
Korean: 내 마우스가 작동하지 않습니다. 

Original message (This is Polish.): Mój klawisz Ctrl jest zepsuty
English: My Ctrl key is broken.
Korean: 제 Ctrl 키가 고장 났어요. 

Original message (This is Chinese (Simplified).): 我的屏幕在闪烁
English: My screen is flickering.
Korean: 내 화면이 깜빡입니다. 
"""

风格转换

prompt = f"""
Translate the following from slang to a business letter: 
'Dude, This is Joe, check out this spec on this standing lamp.'
"""
response = get_completion(prompt)
print(response)
"""
Dear Sir/Madam,

I am writing to bring to your attention a standing lamp that I believe may be of interest to you. Please find attached the specifications for your review.

Thank you for your time and consideration.

Sincerely,

Joe
"""

格式转换

ChatGPT非常擅长在不同格式之间进行翻译,例如JSON到HTML、XML等各种格式。在提示中,我们将描述输入和输出格式。
我们有一个包含餐厅员工姓名和电子邮件列表的JSON,下面的例子从JSON转换为HTML表格。

data_json = { "resturant employees" :[     {"name":"Shyam", "email":"shyamjaiswal@gmail.com"},    {"name":"Bob", "email":"bob32@gmail.com"},    {"name":"Jai", "email":"jai87@gmail.com"}]}

prompt = f"""
Translate the following python dictionary from JSON to an HTML \
table with column headers and title: {data_json}
"""
response = get_completion(prompt)
print(response)
"""
<table>
  <caption>Restaurant Employees</caption>
  <thead>
    <tr>
      <th>Name</th>
      <th>Email</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Shyam</td>
      <td>shyamjaiswal@gmail.com</td>
    </tr>
    <tr>
      <td>Bob</td>
      <td>bob32@gmail.com</td>
    </tr>
    <tr>
      <td>Jai</td>
      <td>jai87@gmail.com</td>
    </tr>
  </tbody>
</table>
"""

语法检查

检查语法和拼写问题

text = [ 
  "The girl with the black and white puppies have a ball.",  # The girl has a ball.
  "Yolanda has her notebook.", # ok
  "Its going to be a long day. Does the car need it’s oil changed?",  # Homonyms
  "Their goes my freedom. There going to bring they’re suitcases.",  # Homonyms
  "Your going to need you’re notebook.",  # Homonyms
  "That medicine effects my ability to sleep. Have you heard of the butterfly affect?", # Homonyms
  "This phrase is to cherck chatGPT for speling abilitty"  # spelling
]
for t in text:
    prompt = f"""Proofread and correct the following text
    and rewrite the corrected version. If you don't find
    and errors, just say "No errors found". Don't use 
    any punctuation around the text:
    ``{t}``"""
    response = get_completion(prompt)
    print(response)

 """
 The girl with the black and white puppies has a ball.
No errors found.
It's going to be a long day. Does the car need its oil changed?
Their goes my freedom. There going to bring they're suitcases.

Corrected version: 
There goes my freedom. They're going to bring their suitcases.
You're going to need your notebook.
That medicine affects my ability to sleep. Have you heard of the butterfly effect?
This phrase is to check ChatGPT for spelling ability.
 """

例子:检查您在公共论坛上发布文本之前进行拼写和语法检查的示例。

text = f"""
Got this for my daughter for her birthday cuz she keeps taking \
mine from my room.  Yes, adults also like pandas too.  She takes \
it everywhere with her, and it's super soft and cute.  One of the \
ears is a bit lower than the other, and I don't think that was \
designed to be asymmetrical. It's a bit small for what I paid for it \
though. I think there might be other options that are bigger for \
the same price.  It arrived a day earlier than expected, so I got \
to play with it myself before I gave it to my daughter.
"""
prompt = f"proofread and correct this review: ``{text}``"
response = get_completion(prompt)
print(response)
"""
I got this for my daughter's birthday because she keeps taking mine from my room. Yes, adults also like pandas too. She takes it everywhere with her, and it's super soft and cute. However, one of the ears is a bit lower than the other, and I don't think that was designed to be asymmetrical. Additionally, it's a bit small for what I paid for it. I think there might be other options that are bigger for the same price. On the positive side, it arrived a day earlier than expected, so I got to play with it myself before I gave it to my daughter.
"""

可以用RedLines Python包来找到原始评论和模型输出之间的差异,并且显示出来。

from redlines import Redlines

diff = Redlines(text,response)
display(Markdown(diff.output_markdown))

不仅可以校对此评论,还可以改变语气,下面例子中改变成APA风格评论《软性熊猫》文章来源地址https://www.toymoban.com/news/detail-731175.html

prompt = f"""
proofread and correct this review. Make it more compelling. 
Ensure it follows APA style guide and targets an advanced reader. 
Output in markdown format.
Text: ``{text}``
"""
response = get_completion(prompt)
display(Markdown(response))

"""
prompt = f"""
proofread and correct this review. Make it more compelling. 
Ensure it follows APA style guide and targets an advanced reader. 
Output in markdown format.
Text: ``{text}``
"""
response = get_completion(prompt)
display(Markdown(response))

"""
Title: A Soft and Cute Panda Plushie for All Ages
As an adult, I can attest that pandas are not just for kids. That's why I got this adorable panda plushie for my daughter's birthday, after she kept taking mine from my room. And let me tell you, it was a hit!
The plushie is super soft and cuddly, making it the perfect companion for my daughter. She takes it everywhere with her, and it has quickly become her favorite toy. However, I did notice that one of the ears is a bit lower than the other, which I don't think was designed to be asymmetrical. But that doesn't take away from its cuteness.
The only downside is that it's a bit small for the price I paid. I think there might be other options that are bigger for the same price. But overall, I'm happy with my purchase.
One thing that surprised me was that it arrived a day earlier than expected. This gave me the chance to play with it myself before giving it to my daughter. And I have to say, I was impressed with the quality and attention to detail.
In conclusion, if you're looking for a soft and cute panda plushie for yourself or a loved one, this is definitely a great option. Just be aware that it might be a bit smaller than expected.
"""

"""

到了这里,关于OpenAI官方吴达恩《ChatGPT Prompt Engineering 提示词工程师》(5)转换 / Transforming翻译的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Openai+Deeplearning.AI: ChatGPT Prompt Engineering(六)

    想和大家分享一下最近学习的Deeplearning.AI和openai联合打造ChatGPT Prompt Engineering在线课程.以下是我写的关于该课程的前五篇博客: ChatGPT Prompt Engineering(一) ChatGPT Prompt Engineering(二) ChatGPT Prompt Engineering(三) ChatGPT Prompt Engineering(四) ChatGPT Prompt Engineering(五) 今天我们来学习第五部分

    2024年02月07日
    浏览(23)
  • 吴恩达 & OpenAI 的Prompt教程笔记 - ChatGPT Prompt Engineering for Developers

    课程标题:ChatGPT Prompt Engineering for Developers (Andrew Ng Isa Fulford) 课程章节: 课程简介(Introduction) 提示工程关键原则 (Guidelines) 提示工程需要迭代(lterative) 总结类应用(Summarizing) 推理类应用(Inferring) 转换类应用(Transforming) 扩展类应用(Expanding) 打造聊天机器人(Chatbot) 课程总结(Concl

    2024年02月07日
    浏览(25)
  • ChatGPT prompt engineering (中文版)笔记 |吴恩达ChatGPT 提示工程

    出处:https://download.csdn.net/download/weixin_45766780/87746321 感谢中文版翻译https://github.com/datawhalechina/prompt-engineering-for-developers/tree/main/content 国内 == 需要对openapi的endpoint做一个反向代理,并修改本地openai包的源代码== 如下图: completion 原则一:编写清晰、具体的指令 你应该通过提供

    2024年02月03日
    浏览(40)
  • 《ChatGPT Prompt Engineering for Developers》课程-提示词原则

    本章的主要内容为编写 Prompt 的原则,在本章中,我们将给出两个编写 Prompt 的原则与一些相关的策略,你将练习基于这两个原则来编写有效的 Prompt,从而便捷而有效地使用 LLM。 本教程使用 OpenAI 所开放的 ChatGPT API,因此你需要首先拥有一个 ChatGPT 的 API_KEY(也可以直接访问

    2024年02月03日
    浏览(27)
  • 【简单入门】ChatGPT prompt engineering (中文版)笔记 |吴恩达ChatGPT 提示工程

    出处:https://download.csdn.net/download/weixin_45766780/87746321 感谢中文版翻译https://github.com/datawhalechina/prompt-engineering-for-developers/tree/main/content 国内 == 需要对openapi的endpoint做一个反向代理,并修改本地openai包的源代码== 如下图: completion 原则一:编写清晰、具体的指令 你应该通过提供

    2024年02月05日
    浏览(36)
  • 提示工程(Prompt Engineering)将ChatGPT调教为傲娇猫娘~喵

    Prompt Engineering(提示工程)是指通过设计精心构造的提示(prompt)或者输入,来引导大型语言模型生成特定类型的输出。这个技术背后的原理是利用模型对输入的敏感性,通过提供特定格式或者内容的提示,引导模型生成符合预期的输出。 Prompt Engineering通过设计和构造精心设

    2024年02月05日
    浏览(43)
  • 吴恩达与OpenAI官方合作的ChatGPT提示工程课程笔记

    🥸 下述代码均在煮皮特上运行喔 Base LLM:基于文本训练数据来预测做“文字接龙” Instruction Tuned LLM(指令调整型LLM):接受了遵循指示的培训,可以根据提前培训的输入输出对结果进行调整 编写明确和具体的指令(明确 ≠ 短) 策略一:用分隔符清楚的指示输入的不同部分

    2024年02月07日
    浏览(33)
  • ChatGPT中文版Prompt提示工程超详细指南《提示工程简介及示例》Github最新破万星项目Meta AI前工程师解密百万年薪提示工程师GPT-4模型优化利器(一)

    近期,Meta AI前工程师推出的最强辅助——提示工程师指南在Github上引起了极大的反响。 这份全面指南详细列出了提示工程师所需的所有资料,使得他们在开发过程中拥有更多的技巧。这份指南提供的信息十分丰富,覆盖了从提示技巧使用到提示应用等各个方面,甚至还提供

    2024年02月02日
    浏览(42)
  • Prompt Engineering 提示工程教程详情

    Prompt Engineering(提示工程)是一种在自然语言处理(NLP)领域越来越受欢迎的技术。它涉及到创建和优化提示(prompts),以便从大型语言模型(如GPT-3)中获得高质量和目标导向的输出。在本教程中,我们将详细介绍提示工程的基本概念、实践方法和一些高级技巧。 一、提示

    2024年02月20日
    浏览(27)
  • Prompt Engineering 高级提示工程技巧

    Prompt Engineering(提示工程)是一种在自然语言处理(NLP)领域越来越受欢迎的技术。它涉及到创建和优化提示(prompts),以便从大型语言模型(如GPT-3)中获得高质量和目标导向的输出。在本教程中,我们将详细介绍一些高级提示工程技巧,帮助您更有效地利用大型语言模型

    2024年02月20日
    浏览(34)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包