Skip to content

Commit 874921e

Browse files
committed
more ai-related docs
1 parent 61d27f7 commit 874921e

File tree

8 files changed

+164
-93
lines changed

8 files changed

+164
-93
lines changed
457 KB
Loading
454 KB
Loading
494 KB
Loading
453 KB
Loading

docs/ai_builder/features/code_editor.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ platform, the IDE empowers users to stay focused and productive without ever lea
2020

2121
## IDE Features
2222

23-
2423
### Real-Time Editing
2524

2625
Changes you make in the editor are immediately reflected across your project—no manual saves or rebuilds required. Stay in flow and iterate faster.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Editor Modes
2+
3+
The AI Builder includes a powerful dual-mode editor that lets you view and edit your application code while tracking changes made by the AI. You can seamlessly switch between **Editor Mode** for manual code editing and **Diff Mode** for reviewing AI-generated changes.
4+
5+
6+
```python exec
7+
import reflex as rx
8+
from reflex_image_zoom import image_zoom
9+
10+
def render_image():
11+
return rx.el.div(
12+
image_zoom(
13+
rx.image(
14+
src=rx.color_mode_cond(
15+
"/ai_builder/features/diff_light.png",
16+
"/ai_builder/features/diff_dark.png",
17+
),
18+
class_name="p-2 rounded-md h-auto",
19+
border=f"0.81px solid {rx.color('slate', 5)}",
20+
),
21+
class_name="rounded-md overflow-hidden",
22+
),
23+
class_name="w-full flex flex-col rounded-md cursor-pointer",
24+
)
25+
```
26+
27+
```python eval
28+
29+
rx.el.div(render_image())
30+
31+
```
32+
## Modes: Editor vs Diff
33+
34+
### Editor Mode
35+
The standard code editor where you can:
36+
- **Write and modify code** directly in the interface
37+
- **Navigate through files** using the file tree
38+
- **Make manual changes** to your application
39+
- **Save your modifications** which persist across sessions
40+
41+
### Diff Mode
42+
A specialized view that highlights changes from the last AI prompt:
43+
- **Green highlights** show code additions made by the AI
44+
- **Red highlights** show code deletions made by the AI
45+
- **Side-by-side comparison** of what changed
46+
- **Line-by-line tracking** of modifications
47+
48+
## Switching Between Modes
49+
50+
### Toggle Controls
51+
Located in the editor toolbar, you'll find:
52+
- **Editor** button - Switch to normal editing mode
53+
- **Diff** button - Switch to change tracking mode
54+
55+
### When to Use Each Mode
56+
- **Use Editor Mode when:**
57+
- Making manual code changes
58+
- Writing new functionality
59+
- Debugging or fixing issues
60+
- General code development
61+
62+
- **Use Diff Mode when:**
63+
- Reviewing what the AI changed after a prompt
64+
- Understanding modifications before accepting them
65+
- Tracking the impact of AI suggestions
66+
- Learning from AI-generated code patterns
67+
68+
## Understanding Diff Visualizations
69+
70+
### Code Highlighting
71+
**Additions (Green):**
72+
- New code lines added by the AI
73+
- New functions, components, or logic
74+
- Enhanced features and improvements
75+
76+
**Deletions (Red):**
77+
- Code removed by the AI
78+
- Replaced or refactored sections
79+
- Deprecated functionality
80+
81+
### File Tree Indicators
82+
The file tree shows change statistics for each modified file:
83+
84+
**Change Indicators:**
85+
- **`+5`** - 5 lines added to this file
86+
- **`-3`** - 3 lines removed from this file
87+
- **`+12 -8`** - 12 lines added, 8 lines removed
88+
- **No indicator** - File unchanged
89+
90+
**Visual Cues:**
91+
- **Green `+` symbol** indicates files with additions
92+
- **Red `-` symbol** indicates files with deletions
Lines changed: 71 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,100 @@
1-
# Connecting to a Database
1+
# Database Integration
2+
3+
The Database Integration allows you to connect your AI-generated applications to real databases, automatically generating schemas and enabling data-driven functionality.
24

