diff options
| author | tanaka takashi <isazaka@gmail.com> | 2026-06-27 17:00:42 +0900 |
|---|---|---|
| committer | tanaka takashi <isazaka@gmail.com> | 2026-06-27 17:00:42 +0900 |
| commit | 6a362d58a952c2de0d3097b03b212388a6bc35e4 (patch) | |
| tree | 0034d4e8dee2a1dcac2a1c2c1d71ad41c0e455ea /src/ollama_web/routes/settings_route.py | |
| parent | ff09d6ed60998e31f8baf0846b9bdd31282979ed (diff) | |
一般設定の追加(UI/Ollama設定) settings.jsonに設定を保存 UIから言語設定対応 Ollama設定でシステムプロンプト, temperature, コンテキスト長などのパラメータを設定可能
Diffstat (limited to 'src/ollama_web/routes/settings_route.py')
| -rw-r--r-- | src/ollama_web/routes/settings_route.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/ollama_web/routes/settings_route.py b/src/ollama_web/routes/settings_route.py new file mode 100644 index 0000000..560f8d9 --- /dev/null +++ b/src/ollama_web/routes/settings_route.py @@ -0,0 +1,30 @@ +"""Application settings API endpoints.""" + +from __future__ import annotations + +from starlette.requests import Request +from starlette.responses import JSONResponse + +from ..settings_store import ( + SettingsValidationError, + load_app_settings, + save_app_settings, +) + + +async def get_settings(request: Request) -> JSONResponse: + """GET /api/settings: return effective persisted application settings.""" + runtime = request.app.state.settings + return JSONResponse(load_app_settings(runtime.data_dir, runtime.language)) + + +async def put_settings(request: Request) -> JSONResponse: + """PUT /api/settings: validate and persist application settings.""" + try: + body = await request.json() + cleaned = save_app_settings(request.app.state.settings.data_dir, body) + except SettingsValidationError as exc: + return JSONResponse({"error": str(exc)}, status_code=400) + except Exception: # noqa: BLE001 + return JSONResponse({"error": "Invalid JSON body"}, status_code=400) + return JSONResponse(cleaned) |
