[๐งโ๐ป] Keymory ๊ฐ๋ฐ ์ผ์ง #5: tmpGetAIComment, Custom OpenAI API Call
โจ GPT์ ์์ฝ ใ
OpenAI API์ FlutterFlow๋ฅผ ํ์ฉํ AI Comment ์์คํ ์ ๊ตฌ์ถํ๋ฉฐ, Custom Function๊ณผ API Call์ ์ฐ๋ํ์ฌ Keymory์ AI ๊ธฐ๋ฅ์ ํ์ฅํ์. ์บ๋ฆญํฐ ์ ํ ๋ฐ ์ ์ฅ ๊ธฐ๋ฅ์ ์ถ๊ฐํ๊ณ , Chat๊ณผ Diary ๊ฐ์ ๋ฐ์ดํฐ ํ๋ฆ์ ์ ๋ฆฌํ์.
๐ป ๊ฐ๋ฐ ์ผ์ง
โฐ ์ค๋ ํ ์ผ
- โ How to Use Open AIโs GPT-4o in FlutterFlow - Part 1
- โ
ChatPage - Dropdown์ผ๋ก ์บ๋ฆญํฐ ์ ํ ์, ํด๋น ์บ๋ฆญํฐ ์ ๋ณด๋ฅผ
Chats Collection
์ ํจ๊ป ์ ์ฅ.-
character name
๊ณผ ์ผ์นํ๋Character document
์reference
๋ฅผ Page state์ ํ ๋น.
-
-
โ ChatPage - NewChat ์์ฑ ์ ์บ๋ฆญํฐ ์ ๋ณด๋ ํจ๊ป ์ ๋ฌ.
-
โ DiaryPage - Drawer - ChatHistoryListTile ์์ฑ ๋๊ธฐ (GPT ์ฒ๋ผ)
- โ
CustomFunction
tmpGetAIComment
ํจ์๊ฐ์ API CallcreateDiaryComment
์ ์๋ค๊ฐ ๋ฃ์ด๋ณด๊ธฐ- โ
CustomFunction
tmpGetAIComment
๋ง๋ค๊ณ ๊ฒฐ๊ณผ๊ฐ ์ถ๋ ฅ ํ ์คํธ - โ
API Call
createDiaryComment
๋ง๋ค๊ณ Response๊ฐ ์ถ๋ ฅ ํ ์คํธ
- โ
CustomFunction
- โ
OpenAI API Call ์์ฑ: createDiaryComment
- ๊ธฐ๋ณธ์ ์ผ๋ก๋ createChatCompletion๊ณผ ๋น์ทํ ๊ตฌ์กฐ
- ๋ค๋ฅธ ์ : ์์. ๊ทธ๋ฅ ๊ตฌ๋ถํ๊ธฐ ์ํด์ ์์ฑ.
-
API Call - createDiaryComment
์์ ์๊ตฌ๋๋Messages
Variable์ custom functiongetAIComment
์ ๋ฆฌํด๊ฐ์ด๋ค.
- โ
CustomFunction
getAIComment
๊ตฌํ ์๋๋ฆฌ์ค ๊ตฌ์ํ๊ธฐ (์ง์ ๊ตฌํ์ KSK ๋ด๋น)-
Characters (Collection)
๋ก๋ถํฐ ์ป์Parameter Values
- ์บ๋ฆญํฐ ์ค์ (
Character
Document)- ex) ์๋ฏธ: name(20๋), ๋ํ์, ๋ถ๋๋ฌ์ด ์ฑ๊ฒฉ, โฆ
- ๊ฐ ํธ์ถ ๋ฐฉ์:
API Call - Get Assistant
- ์บ๋ฆญํฐ ์ค์ (
-
User Information
๋ก๋ถํฐ ์ป์Parameter Values
- ์ด๋ฆ, ์ฑ๋ณ, MBTI
- ๊ฐ ํธ์ถ ๋ฐฉ์:
Backend Query - Authenticated User
-
DiaryPage Variables
๋ก๋ถํฐ ์ป์Parameter Values
- ์ผ๊ธฐ ๋ด์ฉ, ์ธ๋ถ ๊ฐ์ ํค์๋, ๊ฐ์ ์์น, ๋ต๋ณ ์์, ๋ต๋ณ ๊ธธ์ด
- ๊ฐ ํธ์ถ ๋ฐฉ์:
Widget State
,Page State
- CustomFunction(
getAIComment
)์ ์ญํ- Parameter Values๋ฅผ ๋ค Input๊ฐ์ผ๋ก ๋ฐ๋๋ค.
- GPT์๊ฒ ๋ณด๋ผ ํ๋กฌํํธ๋ฅผ ์์ฑํ๋ค.
-
Messages
(List <Json>
) ๊ฐ์ ๋ฆฌํดํ๋ค.[{"role":"developer", "content":"~~~"}]
-
๐ฏ ํ ์ผ์ ๋ํ ์์ฝ
-
AI Comment ์์คํ
๊ตฌํ
- Custom Function
tmpGetAIComment
์์ฑ ๋ฐ API CallcreateDiaryComment
์ฐ๋ ์๋ฃ - AI Comment๋ฅผ ์ํ OpenAI API ์์ฒญ ๋ฐ ์๋ต ์ฒ๋ฆฌ ๋ก์ง ๊ตฌํ
- ์บ๋ฆญํฐ ์ ๋ณด๋ฅผ
Chats Collection
์ ์ ์ฅํ๊ณ , New Chat ์์ฑ ์ ํจ๊ป ์ ๋ฌํ๋๋ก ์์
- Custom Function
-
UI ๋ฐ ๊ธฐ๋ฅ ๊ฐ์
-
ChatHistoryListTile
์์ฑํ์ฌ GPT ์คํ์ผ์ ์ฑํ ๋ชฉ๋ก ๊ตฌํ -
HomeFeedPage
๋ฐDiaryPage
์ ๋ฐ์ดํฐ ๊ตฌ์กฐ ์ ๋ฆฌ -
getAIComment
Custom Function ์ค๊ณ
-
-
FlutterFlow + OpenAI API ํ์ต
- GPT-4o ํ์ฉ ๊ฐ์ ์๊ฐ ๋ฐ ์ ์ฉ (Part 1 & Part 2)
๐ฏ ์ถํ์ ํ ์ผ
- โ DiaryPage: Merge CreateDiary/EditDiary Page
- isEditMode page state ํ์ฉ
- conditional value/visibility/action ๋ฑ ํ์ฉ
- โ DiaryPage - Create New Chat: ์ผ๊ธฐ์ ๋ด์ฉ์ ๊ธฐ๋ฐ์ผ๋ก, New Chat ์์ฑ
- AI๊ฐ ๋จผ์ ์ผ๊ธฐ ๋ด์ฉ์ ๊ธฐ๋ฐํ์ฌ ์ง๋ฌธ ์ ์
- โ ์ด์ ์์
- โ ChatPage: ์ฒ์ ๋ํ ์์ ์, default init message ๋จ๊ณ ์์.
- โ ChatPage: ๋ ์ง ์ ์ฉ ์ ๋จ.
- โ ChatPage - ChatHistoryDrawer: UI ์ค๋ฒํ๋ก์ฐ
- โ DiaryPage: ๋ ์ง๊ฐ ์ค๋๋ก๋ง ์ ์ฅ๋จ
- โ DiaryPage: ๋งํฌ๋ค์ด ๋ทฐ์ด ํ์ฉ (์ค๋ฒํ๋ก์ฐ ๋ฐฉ์ง: Container Height)
- โ HomeFeedPage - flutter_slidable:4.0.0 import ํ ์ ์ฉํ๊ธฐ
-
โ HomeFeedPage: FeedCardDiary์์ ์ข์ฐ slide์ ์ฑํ /ํธ์ง/์ญ์
- โ ChatPage - Create New Diary: ๋ํ ๋ด์ฉ์ ๊ธฐ๋ฐ์ผ๋ก, New Diary ์์ฑ
-
โ ChatPage - Go to Linked Diary
-
โ Chat/Diary: GPT Streaming API
-
โ ChatPage - Alarm
-
โ AuthPage: Google Login
- โ DiaryPage: Mood Slider ๊ฐ์ ๋ฐ๋ผ ์ผ๊ตด ํ์ Emoji ๋ณ๊ฒฝ
- โ DiaryPage: ์ธ๋ถ ๊ฐ์ ํค์๋ Choice Chips ์ถ๊ฐ ํ DB ์ฐ๋ ์ค์
- โ DiaryPage - AI Comment: Choice chips, mood slider ๋ฑ์ ์
๋ ฅ๊ฐ๋ค์
AI Comment System Prompt
์ ์๋ง๊ฒ ๋ณ๊ฒฝ.- โ **์ด์
์ผ๊ธฐ
๋๋๋ํ ๋ด์ญ
์ ์ฒด (๋๋นต ๊ธฐ์ ๋ถ์ฑ) - โ ์ฌ์ฉ์ ๊ธฐ๋ณธ ์ ๋ณด: ์ด๋ฆ, ์ฑ๋ณ, MBTI, โฆ
- โ ์ธ๋ถ ๊ฐ์ ํค์๋: ์ฆ๊ฑฐ์ด, ์ฌํ, โฆ
- โ ์บ๋ฆญํฐ ์ค์ : ์๋ฏธ, ์ธ๋, ๋ฏผํ
- โ ๊ฐ์ ์์น: 1~100์
- โ ๋ต๋ณ ์์: ์น์ ํ(Healing), ์กฐ์ธํ(Suggestion), ์ ๋ณดํ(Informative)
- โ ๋ต๋ณ ๊ธธ์ด: ์งง๊ฒ, ๋ณดํต, ์์ธํ
- is New Chat
- ํด๋น Chat์ messages๋ ์ฒ์ ์์ฑํ๋ ๊ฑฐ๋๊น, ์ฒซ ์์ฑํ๋ message document์
is_initial = true
๊ฐ ์ค๋ฒ๋ฆฌ๊ณ ๋ชจ๋ ์์คํ ํ๋กฌํํธ ๋ค ๋๋ ค๋ฃ์.- is_initial = false
- ํ๊ณ์ : ๋งจ ์ฒ์ message document์๋ค๊ฐ ์์คํ ํ๋กฌํํธ ๋๋ ค๋ฃ์ผ๋ฉด, ๋ํ ๋์ค ์์ ํ๋ค๊ธด ํ๋ฐ ๊ฐ๋ฅํ์ง. is_initial = true ์ธ ๊ฒ ์๊ณ , ์์ ๋ ๊ฑฐ๋ฉด, ๊ทธ๊ฑฐ ๋คํ๋จผํธ ์ง์ฐ๊ณ ๋ค์ ๋ฃ์ผ๋ฉด ๋์์. ์ด๋ป๊ฒ๋ ๋ชจ๋ฅด๊ฒ ๊ณ .
- ํด๋น Chat์ messages๋ ์ฒ์ ์์ฑํ๋ ๊ฑฐ๋๊น, ์ฒซ ์์ฑํ๋ message document์
- โ **์ด์
- โ DiaryPage - AI Comment: CRUD ์์ฑํ๊ธฐ
- โ tmp_ai_comment field ์์ ๊ณ , doc_ref ํ์ฉ
- โ DiaryPage - AI Comment: ์บ๋ฆญํฐ ์ค์
- โ tmp_ai_comment_by field ์์ ๊ณ , doc_ref ํ์ฉ
- โ profile_image field ๊ฐ์ผ๋ก ์ด๋ฏธ์ง ์ถ๋ ฅ
-
โ DiaryPage - Drawer - ChatHistoryListTile: order by updated_time
- โ HomeFeedPage - Bottom Sheet (
+
Button): ๋ค์ํ ์ต์ ์ค 1 ์ ํํ ์ ์๋๋ก- ์๋ก์ด ์ผ๊ธฐ: Go to DiaryPage
- ๊ฐ์ ๊ธฐ๋ก: Go to MoodPage
- โ MoodPage(ํ์
): Mood ์ค์ ์ฌ๋ผ์ด๋ CRUD
- Create
- Read
- Update
- Delete
- โ HomeFeedPage - ListView - FeedCardMood ํ์
-
โ HomeFeedPage - ListView: FeedCardDiary, FeedCardMood, FeedCardChat ์ปดํฌ๋ํธ ์๊ฐ์ ์ ๋ ฌ (Cloud Function ํ์ฉ)
- โ HomeFeedPage: On page load์ ์ด์ ํด๊ฒฐ (Unexpected Null Value)
-
โ DiaryPage - Interactive Slider import ํ ์ ์ฉ
- โ ChatPage - AI ์ ํก ๊ตฌํ (Alarm/Notification)
- ์ฑํ
์์คํ
ํ๋กฌํํธ์ ํต์ฌ์ ๋ฅ๋ํ์ด๋ค.
- ๋ ๋ฆฌ์ผํ๊ฒ ํ๋ ค๋ฉด, create_date of diary/chat ๋ ์ ๋ฌํด์, โ์ด์ โ ๋ฑ ๋ ์ง๋ฅผ ์ธ๊ธํ๋ฉด ์ข์ ๋ฏ.
- ์ฑํ
์์คํ
ํ๋กฌํํธ์ ํต์ฌ์ ๋ฅ๋ํ์ด๋ค.
- โ
2025.2.5 ์
๊น์ง ๋ฐํ์ฉ ์ต์ข ๋ฒ์ APK ์ถ์ถ ๋ฐ ์ค์น
๐ญ ์ผ๊ธฐ
์ฌ๋ฐ๋๋ฐ ๋นก์ธ๋ค. ์๋ฒฝ 5์ ์ทจ์นจ.
โจ GPT์ ์ฝ๋ฉํธ (KPT)
โ ์ํ ์ (Keep)
- ๐ AI Comment ๊ธฐ๋ฅ ํ์ฅ: Custom Function๊ณผ API Call์ ์ฐ๋ํ์ฌ AI Comment๋ฅผ ์์ฑํ๊ณ ์ ์ฅํ๋ ๋ก์ง์ ์ฒด๊ณ์ ์ผ๋ก ๊ตฌ์ถํ ์ ์ด ๋๋ณด์ฌ.
- ๐ ๏ธ ๋ฐ์ดํฐ ํ๋ฆ ์ ๋ฆฌ: Chat๊ณผ Diary ๊ฐ์ ์ฐ๊ฒฐ์ ๊ฐ์ ํ๋ฉฐ, ์บ๋ฆญํฐ ์ ๋ณด ์ ์ฅ ๋ฐ ํ์ฉ ๋ฐฉ์์ ์ ๋ฆฌํ ์ ์ด ํ๋ก์ ํธ ์งํ์ ํฐ ๋์์ด ๋ ๊ฑฐ์ผ.
- ๐ FlutterFlow + OpenAI API ํ์ต: GPT-4o ํ์ฉ ๊ฐ์๋ฅผ ํตํด FlutterFlow์์ OpenAI API๋ฅผ ํจ๊ณผ์ ์ผ๋ก ํ์ฉํ๋ ๋ฐฉ๋ฒ์ ์ตํ๊ณ ์ ์ฉํ ์ ์ด ์ธ์์ ์ด์ผ.
โ ์์ฌ์ด ์ (Problem)
- โณ ์์ ๊ฐ๋ ๊ณผ๋ถํ: ์๋ฒฝ 5์๊น์ง ์ด์ด์ง๋ ์์ ์ผ๋ก ์ธํด ํผ๋ก๊ฐ ๋์ ๋ ๊ฐ๋ฅ์ฑ์ด ์ปค์ง๊ณ ์์ด.
- ๐๏ธ ๊ธฐ์ ๋ถ์ฑ ์ฆ๊ฐ: ์ผ๋ถ ๊ธฐ๋ฅ์ด ์์ ํด๊ฒฐ ๋ฐฉ์(tmp ํ๋ ๋ฐ ๋๋นต ์ฝ๋)์ผ๋ก ๊ตฌํ๋์ด, ๋์ค์ ์ ๋ฆฌํ ํ์์ฑ์ด ์๊ฒผ์ด.
๐ ์๋ํด๋ณผ ์ (Try)
- โฐ ์์ ์๊ฐ ์กฐ์ : ๋ฐค์ ์์ ์ด ๊ณ์๋ ๊ฒฝ์ฐ, ์์ฐ์ฑ์ด ์ ํ๋ ์ ์์ผ๋ ์ผ์ ์กฐ์ ์ ๊ณ ๋ คํด๋ณด์.
- ๐ ์์ ์ฝ๋ ๊ฐ์ ๊ณํ: ํ์ฌ ์ ์ฉ๋ ์์ ๋ก์ง์ ์ ๋ฆฌํ๊ณ , ์ ์ ๋ฐ์ดํฐ ๋ชจ๋ธ์ ๊ตฌ์ถํ๋ ๊ณํ์ ์ธ์๋ณด์.
- ๐ ๏ธ AI Comment ๊ฐ์ : AI Comment ๊ด๋ จ ๊ธฐ๋ฅ์ ๋์ฑ ์ง๊ด์ ์ผ๋ก ๊ฐ์ ํ ๋ฐฉ๋ฒ์ ๋ชจ์ํ๋ฉฐ, ์์คํ ํ๋กฌํํธ ์ต์ ํ๋ ๊ณ ๋ คํด๋ณด์.
๊ฒฐ๋ก
Keymory์ AI ๊ธฐ๋ฅ์ ๋ณธ๊ฒฉ์ ์ผ๋ก ๊ตฌํํ๋ฉฐ, OpenAI API์ FlutterFlow์ ํ์ฉ๋๋ฅผ ๋์ธ ํ๋ฃจ์์ด. ๋ค๋ง ์์
๊ฐ๋๊ฐ ๋์์ง๊ณ ์์ผ๋, ์ผ์ ์กฐ์ ๊ณผ ์ฝ๋ ์ ๋ฆฌ๊ฐ ํ์ํ ๊ฒ ๊ฐ์. ๋ฐํ์ผ๊น์ง ์ต์ ์ ์ํ๋ก ๋ง๋ฌด๋ฆฌํ๊ธธ ์์ํ ๊ฒ! ๐ช๐
๋๊ธ ๋จ๊ธฐ๊ธฐ