使用 LLM 生成 MySQL 查询
背景
本提示测试 LLM 的代码生成能力,通过提供有关数据库模式信息来提示其生成有效的 MySQL 查询。
提示词
"""
Table departments, columns = [DepartmentId, DepartmentName]
Table students, columns = [DepartmentId, StudentId, StudentName]
为计算机科学系的所有学生创建 MySQL 查询
"""
Code / API
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4",
messages=[
{
"role": "user",
"content": "\"\"\"\nTable departments, columns = [DepartmentId, DepartmentName]\nTable students, columns = [DepartmentId, StudentId, StudentName]\n为计算机科学系的所有学生创建 MySQL 查询\n\"\"\""
}
],
temperature=1,
max_tokens=1000,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
参考
- Prompt Engineering Guide (16 March 2023)