Variable: leaflet
const
leaflet:ExtendedTool
<LeafletToolArgs
,LeafletToolLlmResult
,LeafletToolAdditionalData
,MapToolContext
>
Defined in: packages/tools/map/src/leaflet/tool.ts:106
The leaflet tool is used to create a leaflet map from GeoJSON data.
note
This tool should be used in Browser environment.
Example
import { leaflet, LeafletTool } from '@openassistant/map';
import { convertToVercelAiTool, ToolCache } from '@openassistant/utils';
import { generateText } from 'ai';
const leafletTool: LeafletTool = {
...leaflet,
context: {
getDataset: async (datasetName) => {
return YOUR_DATASET;
},
},
};
generateText({
model: openai('gpt-4o-mini', { apiKey: key }),
prompt: 'Create a leaflet map using the dataset "my_venues"',
tools: {createMap: convertToVercelAiTool(leafletTool)},
});
tip
You can use the downloadMapData
tool with the leaflet
tool to download a dataset from a geojson from a url and use it to create a map.
Example
import { downloadMapData, isDownloadMapAdditionalData, leaflet, LeafletTool } from '@openassistant/map';
import { convertToVercelAiTool, ToolCache } from '@openassistant/utils';
import { generateText } from 'ai';
const toolResultCache = ToolCache.getInstance();
const downloadMapTool = {
...downloadMapData,
onToolCompleted: (toolCallId: string, additionalData?: unknown) => {
toolResultCache.addDataset(toolCallId, additionalData);
},
};
const leafletTool: LeafletTool = {
...leaflet,
context: {
getDataset: async (datasetName) => {
// find dataset based on datasetName first
// return MYDATASETS[datasetName];
// if no dataset is found, check if dataset is in toolResultCache
if (toolResultCache.hasDataset(datasetName)) {
return toolResultCache.getDataset(datasetName);
}
throw new Error(`Dataset ${datasetName} not found`);
},
},
};
generateText({
model: openai('gpt-4o-mini', { apiKey: key }),
prompt: 'Create a leaflet map using the dataset "my_venues"',
tools: {createMap: convertToVercelAiTool(leafletTool), downloadMapData: convertToVercelAiTool(downloadMapTool)},
});