Update .gitignore to exclude Python-related files and directories. Enhance AGENTS.md and README.md with clarifications on documentation structure and product identity. Add technical architecture references and local setup instructions. Revise privacy guardrails and product identity documents for consistency. Remove obsolete memory and context documentation. Expand reflection spaces documentation to define context boundaries and lifecycle. Ensure all changes align with the ongoing development of the Kanshō project.
This commit is contained in:
1 parent
3a367b7bcc
commit
d62673e48b
89 files changed
+13463
-241
No files matched your search
@@ -0,0 +1,57 @@
|
||||
"""Single prompt execution entry. Templates live in the DB; LLM egress only via Privacy Gateway."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
import placeholder_system # noqa: F401 registers system keys
|
||||
import privacy_placeholders
|
||||
from entitlements import EntitlementError, check_feature_access
|
||||
from placeholders import PlaceholderError, resolve_template
|
||||
from privacy_gateway import GatewayRequest, PrivacyGatewayError, complete
|
||||
|
||||
|
||||
class EngineError(Exception):
|
||||
def __init__(self, code: str, message: str, status_code: int = 400):
|
||||
super().__init__(message)
|
||||
self.code = code
|
||||
self.message = message
|
||||
self.status_code = status_code
|
||||
|
||||
|
||||
def preview_prompt(prompt: dict, context: dict[str, Any] | None = None) -> dict:
|
||||
template = prompt.get("template") or ""
|
||||
if prompt.get("prompt_type") != "base":
|
||||
raise EngineError("prompt_type_not_ready", "Pipeline- und Workflow-Typen sind vorbereitet, aber noch ohne Executor-Stufen.")
|
||||
try:
|
||||
rendered = resolve_template(template, context or {})
|
||||
privacy_tokens = privacy_placeholders.validate_tokens(template)
|
||||
except PlaceholderError as exc:
|
||||
raise EngineError(exc.code, exc.message) from exc
|
||||
return {
|
||||
"prompt_id": prompt["id"],
|
||||
"slug": prompt["slug"],
|
||||
"rendered": rendered,
|
||||
"privacy_tokens": privacy_tokens,
|
||||
"llm": False,
|
||||
}
|
||||
|
||||
|
||||
def execute_prompt(prompt: dict, profile_id: str, purpose: str, data_class: str, context: dict[str, Any] | None = None) -> dict:
|
||||
preview = preview_prompt(prompt, context)
|
||||
feature_id = prompt.get("required_feature") or "ai_calls"
|
||||
try:
|
||||
check_feature_access(profile_id, feature_id)
|
||||
except EntitlementError as exc:
|
||||
raise EngineError(exc.code, exc.message, exc.status_code) from exc
|
||||
try:
|
||||
complete(
|
||||
GatewayRequest(
|
||||
prompt_id=prompt["id"],
|
||||
purpose=purpose,
|
||||
data_class=data_class,
|
||||
payload={"template_chars": len(preview["rendered"]), "privacy_tokens": preview["privacy_tokens"]},
|
||||
)
|
||||
)
|
||||
except PrivacyGatewayError as exc:
|
||||
raise EngineError(exc.code, exc.message, exc.status_code) from exc
|
||||
raise EngineError("provider_missing", "Gateway erlaubte einen Aufruf ohne konfigurierten Provider", 500)
|
||||
Reference in new issue
Block a user