Skip to content

Commit

Permalink
created api provider /inital-message
Browse files Browse the repository at this point in the history
  • Loading branch information
Karol committed Jan 15, 2025
1 parent 741f0f1 commit 02ae307
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions app/lib/providers/api_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,31 @@ class ApiProvider with ChangeNotifier {
List<Message> get messages => _messages;
bool get isLoading => _isLoading;

ApiProvider() {
_fetchInitialMessage(); // Fetch the initial message when ApiProvider is created
}

Future<void> _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<void> generateResponse(String question) async {
var url = Uri.parse('https://government-assistant-api-183025368636.us-central1.run.app/generate-response');
try {
Expand Down

0 comments on commit 02ae307

Please sign in to comment.