Skip to content

Commit

Permalink
added ask frong/chatgpt
Browse files Browse the repository at this point in the history
  • Loading branch information
Soulsender committed Sep 7, 2024
1 parent 6e48f08 commit 0535a48
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
24 changes: 11 additions & 13 deletions cogs/ask-frong.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import nextcord
from nextcord.ext import commands
from dotenv import load_dotenv
import openai
from openai import OpenAI
import os

openai.api_key = str(os.getenv('OPENAI_KEY'))
client = OpenAI(api_key=str(os.getenv('OPENAI_KEY')))

def ask_chatgpt(question):
response = openai.ChatCompletion.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']
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 AskFrong(commands.Cog):
def __init__(self,bot):
Expand All @@ -25,10 +23,10 @@ async def on_ready(self):
print(f"ask-frong - Loaded")

# for testing add guild_ids=[guild_id]
@nextcord.slash_command(name="askfrong", description="Ask the almighty.", guild_ids=[414625175217242113])
@nextcord.slash_command(name="askfrong", description="Ask the almighty.")
async def askfrong(self, interaction: nextcord.Interaction, question):
answer = ask_chatgpt(question)
await interaction.response.send_message(f"{answer}")
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)
await interaction.response.send_message(f"**Question: **{question} \n\n **Answer: **{answer}")

def setup(bot):
bot.add_cog(AskFrong(bot))
32 changes: 32 additions & 0 deletions cogs/chatgpt.py
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))

0 comments on commit 0535a48

Please sign in to comment.