mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-14 21:38:38 +00:00
var fx
This commit is contained in:
@@ -140,3 +140,14 @@ with open(MEMORY_FIVE_MUZYKA, "r+", encoding=ENCODING) as temp_music_memory_file
|
||||
MESSAGE_TABLE_MUZYKA = json.load(temp_music_memory_file)
|
||||
SPECJALNE_ZIEMNIACZKI = GPT_SETTINGS[1]
|
||||
ASSISTANTS = {}
|
||||
|
||||
|
||||
LATEX_TEX_ENGINE = "pdflatex"
|
||||
LATEX_MAX_COMPILE_SECONDS = 45
|
||||
LATEX_MAX_ATTACH_MB = 8
|
||||
LATEX_MAX_ZIP_MB = 25
|
||||
|
||||
OPENAI_MODEL = "gpt-4o-mini"
|
||||
|
||||
ALLOWED_ROLES = ["Nocna Zmiana", "Jarl", "Thane", "Bartender"]
|
||||
GUILD_ID = 664789470779932693
|
||||
+7
-7
@@ -11,7 +11,7 @@ from discord.ext import commands
|
||||
|
||||
from constants import (
|
||||
LATEX_TEX_ENGINE, LATEX_MAX_COMPILE_SECONDS, LATEX_MAX_ATTACH_MB, LATEX_MAX_ZIP_MB,
|
||||
OPENAI_API_KEY, OPENAI_MODEL, LATEX_ALLOWED_ROLES, LATEX_GUILD_ID
|
||||
OPENAI_API_KEY, OPENAI_MODEL, ALLOWED_ROLES, GUILD_ID
|
||||
)
|
||||
from latex_functions import (
|
||||
is_tex_attachment, compile_single_tex_bytes, compile_zip_to_zip, ask_openai_diagnosis
|
||||
@@ -28,9 +28,9 @@ class LatexModule(commands.Cog):
|
||||
nsfw=False,
|
||||
name="tex",
|
||||
description="Kompiluje załączone .tex; PDF-y odsyła. Błędy: diagnoza z OpenAI.",
|
||||
guild=None if LATEX_GUILD_ID is None else discord.Object(id=LATEX_GUILD_ID),
|
||||
guild=None if GUILD_ID is None else discord.Object(id=GUILD_ID),
|
||||
)
|
||||
@commands.has_any_role(*LATEX_ALLOWED_ROLES)
|
||||
@commands.has_any_role(*ALLOWED_ROLES)
|
||||
async def tex(self, ctx: commands.Context, include_source_excerpt: Optional[bool] = True):
|
||||
ch = ctx.message.channel
|
||||
async with ch.typing():
|
||||
@@ -58,7 +58,7 @@ class LatexModule(commands.Cog):
|
||||
excerpt = data.decode("utf-8", errors="ignore")[:4000]
|
||||
except Exception:
|
||||
excerpt = ""
|
||||
advice = await ask_openai_diagnosis(res["log_text"] or "", excerpt, OPENAI_API_KEY, OPENAI_MODEL, logger=self.logger)
|
||||
advice = await ask_openai_diagnosis(res["log_text"] or "", excerpt, OPENAI_MODEL, logger=self.logger)
|
||||
parts.append(f"❌ `{att.filename}` — błąd kompilacji.\nDiagnoza:\n{advice}")
|
||||
except Exception as e:
|
||||
self.logger.debug("Exception %s: %s", att.filename, e)
|
||||
@@ -72,9 +72,9 @@ class LatexModule(commands.Cog):
|
||||
nsfw=False,
|
||||
name="latexclean",
|
||||
description="Kompiluje .tex i odsyła TYLKO PDF (log w debug).",
|
||||
guild=None if LATEX_GUILD_ID is None else discord.Object(id=LATEX_GUILD_ID),
|
||||
guild=None if GUILD_ID is None else discord.Object(id=GUILD_ID),
|
||||
)
|
||||
@commands.has_any_role(*LATEX_ALLOWED_ROLES)
|
||||
@commands.has_any_role(*ALLOWED_ROLES)
|
||||
async def latexclean(self, ctx: commands.Context):
|
||||
ch = ctx.message.channel
|
||||
async with ch.typing():
|
||||
@@ -109,7 +109,7 @@ class LatexModule(commands.Cog):
|
||||
description="Wyślij ZIP z .tex → odeślę ZIP z PDF-ami (tylko udane)."
|
||||
)
|
||||
@app_commands.describe(archive=f"Archiwum .zip (max ~{LATEX_MAX_ZIP_MB} MiB)")
|
||||
@app_commands.checks.has_any_role(*LATEX_ALLOWED_ROLES)
|
||||
@app_commands.checks.has_any_role(*ALLOWED_ROLES)
|
||||
async def texbatch(self, interaction: discord.Interaction, archive: discord.Attachment):
|
||||
await interaction.response.defer()
|
||||
if not archive or not archive.filename.lower().endswith(".zip"):
|
||||
|
||||
+5
-1
@@ -7,6 +7,7 @@ import re
|
||||
import shlex
|
||||
import tempfile
|
||||
import zipfile
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
|
||||
@@ -32,6 +33,7 @@ async def run_latex_two_passes(
|
||||
tex_filename: str, workdir: Path, tex_engine: str, timeout_sec: int, logger=None
|
||||
) -> Tuple[bool, str, Path]:
|
||||
cmd = f"{tex_engine} -interaction=nonstopmode -halt-on-error -file-line-error -no-shell-escape {shlex.quote(tex_filename)}"
|
||||
logger = logging.getLogger(logger) if logger else None
|
||||
if logger:
|
||||
logger.debug("LaTeX cmd: %s (cwd=%s)", cmd, workdir)
|
||||
|
||||
@@ -151,12 +153,14 @@ async def compile_zip_to_zip(
|
||||
|
||||
|
||||
async def ask_openai_diagnosis(
|
||||
log_text: str, tex_excerpt: str, api_key: str, model: str, logger=None
|
||||
log_text: str, tex_excerpt: str, model: str, logger:str = None
|
||||
) -> str:
|
||||
logger = logging.getLogger(logger) if logger else None
|
||||
sys = (
|
||||
"You are a LaTeX build diagnostician. Analyze pdflatex log and return:\n"
|
||||
"1) Root causes (bullets)\n2) Minimal working fix (code block)\n3) Alternative fix"
|
||||
)
|
||||
logger.debug("LaTeX DIAG (%s)\n%s", model, log_text[-9000:])
|
||||
usr = f"---LOG---\n{log_text[-9000:]}\n---END LOG---"
|
||||
if tex_excerpt:
|
||||
usr += f"\n---TEX EXCERPT---\n{tex_excerpt[:4000]}\n---END EXCERPT---"
|
||||
|
||||
Reference in New Issue
Block a user