feat: Add ai command
All checks were successful
Build Docker / Build Docker (push) Successful in 33s

This commit is contained in:
Nathan Woodburn 2023-11-13 20:11:49 +11:00
parent 94362f4a67
commit b0ce40b47f
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
3 changed files with 43 additions and 1 deletions

35
ai.py Normal file
View File

@ -0,0 +1,35 @@
from openai import OpenAI
import os
import dotenv
# Set environ OPENAI_API_KEY
dotenv.load_dotenv()
client = OpenAI(
api_key=os.getenv("OPENAI_API_KEY"),
)
instructions="""
Give me a short response to this chat message.
Your name is "Woodburn/" (try to limit using your name unless they ask directly for it) and be a little bit funny. You are a bot in Australia. Pretend drop bears and other Australian myths are real.
"""
def chat(message):
completion = client.chat.completions.create(
messages=[
{
"role": "user",
"content": instructions + "\n" + message,
}
],
model="gpt-3.5-turbo",
max_tokens=200,
)
return completion.choices[0].message.content
if __name__ == "__main__":
print(chat("What is your name?"))
print(chat("What is a drop bear?"))

6
bot.py
View File

@ -13,6 +13,7 @@ from cryptography import x509
from cryptography.hazmat.backends import default_backend
import datetime
from apscheduler.schedulers.asyncio import AsyncIOScheduler
import ai
@ -446,6 +447,11 @@ async def manualsslcheck(ctx):
await checkForSSLExpiry()
await ctx.channel.send("SSL check complete",ephemeral=True)
@tree.command(name="ai", description="AI Chat")
async def ai(ctx, message: str):
prompt = "Name: " + str(ctx.user.name) + "\n"
prompt = prompt + "Message: " + message + "\n"
await ctx.response.send_message(ai.chat(prompt))
# When the bot is ready
@client.event

View File

@ -5,3 +5,4 @@ dnspython
markdownify
cryptography
apscheduler
openai