LLMs for Code Generation (用於程式碼生成的大型語言模型)
本段包含一組用於測試大型語言模型程式碼生成能力的提示集合。
目錄
使用大型語言模型生成程式碼片段
背景
此提示透過以註解形式提供程式說明(使用 /* <指令> */),要求大型語言模型生成對應的程式碼片段,以測試其程式碼生成能力。
提示詞
/*請求使用者輸入他們的名字,並說「Hello」*/
程式
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4",
messages=[
{
"role": "user",
"content": "/*\nAsk the user for their name and say \"Hello\"\n*/"
}
],
temperature=1,
max_tokens=1000,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
import fireworks.client
fireworks.client.api_key = "<FIREWORKS_API_KEY>"
completion = fireworks.client.ChatCompletion.create(
model="accounts/fireworks/models/mixtral-8x7b-instruct",
messages=[
{
"role": "user",
"content": "/*\nAsk the user for their name and say \"Hello\"\n*/",
}
],
stop=["<|im_start|>","<|im_end|>","<|endoftext|>"],
stream=True,
n=1,
top_p=1,
top_k=40,
presence_penalty=0,
frequency_penalty=0,
prompt_truncate_len=1024,
context_length_exceeded_behavior="truncate",
temperature=0.9,
max_tokens=4000
)
使用大型語言模型產生 MySQL 查詢語句
背景
此提示透過提供資料庫結構的資訊,要求大型語言模型生成有效的 MySQL 查詢語句,以測試其程式碼生成能力。
提示詞
資料表 students,欄位 = [DepartmentId, StudentId, StudentName]
請撰寫一個 MySQL 查詢語句,用於查詢所有在「Computer Science」系的學生
程式
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
)
import fireworks.client
fireworks.client.api_key = "<FIREWORKS_API_KEY>"
completion = fireworks.client.ChatCompletion.create(
model="accounts/fireworks/models/mixtral-8x7b-instruct",
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\"\"\"",
}
],
stop=["<|im_start|>","<|im_end|>","<|endoftext|>"],
stream=True,
n=1,
top_p=1,
top_k=40,
presence_penalty=0,
frequency_penalty=0,
prompt_truncate_len=1024,
context_length_exceeded_behavior="truncate",
temperature=0.9,
max_tokens=4000
)
繪製 TiKZ 圖示
背景
此提示透過要求大型語言模型使用 TiKZ 繪製獨角獸,來測試其程式碼生成能力。
在下列範例中,模型預期應生成可用於產生獨角獸(或其他指定物件)的 LaTeX 程式碼。
提示詞
用 TiKZ 繪製一隻獨角獸。
程式
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4",
messages=[
{
"role": "user",
"content": "Draw a unicorn in TiKZ"
}
],
temperature=1,
max_tokens=1000,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
import fireworks.client
fireworks.client.api_key = "<FIREWORKS_API_KEY>"
completion = fireworks.client.ChatCompletion.create(
model="accounts/fireworks/models/mixtral-8x7b-instruct",
messages=[
{
"role": "user",
"content": "Draw a unicorn in TiKZ",
}
],
stop=["<|im_start|>","<|im_end|>","<|endoftext|>"],
stream=True,
n=1,
top_p=1,
top_k=40,
presence_penalty=0,
frequency_penalty=0,
prompt_truncate_len=1024,
context_length_exceeded_behavior="truncate",
temperature=0.9,
max_tokens=4000
)
References
上一篇: Prmpt Hub - 用於分類任務的大型語言模型 (LLMs for Classification)
下一篇: Prompt Hub - 用於創意生成的大型語言模型 (LLMs for Creativity)