-
Notifications
You must be signed in to change notification settings - Fork 389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve chat initial experience #885
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThis update introduces a feature to clear chat history in both the frontend and backend. It includes UI changes for better user engagement, new API endpoints for clearing chat messages, and updates to the message provider and database logic to support this functionality. Changes
Uplevel your code reviews with Entelligence.AI ProEntelligence.AI ProIf you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, Entelligence.AI Pro is free for open source projects. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Files selected (1)
- app/lib/pages/chat/widgets/ai_message.dart (3)
Review comments generated (3)
- Review: 2
- LGTM: 1
Tips
Chat with Entelligence.AI Bot (@Entelligence.AI
)
- Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
- Invite the bot into a review comment chain by tagging
@Entelligence.AI
in a reply.
Code suggestions
- The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
- You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.
Pausing incremental reviews
- Add
@Entelligence.AI: ignore
anywhere in the PR description to pause further reviews from the bot.
@@ -256,7 +256,7 @@ class _AIMessageState extends State<AIMessage> { | |||
_getInitialOption(BuildContext context, String optionText) { | |||
return GestureDetector( | |||
child: Container( | |||
padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8), | |||
padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 10), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_getInitialOption(context, 'What\'s been on my mind a lot?'), | ||
const SizedBox(height: 8), | ||
_getInitialOption(context, 'What conversations did I have with John?'), | ||
_getInitialOption(context, 'Did I forget to follow up on something?'), | ||
const SizedBox(height: 8), | ||
_getInitialOption(context, 'What advise have I received about entrepreneurship?'), | ||
_getInitialOption(context, 'What\'s the funniest thing I\'ve said lately?'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initial options have been changed to more engaging questions. This seems like a good change for user engagement, but it's important to ensure these new questions are supported by the underlying AI model.
- _getInitialOption(context, 'What tasks do I have from yesterday?'),
- const SizedBox(height: 8),
- _getInitialOption(context, 'What conversations did I have with John?'),
- const SizedBox(height: 8),
- _getInitialOption(context, 'What advise have I received about entrepreneurship?'),
+ _getInitialOption(context, 'What\'s been on my mind a lot?'),
+ const SizedBox(height: 8),
+ _getInitialOption(context, 'Did I forget to follow up on something?'),
+ const SizedBox(height: 8),
+ _getInitialOption(context, 'What\'s the funniest thing I\'ve said lately?'),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Files selected (4)
- app/lib/backend/http/api/messages.dart (1)
- app/lib/providers/message_provider.dart (1)
- backend/database/chat.py (1)
- backend/routers/chat.py (1)
Files skipped from review due to trivial changes (1)
- backend/routers/chat.py
Review comments generated (5)
- Review: 3
- LGTM: 2
Tips
Chat with Entelligence.AI Bot (@Entelligence.AI
)
- Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
- Invite the bot into a review comment chain by tagging
@Entelligence.AI
in a reply.
Code suggestions
- The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
- You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.
Pausing incremental reviews
- Add
@Entelligence.AI: ignore
anywhere in the PR description to pause further reviews from the bot.
Future clearChat() async { | ||
var mes = await clearChatServer(); | ||
messages = mes; | ||
notifyListeners(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The clearChat
method is not handling potential errors that might occur during the API call to clearChatServer()
. It's important to add error handling here to prevent the application from crashing or entering an inconsistent state if the server request fails. You can use a try-catch block to handle any exceptions that might be thrown.
Future clearChat() async {
try {
var mes = await clearChatServer();
messages = mes;
notifyListeners();
} catch (e) {
// Handle or log the error as appropriate for your application.
print('Error clearing chat: $e');
}
}
|
||
|
||
def clear_chat(uid,batch_size): | ||
user_ref = db.collection('users').document(uid) | ||
messages_ref = user_ref.collection('messages') | ||
if batch_size == 0: | ||
return | ||
docs = messages_ref.list_documents(page_size=batch_size) | ||
deleted = 0 | ||
|
||
for doc in docs: | ||
print(f"Deleting doc {doc.id} => {doc.get().to_dict()}") | ||
doc.delete() | ||
deleted = deleted + 1 | ||
|
||
if deleted >= batch_size: | ||
return clear_chat(uid,batch_size) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The clear_chat
function recursively deletes messages from the database. However, it's not a good practice to use recursion for this kind of operation because it can lead to a stack overflow if the number of recursive calls is too large. Instead, consider using a loop to delete the messages.
Also, the print statement on line 96 could potentially expose sensitive user data in logs. It's best to avoid logging sensitive information.
Here's a suggested change:
- def clear_chat(uid,batch_size):
- user_ref = db.collection('users').document(uid)
- messages_ref = user_ref.collection('messages')
- if batch_size == 0:
- return
- docs = messages_ref.list_documents(page_size=batch_size)
- deleted = 0
-
- for doc in docs:
- print(f"Deleting doc {doc.id} => {doc.get().to_dict()}")
- doc.delete()
- deleted = deleted + 1
-
- if deleted >= batch_size:
- return clear_chat(uid,batch_size)
+ def clear_chat(uid, batch_size):
+ user_ref = db.collection('users').document(uid)
+ messages_ref = user_ref.collection('messages')
+ while True:
+ docs = messages_ref.list_documents(page_size=batch_size)
+ deleted = 0
+ for doc in docs:
+ doc.delete()
+ deleted += 1
+ if deleted < batch_size:
+ break
Future<List<ServerMessage>> clearChatServer() async { | ||
var response = await makeApiCall(url: '${Env.apiBaseUrl}v1/clear-chat', headers: {}, method: 'DELETE', body: ''); | ||
if (response == null) throw Exception('Failed to delete chat'); | ||
if (response.statusCode == 200) { | ||
return [ServerMessage.fromJson(jsonDecode(response.body))]; | ||
} else { | ||
throw Exception('Failed to delete chat'); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The clearChatServer
function is making an API call to clear the chat. However, it's not passing any user identification or authentication headers in the request. This could lead to security issues as anyone can clear the chat without proper authorization. Please ensure that you are passing the necessary headers for user identification and authorization.
- var response = await makeApiCall(url: '${Env.apiBaseUrl}v1/clear-chat', headers: {}, method: 'DELETE', body: '');
+ var response = await makeApiCall(url: '${Env.apiBaseUrl}v1/clear-chat', headers: {'Authorization': 'Bearer $userToken'}, method: 'DELETE', body: '');
Also, consider adding error handling for different types of HTTP status codes. Currently, if the status code is not 200, it throws a generic exception. It would be more informative to throw specific exceptions based on the status code.
- if (response.statusCode == 200) {
- return [ServerMessage.fromJson(jsonDecode(response.body))];
- } else {
- throw Exception('Failed to delete chat');
- }
+ switch (response.statusCode) {
+ case 200:
+ return [ServerMessage.fromJson(jsonDecode(response.body))];
+ case 401:
+ throw Exception('Unauthorized request');
+ case 404:
+ throw Exception('Chat not found');
+ default:
+ throw Exception('Failed to delete chat');
+ }
Summary by Entelligence.AI
Release Notes: