Sure, here's how you could structure it in HTML with the translation included: ```html 如何使用OpenAI的新Structured Outputs API(附带代码)

如何使用OpenAI的新Structured Outputs API(附带代码)

在本文中,我们将介绍如何使用OpenAI的最新Structured Outputs API,并提供相关代码示例。

``` This HTML structure includes the translated title and a brief description of the content in Simplified Chinese.

Certainly! Here's the translation in simplified Chinese while maintaining the HTML structure: ```html OpenAI最近发布了一个对开发人员而言具有革命性意义的功能,帮助他们构建更可靠的系统。 ``` This HTML snippet now contains the translated text in simplified Chinese.

The new model, gpt-4o-2024–08–06, with Structured Outputs scores a perfect 100% on OpenAI’s structured extraction evaluation. In comparison, gpt-4–0613 scores less than 40%.

Certainly! Here's the translated text in simplified Chinese, while maintaining the HTML structure: ```html 这一新功能确保模型的输出将完全匹配开发者提供的 JSON 模式,使得构建强大助手和提取结构化数据变得更加容易。 ``` In HTML context, it would look like this: ```html

这一新功能确保模型的输出将完全匹配开发者提供的 JSON 模式,使得构建强大助手和提取结构化数据变得更加容易。

```

Sure, here's the translation of the text into simplified Chinese while keeping the HTML structure intact: ```html

⚠️ 如果您想要使用这种技术与GPT-4或其他LLM从任何PDF、Word文档或网站中提取干净的结构化数据,请查看这款开源提取工具。

``` This HTML code represents the translated text in simplified Chinese.

Certainly! Here is the HTML structure with the simplified Chinese translation: ```html

它是如何工作的?

``` This HTML structure ensures that "How does it work?" is translated into simplified Chinese and maintains the basic paragraph structure in HTML.

Certainly! Here's the HTML structure with the translated text in simplified Chinese: ```html

在幕后,OpenAI 使用一种称为受限抽样或受限解码的技术。不允许模型从词汇表中选择任何令牌,而是将输出限制为仅符合提供的模式的有效令牌。这是动态完成的,因此模型仍然可以生成灵活多样的响应,同时遵循指定的结构。

``` In Chinese (Simplified): ```html

在幕后,OpenAI 使用一种称为受限抽样或受限解码的技术。不允许模型从词汇表中选择任何令牌,而是将输出限制为仅符合提供的模式的有效令牌。这是动态完成的,因此模型仍然可以生成灵活多样的响应,同时遵循指定的结构。

```

Sure, here's the HTML structure with the translated text in simplified Chinese: ```html

OpenAI 使用的受限解码方法涉及动态确定在生成每个令牌后,哪些令牌是有效的。这是根据先前生成的令牌和上下文无关文法(CFG)中的规则来确定下一个有效的令牌。这确保模型的输出始终遵循指定的模式。

``` Translated text (simplified Chinese): "OpenAI 使用的受限解码方法涉及动态确定在生成每个令牌后,哪些令牌是有效的。这是根据先前生成的令牌和上下文无关文法(CFG)中的规则来确定下一个有效的令牌。这确保模型的输出始终遵循指定的模式。"

Certainly! Here's how you can express "How to use it" in simplified Chinese within an HTML structure: ```html 如何使用 ``` In this snippet: - `` is used to enclose the translated text "如何使用", which means "How to use" in simplified Chinese. This HTML structure preserves the text while allowing it to be styled or formatted according to your needs on a webpage.

Certainly! Here's how you can structure the HTML to display the translated text in simplified Chinese: ```html

Translate to Chinese

我更喜欢通过例子来学习,所以我将给出我能想到的最简单的例子。

``` In this HTML: - `lang="zh-CN"` specifies the language as simplified Chinese. - The paragraph `

` tag contains the translated text: "我更喜欢通过例子来学习,所以我将给出我能想到的最简单的例子。" Make sure to save the file with UTF-8 encoding to correctly display Chinese characters.

Certainly! Here's the translated text in simplified Chinese, while keeping the HTML structure: ```html

在这个例子中,我们使用 Pydantic 定义了一个 Person 类,它包含两个字段:name 和 age。

``` This HTML snippet contains the translated text: "在这个例子中,我们使用 Pydantic 定义了一个 Person 类,它包含两个字段:name 和 age。"
from pydantic import BaseModel

class Person(BaseModel):
name: str
age: int

Certainly! Here's how you could structure the HTML while providing the translation: ```html

