Your code seems to be on the right track for creating a slash command in Discord that interacts with the OpenAI GPT-3.5 Turbo model. However, there are a few adjustments needed to ensure the correct interaction with the model.
The messages parameter in the AI.chat.completions.create function call should be a list of message objects. Each object should have a role that can be 'system', 'user', or 'assistant', and content which is the text of the message from that role. The 'system' role is generally used to set the behavior of the 'assistant' (which is the AI model).
In your case, you want to ask a question to the AI, so the role should be 'user'. Here's how you can modify your code:
@client.tree.command(
name="ask",
description="pose une question à chat gpt ! il se fera un plaisir d'y répondre",
)
async def ask(interaction: discord.Interaction, demande: str):
response = await AI.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": demande}],
)
bot_response = response["choices"][0]["message"]["content"]
await interaction.response.send_message(bot_response)
Please note that you need to replace AI with your OpenAI client instance. Also, ensure that you have the necessary permissions and have set up the OpenAI API key correctly.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: