⚡ Building AI Features
Implement các AI features phổ biến trong no-code apps.
Common AI Features
Text
11. Text Generation - Write content22. Chat Interface - Conversations33. Summarization - Condense text44. Analysis - Extract insights55. Translation - Multi-language66. Q&A - Answer questionsFeature 1: Text Generation
Use Cases
- Product descriptions
- Email drafts
- Social media posts
- Blog outlines
Implementation (Bubble)
Text
1UI Elements:2- Input: Topic/keywords3- Dropdown: Tone (professional, casual, fun)4- Dropdown: Length (short, medium, long)5- Button: Generate6- Text: ResultPrompt Template
Text
1System:2"You are a content writer. Generate content based on user input.3Tone: {tone}4Length: {length} (short=50 words, medium=150, long=300)"5 6User:7"Write about: {topic}"Workflow
Text
11. Button clicked22. Validate inputs (not empty)33. Call OpenAI API4 - Build prompt with parameters54. Display result in Text65. Enable "Copy" buttonFeature 2: Chat Interface
UI Design
Text
1┌─────────────────────────┐2│ Chat with AI │3├─────────────────────────┤4│ │5│ [Bot] Hello! How can │6│ I help? │7│ │8│ [User] What is │9│ AI? │10│ │11│ [Bot] AI stands for... │12│ │13├─────────────────────────┤14│ [Type message...] [→] │15└─────────────────────────┘Data Structure
Text
1Message (Data Type):2- content (text)3- role (text: user/assistant) 4- conversation_id (text)5- created_date (date)6- user (User)Implementation
Text
1Page State:2- conversation_id (generate unique ID on load)3 4Repeating Group:5- Type: Message6- Filter: conversation_id = Page's conversation_id7- Sort: created_date ascending8 9Send Workflow:101. Create Message (role: user, content: input)112. Build messages array for API123. Call OpenAI with full conversation134. Create Message (role: assistant, content: response)145. Clear inputConversation Context
JSON
1{2 "model": "gpt-4o-mini",3 "messages": [4 {"role": "system", "content": "You are helpful assistant"},5 {"role": "user", "content": "What is AI?"},6 {"role": "assistant", "content": "AI is..."},7 {"role": "user", "content": "Give me examples"}8 ]9}Feature 3: Summarization
Use Cases
- Article summarization
- Meeting notes
- Document highlights
- Key points extraction
UI Elements
Text
1- Multiline Input (paste long text)2- Dropdown: Summary type3 - Brief (1-2 sentences)4 - Key points (bullet)5 - Detailed (paragraph)6- Button: Summarize7- Text: Summary resultPrompts
Text
1Brief:2"Summarize this in 1-2 sentences: {text}"3 4Key Points:5"Extract 5 key points as bullet points: {text}"6 7Detailed:8"Write a comprehensive summary (150 words): {text}"Feature 4: Content Analysis
Use Cases
- Sentiment analysis
- Topic extraction
- Content classification
- Quality scoring
Sentiment Analysis
Text
1Prompt:2"Analyze the sentiment of this text.3Return JSON format:4{5 'sentiment': 'positive/negative/neutral',6 'score': 0.0-1.0,7 'keywords': ['word1', 'word2'],8 'summary': 'brief explanation'9}10 11Text: {user_input}"Parse JSON Response
Text
1In Bubble:21. API response is text32. Use "JSON Safe" plugin43. Extract: response:formatted as JSON:sentimentDisplay Results
Text
1Visual representation:2- Positive: Green badge3- Negative: Red badge4- Neutral: Gray badge5 6Score: Progress bar (0-100%)7Keywords: Tag chipsFeature 5: Smart Forms
Auto-Complete
Text
1As user types:21. Detect pause (debounce)32. Call AI with partial input43. Suggest completion54. User accepts or continuesForm Assistance
Text
1"Help me write" button:2 3Prompt:4"User is filling a form field: {field_name}5Current input: {partial_text}6Suggest a complete, professional response."Validation + Enhancement
Text
1Before submit:21. AI reviews form content32. Suggests improvements43. Checks for errors54. User confirms or editsFeature 6: Multi-language
Translation Feature
Text
1UI:2- Input text3- Source language (auto-detect)4- Target language dropdown5- Translate button6- Result textPrompt
Text
1"Translate the following text to {target_language}.2Keep the tone and style.3If there are cultural references, adapt them appropriately.4 5Text: {input_text}"Performance Tips
Caching
Text
1Don't call AI for same input:2 31. Hash the prompt42. Check database for existing response53. If exists, return cached64. If not, call AI and saveStreaming (Advanced)
Text
1For long responses:2- Stream tokens as they generate3- Better UX for chat4- Requires server-side setupLoading States
Text
1Good UX:2- Disable button while loading3- Show spinner/animation4- "AI is thinking..."5- Progress indicatorError Handling
Handle Errors
Text
1Common errors:2- Empty response3- API timeout4- Rate limit5- Invalid content6 7User feedback:8- Clear error messages9- Retry option10- Fallback behaviorBài Tập
Practice
Build 2 features trong app của bạn:
-
Text Generator
- Topic input
- Tone selection
- Generate button
- Copy result
-
Simple Chat
- Chat history display
- Message input
- Send button
- Bot responses
Tiếp theo: Bài 7 - Prompt Management
