ollama local chat completion #11
14
garfmain.py
14
garfmain.py
@@ -160,13 +160,13 @@ async def garfchat(ctx, *, prompt):
|
|||||||
await ctx.send(answer)
|
await ctx.send(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.send(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")
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from garfpy import logger
|
|||||||
class GarfAI:
|
class GarfAI:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.openaikey = config.OPENAI_TOKEN
|
self.openaikey = config.OPENAI_TOKEN
|
||||||
|
self.baseurl = config.BASE_URL
|
||||||
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 +81,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": "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}"},
|
{"role": "user", "content": f"{question}"},
|
||||||
],
|
],
|
||||||
max_tokens=400,
|
max_tokens=400,
|
||||||
|
temperature=1.5,
|
||||||
)
|
)
|
||||||
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