🚀 在我们的新课程中掌握提示工程和构建 AI Agents!使用 PROMPTING20 优惠码可享八折优惠 ➜ 立即注册
生成 MySQL 查询

使用 LLMs 生成 MySQL 查询

背景

此提示通过提供数据库模式信息,测试 LLM 生成有效 MySQL 查询的代码生成能力。

提示

"""
Table departments, columns = [DepartmentId, DepartmentName]
Table students, columns = [DepartmentId, StudentId, StudentName]
Create a MySQL query for all students in the Computer Science Department
"""

代码 / 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]\nCreate a MySQL query for all students in the Computer Science Department\n\"\"\""
        }
    ],
    temperature=1,
    max_tokens=1000,
    top_p=1,
    frequency_penalty=0,
    presence_penalty=0
)

参考