feat: Add ai command
All checks were successful
Build Docker / Build Docker (push) Successful in 33s
All checks were successful
Build Docker / Build Docker (push) Successful in 33s
This commit is contained in:
parent
94362f4a67
commit
b0ce40b47f
35
ai.py
Normal file
35
ai.py
Normal 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
6
bot.py
@ -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
|
||||
|
@ -5,3 +5,4 @@ dnspython
|
||||
markdownify
|
||||
cryptography
|
||||
apscheduler
|
||||
openai
|
Loading…
Reference in New Issue
Block a user