gpt和llama的推理prompt

gpt

completion = openai.ChatCompletion.create(
# model="gpt-3.5-turbo",
model='gpt-4',
messages=[
{
"role": "system",
"content": 
'''
You are a helpful assistant ...
'''
},

{
"role": "user",
"content":
f'''
The input question is:{question}
For example, your answer should be like this: ...
'''
}
])

print(completion.choices[0].message["content"])

llama

query=f'''
<s>[INST] <<SYS>>
As an intelligent robot ...<</SYS>>
The input question is:{question}
For example, your answer should be like this: ...
[/INST]
'''

output = generate_text(query)
print(output[0]['generated_text'].replace(query,'').strip())

prompt engineering: https://www.promptingguide.ai/

  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
生成式预训练模型(GPT)可以用来生成文本,但是要用它来制作游戏可能会有些困难。不过,我们可以使用 GPT 来生成游戏的提示和说明,例如贪吃蛇游戏。 下面是一个使用 GPT-2 模型生成贪吃蛇游戏提示的示例代码: ```python import openai import re # 设置 OpenAI API 密钥 openai.api_key = "YOUR_API_KEY" # 准备 GPT-2 模型 model_engine = "text-davinci-002" prompt = "Generate a prompt for playing the snake game." temperature = 0.5 max_tokens = 100 # 生成游戏提示 response = openai.Completion.create( engine=model_engine, prompt=prompt, temperature=temperature, max_tokens=max_tokens ) # 清理生成的文本 prompt_text = response.choices[0].text.strip() prompt_text = re.sub(r"\n\n+", "\n", prompt_text) prompt_text = re.sub(r"\n+", "\n", prompt_text) # 输出游戏提示 print(prompt_text) ``` 运行上面的代码后,你将得到一个游戏提示,例如: ``` The snake game is a classic arcade game where players control a snake that grows in length as it eats food. The game is won by eating all of the food on the board without colliding with the walls or the snake's own body. The snake moves continuously in a straight line, and the player can change the direction of the snake by using the arrow keys on their keyboard. The game becomes more difficult as the snake grows longer and the board becomes more crowded with food and obstacles. ``` 你可以将这个提示放在游戏界面中,让玩家更好地理解游戏规则和玩法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值