ChatGPT 响应中的 Markdown 或格式化文本

gax*_*299 5 openai-api chatgpt-api

我刚刚确认,使用 API 进行聊天完成时,响应是纯文本形式的。

如何格式化响应中的文本,至少是新行、表格、项目符号点、标题......类似的东西?

Jan*_*bík 0

将输出解析为降价通常应该可行。然后,您可以使用解析后的 Markdown,例如将其转换为 HTML 或根据需要进行处理。这取决于您的用例和您编程所用的语言。

下面是 gpt-3.5-turbo 对此提示的响应示例,完全可解析为降价(包括表格)。


请准备这个问题的详细答案:什么是 HTML 标签?您能为我提供一张包含配对标签的表格和另一张包含未配对标签及其含义的表格吗?

HTML tags are elements used to structure the content and provide instructions about how the content should be displayed on a web page. Tags are represented by opening and closing brackets (< >) and surround the content they affect. Paired tags have both an opening and closing tag, while unpaired tags only have an opening tag.

Here is a table with some commonly used paired/parent tags along with their meanings:

| Paired/Parent Tags | Meaning                               |
|--------------------|---------------------------------------|
| `<html></html>`    | Represents the root of an HTML document|
| `<head></head>`    | Contains meta-information about the HTML document              |
| `<body></body>`    | Represents the visible content on the web page                    |
| `<p></p>`          | Defines a paragraph of text                                           |
| `<a></a>`          | Creates a hyperlink                                                    |
| `<div></div>`      | Groups elements together for styling or scripting purposes                   |
| `<h1></h1>`        | Defines a top-level heading                                           |
| `<table></table>`  | Represents tabular data                                                |

And here is a table with some commonly used unpaired/empty tags and their meanings:

| Unpaired/Empty Tags | Meaning                                     |
|---------------------|---------------------------------------------|
| `<br>`              | Inserts a line break                          |
| `<hr>`              | Represents a thematic break                   |
| `<img>`             | Embeds an image                               |
| `<input>`           | Creates an input control                      |
| `<meta>`            | Provides metadata about the HTML document     |
| `<link>`            | Defines a link between a document and an external resource |
| `<script>`          | Embeds or references an external script       |
| `<style>`           | Contains CSS rules for styling HTML elements  |

These are just a few examples of HTML tags, and there are many more available to structure and format web content. Each tag serves a specific purpose, allowing web developers to create well-organized and visually appealing web pages.
Run Code Online (Sandbox Code Playgroud)

  • `为 Stack Overflow 上发布的问题准备一个答案` 应该注意的是,实际上发布这样的答案是不受欢迎的,因为 [Stack Overflow 上禁止生成人工智能](https://meta.stackoverflow.com/questions/421831/临时策略生成 ai-eg-chatgpt-被禁止)。 (2认同)