Skip to content

Commit 6f60c4d

Browse files
authored
Merge pull request #66 from DHTMLX/add-ai-integration-page-5091
Add the AI integration guide
2 parents cef15f8 + b1b4ef1 commit 6f60c4d

File tree

2 files changed

+92
-2
lines changed

2 files changed

+92
-2
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
sidebar_label: Integrating Diagram with AI
3+
title: Integrating Diagram with AI
4+
description: You can learn about the Integrating Diagram with AI in the documentation of the DHTMLX JavaScript Diagram library. Browse developer guides and API reference, try out code examples and live demos, and download a free 30-day evaluation version of DHTMLX Diagram.
5+
---
6+
7+
# Integrating Diagram with AI
8+
9+
DHTMLX Diagram can be integrated with AI for creating AI-powered diagramming applications. We have prepared an example on how to use DHTMLX Diagram with AI to build an application for creating an org chart out of a request provided in natural language.
10+
11+
The [demo app](https://dhtmlx.com/docs/demo/ai-org-chart-builder/) includes such features as text-to-diagram conversion, AI-driven JSON generation, an instant live preview of a ready diagram and an inbuilt code editor for viewing and adjusting the generated JSON data to update the diagram preview on the fly. For more information, refer to the corresponding [GitHub repository](https://github.com/DHTMLX/diagram-org-chart-builder-ai-demo).
12+
13+
## Project setup
14+
15+
To download the project, clone the repository by using the following command:
16+
17+
~~~jsx
18+
git clone diagram-org-chart-builder-ai-demo
19+
~~~
20+
21+
and then go the project repository via the command below:
22+
23+
~~~jsx
24+
cd diagram-org-chart-builder-ai-demo
25+
~~~
26+
27+
### Installing dependencies
28+
29+
To install dependencies and run the app, you need to make use of a package manager. To install the demo app described in this guide, you should use [npm](https://www.npmjs.com/) by calling the following command:
30+
31+
~~~jsx
32+
npm install
33+
~~~
34+
35+
### Adjusting environment variables
36+
37+
Then you need to configure the environment variables. For this, create a new file named `.env` inside the **diagram-org-chart-builder-ai-demo** directory by copying the content of the `env.sample` file.
38+
The newly created `.env` file will store your keys and configuration. Fill in the required values provided below:
39+
40+
~~~jsx title="diagram-org-chart-builder-ai-demo/.env"
41+
# --- OpenAI API Configuration ---
42+
OPENAI_API_KEY=sk-YourSecretApiKeyGoesHere
43+
OPENAI_BASE_URL=https://api.openai.com/v1
44+
45+
# --- Security Configuration ---
46+
CORS_ALLOWED_ORIGINS=http://localhost:3001,http://127.0.0.1:3001,http://localhost:5500,http://127.0.0.1:5500
47+
48+
# --- Server Configuration (optional) ---
49+
PORT=3001
50+
~~~
51+
52+
:::info
53+
Do NOT upload your `.env` file, since it contains sensitive information!
54+
:::
55+
56+
Check descriptions of the `.env` file variables below:
57+
58+
- `OPENAI_API_KEY`: (Required) Your secret API key for the AI service.
59+
- `OPENAI_BASE_URL`: The API endpoint for the AI service. Can be changed to use a proxy or a different provider compatible with the OpenAI API.
60+
- `CORS_ALLOWED_ORIGINS`: A crucial security setting. This is a comma-separated list of web addresses allowed to connect to your backend server. For production, you **must** change this to your public frontend's URL (e.g., `https://myapp.com`).
61+
- `PORT`: (Optional) The port number on which the server will run. Defaults to 3001 if not set.
62+
63+
### Running the application
64+
65+
To start the application, use the following command in the app directory:
66+
67+
~~~jsx
68+
npm start // this is the required start command
69+
~~~
70+
71+
You should see the output below in your terminal:
72+
73+
~~~jsx
74+
Server started on port 3001.
75+
~~~
76+
77+
Then open the web browser and navigate to: `http://localhost:3001` to see the application ready to generate diagrams.
78+
79+
## How the demo app works
80+
81+
These are the basic steps for transforming a text request into a diagram:
82+
83+
- First, the user enters a text description of the diagram in plain terms, for example: "A diagram with a top manager and five departments each having two employees".
84+
- Then the prompt is sent to the backend, where the AI service generates a structured JSON configuration based on the request.
85+
- After that the frontend gets the resulting data and renders an interactive DHTMLX diagram instantly.
86+
- At the following stage, the corresponding JSON code is displayed in the code editor below the diagram. The user can fine-tune the code and edit the resulting diagram in real time.
87+
- Finally, the user can save the generated data in a JSON file or export the diagram to a PDF or PNG file.
88+
89+

sidebars.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ module.exports = {
863863
link: {
864864
type: 'generated-index',
865865
title: "Integrations",
866-
keywords: ['angular', 'react', 'vue'],
866+
keywords: ['angular', 'react', 'vue', 'svelte'],
867867
image: '/img/docusaurus.png',
868868
},
869869
items: [
@@ -873,8 +873,9 @@ module.exports = {
873873
"guides/integrations/svelte_integration"
874874
],
875875
},
876+
"guides/integrations/ai_integration",
876877
"guides/touch_support",
877-
"guides/using_typescript",
878+
"guides/using_typescript"
878879
]
879880
},
880881
]

0 commit comments

Comments
 (0)