35
```python exec
46
import reflex as rx
5-
```
6-
7-
Connecting to a database is critical to give your app access to real data. This section will cover how to connect to a database using the AI Builder.
8-
9-
To connect to a database you will need a `DB_URI`. Reflex.build currently supports `postgresql` and `mysql` databases.
10-
11-
This is what it looks like for a Postgres database:
12-
13-
```bash
14-
postgresql://username:password@hostname:port/database_name
15-
```
16-
17-
```bash
18-
postgresql://admin:secret123@db.mycompany.com:5432/mydatabase
19-
```
20-
21-
```python eval
22-
rx.box(height="1rem")
7+
from reflex_image_zoom import image_zoom
238
```
249

2510
```python eval
26-
rx.accordion.root(
27-
rx.accordion.item(
28-
header="DB URI (More Details)",
29-
content=rx.table.root(
30-
rx.table.header(
31-
rx.table.row(
32-
rx.table.column_header_cell("Component"),
33-
rx.table.column_header_cell("Example"),
34-
rx.table.column_header_cell("Description"),
35-
),
11+
rx.el.div(
12+
image_zoom(
13+
rx.image(
14+
src=rx.color_mode_cond(
15+
"/ai_builder/integrations/database_light.png",
16+
"/ai_builder/integrations/database_dark.png",
3617
),
37-
rx.table.body(
38-
rx.table.row(
39-
rx.table.row_header_cell(rx.code("postgresql://")),
40-
rx.table.cell(rx.code("postgresql://")),
41-
rx.table.cell("The database ", rx.el.span("dialect", font_weight="bold"), " or driver (can also be ",
42-
rx.code("mysql://"), ", ", rx.code("sqlite:///"), ", etc.)"),
43-
),
44-
rx.table.row(
45-
rx.table.row_header_cell(rx.code("username")),
46-
rx.table.cell(rx.code("admin")),
47-
rx.table.cell("The ", rx.el.span("username", font_weight="bold"), " used to authenticate with the database"),
48-
),
49-
rx.table.row(
50-
rx.table.row_header_cell(rx.code("password")),
51-
rx.table.cell(rx.code("secret123")),
52-
rx.table.cell("The ", rx.el.span("password", font_weight="bold"), " for the database user (insecure to expose this in plain text)"),
53-
),
54-
rx.table.row(
55-
rx.table.row_header_cell(rx.code("hostname")),
56-
rx.table.cell(rx.code("db.mycompany.com")),
57-
rx.table.cell("The ", rx.el.span("host", font_weight="bold"), " where the database server is running"),
58-
),
59-
rx.table.row(
60-
rx.table.row_header_cell(rx.code("port")),
61-
rx.table.cell(rx.code("5432")),
62-
rx.table.cell("The ", rx.el.span("port", font_weight="bold"), " the database server is listening on (default for PostgreSQL)"),
63-
),
64-
rx.table.row(
65-
rx.table.row_header_cell(rx.code("database_name")),
66-
rx.table.cell(rx.code("mydatabase")),
67-
rx.table.cell("The ", rx.el.span("name", font_weight="bold"), " of the database to connect to"),
68-
),
69-
),
70-
width="100%",
18+
class_name="p-2 rounded-md h-auto",
19+
border=f"0.81px solid {rx.color('slate', 5)}",
7120
),
21+
class_name="rounded-md overflow-hidden",
7222
),
73-
variant="surface",
23+
class_name="w-full flex flex-col rounded-md cursor-pointer",
7424
)
7525
```
7626

77-
```python eval
78-
rx.box(height="1rem")
79-
```
27+
## Supported Databases
8028

81-
You can also use a MySQL database. The connection string looks like this:
29+
- **PostgreSQL** - Recommended for production applications
30+
- **MySQL** - Popular open-source database
31+
- **SQLite** - Lightweight database, perfect for development and small applications
8232

