Compare commits
2 Commits
env-vars
...
f77940dff9
| Author | SHA1 | Date | |
|---|---|---|---|
| f77940dff9 | |||
| 68696e25f0 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,7 +2,6 @@ config.py
|
|||||||
__pycache__/
|
__pycache__/
|
||||||
garfpy/__pycache__/
|
garfpy/__pycache__/
|
||||||
*.venv*
|
*.venv*
|
||||||
.idea
|
|
||||||
*.json
|
*.json
|
||||||
*.old
|
*.old
|
||||||
*.log*
|
*.log*
|
||||||
|
|||||||
@@ -2,14 +2,6 @@ services:
|
|||||||
garfbot:
|
garfbot:
|
||||||
image: git.crate.zip/crate/garfbot:latest
|
image: git.crate.zip/crate/garfbot:latest
|
||||||
container_name: garfbot
|
container_name: garfbot
|
||||||
environment:
|
|
||||||
- TXT_MODEL=${TXT_MODEL}
|
|
||||||
- IMG_MODEL=${IMG_MODEL}
|
|
||||||
- GARFBOT_TOKEN=${GARFBOT_TOKEN}
|
|
||||||
- OPENAI_TOKEN=${OPENAI_TOKEN}
|
|
||||||
- WEATHER_TOKEN=${WEATHER_TOKEN}
|
|
||||||
- KROGER_ID=${KROGER_ID}
|
|
||||||
- KROGER_SECRET=${KROGER_SECRET}
|
|
||||||
restart: always
|
restart: always
|
||||||
volumes:
|
volumes:
|
||||||
- /home/crate/garfbot:/usr/src/app
|
- /home/crate/garfbot:/usr/src/app
|
||||||
|
|||||||
14
garfmain.py
14
garfmain.py
@@ -1,4 +1,4 @@
|
|||||||
import os
|
import config
|
||||||
import asyncio
|
import asyncio
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
@@ -16,9 +16,10 @@ from garfpy import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
garfkey = os.getenv("GARFBOT_TOKEN")
|
# gapikey = config.GIF_TOKEN
|
||||||
txtmodel = os.getenv("TXT_MODEL")
|
garfkey = config.GARFBOT_TOKEN
|
||||||
imgmodel = os.getenv("IMG_MODEL")
|
txtmodel = config.TXT_MODEL
|
||||||
|
imgmodel = config.IMG_MODEL
|
||||||
|
|
||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
intents.members = True
|
intents.members = True
|
||||||
@@ -117,6 +118,9 @@ async def garfbot_weather(ctx, *, location):
|
|||||||
|
|
||||||
@garfbot.command(name="chat")
|
@garfbot.command(name="chat")
|
||||||
async def garfchat(ctx, *, prompt):
|
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
|
||||||
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}"
|
||||||
@@ -180,7 +184,7 @@ async def on_message(message):
|
|||||||
async def garfbot_connect():
|
async def garfbot_connect():
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
await garfbot.start(garfkey) # type: ignore
|
await garfbot.start(garfkey)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
e = str(e)
|
e = str(e)
|
||||||
logger.error(f"Garfbot couldn't connect! {e}")
|
logger.error(f"Garfbot couldn't connect! {e}")
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import io
|
import io
|
||||||
import os
|
|
||||||
import openai
|
import openai
|
||||||
|
import config
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import asyncio
|
import asyncio
|
||||||
import discord
|
import discord
|
||||||
@@ -11,9 +11,9 @@ from garfpy import logger
|
|||||||
|
|
||||||
class GarfAI:
|
class GarfAI:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.openaikey = os.getenv('OPENAI_TOKEN')
|
self.openaikey = config.OPENAI_TOKEN
|
||||||
self.txtmodel = os.getenv('TXT_MODEL')
|
self.txtmodel = config.TXT_MODEL
|
||||||
self.imgmodel = os.getenv('IMG_MODEL')
|
self.imgmodel = config.IMG_MODEL
|
||||||
self.image_request_queue = asyncio.Queue()
|
self.image_request_queue = asyncio.Queue()
|
||||||
|
|
||||||
async def garfpic(self, ctx, prompt):
|
async def garfpic(self, ctx, prompt):
|
||||||
@@ -82,7 +82,7 @@ class GarfAI:
|
|||||||
try:
|
try:
|
||||||
client = AsyncOpenAI(api_key=self.openaikey)
|
client = AsyncOpenAI(api_key=self.openaikey)
|
||||||
response = await client.chat.completions.create(
|
response = await client.chat.completions.create(
|
||||||
model=self.txtmodel, # type: ignore
|
model=self.txtmodel,
|
||||||
messages=[
|
messages=[
|
||||||
{
|
{
|
||||||
"role": "system",
|
"role": "system",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import os
|
import config
|
||||||
import requests
|
import requests
|
||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
from garfpy import logger
|
from garfpy import logger
|
||||||
@@ -6,8 +6,8 @@ from garfpy import logger
|
|||||||
|
|
||||||
class Kroger:
|
class Kroger:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.client_id = os.getenv('CLIENT_ID')
|
self.client_id = config.CLIENT_ID
|
||||||
self.client_secret = os.getenv('CLIENT_SECRET')
|
self.client_secret = config.CLIENT_SECRET
|
||||||
self.auth = b64encode(
|
self.auth = b64encode(
|
||||||
f"{self.client_id}:{self.client_secret}".encode()
|
f"{self.client_id}:{self.client_secret}".encode()
|
||||||
).decode()
|
).decode()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import os
|
|
||||||
import re
|
import re
|
||||||
|
import config
|
||||||
import discord
|
import discord
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from garfpy import logger
|
from garfpy import logger
|
||||||
@@ -7,7 +7,7 @@ from garfpy import logger
|
|||||||
|
|
||||||
class WeatherAPI:
|
class WeatherAPI:
|
||||||
def __init__(self, api_key=None):
|
def __init__(self, api_key=None):
|
||||||
self.api_key = api_key or os.getenv("WEATHER_TOKEN")
|
self.api_key = api_key or config.WEATHER_TOKEN
|
||||||
self.base_url = "https://api.openweathermap.org/data/2.5/weather"
|
self.base_url = "https://api.openweathermap.org/data/2.5/weather"
|
||||||
|
|
||||||
def parse_location(self, location):
|
def parse_location(self, location):
|
||||||
@@ -126,7 +126,7 @@ class WeatherAPI:
|
|||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return await response.json()
|
return await response.json()
|
||||||
except aiohttp.ClientError as e:
|
except aiohttp.ClientError as e:
|
||||||
logger.error(f"Error fetching weather data for '{location}'")
|
logger.error(f"Error fetching weather data for '{location}' - {e}")
|
||||||
await ctx.send(f"`Error fetching weather data for '{location}'`")
|
await ctx.send(f"`Error fetching weather data for '{location}'`")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user