-
Notifications
You must be signed in to change notification settings - Fork 401
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
Changes from 3 commits
a8e4ed8
22fbf89
a280ead
eb1b0aa
9cbb312
83c747d
2c52e5b
4c4fdae
f38bd58
5250c23
f945d41
8be59e4
47e8f15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,8 +116,8 @@ class _AIMessageState extends State<AIMessage> { | |
style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.w500, color: Colors.grey.shade300), | ||
)), | ||
if (widget.message.id != 1) _getCopyButton(context), // RESTORE ME | ||
// if (message.id == 1 && displayOptions) const SizedBox(height: 8), | ||
// if (message.id == 1 && displayOptions) ..._getInitialOptions(context), | ||
if (widget.displayOptions) const SizedBox(height: 8), | ||
if (widget.displayOptions) ..._getInitialOptions(context), | ||
Comment on lines
+121
to
+122
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
if (messageMemories.isNotEmpty) ...[ | ||
const SizedBox(height: 16), | ||
for (var data in messageMemories.indexed) ...[ | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. |
||
width: double.maxFinite, | ||
decoration: BoxDecoration( | ||
color: Colors.grey.shade900, | ||
|
@@ -273,11 +273,11 @@ class _AIMessageState extends State<AIMessage> { | |
_getInitialOptions(BuildContext context) { | ||
return [ | ||
const SizedBox(height: 8), | ||
_getInitialOption(context, 'What tasks do I have from yesterday?'), | ||
_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?'), | ||
Comment on lines
+306
to
+310
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,12 @@ class MessageProvider extends ChangeNotifier { | |
return messages; | ||
} | ||
|
||
Future clearChat() async { | ||
var mes = await clearChatServer(); | ||
messages = mes; | ||
notifyListeners(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The 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');
}
} |
||
|
||
void addMessage(ServerMessage message) { | ||
messages.insert(0, message); | ||
notifyListeners(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,3 +82,20 @@ def get_messages(uid: str, limit: int = 20, offset: int = 0, include_memories: b | |
] | ||
|
||
return messages | ||
|
||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. The 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 |
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.
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.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.