#im trying to create a slash command which ask a prompt to the user

1 messages · Page 1 of 1 (latest)

haughty crag
#

im trying to create a slash command which ask a prompt to the user and the user get an answer from chat gpt

@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": "system", "content": demande}],
    )
    # Extraire la réponse du dictionnaire de réponse
    bot_response = response["choices"][0]["message"]["content"]
    await interaction.response.send_message(bot_response)
half snowBOT
#

Hi @haughty crag. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

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}],
    )
    # Extraire la réponse du dictionnaire de réponse
    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.

For more details, you can refer to the OpenAI API documentation (https://platform.openai.com/docs/quickstart?context=python) and the OpenAI community forum (https://community.openai.com/t/640637) for examples of how to use the API.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: