Compare commits
5 Commits
boy-you-sa
...
3afb2e5132
| Author | SHA1 | Date | |
|---|---|---|---|
| 3afb2e5132 | |||
| 0ef3fd1e82 | |||
| f81a76e505 | |||
| 8212edc406 | |||
| 386a7e764d |
@@ -18,6 +18,7 @@ RUN apk update && \
|
|||||||
tcl-dev
|
tcl-dev
|
||||||
|
|
||||||
RUN pip3 install --no-cache-dir \
|
RUN pip3 install --no-cache-dir \
|
||||||
|
config \
|
||||||
discord \
|
discord \
|
||||||
openai \
|
openai \
|
||||||
aiohttp \
|
aiohttp \
|
||||||
|
|||||||
29
garfmain.py
29
garfmain.py
@@ -117,30 +117,30 @@ async def garfbot_qr(ctx, *, text):
|
|||||||
f"QR Code Request - User: {ctx.author.name}, Server: {ctx.guild.name}, Text: {text}"
|
f"QR Code Request - User: {ctx.author.name}, Server: {ctx.guild.name}, Text: {text}"
|
||||||
)
|
)
|
||||||
if len(text) > 1000:
|
if len(text) > 1000:
|
||||||
await ctx.send("❌ Text too long! Maximum 1000 characters.")
|
await ctx.reply("❌ Text too long! Maximum 1000 characters.")
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
qr_code = await generate_qr(text)
|
qr_code = await generate_qr(text)
|
||||||
sendfile = discord.File(fp=qr_code, filename="qrcode.png")
|
sendfile = discord.File(fp=qr_code, filename="qrcode.png")
|
||||||
await ctx.send(file=sendfile)
|
await ctx.reply(file=sendfile)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
await ctx.send(e)
|
await ctx.reply(e)
|
||||||
|
|
||||||
|
|
||||||
@garfbot.command(name="wiki")
|
@garfbot.command(name="wiki")
|
||||||
async def garfbot_wiki(ctx, *, query):
|
async def garfbot_wiki(ctx, *, query):
|
||||||
summary = await garfield.wikisum(query)
|
summary = await garfield.wikisum(query)
|
||||||
await ctx.send(summary)
|
await ctx.reply(summary)
|
||||||
|
|
||||||
|
|
||||||
@garfbot.command(name="shop")
|
@garfbot.command(name="shop")
|
||||||
async def garfbot_shop(ctx, *, query):
|
async def garfbot_shop(ctx, *, query):
|
||||||
try:
|
try:
|
||||||
response = kroger.garfshop(query)
|
response = kroger.garfshop(query)
|
||||||
await ctx.send(response)
|
await ctx.reply(response)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await ctx.send(f"`GarfBot Error: {str(e)}`")
|
await ctx.reply(f"`GarfBot Error: {str(e)}`")
|
||||||
|
|
||||||
|
|
||||||
@garfbot.command(name="weather")
|
@garfbot.command(name="weather")
|
||||||
@@ -153,20 +153,21 @@ async def garfchat(ctx, *, prompt):
|
|||||||
if "is this true" in prompt.lower():
|
if "is this true" in prompt.lower():
|
||||||
messages = [msg async for msg in ctx.channel.history(limit=2)]
|
messages = [msg async for msg in ctx.channel.history(limit=2)]
|
||||||
prompt = messages[1].content
|
prompt = messages[1].content
|
||||||
|
prompt = f"Is this true: {prompt}"
|
||||||
answer = await garfield.generate_chat(prompt)
|
answer = await garfield.generate_chat(prompt)
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Chat Request - User: {ctx.author.name}, Server: {ctx.guild.name}, Prompt: {prompt}"
|
f"Chat Request - User: {ctx.author.name}, Server: {ctx.guild.name}, Prompt: {prompt}"
|
||||||
)
|
)
|
||||||
await ctx.send(answer)
|
await ctx.reply(answer)
|
||||||
|
|
||||||
|
|
||||||
@garfbot.command(name="pic")
|
# @garfbot.command(name="pic")
|
||||||
async def garfpic(ctx, *, prompt):
|
# async def garfpic(ctx, *, prompt):
|
||||||
logger.info(
|
# logger.info(
|
||||||
f"Image Request - User: {ctx.author.name}, Server: {ctx.guild.name}, Prompt: {prompt}"
|
# f"Image Request - User: {ctx.author.name}, Server: {ctx.guild.name}, Prompt: {prompt}"
|
||||||
)
|
# )
|
||||||
await ctx.send(f"`Please wait... image generation queued: {prompt}`")
|
# await ctx.reply(f"`Please wait... image generation queued: {prompt}`")
|
||||||
await garfield.garfpic(ctx, prompt)
|
# await garfield.garfpic(ctx, prompt)
|
||||||
|
|
||||||
|
|
||||||
@garfbot.command(name="help")
|
@garfbot.command(name="help")
|
||||||
|
|||||||
@@ -123,16 +123,16 @@ async def aod_message(garfbot, message):
|
|||||||
stats_embed.add_field(name=field, value="\n".join(values), inline=True)
|
stats_embed.add_field(name=field, value="\n".join(values), inline=True)
|
||||||
await message.channel.send(embed=stats_embed)
|
await message.channel.send(embed=stats_embed)
|
||||||
|
|
||||||
# Boy You Said It
|
# # Boy You Said It
|
||||||
words = re.findall(r"[a-zA-Z']+", message.content.lower())
|
# words = re.findall(r"[a-zA-Z']+", message.content.lower())
|
||||||
stops = {"a", "an", "the", "and", "or", "but", "is", "it", "in", "on", "at", "to", "of"}
|
# stops = {"a", "an", "the", "and", "or", "but", "is", "it", "in", "on", "at", "to", "of"}
|
||||||
words = [w for w in words if w not in stops]
|
# words = [w for w in words if w not in stops]
|
||||||
|
|
||||||
if words:
|
# if words:
|
||||||
firsts = [w[0] for w in words]
|
# firsts = [w[0] for w in words]
|
||||||
commons = max(set(firsts), key=firsts.count)
|
# commons = max(set(firsts), key=firsts.count)
|
||||||
count = firsts.count(commons)
|
# count = firsts.count(commons)
|
||||||
|
|
||||||
if count >= 3 or (len(words) >= 2 and count / len(words) >= 0.75):
|
# if count >= 3 or (len(words) >= 2 and count / len(words) >= 0.75):
|
||||||
await message.channel.send("Boy, you said it!")
|
# await message.channel.send("Boy, you said it!")
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ from garfpy import logger
|
|||||||
|
|
||||||
class GarfAI:
|
class GarfAI:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.baseurl = config.BASE_URL
|
||||||
self.openaikey = config.OPENAI_TOKEN
|
self.openaikey = config.OPENAI_TOKEN
|
||||||
|
self.sysprompt = config.SYSTEM_PROMPT
|
||||||
self.txtmodel = config.TXT_MODEL
|
self.txtmodel = config.TXT_MODEL
|
||||||
self.imgmodel = config.IMG_MODEL
|
self.imgmodel = config.IMG_MODEL
|
||||||
self.image_request_queue = asyncio.Queue()
|
self.image_request_queue = asyncio.Queue()
|
||||||
@@ -80,17 +82,21 @@ class GarfAI:
|
|||||||
|
|
||||||
async def generate_chat(self, question):
|
async def generate_chat(self, question):
|
||||||
try:
|
try:
|
||||||
client = AsyncOpenAI(api_key=self.openaikey)
|
client = AsyncOpenAI(
|
||||||
|
api_key=self.openaikey,
|
||||||
|
base_url=self.baseurl
|
||||||
|
)
|
||||||
response = await client.chat.completions.create(
|
response = await client.chat.completions.create(
|
||||||
model=self.txtmodel,
|
model=self.txtmodel,
|
||||||
messages=[
|
messages=[
|
||||||
{
|
{
|
||||||
"role": "system",
|
"role": "system",
|
||||||
"content": "Pretend you are sarcastic Garfield.",
|
"content": self.sysprompt,
|
||||||
},
|
},
|
||||||
{"role": "user", "content": f"{question}"},
|
{"role": "user", "content": question},
|
||||||
],
|
],
|
||||||
max_tokens=400,
|
max_tokens=400,
|
||||||
|
temperature=1.2,
|
||||||
)
|
)
|
||||||
answer = str(response.choices[0].message.content)
|
answer = str(response.choices[0].message.content)
|
||||||
return answer.replace("an AI language model", "a cartoon animal")
|
return answer.replace("an AI language model", "a cartoon animal")
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ async def help(message):
|
|||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="hey garfield `prompt`", value="*Responds with text.*", inline=True
|
name="hey garfield `prompt`", value="*Responds with text.*", inline=True
|
||||||
)
|
)
|
||||||
embed.add_field(
|
# embed.add_field(
|
||||||
name="garfpic `prompt`", value="*Responds with an image.*", inline=True
|
# name="garfpic `prompt`", value="*Responds with an image.*", inline=True
|
||||||
)
|
# )
|
||||||
embed.add_field(
|
embed.add_field(
|
||||||
name="garfping `target`",
|
name="garfping `target`",
|
||||||
value="*Responds with iputils-ping result from target.*",
|
value="*Responds with iputils-ping result from target.*",
|
||||||
|
|||||||
Reference in New Issue
Block a user