Merge pull request #363 from cogwheel0/fix-model-selection
feat(api): Improve default model selection with fallback mechanism
This commit is contained in:
@@ -794,15 +794,7 @@ class ApiService {
|
|||||||
DebugLogger.log('settings-ok', scope: 'api/user-settings');
|
DebugLogger.log('settings-ok', scope: 'api/user-settings');
|
||||||
|
|
||||||
final data = response.data;
|
final data = response.data;
|
||||||
if (data is! Map<String, dynamic>) {
|
if (data is Map<String, dynamic>) {
|
||||||
DebugLogger.warning(
|
|
||||||
'settings-format',
|
|
||||||
scope: 'api/user-settings',
|
|
||||||
data: {'type': data.runtimeType},
|
|
||||||
);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extract default model from ui.models array
|
// Extract default model from ui.models array
|
||||||
final ui = data['ui'];
|
final ui = data['ui'];
|
||||||
if (ui is Map<String, dynamic>) {
|
if (ui is Map<String, dynamic>) {
|
||||||
@@ -818,21 +810,51 @@ class ApiService {
|
|||||||
return defaultModel;
|
return defaultModel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DebugLogger.warning('default-model-missing', scope: 'api/user-settings');
|
// Fallback: user has no default model configured, pick first available
|
||||||
return null;
|
// This fixes issue #353 where secondary accounts couldn't send messages
|
||||||
|
DebugLogger.log(
|
||||||
|
'default-model-fallback',
|
||||||
|
scope: 'api/user-settings',
|
||||||
|
);
|
||||||
|
return _getFirstAvailableModelId();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
DebugLogger.error(
|
DebugLogger.error(
|
||||||
'default-model-error',
|
'default-model-error',
|
||||||
scope: 'api/user-settings',
|
scope: 'api/user-settings',
|
||||||
error: e,
|
error: e,
|
||||||
);
|
);
|
||||||
// Do not call admin-only configs endpoint here; let the caller
|
// Attempt fallback even on error
|
||||||
// handle fallback (e.g., first available model from /api/models).
|
return _getFirstAvailableModelId();
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the ID of the first available model, or null if none available.
|
||||||
|
///
|
||||||
|
/// Used as a fallback when user has no default model configured.
|
||||||
|
Future<String?> _getFirstAvailableModelId() async {
|
||||||
|
try {
|
||||||
|
final models = await getModels();
|
||||||
|
if (models.isNotEmpty) {
|
||||||
|
final fallbackId = models.first.id;
|
||||||
|
DebugLogger.log(
|
||||||
|
'default-model-fallback-selected',
|
||||||
|
scope: 'api/user-settings',
|
||||||
|
data: {'id': fallbackId},
|
||||||
|
);
|
||||||
|
return fallbackId;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
DebugLogger.error(
|
||||||
|
'default-model-fallback-failed',
|
||||||
|
scope: 'api/user-settings',
|
||||||
|
error: e,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Conversations - Updated to use correct OpenWebUI API
|
// Conversations - Updated to use correct OpenWebUI API
|
||||||
Future<List<Conversation>> getConversations({int? limit, int? skip}) async {
|
Future<List<Conversation>> getConversations({int? limit, int? skip}) async {
|
||||||
final pinnedFuture = _fetchChatCollection(
|
final pinnedFuture = _fetchChatCollection(
|
||||||
|
|||||||
Reference in New Issue
Block a user