-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e48f08
commit 0535a48
Showing
2 changed files
with
43 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import nextcord | ||
from nextcord.ext import commands | ||
from dotenv import load_dotenv | ||
from openai import OpenAI | ||
import os | ||
|
||
client = OpenAI(api_key=str(os.getenv('OPENAI_KEY'))) | ||
|
||
def ask_chatgpt(question): | ||
response = client.chat.completions.create(model="gpt-3.5-turbo", | ||
messages=[ | ||
{"role": "system", "content": "You are a helpful assistant."}, | ||
{"role": "user", "content": question}, | ||
]) | ||
return response.choices[0].message.content | ||
|
||
class AskChatGPT(commands.Cog): | ||
def __init__(self,bot): | ||
self.bot=bot | ||
|
||
@commands.Cog.listener() | ||
async def on_ready(self): | ||
print(f"chatgpt - Loaded") | ||
|
||
# for testing add guild_ids=[guild_id] | ||
@nextcord.slash_command(name="chatgpt", description="Ask ChatGPT.") | ||
async def askchatgpt(self, interaction: nextcord.Interaction, question): | ||
answer = ask_chatgpt(question) | ||
await interaction.response.send_message(f"**Question: **{question} \n\n **Answer: **{answer}") | ||
|
||
def setup(bot): | ||
bot.add_cog(AskChatGPT(bot)) |