当前位置:   article > 正文

OpenAI-ChatGPT最新官方接口《文本交互》全网最详细中英文实用指南和教程,助你零基础快速轻松掌握全新技术(一)(附源码)_怎么使openai接口返回的结果包含中文和英文两种语言

怎么使openai接口返回的结果包含中文和英文两种语言

在这里插入图片描述

Text completion 文本交互
Learn how to generate or manipulate text
了解如何生成或处理文本

前言

ChatGPT的文本交互是与用户交互并为他们提供创新体验的最强大的工具。ChatGPT文本交互的核心在于其轻松处理自然语言处理的能力。这允许用户进行直接的对话,ChatGPT通过理解对话的意图和上下文,可以提供针对用户需求量身定制的响应。

它可用于许多行业,如客户服务、营销、电子商务和医疗保健等等。例如,在客户服务应用程序中,ChatGPT可以帮助客户快速获得所需的答案。在市场营销中,ChatGPT可以建议根据客户的兴趣量身定制内容。在电子商务中,ChatGPT可以通过了解客户的偏好来帮助客户更容易地探索产品或服务。在医疗保健领域,ChatGPT可以帮助患者快速获得准确的医疗建议。

正如著名作家兼企业家Vashti Quiroz-Vega所说,“人工智能有可能彻底改变客户服务体验。”通过ChatGPT的文本交互,企业有机会为客户提供一种革命性的体验,这种体验比传统的客户服务渠道更直观、更吸引人。

Introduction 导言

The completions endpoint can be used for a wide variety of tasks. It provides a simple but powerful interface to any of our models. You input some text as a prompt, and the model will generate a text completion that attempts to match whatever context or pattern you gave it. For example, if you give the API the prompt, “As Descartes said, I think, therefore”, it will return the completion " I am" with high probability.
完成端点可用于各种各样的任务。它为我们的任何模型提供了一个简单而强大的接口。您输入一些文本作为提示,模型将生成一个文本补全,尝试匹配您提供的任何上下文或模式。例如,如果您向API提供提示“正如笛卡尔所说,我认为,因此”,它将以很高的概率返回补全“I am”。

The best way to start exploring completions is through our Playground. It’s simply a text box where you can submit a prompt to generate a completion. You can start with an example like the following:
开始探索完成的最佳方式是通过我们的游乐场。它只是一个文本框,您可以在其中提交提示以生成完成。您可以从如下示例开始:

Write a tagline for an ice cream shop.
为一家冰淇淋店写一句口号。

Once you submit, you’ll see something like this:
提交后,您将看到如下内容:

Write a tagline for an ice cream shop. 为冰淇淋店写一句口号。
We serve up smiles with every scoop! 我们为每一勺冰淇淋提供微笑!

The actual completion you see may differ because the API is non-deterministic by default. This means that you might get a slightly different completion every time you call it, even if your prompt stays the same. Setting temperature to 0 will make the outputs mostly deterministic, but a small amount of variability may remain.
您看到的实际完成可能会有所不同,因为API在默认情况下是不确定的。这意味着每次调用它时,得到的完成可能略有不同,即使提示保持不变。将temperature设置为0将使输出基本上具有确定性,但可能仍存在少量变化。

This simple text-in, text-out interface means you can “program” the model by providing instructions or just a few examples of what you’d like it to do. Its success generally depends on the complexity of the task and quality of your prompt. A good rule of thumb is to think about how you would write a word problem for a middle-schooler to solve. A well-written prompt provides enough information for the model to know what you want and how it should respond.
这个简单的文本输入、文本输出界面意味着您可以通过提供指令或几个您希望它做什么的示例来“编程”模型。它的成功通常取决于任务的复杂性和提示的质量。一个很好的经验法则是思考你将如何写一道应用题让一个中学生来解决。一个写得很好的提示为模型提供了足够的信息来了解您想要什么以及它应该如何响应。

This guide covers general prompt design best practices and examples. To learn more about working with code using our Codex models, visit our code guide.
本指南介绍了一般提示设计最佳实践和示例。要了解有关使用Codex模型处理代码的更多信息,请访问我们的代码指南

Keep in mind that the default models’ training data cuts off in 2021, so they may not have knowledge of current events. We plan to add more continuous training in the future.
请记住,默认模型的训练数据在2021年截止,因此它们可能不了解当前事件。我们计划在未来增加更多的持续培训。

Prompt design 提示设计

Basics基础知识

Our models can do everything from generating original stories to performing complex text analysis. Because they can do so many things, you have to be explicit in describing what you want. Showing, not just telling, is often the secret to a good prompt.
我们的模型可以完成从生成原始故事到执行复杂文本分析的所有工作。因为它们可以做很多事情,所以你必须明确地描述你想要什么。展示,而不仅仅是讲述,往往是一个好的提示的秘诀。

There are three basic guidelines to creating prompts:
创建提示有三个基本准则:

