[๐ ] Keymory Dev Log #9: Implementing Diary to Chat, Optimizing the AI Comment System
โจ GPT Summary ใ
I implemented Diary to Chat, resolved issues that occurred during creation, and fixed emotion score and character setting errors in the AI comment system.
๐ป Development Log
โฐ Todayโs tasks
- โ
Help create Custom Function -
systemPromptTemplate(main worker: KSK)- โ Reviewed added parameters and internal function structure
- โ
Test whether Custom Function -
getAICommentis actually applied- โ Confirmed input values are reflected properly
- โ Confirmed output value prints properly as String
- โ
Chat Page - Create New Chat: apply system prompt (main worker: KSK)
- โ
OpenAI API Call (createChatCompletion)
- Input: System Prompt (Chat)
- Output: New Chat Message by AI ($.choices[0].message.content)
- Additional Actions: Create New Chat, Create New Message
- โ
OpenAI API Call (createChatCompletion)
- โ
DiaryPage - Create New Chat by Diary: create a New Chat based on diary content (main worker: KSK)
- โ
OpenAI API Call (createDiaryComment)
- Input: Diary Content, System Prompt (AI Comment)
- Output: AI Comment ($.choices[0].message.content)
- โ
OpenAI API Call (createDiarySummary)
- Input: Diary Content, AI Comment, System Prompt (Diary Summary)
- Output: Diary Summary ($.choices[0].message.content)
- โ
OpenAI API Call (createChatFromDiary)
- Input: Diary Summary, System Prompt (Chat From Diary)
- Output: New Chat Message by AI ($.choices[0].message.content)
- Additional Actions: Create New Chat, Create New Message
- โ
OpenAI API Call (createDiaryComment)
- โ
(Issue) Create New Chat by Diary only works after saving only the diary, returning home, entering the diary page again, and then creating New Chat.
- Cause of the issue
- I was pulling in an Output variable from a different action chain
- Unexpected Null Value prevention was not in place
- JSON Path was not specified properly
- I had defined
tmpDiariesDocForNewChatas Page State and assigned the diary Document to it.- More precisely,
- I had it assign the
diariesDocpassed as a Page Parameter, or - assign the
newDiariesDoccreated when pressing the Save button.
- I had it assign the
- But the app kept freezing when pressing the
Save Diary and Chat with AIbutton.- Looking with F12, an Exception was thrown because of an
Unexpected Null Valueerror. - Looking at the Debug Panel,
tmpDiariesDocForNewChatwas set toNull.
- Looking with F12, an Exception was thrown because of an
- Changed Page State from
tmpDiariesDocForNewChatback totmpDiariesDocRefForNewChat. (Document -> Document Reference)- After changing the Actions appropriately around Document Reference, it finally worked normally!
- More precisely,
- ๐ก What I learned: In an Action Chain, assigning a value to Page State and immediately reading it can cause Unexpected Null Value. Use Document Reference a lot instead of Document. Of course, reading Document with Backend Query a lot may cause performance degradationโฆ but that can just be handled sufficiently on OnPageLoad Event or when creating major Action Chains.
- Cause of the issue
- โ
(Issue) When generating AI Comment, the userโs emotion score sometimes keeps getting saved as 0.
- I emphasized โEspecially do the โ5. weighted formula calculationโ accurately. The userโs emotion score is absolutely not 0.โ and cases where it writes 0 decreased. (Not gone completely.)
- Let us move on for now.
- โ
(Issue) ChatPage: the character does not know information about itself!
- Seems to have fixed itself while resolving save-related issues. Nice.
- โ
(Issue) ChatPage: the character is ignoring the โfollow-up question listโ!
- Seems to have fixed itself while resolving save-related issues. Nice.
- โ
(Issue) bottom navigation bar disappears when moving to ChatPage.
- Always Show Nav bar Toggle On
- โ
(Issue) Character image is displayed differently in ChatPage Drawer.
- This happened because I wrote the AI Comment saving logic wrong before. It only happens in old chats, so resolved by deleting that Chat document.
๐ฏ Summary of what I did
-
Improved Chat creation logic
- Reviewed parameter structure for
systemPromptTemplateandgetAIComment - Applied system prompt in Create New Chat and optimized OpenAI API Call
- Organized the Diary-based New Chat creation process: AI comment -> diary summary -> Chat creation
- Reviewed parameter structure for
-
Optimized AI comment system
- Fixed issue where emotion score was saved as 0
- Resolved issue where AI could not recognize character information
- Improved issue where follow-up question list was ignored
-
Issue resolution and performance improvement
- Fixed navigation bar disappearing when moving to ChatPage
- Fixed character image mismatch by modifying AI Comment save logic
- Used Document -> Document Reference to prevent Unexpected Null Value
๐ฏ Future tasks
Click to see details
- โ (Issue) DiaryPage: if the AI Comment answer has not been received, it moves on with the character unset.
- For now, patch by showing an alert: You must receive a Comment from AI before starting chat!
-
โ (Issue) DiaryPage: use markdown viewer for AI Comment response (prevent overflow: Container Height)
-
โ ChatPage: align user conversation output to the right
-
โ DiaryPage: change face expression Emoji and color according to Mood Slider value
- โ DiaryPage: Go to Linked Chat
- โ ChatPage: Go to Linked Diary
- When saving from DiaryPageโs Diary Document, also add Chat Reference value as a Diary Document DB field. (linkedChat)
- In ChatPageโs Chat Document, naturally also add Diary Reference value as a Chat Document DB field. (linkedDiary)
- โ ChatPage - Create New Diary: create a New Diary based on conversation content (use Go to Linked Diary logic)
- โ OpenAI API Call (createChatSummary)
- Input: Chat Content, System Prompt (Diary From Chat)
- Output: Chat Summary
- โ OpenAI API Call (createDiaryFromChat)
- Input: Chat Summary, System Prompt (Diary From Chat)
- Output: New Diary (Title, Content, Mood score)
- โ OpenAI API Call (createChatSummary)
- โ MoodPage (top) - Mood Calendar
- โ Check the number of posts written by date
- โ Move to the selected date when clicking a date
- โ MoodPage (bottom) - Mood stats
- โ Output statistics for the focused month
- โ Output AI comment on the displayed statistics
- โ Output statistics for the focused month
- โ HomeFeedPage - import and apply flutter_slidable:4.0.0
-
โ HomeFeedPage: on left/right slide from FeedCardDiary, chat/edit/delete
-
โ Chat/Diary: GPT Streaming API
- โ ChatPage - implement AI first message (Alarm/Notification)
- The core of the chat system prompt is proactivity.
- To make it more realistic, it might be good to pass create_date of diary/chat too, so the AI can mention dates like โyesterday.โ
- Alarm implementation reference
- The core of the chat system prompt is proactivity.
- โ DiaryPage: add detailed emotion keyword Choice Chips and set DB integration
- โ DiaryPage - AI Comment: change inputs such as Choice chips and mood slider to fit the
AI Comment System Prompt.- โ **previous
diaryor entireconversation history(patchy technical debt) - โ basic user information: name, gender, MBTI, โฆ
- โ detailed emotion keywords: happy, sad, โฆ
- โ character settings: Somi, Sena, Minhyuk
- โ emotion score: 1 to 100
- โ response format: Healing, Suggestion, Informative
- โ response length: short, normal, detailed
- is New Chat
- Since this Chatโs messages are being created for the first time, set
is_initial = trueon the first message document and shove in all system prompts.- is_initial = false
- Limit: if I put the system prompt into the very first message document, it is hard to modify in the middle of a conversation, but possible. If there is an is_initial = true document and it was modified, I can delete that document and put it back in. I do not know how, but still.
- Since this Chatโs messages are being created for the first time, set
- โ **previous
- โ DiaryPage - AI Comment: complete CRUD
- โ remove tmp_ai_comment field and use doc_ref
-
โ DiaryPage - Drawer - ChatHistoryListTile: order by updated_time
-
โ DiaryPage - import and apply Interactive Slider
-
โ HomeFeedPage: implement Search Diary feature
-
โ AuthPage: implement Google Login
- โ HomeFeedPage - Bottom Sheet (
+Button): make it possible to choose one of several options- New diary: Go to DiaryPage
- Emotion record: Go to MoodPage
- โ MoodPage (popup): Mood setting slider CRUD
- Create
- Read
- Update
- Delete
- โ HomeFeedPage - ListView - show FeedCardMood
-
โ HomeFeedPage - ListView: sort FeedCardDiary, FeedCardMood, FeedCardChat components chronologically (using Cloud Function)
-
โ Create MoodEditPage between HomeFeedPage and DiaryPage: move MoodSlider, MoodKeywordsRate (5~1), MoodDescription widgets, etc.
-
โ (Issue) tmpGetAIComment does not consider the emotion keywords selected by the user when creating.
- โ Extract and install the final presentation APK by
Wed 2025.2.5
๐ญ Diary
Issues exploded one after another and my mind almost went distantโฆ Is my strategy of โeven if technical debt piles up, if I implement first, my skill will keep growing and I can pay off the debt later!โ hitting its limitโฆ or was it still an efficient judgmentโฆ
Whatever, I do not know~ That is not what matters right now. There is seriously no time! Patchwork go go.
โจ GPT-4o Comment (KPT)
โ What Went Well (Keep)
- ๐ Organized Chat creation logic: It was good that you organized and resolved various issues occurring during New Chat creation!
- ๐ญ Improved AI comment system: It was impressive that you fixed emotion score and character setting errors and guided more accurate AI responses.
- ๐ Improved debugging ability: Resolving Unexpected Null Value and learning how to use Document Reference will help a lot going forward.
โ What Was Missing (Problem)
- โณ Lots of time spent resolving issues: Debugging took longer than expected, so there may have been less time for the feature development originally targeted.
- ๐ Increasing technical debt: The fast implementation strategy is accumulating technical debt, so follow-up cleanup will be needed.
- ๐ Insufficient documentation: If you organize major problem-resolution processes a little more, similar issues can be solved quickly when they happen again.
๐ What to Try (Try)
- ๐ Analyze issue patterns: Identify repeatedly occurring problems and think about improving the development pattern.
- ๐ Set a technical debt management strategy: Short-term fast fixes are necessary, but long-term maintenance and optimization need a roadmap.
- ๐ Build a habit of problem-solving records: Document major issue-resolution processes to save future development time.
๐ Conclusion
Today was a day where you improved Chat creation logic and fixed AI comment system errors, raising stability. Debugging took longer than expected, but you learned a lot in the process too! Going forward, think about a more efficient development strategy while managing technical debt. ๐๐ฅ
Leave a comment