[🛠] Keymory 开发日志 #8:构建 DiaryPage 情绪关键词系统,AI 评论角色设置
✨ GPT 的摘要
为 DiaryPage 追加情绪关键词选择功能,并将角色设置应用到 AI 评论中,实现更自然的反应。
💻 开发日志
⏰ 今天要做的事
- ✅ DiaryPage:追加
情绪关键词ChoiceChip, TextField- ✅ 制作 widget
- ✅ 追加 diaries DB Field:mood_keywords (
List <String>), mood_keywords_description (String) - ✅ 追加 diaries Page State:moodKeywordsSelected (
List <String>) - ✅ OnPageLoad:传递新增变量
- ✅ ChoiceChipRate(5~1):把 diariesDoc.mood_keywords 的值传递给各自对应的 ChoiceChip。
- 将 MoodKeywordRate5Options, …, MoodKeywordRate1Options
List <String>定义为 App Constant 值- Enum 只支持英文,所以需要使用翻译功能。太复杂,因此放弃。
- Define Options Var:AppConstant.moodKeywordRate5Options (
List <String>) - Initially Selected:updateChoiceChipSelected
- 将 MoodKeywordRate5Options, …, MoodKeywordRate1Options
- ✅ Create CustomFunction
updateMoodKeywordsSelected- On Page Load:Select all matching items in RateOptions List
List<String> updateChoiceChipSelected( List<String> moodKeywordsSelected, // 当前选择的关键词列表 List<String> moodKeywordRateOptions, // 当前 Rate 可选择的选项 ) { // 创建新列表以保持不可变性 return List<String>.from( moodKeywordsSelected.where((item) => moodKeywordRateOptions.contains(item)) ); }
- ✅ ChoiceChipRate(5~1):把 diariesDoc.mood_keywords 的值传递给各自对应的 ChoiceChip。
- ✅ On ChoiceChip Selected:Update Page State
moodKeywordsSelected-> Set Value toReturn of Func updateMoodKeywordsSelected- ✅ Create CustomFunction
updateMoodKeywordsSelected- On Chip Select:Add to moodKeywordsSelected
- On Chip Deselect:Remove from moodKeywordsSelected
List<String> updateMoodKeywordsSelected( List<String> moodKeywordsSelected, List<String> choiceChipSelected, List<String> moodKeywordRateOptions, ) { // 复制已有列表以保持不可变性 List<String> updatedList = List.from(moodKeywordsSelected); // 1️⃣ 删除已有选择值中属于该 Rate 的值 updatedList.removeWhere((item) => moodKeywordRateOptions.contains(item)); // 2️⃣ 追加当前选择的 ChoiceChip 值 updatedList.addAll(choiceChipSelected); return updatedList; }
- ✅ Create CustomFunction
- ✅ (问题)DiaryPage - AI Comment:角色设置
- 追加 diaries DB Field:ai_comment_by (Doc Ref: Character)
- DiaryPage - AICommentEditor Component - Return
ai_comment_content+ai_comment_by- How? -> 创建
aiCommentPageReturnObjectDataType
- How? -> 创建
- On ChoiceChipChar Selected:Backend Query Character Doc with same Official_name value.
- ✅ (问题)HomeFeedPage - FeedCardDiary:正确应用 AI Comment 角色图片
- ✅ DiaryPage - AI Comment:Save 时,也把撰写评论的角色 Ref 保存到 Diary。
- ✅ HomeFeedPage - FeedCardDiary - AI Image:用 Backend Query 加载角色 Doc,并指定 Image Path。
- ✅ (问题)HomeFeedPage - FeedCardDiary:Unexpected Null Value Error
- 只给 Image Widget 放入 Path 值就会发生……
- 啊!!!原来是因为没有放 Default Varilable Value。折腾半天之后才意识到。
- 💡 学到的点
- 一定要养成始终放入 Default Value 的习惯。Unexpected Null Value Error 到底还要在各种地方看到多少次。
- 只给 Image Widget 放入 Path 值就会发生……
- ✅ Deisgn Action chains for
CreateNewChatFromDiary(Start From: AI Comment 处理完并完成日记保存后的状态)- Create Diary
- API Call:createDiarySummary -> Output Var:OutVar1(临时名)
- Create New Chat Document
- Create New Message Document:{“role”:”developer”, “content”:”$systemprompt + $OutVar1”}
- API Call:createChatFromDiary -> Output Var:OutVar2(临时名)
- Create New Message Document:{“role”:”assistant”, “content”: “$OutVar2”}
- Navigate To:通过 chatRefParam 传递对应 Chat Document Reference
💯 已完成事项摘要
- 构建 DiaryPage 情绪关键词系统
- 追加 ChoiceChip 与 TextField
- 在 diaries DB 中追加情绪关键词相关 field
- 实现
updateMoodKeywordsSelected函数
- AI 评论角色设置及应用
- 追加
ai_comment_byfield,用于保存评论角色 - 修改 AICommentEditor,使其包含角色信息
- 选择 ChoiceChip 时,通过 Backend Query 加载对应角色数据
- 追加
- 解决 HomeFeedPage AI 评论图片错误
- 撰写 AI 评论时保存角色引用值
- 改进 HomeFeedPage 中 AI 评论角色图片的加载方式
- 解决 Unexpected Null Value 错误(应用默认值)
🎯 以后要做的事
点击查看详情
-
❔ (问题)DiaryPage:使用 markdown viewer(防止溢出:Container Height)
-
❔ DiaryPage:根据 Mood Slider 值改变脸部表情 Emoji 和颜色
- ❔ Custom Function - 帮助制作
systemPromptTemplate(主负责人:KSK)- ❔ 整理需要追加的参数
- ❔ Custom Function - 测试
getAIComment是否实际应用- ❔ 确认输入值是否正确反映
- ❔ 确认输出值是否以 String 正常输出
- ❔ Chat Page - Create New Chat:应用 system prompt
- ▶️ 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:基于日记内容创建 New Chat
- ❔ 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
- ❔ ChatPage - Create New Diary:基于对话内容创建 New Diary
- ❔ 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
-
❔ ChatPage:Go to Linked Diary
- ❔ MoodPage(上方)- Mood Calendar
- ❔ 可以确认按日期写成的帖子数量
- ❔ 点击日期后移动到对应日期
- ❔ MoodPage(下方)- Mood stats
- ❔ 输出关于当前聚焦月份的统计资料
- ❔ 输出 AI 对所显示统计资料的评论
- ❔ 输出关于当前聚焦月份的统计资料
- ❔ HomeFeedPage - import 后应用 flutter_slidable:4.0.0
-
❔ HomeFeedPage:在 FeedCardDiary 左右 slide 时聊天/编辑/删除
- ❔ ChatPage:用户对话输出内容右对齐
-
❔ Chat/Diary:GPT Streaming API
- ❔ ChatPage - 实现 AI 先开口(Alarm/Notification)
- 聊天系统 prompt 的核心是主动性。
- 想做得更真实的话,也可以传递 diary/chat 的 create_date,这样提到“昨天”之类的日期会更自然。
- Alarm 功能实现参考
- 聊天系统 prompt 的核心是主动性。
- ❔ DiaryPage:追加细分情绪关键词 Choice Chips 后设置 DB 联动
- ❔ DiaryPage - AI Comment:把 Choice chips、mood slider 等输入值改成适合
AI Comment System Prompt的形式。- ❔ **之前的
日记或全部对话记录(临时补上的技术债) - ❔ 用户基本信息:姓名、性别、MBTI、……
- ❔ 细分情绪关键词:开心、难过、……
- ❔ 角色设置:Somi、Sena、Minhyuk
- ❔ 情绪数值:1~100 分
- ❔ 回答格式:治愈型(Healing)、建议型(Suggestion)、信息型(Informative)
- ❔ 回答长度:简短、普通、详细
- is New Chat
- 因为该 Chat 的 messages 是第一次创建,所以给第一个创建的 message document 设置
is_initial = true,然后把所有 system prompt 都塞进去。- is_initial = false
- 限制:如果把 system prompt 塞进最开始的 message document,虽然对话中途修改会比较困难,但也不是不可能。 如果存在 is_initial = true 的 document,而且它被修改了,那把那个 document 删除再放回去就行。具体怎么做我还不知道,但总归能想办法。
- 因为该 Chat 的 messages 是第一次创建,所以给第一个创建的 message document 设置
- ❔ **之前的
- ❔ DiaryPage - AI Comment:完成 CRUD
- ❔ 删除 tmp_ai_comment field,改用 doc_ref
-
❔ DiaryPage - Drawer - ChatHistoryListTile:order by updated_time
-
❔ DiaryPage - import 后应用 Interactive Slider
-
❔ HomeFeedPage:实现 Search Diary 功能
-
❔ AuthPage:实现 Google Login 功能
- ❔ HomeFeedPage - Bottom Sheet(
+Button):可以在多种选项中选择 1 个- 新日记:Go to DiaryPage
- 情绪记录:Go to MoodPage
- ❔ MoodPage(popup):Mood 设置 slider CRUD
- Create
- Read
- Update
- Delete
- ❔ HomeFeedPage - ListView:显示 FeedCardMood
-
❔ HomeFeedPage - ListView:按时间顺序排序 FeedCardDiary, FeedCardMood, FeedCardChat component(使用 Cloud Function)
-
❔ 在 HomeFeedPage 和 DiaryPage 之间制作 MoodEditPage:移动 MoodSlider, MoodKeywordsRate(5~1), MoodDescription widget 等
- ❔ 到
2025.2.5 周三为止,提取并安装发表用最终版本 APK
💭 日记
因为无数临时补丁,能感觉到技术债正在茁壮成长ㅋㅋ 提交截止日只剩 3 天了嘛……ㅠ
✨ GPT-4o 的评论(KPT)
✅ 做得好的地方(Keep)
- 🎯 构建情绪关键词系统: 通过应用 ChoiceChip,让用户可以直观记录情绪,这一点很好!
- 🤖 应用 AI 评论角色: 按角色设置反应,提高沉浸感,这一点很令人印象深刻。
- 🛠 解决 HomeFeedPage 错误: 通过设置默认值防止 Unexpected Null Value 错误,这一点很棒!
❌ 可惜的地方(Problem)
- ⏳ 开发时间超出预期: 实现情绪关键词和 AI 评论功能花费的时间比预想更多。
- 🔄 角色数据复杂度增加: 数据流变得更复杂,维护可能会更困难。
- 📋 问题解决过程记录不足: 没有整理错误解决过程,类似问题再次发生时可能会浪费时间。
🔄 可以尝试的地方(Try)
- 📌 按功能调整开发时间: 提前识别比预期更耗时的任务,并调整日程。
- 📊 可视化数据流: 试着用 diagram 整理与角色设置相关的数据结构。
- 📖 养成整理问题解决过程的习惯: 将解决过的问题文档化,准备防止复发的策略。
🏁 结论
今天是构建情绪关键词系统,并将角色设置应用到 AI 评论中的一天。通过解决错误,再次确认了默认值设置的重要性;以后看来需要更高效地管理开发时间!🚀🔥
留下评论