Files
Heimgeist/backend/schemas.py

94 lines
2.2 KiB
Python
Raw Normal View History

from pydantic import BaseModel, ConfigDict
2025-08-22 23:42:34 +02:00
from typing import List, Optional
from datetime import datetime
class ImageAttachment(BaseModel):
name: str
mime_type: Optional[str] = None
data_url: str
2025-08-22 23:42:34 +02:00
class Message(BaseModel):
role: str
content: str
sources: Optional[List[str]] = None
attachments: Optional[List[ImageAttachment]] = None
2025-08-22 23:42:34 +02:00
class ChatRequest(BaseModel):
session_id: str
model: str
message: str
enriched_message: Optional[str] = None
feat: Add streaming chat + scroll persistence; improve markdown & links Backend - /chat: support streaming via StreamingResponse; save full reply after stream ends. Non-stream path unchanged. - ChatRequest: add stream flag (default false). - GenerateTitleRequest: add model and use it instead of hardcoded llama3. - ollama_client.chat_stream(): new async generator parsing Ollama streaming JSON (both formats). - Remove response_model from /chat to allow streaming; non-stream still returns { reply }. Electron - Open external links in system browser (setWindowOpenHandler, shell.openExternal). - New IPC: update-settings, open-external-link. - Set minimum window size; preload exposes updateSettings and openExternalLink. Frontend (React) - Streaming UI with live chunking; sticky-bottom only when user at bottom. - Per-session scroll persistence and robust restore. - New message tip to jump to latest reply when scrolled up. - Disable Send while sending; spinner. - General Settings: stream output toggle; propagate model/stream changes. - Apply color scheme at boot; extract colorSchemes helper. - Sidebar UX tweaks and unread badges. Markdown/rendering - Code blocks: language title bar and wrapper. - Tables: GitHub-style parsing, per-cell borders, rounded wrapper, spacing, alignment. - Headings: remove blank line after h1-h4. - <hr>: handle after tables; strip following whitespace. - Links: target=_blank with icon and URL tooltip. Styles - Add styles for code/table wrappers, new-message tip, toggle, spinner; hover/active vars; narrower sidebar. API notes / breaking changes - /chat accepts stream=true and returns text/plain streamed chunks. - generate-title now requires a model. - Non-stream /chat response shape unchanged.
2025-08-23 16:45:46 +02:00
stream: Optional[bool] = False
sources: Optional[List[str]] = None
attachments: Optional[List[ImageAttachment]] = None
2025-08-22 23:42:34 +02:00
class ChatResponse(BaseModel):
reply: str
class HistoryResponse(BaseModel):
messages: List[Message]
class GenerateTitleRequest(BaseModel):
session_id: str
message: str
feat: Add streaming chat + scroll persistence; improve markdown & links Backend - /chat: support streaming via StreamingResponse; save full reply after stream ends. Non-stream path unchanged. - ChatRequest: add stream flag (default false). - GenerateTitleRequest: add model and use it instead of hardcoded llama3. - ollama_client.chat_stream(): new async generator parsing Ollama streaming JSON (both formats). - Remove response_model from /chat to allow streaming; non-stream still returns { reply }. Electron - Open external links in system browser (setWindowOpenHandler, shell.openExternal). - New IPC: update-settings, open-external-link. - Set minimum window size; preload exposes updateSettings and openExternalLink. Frontend (React) - Streaming UI with live chunking; sticky-bottom only when user at bottom. - Per-session scroll persistence and robust restore. - New message tip to jump to latest reply when scrolled up. - Disable Send while sending; spinner. - General Settings: stream output toggle; propagate model/stream changes. - Apply color scheme at boot; extract colorSchemes helper. - Sidebar UX tweaks and unread badges. Markdown/rendering - Code blocks: language title bar and wrapper. - Tables: GitHub-style parsing, per-cell borders, rounded wrapper, spacing, alignment. - Headings: remove blank line after h1-h4. - <hr>: handle after tables; strip following whitespace. - Links: target=_blank with icon and URL tooltip. Styles - Add styles for code/table wrappers, new-message tip, toggle, spinner; hover/active vars; narrower sidebar. API notes / breaking changes - /chat accepts stream=true and returns text/plain streamed chunks. - generate-title now requires a model. - Non-stream /chat response shape unchanged.
2025-08-23 16:45:46 +02:00
model: str
2025-08-22 23:42:34 +02:00
class GenerateTitleResponse(BaseModel):
title: str
class CreateSessionRequest(BaseModel):
session_id: str
class ChatSession(BaseModel):
id: int
session_id: str
name: str
created_at: datetime
model_config = ConfigDict(from_attributes=True)
2025-08-22 23:42:34 +02:00
class SessionsResponse(BaseModel):
sessions: List[ChatSession]
class EditMessageRequest(BaseModel):
message: str
class RegenerateRequest(BaseModel):
index: int
model: Optional[str] = None
enriched_message: Optional[str] = None
stream: bool = True
sources: Optional[List[str]] = None
# Request payload for the web search enrichment endpoint.
class WebSearchRequest(BaseModel):
prompt: str
model: str
messages: Optional[List[Message]] = None
history_limit: Optional[int] = 8
searx_url: Optional[str] = None
engines: Optional[List[str]] = None
# Response payload for the web search enrichment endpoint.
class WebSearchResponse(BaseModel):
enriched_prompt: str
sources: List[str] = []
context_block: str = ""
2026-03-20 12:00:44 +01:00
class OllamaPullRequest(BaseModel):
model: Optional[str] = None
class AudioTranscriptionRequest(BaseModel):
mime_type: str
audio_base64: str
model: Optional[str] = None
language: Optional[str] = None
class AudioTranscriptionResponse(BaseModel):
text: str
language: Optional[str] = None
model: str