From b93ae09b69f7d9d5832c9f7b0dcf4a87385d72bb Mon Sep 17 00:00:00 2001 From: T-BENZIN Date: Tue, 18 Mar 2025 19:54:34 +0500 Subject: [PATCH] + Applied debug decorator to some functions and methods --- reginaldCog/openai_completion.py | 2 ++ reginaldCog/reginald.py | 2 ++ reginaldCog/weather.py | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/reginaldCog/openai_completion.py b/reginaldCog/openai_completion.py index b19f720..60aa384 100644 --- a/reginaldCog/openai_completion.py +++ b/reginaldCog/openai_completion.py @@ -4,6 +4,7 @@ import openai from openai import OpenAIError from .weather import time_now, get_current_weather, get_weather_forecast from .tools_description import TOOLS +from .debug_stuff import debug CALLABLE_FUNCTIONS = { # Dictionary with functions to call. @@ -20,6 +21,7 @@ class Completion: self.__api_key = api_key self.__messages = [] + @debug async def create_completion(self, messages: list): self.__messages = messages model = self.__model diff --git a/reginaldCog/reginald.py b/reginaldCog/reginald.py index 904de8a..b821293 100644 --- a/reginaldCog/reginald.py +++ b/reginaldCog/reginald.py @@ -14,6 +14,7 @@ from .blacklist import BlacklistMixin from .memory import MemoryMixin from .weather import time_now, get_current_weather, get_weather_forecast from .tools_description import TOOLS +from .debug_stuff import debug CALLABLE_FUNCTIONS = { @@ -189,6 +190,7 @@ class ReginaldCog(PermissionsMixin, BlacklistMixin, MemoryMixin, commands.Cog): return any(message_lower.startswith(invocation) for invocation in direct_invocation) + @debug async def generate_response(self, api_key, messages): model = await self.config.openai_model() try: diff --git a/reginaldCog/weather.py b/reginaldCog/weather.py index 86e6b79..580716d 100644 --- a/reginaldCog/weather.py +++ b/reginaldCog/weather.py @@ -2,20 +2,24 @@ from datetime import datetime, timezone from os import environ import requests import json +from .debug_stuff import debug #WEATHER_API_KEY = environ.get('WEATHER_API_KEY') URL = 'http://api.weatherapi.com/v1' +@debug def time_now() -> str: return str(datetime.now(timezone.utc)) +@debug def get_current_weather(location: str) -> str: weather = Weather(location=location) return json.dumps(weather.realtime()) +@debug def get_weather_forecast(location: str, days: int = 14, dt: str = '2025-03-24') -> str: weather = Weather(location=location) return json.dumps(weather.forecast(days=days, dt=dt)) @@ -35,6 +39,7 @@ class Weather: response = requests.get(url=f'{URL}{method}', params=params) return response.json() + @debug def realtime(self): method = '/current.json' params = { @@ -43,6 +48,7 @@ class Weather: } return self.make_request(method=method, params=params) + @debug def forecast(self, days: int = 14, dt: str = '2025-03-24'): method = '/forecast.json' params = {