Skip to content
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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Improve chat initial experience #885

wants to merge 3 commits into from

Conversation

mdmohsin7
Copy link
Collaborator

@mdmohsin7 mdmohsin7 commented Sep 18, 2024

  • Initial message should include the initial default questions for the user to try, make them exciting to try.
  • Uses the name, to make it more user focused.
  • Clear chat option

Summary by Entelligence.AI

Release Notes:

  • New Feature: Introduced a 'Clear Chat' functionality in the chat interface. Users can now clear their chat history with a single click.
  • Backend Update: Added an API endpoint to handle chat clearing requests and efficiently delete chat messages in batches.
  • UI Improvement: Enhanced the initial chat options for better user engagement by modifying text content and padding.

Copy link

github-actions bot commented Sep 18, 2024

Image description Entelligence.AI

Walkthrough

This 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

Files Summary
app/lib/pages/chat/widgets/ai_message.dart
app/lib/backend/http/api/messages.dart
app/lib/providers/message_provider.dart
Frontend changes include modifying the padding of a container for better user engagement, introducing a new function to delete chat messages via an API call, and adding a method to clear chat messages by fetching new messages from the server.
backend/database/chat.py
backend/routers/chat.py
Backend changes involve adding a function to delete messages in batches from a user's chat history and creating a new endpoint to clear chat history and return the initial message.

🎉🤖

With every message that we clear,

A fresh start is brought near.

No more clutter, no more fear,

For clean chats, let's give a cheer! 🥳


Uplevel your code reviews with Entelligence.AI Pro

Entelligence.AI Pro

If 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.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description Entelligence.AI

Commits Files that changed from the base of the PR and between fd4967a and a8e4ed8 commits.
Files selected (1)
  • app/lib/pages/chat/widgets/ai_message.dart (3)
Review comments generated (3)
  • Review: 2
  • LGTM: 1

Tips

Chat with Image description 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),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description Entelligence.AI

The padding for the container has been increased from 8 to 10. This is a minor UI change and doesn't seem to introduce any issues.

-        padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8),
+        padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 10),

Comment on lines +276 to +280
_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?'),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description Entelligence.AI

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?'),

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description Entelligence.AI

Commits Files that changed from the base of the PR and between a8e4ed8 and a280ead commits.
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 Image description 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.

Comment on lines +44 to +48
Future clearChat() async {
var mes = await clearChatServer();
messages = mes;
notifyListeners();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description Entelligence.AI

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');
    }
  }

Comment on lines +85 to +101


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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description Entelligence.AI

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

Comment on lines +26 to +34
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');
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image description Entelligence.AI

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');
+ }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant