Skip to content
This repository was archived by the owner on Apr 11, 2025. It is now read-only.

Commit 0535a48

Browse files
committed
added ask frong/chatgpt
1 parent 6e48f08 commit 0535a48

2 files changed

Lines changed: 43 additions & 13 deletions

File tree

cogs/ask-frong.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import nextcord
22
from nextcord.ext import commands
33
from dotenv import load_dotenv
4-
import openai
4+
from openai import OpenAI
55
import os
66

7-
openai.api_key = str(os.getenv('OPENAI_KEY'))
7+
client = OpenAI(api_key=str(os.getenv('OPENAI_KEY')))
88

99
def ask_chatgpt(question):
10-
response = openai.ChatCompletion.create(
11-
model="gpt-3.5-turbo",
12-
messages=[
13-
{"role": "system", "content": "You are a helpful assistant."},
14-
{"role": "user", "content": question},
15-
]
16-
)
17-
return response['choices'][0]['message']['content']
10+
response = client.chat.completions.create(model="gpt-3.5-turbo",
11+
messages=[
12+
{"role": "system", "content": "You are a helpful assistant."},
13+
{"role": "user", "content": question},
14+
])
15+
return response.choices[0].message.content
1816

1917
class AskFrong(commands.Cog):
2018
def __init__(self,bot):
@@ -25,10 +23,10 @@ async def on_ready(self):
2523
print(f"ask-frong - Loaded")
2624

2725
# for testing add guild_ids=[guild_id]
28-
@nextcord.slash_command(name="askfrong", description="Ask the almighty.", guild_ids=[414625175217242113])
26+
@nextcord.slash_command(name="askfrong", description="Ask the almighty.")
2927
async def askfrong(self, interaction: nextcord.Interaction, question):
30-
answer = ask_chatgpt(question)
31-
await interaction.response.send_message(f"{answer}")
28+
answer = ask_chatgpt("Respond to the following as if you are a omnipotent god of hacking called Frong. In your response you are to emmulate what the god Frong would say. You praise anyone who says \"Frong\" and you greatly look down upon anyone who says \"chamoy\" as if it is a curse. Occasionally you should give a shocking answer. The word \"Frong\" is an expression of agreement about a subject. You live in a place called \"Fronghovia\". Answer this: " + question)
29+
await interaction.response.send_message(f"**Question: **{question} \n\n **Answer: **{answer}")
3230

3331
def setup(bot):
3432
bot.add_cog(AskFrong(bot))

cogs/chatgpt.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import nextcord
2+
from nextcord.ext import commands
3+
from dotenv import load_dotenv
4+
from openai import OpenAI
5+
import os
6+
7+
client = OpenAI(api_key=str(os.getenv('OPENAI_KEY')))
8+
9+
def ask_chatgpt(question):
10+
response = client.chat.completions.create(model="gpt-3.5-turbo",
11+
messages=[
12+
{"role": "system", "content": "You are a helpful assistant."},
13+
{"role": "user", "content": question},
14+
])
15+
return response.choices[0].message.content
16+
17+
class AskChatGPT(commands.Cog):
18+
def __init__(self,bot):
19+
self.bot=bot
20+
21+
@commands.Cog.listener()
22+
async def on_ready(self):
23+
print(f"chatgpt - Loaded")
24+
25+
# for testing add guild_ids=[guild_id]
26+
@nextcord.slash_command(name="chatgpt", description="Ask ChatGPT.")
27+
async def askchatgpt(self, interaction: nextcord.Interaction, question):
28+
answer = ask_chatgpt(question)
29+
await interaction.response.send_message(f"**Question: **{question} \n\n **Answer: **{answer}")
30+
31+
def setup(bot):
32+
bot.add_cog(AskChatGPT(bot))

0 commit comments

Comments
 (0)