Skip to content

Commit

Permalink
logging
Browse files Browse the repository at this point in the history
  • Loading branch information
bghira committed Jan 28, 2024
1 parent 989e8c6 commit dcd747b
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions discord_tron_master/cogs/image/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from discord_tron_master.models.user_history import UserHistory
import discord_tron_master.classes.discord.message_helpers as helper
import logging, traceback
logger = logging.getLogger("discord_tron.image.generate")
logger.setLevel('DEBUG')
from discord_tron_master.bot import DiscordBot
from discord_tron_master.classes.jobs.image_generation_job import ImageGenerationJob
from discord_tron_master.bot import clean_traceback
Expand Down Expand Up @@ -51,7 +53,7 @@ async def generate_range_random(self, ctx, arg_count = None, *, theme = None):
return
gpt = GPT()
prompt = await gpt.random_image_prompt(out_theme)
logging.info(f"Random prompt generated by GPT: {prompt}")
logger.info(f"Random prompt generated by GPT: {prompt}")
await self.generate(ctx, prompt=prompt)


Expand Down Expand Up @@ -94,7 +96,7 @@ async def generate(self, ctx, *, prompt):
# We are going to ask OpenAI which model to use for this user.
gpt = GPT()
auto_resolution, auto_model = await gpt.auto_model_select(_prompt)
logging.info(f"Auto-model selected by GPT: {auto_model}")
logger.info(f"Auto-model selected by GPT: {auto_model}")
extra_payload["user_config"]["model"] = auto_model
extra_payload["user_config"]["resolution"] = auto_resolution
discord_first_message = await DiscordBot.send_large_message(ctx=ctx, text=f"Job queuing: `" + _prompt + "`")
Expand All @@ -112,10 +114,10 @@ async def generate(self, ctx, *, prompt):
user_history = UserHistory.add_entry(user=ctx.author.id, message=int(f"{ctx.id if hasattr(ctx, 'id') else ctx.message.id}{idx}"), prompt=_prompt, config_blob=extra_payload["user_config"])
idx += 1
except Exception as e:
logging.warning(f"Had trouble adding the user history entry: {e}")
logger.warning(f"Had trouble adding the user history entry: {e}")
# Generate a "Job" object that will be put into the queue.
await discord_first_message.edit(content=f"Job {job.id} queued on {worker.worker_id}: `" + _prompt + "`")
logging.info("Worker selected for job: " + str(worker.worker_id))
logger.info("Worker selected for job: " + str(worker.worker_id))
# Add it to the queue
await discord.queue_manager.enqueue_job(worker, job)
except Exception as e:
Expand Down Expand Up @@ -153,7 +155,7 @@ async def get_statistics(self, ctx, user_id = None):
f"\n -> {common_terms}"
)
except Exception as e:
logging.error("Caught error when getting user history: " + str(e))
logger.error("Caught error when getting user history: " + str(e))
await ctx.send(
f"{ctx.author.mention} Statistics are not currently available at this time, try again later."
)
Expand All @@ -167,7 +169,7 @@ async def search_prompts(self, ctx, search_string: str):
# Shuffle the list:
import random
random.shuffle(discovered_prompts)
logging.info(f"Discovered prompts: {discovered_prompts}")
logger.info(f"Discovered prompts: {discovered_prompts}")
if not discovered_prompts:
# We didn't discover any prompts. Let the user know their search was bonkers.
return await ctx.send(
Expand All @@ -181,7 +183,7 @@ async def search_prompts(self, ctx, search_string: str):
output_string = f"{output_string}\n- `{prompt[0]}`"
await ctx.send(output_string)
except Exception as e:
logging.error("Caught error when searching prompts: " + str(e))
logger.error("Caught error when searching prompts: " + str(e))
await ctx.send(
f"{ctx.author.mention} Search is not currently available at this time, try again later."
)
Expand All @@ -201,7 +203,7 @@ async def invite_to_thread(self, ctx):
f"{ctx.author.mention} is now in the party."
)
except Exception as e:
logging.error("Caught error when inviting to thread: " + str(e))
logger.error("Caught error when inviting to thread: " + str(e))
await ctx.send(
f"{ctx.author.mention} {self.generic_error}."
)
Expand Down Expand Up @@ -232,8 +234,8 @@ async def generate_from_user_config(self, ctx, user_config, user_id, prompt):
user_history = UserHistory.add_entry(user=user_id, message=int(f"{ctx.id if hasattr(ctx, 'id') else ctx.message.id}{idx}"), prompt=_prompt, config_blob=user_config)
idx += 1
except Exception as e:
logging.warning(f"Had trouble adding the user history entry: {e}")
logging.info("Worker selected for job: " + str(worker.worker_id))
logger.warning(f"Had trouble adding the user history entry: {e}")
logger.info("Worker selected for job: " + str(worker.worker_id))
# Add it to the queue
await discord.queue_manager.enqueue_job(worker, job)
except Exception as e:
Expand Down

0 comments on commit dcd747b

Please sign in to comment.