Show and tell. Make it clear what you want either through instructions, examples, or a combination of the two. If you want the model to rank a list of items in alphabetical order or to classify a paragraph by sentiment, show it that’s what you want.
**展示和讲述。**通过说明、例子或两者的结合,明确你想要什么。如果你想让模型按字母顺序排列一系列项目,或者按情感对一段文字进行分类,那么就向它展示你想要的。

Provide quality data. If you’re trying to build a classifier or get the model to follow a pattern, make sure that there are enough examples. Be sure to proofread your examples — the model is usually smart enough to see through basic spelling mistakes and give you a response, but it also might assume this is intentional and it can affect the response.
**提供优质数据。**如果你试图构建一个分类器或让模型遵循一个模式,请确保有足够的例子。一定要校对你的例子–模型通常足够聪明,可以看穿基本的拼写错误,并给予你一个回应,但它也可能认为这是故意的,它可能会影响回应。

Check your settings. The temperature and top_p settings control how deterministic the model is in generating a response. If you’re asking it for a response where there’s only one right answer, then you’d want to set these lower. If you’re looking for more diverse responses, then you might want to set them higher. The number one mistake people use with these settings is assuming that they’re “cleverness” or “creativity” controls.
检查您的设置。temperaturetop_p设置控制模型在生成响应时的确定性。如果你要求它给出一个只有一个正确答案的响应,那么你应该把这些设置得更低。如果您正在寻找更多样化的响应,那么您可能需要将它们设置得更高。人们使用这些设置的第一个错误是假设它们是“聪明”或“创造力”控件。

博主提示:关于ChatGPT超参设置,具体可以查看博主的相关文章《全网最详细中英文ChatGPT-GPT-4示例文档-从0到1快速入门AI智能问答应用场景——官网推荐的48种最佳应用场景》

Troubleshooting

If you’re having trouble getting the API to perform as expected, follow this checklist:
如果您无法让API按预期执行,请按照以下检查表操作:

  1. Is it clear what the intended generation should be?
    是否清楚预期的一代应该是什么样的?
  2. Are there enough examples? 有足够的例子吗?
  3. Did you check your examples for mistakes? (The API won’t tell you directly)
    你检查你的例子中的错误了吗?(API接口不会直接告诉你)
  4. Are you using temperature and top_p correctly?
    您是否正确使用了temperature和top_p?

Classification

To create a text classifier with the API, we provide a description of the task and a few examples. In this example, we show how to classify the sentiment of Tweets.
为了使用API创建文本分类器,我们提供了任务描述和一些示例。在这个例子中,我们展示了如何对推文的情绪进行分类。

Decide whether a Tweet’s sentiment is positive, neutral, or negative.
判断推文的情绪是积极的、中性的还是消极的。
Tweet: I loved the new Batman movie!
推文:我喜欢蝙蝠侠电影!
Sentiment:
情绪:

It’s worth paying attention to several features in this example:
值得注意的是这个例子中的几个特性:

  1. Use plain language to describe your inputs and outputs. We use plain language for the input “Tweet” and the expected output “Sentiment.” As a best practice, start with plain language descriptions. While you can often use shorthand or keys to indicate the input and output, it’s best to start by being as descriptive as possible and then working backwards to remove extra words and see if performance stays consistent.
    **使用简单的语言来描述你的输入和输出。**我们对输入“Tweet”和预期输出“Sentiment”使用简单的语言。“作为最佳实践,从简单的语言描述开始。虽然您可以经常使用速记或按键来指示输入和输出,但最好从尽可能描述开始,然后向后工作以删除多余的单词,看看性能是否保持一致。

  2. Show the API how to respond to any case. In this example, we include the possible sentiment labels in our instruction. A neutral label is important because there will be many cases where even a human would have a hard time determining if something is positive or negative, and situations where it’s neither.
    **展示API如何响应任何情况。**在这个例子中,我们在指令中包含了可能的情感标签。一个中立的标签是很重要的,因为在很多情况下,即使是人类也很难确定某件事是积极的还是消极的,以及两者都不是的情况。

  3. You need fewer examples for familiar tasks. For this classifier, we don’t provide any examples. This is because the API already has an understanding of sentiment and the concept of a Tweet. If you’re building a classifier for something the API might not be familiar with, it might be necessary to provide more examples.
    **对于熟悉的任务,您需要更少的示例。**对于这个分类器,我们不提供任何示例。这是因为API已经理解了情绪和推文的概念。如果您正在为API可能不熟悉的内容构建分类器,则可能需要提供更多示例。

Improving the classifier’s efficiency 提高分类器的效率

Now that we have a grasp of how to build a classifier, let’s take that example and make it even more efficient so that we can use it to get multiple results back from one API call.
现在我们已经掌握了如何构建分类器,让我们以该示例为例,使其更加高效,以便我们可以使用它从一个API调用中获取多个结果。

Classify the sentiment in these tweets:
对这些推文中的情绪进行分类:

  1. “I can’t stand homework” “我受不了作业”
  2. “This sucks. I’m bored
    声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/609113
推荐阅读
相关标签