From ab2a9d5ca7e35054ff745f691e3388a592cbaa10 Mon Sep 17 00:00:00 2001 From: Manas Hejmadi Date: Sun, 15 Jun 2025 20:07:03 +0530 Subject: [PATCH] initializeAIRequest moved out of api_type_dropdown & cleaned --- lib/providers/collection_providers.dart | 14 ++++++++ .../common_widgets/api_type_dropdown.dart | 33 ------------------- 2 files changed, 14 insertions(+), 33 deletions(-) diff --git a/lib/providers/collection_providers.dart b/lib/providers/collection_providers.dart index 38b49c7a..c489c1b3 100644 --- a/lib/providers/collection_providers.dart +++ b/lib/providers/collection_providers.dart @@ -245,7 +245,21 @@ class CollectionStateNotifier debugPrint("Unable to update as Request Id is null"); return; } + var currentModel = state![rId]!; + + if (apiType == APIType.ai) { + //Adding default AI Request Modoel + AIRequestModel? aiRM = currentModel.aiRequestModel; + LLMSaveObject? defaultLLMSO = ref + .watch(settingsProvider.notifier) + .settingsModel + ?.defaultLLMSaveObject; //Settings Default + if (aiRM == null) { + aiRequestModel = AIRequestModel.fromDefaultSaveObject(defaultLLMSO); + } + } + var currentHttpRequestModel = currentModel.httpRequestModel; final newModel = currentModel.copyWith( apiType: apiType ?? currentModel.apiType, diff --git a/lib/screens/common_widgets/api_type_dropdown.dart b/lib/screens/common_widgets/api_type_dropdown.dart index ae9cc726..7085049e 100644 --- a/lib/screens/common_widgets/api_type_dropdown.dart +++ b/lib/screens/common_widgets/api_type_dropdown.dart @@ -16,9 +16,6 @@ class APITypeDropdown extends ConsumerWidget { return APITypePopupMenu( apiType: apiType, onChanged: (type) { - if (type == APIType.ai) { - initializeAIRequest(ref); - } ref .read(collectionStateNotifierProvider.notifier) .update(apiType: type); @@ -26,33 +23,3 @@ class APITypeDropdown extends ConsumerWidget { ); } } - -initializeAIRequest(WidgetRef ref) { - final selectedId = ref.watch(selectedIdStateProvider); - final req = ref.watch(collectionStateNotifierProvider)![selectedId]!; - AIRequestModel? aiRequestModel = req.aiRequestModel; - LLMSaveObject? defaultLLMSO = ref - .watch(settingsProvider.notifier) - .settingsModel - ?.defaultLLMSaveObject; //Settings Default - - if (aiRequestModel == null) { - // Creating the AIRequest Model initially - final gmC = GeminiModelController.instance; - final newAIRM = AIRequestModel( - model: defaultLLMSO?.selectedLLM ?? - LLMProvider.gemini.getLLMByIdentifier('gemini-2.0-flash'), - provider: defaultLLMSO?.provider ?? LLMProvider.gemini, - payload: LLMInputPayload( - endpoint: defaultLLMSO?.endpoint ?? gmC.inputPayload.endpoint, - credential: defaultLLMSO?.credential ?? '', - systemPrompt: '', - userPrompt: '', - configMap: defaultLLMSO?.configMap ?? gmC.inputPayload.configMap, - ), - ); - ref.read(collectionStateNotifierProvider.notifier).update( - aiRequestModel: newAIRM, - ); - } -}