83-
```bash
84-
mysql://username:password@hostname:port/database_name
85-
```
33+
## Getting Started
8634

35+
### Opening the Database Integration
8736

37+
1. Navigate to your app in the AI Builder
38+
2. Open the **Settings drawer** (gear icon)
39+
3. Click on the **Integrations** tab
40+
4. Find and enable the **Database** integration
8841

89-
## Connecting your Database before the app is generated
42+
### Connection Methods
9043

91-
You can add your `Database URI` at the start of your generation as shown below.
44+
The Database Integration offers two convenient ways to connect:
9245

93-
```python eval
94-
rx.image(
95-
src="/ai_builder/add_db_before_app.gif",
96-
height="auto",
97-
padding_bottom="2rem",
98-
)
99-
```
46+
#### 1. Connection Details (Recommended)
10047

101-
Here if you wanted to build a dashboard for example we recommend a prompt as follows:
48+
This user-friendly form breaks down your database connection into individual fields:
10249

103-
`Build a dashboard around my database data`
50+
**For PostgreSQL and MySQL:**
51+
- **Database Type**: Select from dropdown (PostgreSQL/MySQL)
52+
- **Hostname**: Your database server address (e.g., `localhost`, `db.company.com`)
53+
- **Port**: Automatically filled (PostgreSQL: 5432, MySQL: 3306) or specify custom port
54+
- **Username**: Your database username
55+
- **Password**: Your database password (securely handled)
56+
- **Database Name**: The specific database to connect to
10457

58+
**For SQLite:**
59+
- **Database Type**: Select "SQLite" from dropdown
60+
- **SQLite Download URL**: Either a local file path or HTTP URL to download the database file
10561

62+
#### 2. Database URI
10663

107-
## Connecting your Database after the app is generated
64+
For advanced users who prefer the traditional connection string format:
10865

109-
You can add your `Database URI` after you've already generated an app or directly from a template that you have forked as shown below.
66+
**PostgreSQL:**
67+
```
68+
postgresql://username:password@hostname:port/database_name
69+
```
11070

111-
```python eval
112-
rx.image(
113-
src="/ai_builder/add_db_in_app.gif",
114-
height="auto",
115-
padding_bottom="2rem",
116-
)
71+
**MySQL:**
72+
```
73+
mysql://username:password@hostname:port/database_name
11774
```
11875

119-
Here if you wanted to hook up your data correctly we recommend a prompt as follows:
76+
**SQLite:**
77+
```
78+
sqlite:///path/to/database.sqlite
79+
sqlite+https://example.com/database.sqlite
80+
```
12081

121-
`Use the database I added to rewrite the dashboard to display my expense reporting data, keep the existing layout charts and structure the same`
82+
## Database URI Components
83+
84+
Protocol (postgresql://) - Database type identifier
85+
Username (admin) - Database user credentials
86+
Password (secret123) - User password (kept secure)
87+
Hostname (db.company.com) - Server address
88+
Port (5432) - Connection port
89+
Database (mydatabase) - Target database name
90+
91+
## Connection Process
92+
93+
1. **Choose your method**: Use either Connection Details form or Database URI
94+
2. **Fill in credentials**: Provide your database connection information
95+
3. **Click Connect**: The system will validate and test your connection
96+
4. **Schema Generation**: Upon successful connection, the system automatically:
97+
- Connects to your database
98+
- Analyzes the database structure
99+
- Generates SQLAlchemy models
100+
- Makes schema available to the AI for queries

pcweb/components/docpage/sidebar/sidebar_items/ai.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def get_sidebar_items_ai_builder_overview():
2020
ai_builder.features.image_as_prompt,
2121
ai_builder.features.interaction_modes,
2222
ai_builder.features.code_editor,
23+
ai_builder.features.editor_modes,
2324
ai_builder.features.installing_external_packages,
2425
ai_builder.features.knowledge,
2526
ai_builder.features.secrets,

0 commit comments

Comments
 (0)