Skip to content

Commit a1160ab

Browse files
committed
docs: fix first blog
Signed-off-by: Xun Li <lixun910@gmail.com>
1 parent b6814c4 commit a1160ab

2 files changed

Lines changed: 271 additions & 0 deletions

File tree

Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
---
2+
title: Use OpenAssistant to Build AI Apps for Spatial Data Analysis
3+
date: 2025-01-31
4+
author: LLM
5+
tags: [spatial-analysis, ai, maps, tutorial, beginners]
6+
---
7+
8+
# Use OpenAssistant to Build AI Apps for Spatial Data Analysis
9+
10+
Author: LLM (Large Language Model) Editor: Xun Li
11+
12+
Date: 2025-10-15
13+
14+
Join us to build AI applications for spatial data analysis using OpenAssistant.
15+
16+
<img src="/kepler-tool-demo-1.gif" />
17+
18+
## Quick Start
19+
20+
Let me start by showing you the code that made this possible. Don't worry if it looks intimidating at first - I'll explain everything step by step.
21+
22+
```tsx
23+
import { Assistant } from '@openassistant/assistant';
24+
import { keplergl } from '@openassistant/maps';
25+
import { KeplerGlComponent } from '@openassistant/keplergl';
26+
27+
// This is just some sample data about cities
28+
const SAMPLE_DATASETS = {
29+
cities: [
30+
{ name: 'San Francisco', population: 800000, latitude: 37.774929, longitude: -122.419416 },
31+
{ name: 'New York', population: 8400000, latitude: 40.712776, longitude: -74.005974 },
32+
{ name: 'Los Angeles', population: 3900000, latitude: 34.052235, longitude: -118.243683 },
33+
{ name: 'Chicago', population: 2700000, latitude: 41.878113, longitude: -87.629799 },
34+
{ name: 'Houston', population: 2300000, latitude: 29.760427, longitude: -95.369804 },
35+
],
36+
};
37+
38+
// This connects our data to the map tool
39+
const keplerMapTool = {
40+
...keplergl,
41+
context: {
42+
getDataset: async (datasetName: string) => {
43+
if (datasetName in SAMPLE_DATASETS) {
44+
return SAMPLE_DATASETS[datasetName as keyof typeof SAMPLE_DATASETS];
45+
}
46+
throw new Error(`Dataset ${datasetName} not found`);
47+
},
48+
},
49+
component: KeplerGlComponent,
50+
};
51+
52+
// This is our main app component
53+
export function App() {
54+
return (
55+
<div className="flex h-screen w-screen items-center justify-center p-4">
56+
<div className="w-full max-w-[900px] h-full">
57+
<Assistant options={{
58+
ai: {
59+
getInstructions: () => `You are a helpful assistant that can answer questions and help with tasks.
60+
Your name is George.
61+
You can use the following datasets to answer the user's question:
62+
- Dataset: cities
63+
- Fields: name, population, latitude, longitude`,
64+
tools: {
65+
keplergl: keplerMapTool,
66+
},
67+
},
68+
}} />
69+
</div>
70+
</div>
71+
);
72+
}
73+
```
74+
75+
## What Just Happened Here?
76+
77+
Okay, let me break this down in plain English. This code does something pretty amazing:
78+
79+
1. **We imported the tools we need**: Think of these like specialized helpers that know how to work with maps and AI
80+
2. **We created some sample data**: Just a simple list of cities with their populations and coordinates
81+
3. **We connected the data to a map tool**: This tells the AI "hey, when someone asks about maps, use this data"
82+
4. **We created a chat interface**: This is where users can talk to the AI
83+
84+
85+
## The Chat Interface That Makes It All Possible
86+
87+
One of the coolest things about OpenAssistant is that it comes with a ready-made chat interface. You don't have to build your own - it's already there, looking professional and working perfectly.
88+
89+
<img src="/sqlrooms_ai_chat.png" alt="OpenAssistant Chat Interface" />
90+
91+
This interface lets users:
92+
- Easy provider and model selection and configuration
93+
- Support provider and model settings management
94+
- Support custom models
95+
- Support model usage tracking
96+
97+
It's like having a professional chat app built right into your application, without having to code it yourself. For more details, please visit Sqlrooms: https://sqlrooms.org.
98+
99+
## All tools that OpenAssistant provides
100+
101+
OpenAssistant provides a comprehensive suite of tools for spatial data analysis and GIS applications. Each tool is designed to be used with AI language models to help users analyze, visualize, and manipulate spatial data.
102+
103+
- @openassistant/duckdb - SQL query execution in the browser
104+
- @openassistant/geoda - Spatial statistics and analysis
105+
- @openassistant/map - Map data manipulation and visualization tools
106+
- @openassistant/osm - OpenStreetMap data access and routing
107+
- @openassistant/places - Location search and geotagging
108+
- @openassistant/plots - Statistical visualizations
109+
- @openassistant/h3 - Hexagonal spatial indexing
110+
111+
See the [API Reference](/guide/) for more details.
112+
113+
Want to add charts to your app? It's just as easy. Here's how I added a histogram tool:
114+
115+
```ts
116+
import { generateText } from 'ai';
117+
import { histogram, HistogramTool } from '@openassistant/plots';
118+
import { convertToVercelAiTool } from '@openassistant/utils';
119+
120+
const histogramTool: HistogramTool = {
121+
...histogram,
122+
context: {
123+
getValues: async (datasetName, variableName) => {
124+
// This is where you'd get real data from your database
125+
return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
126+
},
127+
},
128+
onToolCompleted: (toolCallId, additionalData) => {
129+
// This runs when the chart is created - you can save it or do something else
130+
console.log('Chart created!', toolCallId, additionalData);
131+
},
132+
};
133+
134+
// Now use it with any AI model
135+
const result = await generateText({
136+
model: openai('gpt-4o', { apiKey: key }),
137+
system: 'You are a helpful assistant',
138+
prompt: 'create a histogram of HR60 in dataset Natregimes',
139+
tools: { histogram: convertToVercelAiTool(histogramTool) },
140+
});
141+
```
142+
143+
<img src="https://openassistant-doc.vercel.app/img/histogram-1-400.png" width="400" alt="Histogram Plugin" />
144+
145+
## Why This Approach Is So Powerful
146+
147+
Here's what makes OpenAssistant special:
148+
149+
**It's built for maps and spatial data**: Unlike generic AI tools, this one actually understands geography. It knows what latitude and longitude mean, it can create heatmaps, and it can analyze spatial relationships.
150+
151+
**It works with any AI model**: Whether you prefer ChatGPT, Claude, or something else, OpenAssistant works with all of them.
152+
153+
**You only install what you need**: Don't need maps? Don't install the map tools. Only want charts? Just install the chart tools. It's like a buffet - take what you want.
154+
155+
**It's production-ready**: This isn't some experimental code. It's been tested and used in real applications.
156+
157+
## Spatial Data Analysis with AI
158+
159+
One of the most exciting applications of OpenAssistant is the **Kepler.GL AI Assistant**, which transforms the popular Kepler.gl mapping platform into a powerful spatial data analysis tool powered by Generative AI. Built on top of OpenAssistant, this integration demonstrates how AI can revolutionize spatial data exploration and analysis.
160+
161+
![Kepler.GL AI Assistant Demo](https://github.com/user-attachments/assets/406afbfe-4671-42a6-8f38-90cdf171c363)
162+
163+
The Kepler.GL AI Assistant provides a comprehensive suite of spatial analysis tools that work seamlessly with large language models. Users can perform complex spatial operations through simple natural language commands, making advanced GIS analysis accessible to everyone.
164+
165+
Try it out yourself by visiting the [https://kepler.gl/](https://kepler.gl/).
166+
167+
For detailed documentation and examples, visit the [Kepler.GL AI Assistant Guide](https://geodaai.github.io/docs-kepler-ai/guide.html).
168+
169+
### Why This Matters
170+
171+
Traditional GIS software requires extensive training and technical expertise. The Kepler.GL AI Assistant democratizes spatial analysis by allowing users to:
172+
- Ask questions in plain English
173+
- Get immediate visual feedback
174+
- Perform complex analyses without writing code
175+
- Focus on insights rather than technical implementation
176+
177+
This integration showcases the true potential of combining OpenAssistant's flexible tool architecture with domain-specific spatial analysis capabilities, creating an AI-powered platform that makes advanced spatial data science accessible to everyone.
178+
179+
## Getting Started Is Easier Than You Think
180+
181+
Ready to try this yourself? Here's how to get started:
182+
183+
1. **Install the tools you need**:
184+
```bash
185+
npm install @openassistant/duckdb @openassistant/geoda @openassistant/map
186+
```
187+
188+
2. **Check out the examples**:
189+
- [Map Example](https://github.com/geodaopenjs/openassistant/tree/main/examples/map_example) - See how to build map-based apps
190+
- [Chat Example](https://github.com/geodaopenjs/openassistant/tree/main/examples/chat_example) - Learn the basics of the chat interface
191+
192+
3. **Read the docs**: The [Getting Started Guide](/guide/getting-started) walks you through everything step by step
193+
194+
4. **Join the community**: Got questions? The [GitHub discussions](https://github.com/geodaopenjs/openassistant/discussions) are super helpful
195+
196+
5. **Building Your Own Custom Tools**
197+
198+
Here's where things get really interesting. You can create your own tools that do exactly what you need. Let me show you how I built a simple weather tool:
199+
200+
```ts
201+
import { OpenAssistantTool, convertToVercelAiTool } from '@openassistant/utils';
202+
import { generateText } from 'ai';
203+
import { z } from 'zod';
204+
205+
// First, I define what my tool needs
206+
type WeatherToolArgs = { cityName: string };
207+
type WeatherToolResult = { weather: string };
208+
type WeatherToolAdditionalData = { station: string };
209+
type WeatherToolContext = {
210+
getStation: (cityName: string) => Promise<{ stationId: string; weather: string; timestamp: string }>;
211+
};
212+
213+
// Then I create the actual tool
214+
const weatherTool: OpenAssistantTool<WeatherToolArgs, WeatherToolResult, WeatherToolAdditionalData, WeatherToolContext> = {
215+
name: 'getWeather',
216+
description: 'Get the weather in a city from a weather station',
217+
parameters: z.object({ cityName: z.string() }),
218+
context: {
219+
getStation: async (cityName: string) => {
220+
// This is where I'd normally call a real weather API
221+
const stations = {
222+
'New York': {
223+
stationId: '123',
224+
weather: 'sunny',
225+
timestamp: '2025-06-20 10:00:00',
226+
},
227+
};
228+
return stations[cityName];
229+
},
230+
},
231+
execute: async (args, options) => {
232+
if (!options || !options.context || !options.context['getStation']) {
233+
throw new Error('Context is required');
234+
}
235+
const getStation = options.context['getStation'];
236+
const station = await getStation(args.cityName as string);
237+
return {
238+
llmResult: {
239+
success: true,
240+
result: `The weather in ${args.cityName} is ${station.weather} from weather station ${station.station}.`,
241+
},
242+
additionalData: {
243+
station,
244+
},
245+
};
246+
},
247+
});
248+
```
249+
250+
This might look complex, but it's actually pretty straightforward:
251+
252+
1. **It takes a city name as input** (like "New York")
253+
2. **It looks up weather data** (in this example, I'm using fake data, but you could connect to a real weather API)
254+
3. **It returns the weather information** in a format the AI can understand and share with the user
255+
256+
Now users can ask: "What's the weather like in New York?" and the AI will use this tool to get the answer.
257+
258+
259+
## The Bottom Line
260+
261+
Building AI applications that understand maps and spatial data used to be really hard. You'd need to know GIS software, understand coordinate systems, and spend months building visualization tools.
262+
263+
OpenAssistant changes all that. Now you can focus on solving real problems instead of building infrastructure. Whether you're analyzing city data, tracking environmental changes, or helping people find the best coffee shops, OpenAssistant gives you the tools to make it happen.
264+
265+
The best part? It's open source, well-documented, and has a community of developers who are happy to help.
266+
267+
**Ready to build something amazing?** Check out the [GitHub repository](https://github.com/geodaopenjs/openassistant) and start creating your own AI-powered spatial applications today!
268+
269+
---
270+
271+
*Questions? Comments? Want to share what you've built? Drop by our [community discussions](https://github.com/geodaopenjs/openassistant/discussions) - we'd love to hear from you!*

docs/public/sqlrooms_ai_chat.png

607 KB
Loading

0 commit comments

Comments
 (0)