From 02ae3073799e13f1a5a5b2939abf30121b229aec Mon Sep 17 00:00:00 2001 From: Karol Date: Wed, 15 Jan 2025 06:38:05 +0100 Subject: [PATCH] created api provider /inital-message --- app/lib/providers/api_provider.dart | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/lib/providers/api_provider.dart b/app/lib/providers/api_provider.dart index 28571cc..0f73afb 100644 --- a/app/lib/providers/api_provider.dart +++ b/app/lib/providers/api_provider.dart @@ -13,6 +13,31 @@ class ApiProvider with ChangeNotifier { List get messages => _messages; bool get isLoading => _isLoading; + ApiProvider() { + _fetchInitialMessage(); // Fetch the initial message when ApiProvider is created + } + + Future _fetchInitialMessage() async { + var url = Uri.parse('https://government-assistant-api-183025368636.us-central1.run.app/initial-message'); + try { + var response = await http.get(url); + if (response.statusCode == 200) { + var responseBody = utf8.decode(response.bodyBytes); + _addMessage(Message( + message: responseBody, + isUserMessage: false, + )); + } else { + throw Exception('Failed to fetch initial message'); + } + } catch (e) { + _addMessage(Message( + message: 'Error fetching initial message: $e', + isUserMessage: false, + )); + } + } + Future generateResponse(String question) async { var url = Uri.parse('https://government-assistant-api-183025368636.us-central1.run.app/generate-response'); try {