wip: implement websocket chat service with Pydantic models and session management

This commit is contained in:
grillazz
2026-07-14 11:12:45 +02:00
parent eb8acd7b7c
commit 2cf22f89cc
9 changed files with 353 additions and 14 deletions
+21
View File
@@ -1,4 +1,5 @@
import os
from typing import Literal
from pydantic import BaseModel, PostgresDsn, RedisDsn, computed_field
from pydantic_core import MultiHostUrl
@@ -13,6 +14,25 @@ class SMTPConfig(BaseModel):
template_path: str = os.getenv("EMAIL_TEMPLATE_PATH", "templates")
class ChatConfig(BaseModel):
"""Configuration for the websocket chat service's model-client adapter.
``backend`` selects which :class:`~app.services.chat_agent.ChatAgent`
implementation is built by
:func:`~app.services.chat_agent.build_chat_agent` during app startup:
- ``"stub"``: a local, dependency-free echo agent (default, no network
calls, ideal for local dev/tests).
- ``"ollama"``: streams completions from an OpenAI-compatible endpoint
(e.g. a local Ollama server), reusing the same adapter interface.
"""
backend: Literal["stub", "ollama"] = os.getenv("CHAT_BACKEND", "stub")
base_url: str = os.getenv("CHAT_BASE_URL", "http://localhost:11434/v1")
model: str = os.getenv("CHAT_MODEL", "llama3.2")
stream_delay_seconds: float = float(os.getenv("CHAT_STREAM_DELAY", "0.02"))
class Settings(BaseSettings):
model_config = SettingsConfigDict(
env_file=".env", env_ignore_empty=True, extra="ignore"
@@ -21,6 +41,7 @@ class Settings(BaseSettings):
jwt_expire: int = os.getenv("JWT_EXPIRE")
smtp: SMTPConfig = SMTPConfig()
chat: ChatConfig = ChatConfig()
REDIS_HOST: str
REDIS_PORT: int