Lucifer 发表于 3 天前

ChatGPT提示词指令分享·技巧篇③

<h1>技巧 3:使用特定引导词,引导AI输出特定内容</h1>
<p>在生成代码时,有个实用的小技巧:在提示语(prompt)结尾加上一条指令,明确告诉 AI 你已经描述完需求,可以开始写代码了。</p>
<p>比如在写 SQL 查询的例子里,你可以这样写:</p>
<pre><code class="language-other">Create a MySQL query for all students in the Computer Science Department:
Table departments, columns =
Table students, columns =
SELECT
</code></pre>
<p>加上“SELECT”这个关键词,会让 AI 立刻明白要输出 SQL 代码。</p>
<p>类似地,如果想让 AI 生成 Python 代码,通常可以用“import”来提示。但要注意,这只是告诉 AI“可以开始写代码”,并不代表它知道你要写什么语言的代码,具体要求还是要在提示里明确说明。</p>
<p>在 ChatGPT 的提示工程中,也有类似方法,不过他们通常直接在 prompt 里详细说明输出格式,比如让 AI 生成 JSON 数据。举个课程中的例子(Python代码示范):</p>
<pre><code class="language-python">prompt = f&quot;&quot;&quot;
Generate a list of three made-up book titles along \
with their authors and genres.
Provide them in JSON format with the following keys:
book_id, title, author, genre.
&quot;&quot;&quot;
</code></pre>
<p>关键是,提前告诉 AI 你需要的输出格式,比如需要 JSON格式,这样它才能准确地生成你想要的内容。</p>
页: [1]
查看完整版本: ChatGPT提示词指令分享·技巧篇③