feat: show AI progress and configure prompt directory

This commit is contained in:
Azimkin
2026-09-14 14:25:50 +02:00
parent b68e715267
commit 40e7930e60
9 changed files with 64 additions and 12 deletions

View File

@@ -123,7 +123,9 @@ def load_prompt_templates(prompt_dir: Path) -> PromptTemplates:
(prompt_dir / "USER.txt").read_text(encoding="utf-8")
)
except OSError as exc:
raise AgentError("Could not load prompts/MASTER.txt and prompts/USER.txt") from exc
raise AgentError(
f"Could not load {prompt_dir / 'MASTER.txt'} and {prompt_dir / 'USER.txt'}"
) from exc
if not master.strip() or not user.strip():
raise AgentError("Prompt templates must not be empty")
return PromptTemplates(master=master, user=user)

View File

@@ -54,11 +54,19 @@ def _split_transcript(value: str, *, limit: int = 4000) -> list[str]:
return chunks
async def _dislike(message: Any) -> None:
async def _set_reaction(message: Any, emoji: str | None) -> None:
try:
await message.react("👎")
await message.react(emoji)
except Exception:
log.exception("Could not add a dislike reaction to message %s", getattr(message, "id", None))
log.exception(
"Could not set reaction %r on message %s",
emoji,
getattr(message, "id", None),
)
async def _dislike(message: Any) -> None:
await _set_reaction(message, "👎")
def _transcribable_media(message: Any) -> Any | None:
@@ -416,6 +424,7 @@ async def echo(ctx: "CommandContext") -> None:
category="shared",
).shared()
async def ai(ctx: "CommandContext") -> None:
await _set_reaction(ctx.message, "🤔")
failed = False
try:
invocation = parse_agent_invocation(ctx.args, ctx.manager.config.ai)
@@ -436,6 +445,8 @@ async def ai(ctx: "CommandContext") -> None:
if failed:
await _dislike(ctx.message)
else:
await _set_reaction(ctx.message, None)
@command_registry.command(

View File

@@ -168,6 +168,14 @@ def _parse_elevenlabs_config(raw: Any) -> ElevenLabsConfig:
def _parse_ai_config(raw: Any) -> AiConfig:
raw_config = _parse_mapping(raw, field_name="ai")
raw_prompt_dir = raw_config.get("prompt_dir", "prompts")
prompt_dir_value = str(raw_prompt_dir).strip()
if os.environ.get("AI_PROMPT_DIR") is not None:
prompt_dir_value = os.environ["AI_PROMPT_DIR"].strip()
if not prompt_dir_value:
raise ValueError("ai.prompt_dir is required")
prompt_dir = Path(prompt_dir_value).expanduser()
def parse_provider(
name: str,
*,
@@ -286,6 +294,7 @@ def _parse_ai_config(raw: Any) -> AiConfig:
return AiConfig(
glm=glm,
deepseek=deepseek,
prompt_dir=prompt_dir,
max_context_messages=max_context_messages,
max_media_bytes=max_media_bytes,
max_tool_rounds=max_tool_rounds,
@@ -439,7 +448,9 @@ def load_app_config(root: Path) -> AppConfig:
elevenlabs = _parse_elevenlabs_config(raw.get("elevenlabs"))
ai = _parse_ai_config(raw.get("ai"))
ai.prompt_dir = root / "prompts"
if not ai.prompt_dir.is_absolute():
ai.prompt_dir = root / ai.prompt_dir
ai.prompt_dir = ai.prompt_dir.resolve()
ai.base_dir = root
if not accounts: