Add note context visibility in chat and standardize UI design tokens
Improve chat context: build_context() now returns metadata about auto-found notes, emitted as an SSE event so the frontend can display context pills showing which notes influenced the response. Users can promote notes for deeper context (+) or exclude irrelevant ones (x). A note picker lets users manually attach notes. Multi-word search uses per-term AND matching, and auto-search iterates keywords individually for broader OR-style coverage. Standardize styling: introduce CSS design tokens (--radius-sm/md/lg/pill, --color-success/warning/overlay, --focus-ring) and migrate all components to use them. Fix header alignment to full-width, add active nav link state, replace hardcoded colors with CSS variables, and normalize button padding. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -85,6 +85,7 @@ async def send_message_route(conv_id: int):
|
||||
if not content:
|
||||
return jsonify({"error": "content is required"}), 400
|
||||
context_note_id = data.get("context_note_id")
|
||||
exclude_note_ids = data.get("exclude_note_ids") or []
|
||||
|
||||
# Save user message
|
||||
await add_message(conv_id, "user", content, context_note_id=context_note_id)
|
||||
@@ -96,11 +97,17 @@ async def send_message_route(conv_id: int):
|
||||
history.append({"role": msg.role, "content": msg.content})
|
||||
|
||||
# Build context with note search, URL fetching, etc.
|
||||
messages = await build_context(history, context_note_id, content)
|
||||
messages, context_meta = await build_context(
|
||||
history, context_note_id, content, exclude_note_ids=exclude_note_ids
|
||||
)
|
||||
|
||||
model = conv.model or await get_setting("default_model", Config.OLLAMA_MODEL)
|
||||
|
||||
async def generate():
|
||||
# Emit context metadata before streaming LLM response
|
||||
context_event = json.dumps({"context": context_meta})
|
||||
yield f"data: {context_event}\n\n"
|
||||
|
||||
full_response = []
|
||||
try:
|
||||
async for chunk in stream_chat(messages, model):
|
||||
|
||||
@@ -1,10 +1,29 @@
|
||||
import httpx
|
||||
from quart import Blueprint, jsonify, request
|
||||
|
||||
from fabledassistant.config import Config
|
||||
from fabledassistant.services.settings import get_all_settings, set_setting
|
||||
|
||||
settings_bp = Blueprint("settings", __name__, url_prefix="/api/settings")
|
||||
|
||||
|
||||
async def _get_installed_models() -> set[str]:
|
||||
"""Return set of installed Ollama model names, with and without :latest."""
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=5.0) as client:
|
||||
resp = await client.get(f"{Config.OLLAMA_URL}/api/tags")
|
||||
resp.raise_for_status()
|
||||
data = resp.json()
|
||||
names: set[str] = set()
|
||||
for m in data.get("models", []):
|
||||
name = m["name"]
|
||||
names.add(name)
|
||||
names.add(name.replace(":latest", ""))
|
||||
return names
|
||||
except Exception:
|
||||
return set()
|
||||
|
||||
|
||||
@settings_bp.route("", methods=["GET"])
|
||||
async def get_settings_route():
|
||||
settings = await get_all_settings()
|
||||
@@ -16,6 +35,13 @@ async def update_settings_route():
|
||||
data = await request.get_json()
|
||||
if not isinstance(data, dict):
|
||||
return jsonify({"error": "Expected a JSON object"}), 400
|
||||
|
||||
if "default_model" in data:
|
||||
model = str(data["default_model"])
|
||||
installed = await _get_installed_models()
|
||||
if installed and model not in installed:
|
||||
return jsonify({"error": f"Model '{model}' is not installed"}), 400
|
||||
|
||||
for key, value in data.items():
|
||||
await set_setting(key, str(value))
|
||||
settings = await get_all_settings()
|
||||
|
||||
Reference in New Issue
Block a user