Lý thuyết
35 phút
Bài 6/15

Building AI Features

Xây dựng các AI features phổ biến - chat, generation, analysis

⚡ Building AI Features

Implement các AI features phổ biến trong no-code apps.

Common AI Features

Text
11. Text Generation - Write content
22. Chat Interface - Conversations
33. Summarization - Condense text
44. Analysis - Extract insights
55. Translation - Multi-language
66. Q&A - Answer questions

Feature 1: Text Generation

Use Cases

  • Product descriptions
  • Email drafts
  • Social media posts
  • Blog outlines

Implementation (Bubble)

Text
1UI Elements:
2- Input: Topic/keywords
3- Dropdown: Tone (professional, casual, fun)
4- Dropdown: Length (short, medium, long)
5- Button: Generate
6- Text: Result

Prompt 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 clicked
22. Validate inputs (not empty)
33. Call OpenAI API
4 - Build prompt with parameters
54. Display result in Text
65. Enable "Copy" button

Feature 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: Message
6- Filter: conversation_id = Page's conversation_id
7- Sort: created_date ascending
8
9Send Workflow:
101. Create Message (role: user, content: input)
112. Build messages array for API
123. Call OpenAI with full conversation
134. Create Message (role: assistant, content: response)
145. Clear input

Conversation 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 type
3 - Brief (1-2 sentences)
4 - Key points (bullet)
5 - Detailed (paragraph)
6- Button: Summarize
7- Text: Summary result

Prompts

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 text
32. Use "JSON Safe" plugin
43. Extract: response:formatted as JSON:sentiment

Display Results

Text
1Visual representation:
2- Positive: Green badge
3- Negative: Red badge
4- Neutral: Gray badge
5
6Score: Progress bar (0-100%)
7Keywords: Tag chips

Feature 5: Smart Forms

Auto-Complete

Text
1As user types:
21. Detect pause (debounce)
32. Call AI with partial input
43. Suggest completion
54. User accepts or continues

Form 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 content
32. Suggests improvements
43. Checks for errors
54. User confirms or edits

Feature 6: Multi-language

Translation Feature

Text
1UI:
2- Input text
3- Source language (auto-detect)
4- Target language dropdown
5- Translate button
6- Result text

Prompt

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 prompt
42. Check database for existing response
53. If exists, return cached
64. If not, call AI and save

Streaming (Advanced)

Text
1For long responses:
2- Stream tokens as they generate
3- Better UX for chat
4- Requires server-side setup

Loading States

Text
1Good UX:
2- Disable button while loading
3- Show spinner/animation
4- "AI is thinking..."
5- Progress indicator

Error Handling

Handle Errors
Text
1Common errors:
2- Empty response
3- API timeout
4- Rate limit
5- Invalid content
6
7User feedback:
8- Clear error messages
9- Retry option
10- Fallback behavior

Bài Tập

Practice

Build 2 features trong app của bạn:

  1. Text Generator

    • Topic input
    • Tone selection
    • Generate button
    • Copy result
  2. Simple Chat

    • Chat history display
    • Message input
    • Send button
    • Bot responses

Tiếp theo: Bài 7 - Prompt Management