wrolpi/modules/ai/schema.py
Roland 10f0a4a46c
ai: research mode runs on the compact tool catalog
Research mode switches to nine kind-generic tools: search_files,
get_file, read_content, search_zims, get_zim_entry, get_inventory,
list_files, read_file, search_places.  Tool definitions drop from 20
tools / 8,947 chars (~2,240 tokens) to 9 / 3,881 (~970) on every
request, a sixth of the 8k context the small tier runs with instead of
a quarter.  The remaining descriptions are trimmed toward 300 chars.

The replaced per-kind endpoints are removed (four searches, three
getters, three readers, search_suggestions, the slug inventory route);
their tests move onto the generic routes.  The research prompt, its
worked example, and the empty-search hint no longer tell the model to
list collections first: channels resolve by name from the library map
that is already in the prompt.  list_collections, list_tags, and
get_map_overview stay as endpoints for the MCP wrappers but leave the
chat allowlist; the MCP search_suggestions tool goes since search_files
returns the same matches inline.

scripts/ai_eval.py expects search_files and treats "what channels do I
have" as answerable from context.  On the 1.7B model against the dev
library both catalogs score 14/18, but the compact one answers with one
tool call where the old one needed up to five, no longer invents the
example's channel, and keeps kinds straight when asked for videos.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-13 20:10:18 -06:00

59 lines
1.4 KiB
Python

import dataclasses
from typing import List, Optional
@dataclasses.dataclass
class AIZimSearchRequest:
search_str: Optional[str] = None
zim_id: Optional[int] = None
limit: int = 5
offset: int = 0
@dataclasses.dataclass
class AIHelpSearchRequest:
search_str: Optional[str] = None
limit: int = 5
@dataclasses.dataclass
class AIManageSettingsRequest:
enabled: Optional[bool] = None
active_model: Optional[str] = None
idle_unload_minutes: Optional[int] = None
context_size: Optional[int] = None
@dataclasses.dataclass
class AISearchResponse:
results: list = dataclasses.field(default_factory=list)
total: int = 0
@dataclasses.dataclass
class AIPagedTextResponse:
content: str = ''
next_offset: Optional[int] = None
total_chars: int = 0
@dataclasses.dataclass
class AIListFilesResponse:
path: str = ''
directories: list = dataclasses.field(default_factory=list)
files: list = dataclasses.field(default_factory=list)
total: int = 0
next_offset: Optional[int] = None
@dataclasses.dataclass
class AIFileSearchRequest:
search_str: Optional[str] = None
kind: Optional[str] = None
channel: Optional[str] = None
domain: Optional[str] = None
author: Optional[str] = None
subject: Optional[str] = None
tag_names: Optional[List[str]] = None
limit: int = 5
offset: int = 0