[π ] 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