mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Tool definitions are generated in-process from the /api/ai blueprint's own OpenAPI operations (operationId = tool name, description = tool description, dataclass bodies + declared parameters = one flat JSON schema) — the spec IS the catalog, nothing to drift. Manage endpoints never become tools. A mode is a server-enforced system prompt + tool allowlist (Help / Research / System per ai.md); the executor can only reach allowlisted /api/ai endpoints, path parameters are encoded and traversal-rejected so a crafted argument cannot escape an endpoint. POST /api/chat streams SSE (status/token/tool_call/tool_result/done/ error), starts llama-server on demand, validates tool args server-side with instructive errors the model can retry on, caps tool results with a paging hint, and bounds the loop by ai.yaml max_tool_calls plus a hard timeout. Caddy passes the stream unbuffered (flush_interval -1) in both deployments. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
76 lines
1.7 KiB
Python
76 lines
1.7 KiB
Python
import dataclasses
|
|
from typing import List, Optional
|
|
|
|
|
|
@dataclasses.dataclass
|
|
class AISearchRequest:
|
|
search_str: Optional[str] = None
|
|
limit: int = 5
|
|
offset: int = 0
|
|
mimetypes: Optional[List[str]] = None
|
|
tag_names: Optional[List[str]] = None
|
|
|
|
|
|
@dataclasses.dataclass
|
|
class AIVideoSearchRequest:
|
|
search_str: Optional[str] = None
|
|
limit: int = 5
|
|
offset: int = 0
|
|
channel_id: Optional[int] = None
|
|
tag_names: Optional[List[str]] = None
|
|
|
|
|
|
@dataclasses.dataclass
|
|
class AIArchiveSearchRequest:
|
|
search_str: Optional[str] = None
|
|
limit: int = 5
|
|
offset: int = 0
|
|
domain: Optional[str] = None
|
|
tag_names: Optional[List[str]] = None
|
|
|
|
|
|
@dataclasses.dataclass
|
|
class AIDocSearchRequest:
|
|
search_str: Optional[str] = None
|
|
author: Optional[str] = None
|
|
subject: Optional[str] = None
|
|
language: Optional[str] = None
|
|
mimetype: Optional[str] = None
|
|
limit: int = 5
|
|
offset: int = 0
|
|
tag_names: Optional[List[str]] = None
|
|
|
|
|
|
@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
|