Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions lib/ai_agent/ai_service.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/foundation.dart';
import 'package:connect/config/app_config.dart';
import 'package:connect/services/points_service.dart';

Expand Down Expand Up @@ -154,18 +156,33 @@ Always be encouraging and help users get the most out of Connect!

/// Saves conversation history to Firestore for analytics and improvement.
///
/// This method can be implemented to store user interactions with Dino,
/// Stores user interactions with Dino to the 'ai_conversations' collection,
/// which helps analyze user needs and improve AI responses over time.
///
/// [userId] The ID of the user having the conversation
/// [userMessage] The message sent by the user
/// [aiResponse] The response generated by the AI
///
/// Example implementation would save to a 'conversations' collection
/// in Firestore with timestamp and user context.
/// Saves to the 'ai_conversations' collection in Firestore with timestamp.
static Future<void> saveConversation(String userId, String userMessage, String aiResponse) async {
// You can implement this to save conversations for analytics
// This helps improve the AI responses over time
// Validate input parameters
if (userId.isEmpty || userMessage.trim().isEmpty || aiResponse.trim().isEmpty) {
debugPrint('Cannot save conversation: Invalid parameters provided');
return;
}

try {
await FirebaseFirestore.instance
.collection('ai_conversations')
.add({
'userId': userId,
'userMessage': userMessage,
'aiResponse': aiResponse,
'timestamp': FieldValue.serverTimestamp(),
});
} catch (e) {
debugPrint('Failed to save conversation to Firestore: $e');
}
}

/// Gets a list of suggested questions users can ask Dino.
Expand Down