然后我们创建一个 OpenAI 客户端,并使用 chat.completions.parse 方法发送我们的请求。messages 参数包括一个系统消息,指示模型提取姓名和年龄,以及一个用户消息,包含我们希望从中提取数据的文本。tools 参数包括我们的 Person 类,指定我们希望模型以这种格式提取数据。

``` In this HTML snippet: - `

` tags are used to enclose the translated text to indicate it's a paragraph. - Simplified Chinese characters are used for the translation.

from openai import OpenAI
client = OpenAI()

completion = client.beta.chat.completions.parse(
model="gpt-4o-2024-08-06",
messages=[
{
"role": "system",
"content": "Extract the names and ages of the people mentioned in the following text."
},
{
"role": "user",
"content": "John is 30 years old and his sister Alice is 25."
}
],
tools=[
openai.pydantic_function_tool(Person)
]
)

print(completion.choices[0].message.tool_calls[0].function.parsed_arguments)

```html

completion.choices[0].message.tool_calls[0].function.parsed_arguments 是一个字典,其中包含模型返回的解析参数,这些参数将与您的 Pydantic 类定义的结构匹配。在这种情况下,由于我们定义了一个包含姓名和年龄字段的 Person 类,解析参数也将包含这些字段。

```

这里是解析后参数的示例:

{
'name': 'John',
'age': 30
}

```html

现在,假设你希望在代码中使用这些解析后的参数,而不仅仅是将它们打印出来。以下是如何使用解析后的参数创建一个新的 Person 对象:

```
# Create a new Person object using the parsed arguments
person = Person(**parsed_arguments)
print(person.name) # Output: John
print(person.age) # Output: 30

Certainly! Here's how you could represent "That’s pretty neat!" in simplified Chinese within an HTML structure: ```html

那真不错!

``` In this HTML snippet: - `

` indicates a paragraph element. - `那真不错!` is the simplified Chinese translation of "That’s pretty neat!"

Certainly! Here's the translation of "What models can I use?" in simplified Chinese while keeping the HTML structure intact: ```html

我可以使用哪些模型?

``` In this translation: - `

` denotes a paragraph element in HTML. - "我可以使用哪些模型?" translates to "What models can I use?"

```html

结构化输出支持所有包含 GPT-4 及更新版本的模型,响应格式适用于 GPT-4o-mini 和 GPT-4o-2024-08-06。

```

Certainly! Here's the translation of "Limitations and Restrictions" into simplified Chinese, while keeping the HTML structure: ```html 限制和约束 ```

Certainly! Here's the translated text in simplified Chinese, formatted within an HTML structure: ```html

使用结构化输出时需要记住一些限制:

``` In this HTML snippet: - `

` tags denote a paragraph, maintaining the structure as requested. - The Chinese text translates to: "使用结构化输出时需要记住一些限制:"

  • Sure, here's the HTML structure with the translated text in simplified Chinese: ```html

    结构化输出仅支持 JSON Schema 的子集,详细信息请参阅 OpenAI 的文档。

    ``` In this structure: - `

    ` represents a paragraph element. - `` is used for inline styling or grouping elements. The translated text "结构化输出仅支持 JSON Schema 的子集,详细信息请参阅 OpenAI 的文档。" conveys the meaning accurately in simplified Chinese.

  • Certainly! Here's the text translated into simplified Chinese while keeping the HTML structure intact: ```html

    第一个采用新架构的 API 响应会因为架构预处理而增加额外的延迟。随后的响应将更快,没有延迟惩罚。

    ``` This HTML snippet contains the translated text in simplified Chinese, suitable for embedding in an HTML document while maintaining the structure.
  • Sure, here is the translation of the text into simplified Chinese, keeping the HTML structure intact: ```html

    模型可能会拒绝不安全的请求,或在达到最大标记数或其他停止条件之前停止生成模式。

    ```
  • Certainly! Here's the translation in simplified Chinese, keeping the HTML structure: ```html

    Structured Outputs 不会阻止 JSON 对象中数值方面的所有模型错误。

    ```
  • Sure, here is the text translated to simplified Chinese while keeping the HTML structure intact: ```html
    结构化输出与并行函数调用不兼容。
    ```

2024-08-09 04:12:39 AI中文站翻译自原文