initializeAIRequest moved out of api_type_dropdown & cleaned

This commit is contained in:
Manas Hejmadi
2025-06-15 20:07:03 +05:30
parent 49a93cacde
commit ab2a9d5ca7
2 changed files with 14 additions and 33 deletions

View File

@@ -245,7 +245,21 @@ class CollectionStateNotifier
debugPrint("Unable to update as Request Id is null"); debugPrint("Unable to update as Request Id is null");
return; return;
} }
var currentModel = state![rId]!; 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; var currentHttpRequestModel = currentModel.httpRequestModel;
final newModel = currentModel.copyWith( final newModel = currentModel.copyWith(
apiType: apiType ?? currentModel.apiType, apiType: apiType ?? currentModel.apiType,

View File

@@ -16,9 +16,6 @@ class APITypeDropdown extends ConsumerWidget {
return APITypePopupMenu( return APITypePopupMenu(
apiType: apiType, apiType: apiType,
onChanged: (type) { onChanged: (type) {
if (type == APIType.ai) {
initializeAIRequest(ref);
}
ref ref
.read(collectionStateNotifierProvider.notifier) .read(collectionStateNotifierProvider.notifier)
.update(apiType: type); .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,
);
}
}