From f81a76e50570ac5027b4bfce7a55e11e2b3aa1dc Mon Sep 17 00:00:00 2001 From: Aaron Crate Date: Fri, 5 Jun 2026 13:46:30 -0500 Subject: [PATCH 1/2] ollama local chat completion --- garfmain.py | 14 +++++++------- garfpy/garfai.py | 9 +++++++-- garfpy/help.py | 6 +++--- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/garfmain.py b/garfmain.py index 9e89385..40c729c 100644 --- a/garfmain.py +++ b/garfmain.py @@ -160,13 +160,13 @@ async def garfchat(ctx, *, prompt): await ctx.send(answer) -@garfbot.command(name="pic") -async def garfpic(ctx, *, prompt): - logger.info( - f"Image Request - User: {ctx.author.name}, Server: {ctx.guild.name}, Prompt: {prompt}" - ) - await ctx.send(f"`Please wait... image generation queued: {prompt}`") - await garfield.garfpic(ctx, prompt) +# @garfbot.command(name="pic") +# async def garfpic(ctx, *, prompt): +# logger.info( +# f"Image Request - User: {ctx.author.name}, Server: {ctx.guild.name}, Prompt: {prompt}" +# ) +# await ctx.send(f"`Please wait... image generation queued: {prompt}`") +# await garfield.garfpic(ctx, prompt) @garfbot.command(name="help") diff --git a/garfpy/garfai.py b/garfpy/garfai.py index f46e2d5..da0c429 100644 --- a/garfpy/garfai.py +++ b/garfpy/garfai.py @@ -12,6 +12,7 @@ from garfpy import logger class GarfAI: def __init__(self): self.openaikey = config.OPENAI_TOKEN + self.baseurl = config.BASE_URL self.txtmodel = config.TXT_MODEL self.imgmodel = config.IMG_MODEL self.image_request_queue = asyncio.Queue() @@ -80,17 +81,21 @@ class GarfAI: async def generate_chat(self, question): try: - client = AsyncOpenAI(api_key=self.openaikey) + client = AsyncOpenAI( + api_key=self.openaikey, + base_url=self.baseurl + ) response = await client.chat.completions.create( model=self.txtmodel, messages=[ { "role": "system", - "content": "Pretend you are sarcastic Garfield.", + "content": "You are Garfield the cat. You are deeply, catastrophically sarcastic. You hate Mondays with a burning passion, you are obsessed with lasagna to an unreasonable degree, and you treat every question as a personal attack on your nap schedule. Respond dramatically. Use ALL CAPS for emphasis occasionally. Reference lasagna at least once no matter what.", }, {"role": "user", "content": f"{question}"}, ], max_tokens=400, + temperature=1.5, ) answer = str(response.choices[0].message.content) return answer.replace("an AI language model", "a cartoon animal") diff --git a/garfpy/help.py b/garfpy/help.py index cf42377..d7aa953 100644 --- a/garfpy/help.py +++ b/garfpy/help.py @@ -6,9 +6,9 @@ async def help(message): embed.add_field( name="hey garfield `prompt`", value="*Responds with text.*", inline=True ) - embed.add_field( - name="garfpic `prompt`", value="*Responds with an image.*", inline=True - ) + # embed.add_field( + # name="garfpic `prompt`", value="*Responds with an image.*", inline=True + # ) embed.add_field( name="garfping `target`", value="*Responds with iputils-ping result from target.*", -- 2.49.1 From 0ef3fd1e82891cad753ad82a5074f62ea9ded106 Mon Sep 17 00:00:00 2001 From: Aaron Crate Date: Fri, 5 Jun 2026 14:46:24 -0500 Subject: [PATCH 2/2] small tweaks --- garfmain.py | 17 +++++++++-------- garfpy/garfai.py | 9 +++++---- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/garfmain.py b/garfmain.py index 40c729c..2aee6e1 100644 --- a/garfmain.py +++ b/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}" ) if len(text) > 1000: - await ctx.send("❌ Text too long! Maximum 1000 characters.") + await ctx.reply("❌ Text too long! Maximum 1000 characters.") else: try: qr_code = await generate_qr(text) sendfile = discord.File(fp=qr_code, filename="qrcode.png") - await ctx.send(file=sendfile) + await ctx.reply(file=sendfile) except Exception as e: logger.error(e) - await ctx.send(e) + await ctx.reply(e) @garfbot.command(name="wiki") async def garfbot_wiki(ctx, *, query): summary = await garfield.wikisum(query) - await ctx.send(summary) + await ctx.reply(summary) @garfbot.command(name="shop") async def garfbot_shop(ctx, *, query): try: response = kroger.garfshop(query) - await ctx.send(response) + await ctx.reply(response) except Exception as e: - await ctx.send(f"`GarfBot Error: {str(e)}`") + await ctx.reply(f"`GarfBot Error: {str(e)}`") @garfbot.command(name="weather") @@ -153,11 +153,12 @@ async def garfchat(ctx, *, prompt): if "is this true" in prompt.lower(): messages = [msg async for msg in ctx.channel.history(limit=2)] prompt = messages[1].content + prompt = f"Is this true: {prompt}" answer = await garfield.generate_chat(prompt) logger.info( 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") @@ -165,7 +166,7 @@ async def garfchat(ctx, *, prompt): # logger.info( # 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) diff --git a/garfpy/garfai.py b/garfpy/garfai.py index da0c429..3b92f89 100644 --- a/garfpy/garfai.py +++ b/garfpy/garfai.py @@ -11,8 +11,9 @@ from garfpy import logger class GarfAI: def __init__(self): - self.openaikey = config.OPENAI_TOKEN self.baseurl = config.BASE_URL + self.openaikey = config.OPENAI_TOKEN + self.sysprompt = config.SYSTEM_PROMPT self.txtmodel = config.TXT_MODEL self.imgmodel = config.IMG_MODEL self.image_request_queue = asyncio.Queue() @@ -90,12 +91,12 @@ class GarfAI: messages=[ { "role": "system", - "content": "You are Garfield the cat. You are deeply, catastrophically sarcastic. You hate Mondays with a burning passion, you are obsessed with lasagna to an unreasonable degree, and you treat every question as a personal attack on your nap schedule. Respond dramatically. Use ALL CAPS for emphasis occasionally. Reference lasagna at least once no matter what.", + "content": self.sysprompt, }, - {"role": "user", "content": f"{question}"}, + {"role": "user", "content": question}, ], max_tokens=400, - temperature=1.5, + temperature=1.2, ) answer = str(response.choices[0].message.content) return answer.replace("an AI language model", "a cartoon animal") -- 2.49.1