Fix 'default' model selection breaking readiness indicator
When a user selected the 'Default' option in Settings, the dropdown sent an empty string "" to the backend. The route saved it as a DB row, which caused get_setting() to return "" instead of falling back to Config defaults. The chat status endpoint then tried to match "" against installed model names — always failing — resulting in model: "not_found" and a permanently failing readiness indicator. services/settings.py: - Add delete_setting() helper: removes a setting row so get_setting() correctly falls back to its hardcoded default argument routes/settings.py: - Import delete_setting - When default_model or intent_model are saved as empty string, delete the DB row instead of storing "" — cleanly restores Config fallback routes/chat.py: - chat_status_route: add explicit `or Config.OLLAMA_MODEL` guard for any existing "" rows written before this fix (migration safety net) - send_message and summarize routes: same guard on model resolution so empty settings never cause silent generation failures Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -135,7 +135,7 @@ async def send_message_route(conv_id: int):
|
||||
if msg.role != "system":
|
||||
history.append({"role": msg.role, "content": msg.content})
|
||||
|
||||
model = conv.model or await get_setting(uid, "default_model", Config.OLLAMA_MODEL)
|
||||
model = conv.model or await get_setting(uid, "default_model", Config.OLLAMA_MODEL) or Config.OLLAMA_MODEL
|
||||
|
||||
# Launch background generation task (context building happens inside the task)
|
||||
asyncio.create_task(run_generation(
|
||||
@@ -257,7 +257,7 @@ async def summarize_conversation_route(conv_id: int):
|
||||
conv = await get_conversation(uid, conv_id)
|
||||
if conv is None:
|
||||
return jsonify({"error": "Conversation not found"}), 404
|
||||
model = conv.model or await get_setting(uid, "default_model", Config.OLLAMA_MODEL)
|
||||
model = conv.model or await get_setting(uid, "default_model", Config.OLLAMA_MODEL) or Config.OLLAMA_MODEL
|
||||
try:
|
||||
note = await summarize_conversation_as_note(uid, conv_id, model)
|
||||
return jsonify(note), 201
|
||||
@@ -319,6 +319,9 @@ async def chat_status_route():
|
||||
"""Check Ollama availability, model installation, and model load state."""
|
||||
uid = get_current_user_id()
|
||||
default_model = await get_setting(uid, "default_model", Config.OLLAMA_MODEL)
|
||||
# Guard against empty-string rows written by older code when user selected "default"
|
||||
if not default_model:
|
||||
default_model = Config.OLLAMA_MODEL
|
||||
result = {
|
||||
"ollama": "unavailable",
|
||||
"model": "not_found",
|
||||
|
||||
Reference in New Issue
Block a user