Skip to content

Documentation v1.0.0


Documentation / @openassistant/osm / getUsStateGeojson

Variable: getUsStateGeojson

const getUsStateGeojson: OpenAssistantTool<GetUsStateGeojsonFunctionArgs, GetUsStateGeojsonLlmResult, GetUsStateGeojsonAdditionalData>

Defined in: us/state.ts:78

getUsStateGeojson Tool

This tool can be used to get the GeoJSON data of one or more United States states using the Github repository: https://github.com/glynnbird/usstatesgeojson

Example user prompts:

  • "Get the GeoJSON for California"
  • "Get all states in current map view"

TIP

This tool can be mixed with other tools for more complex tasks. For example, if you have a point datasets, you can use this tool to answer questions like "What are the total revenus in the state of California?"

INFO

to avoid overloading the Github API, we only fetch the GeoJSON data every 1 second.

Example

typescript
import { getUsStateGeojson, GetUsStateGeojsonTool } from "@openassistant/osm";
import { convertToVercelAiTool, ToolCache } from '@openassistant/utils';
import { generateText } from 'ai';

// you can use ToolCache to save the state geojson dataset for later use
const toolResultCache = ToolCache.getInstance();

const stateTool: GetUsStateGeojsonTool = {
  ...getUsStateGeojson,
  onToolCompleted: (toolCallId, additionalData) => {
    toolResultCache.addDataset(toolCallId, additionalData);
  },
};

generateText({
  model: openai('gpt-4.1', { apiKey: key }),
  prompt: 'Get the GeoJSON for California',
  tools: {
    state: convertToVercelAiTool(stateTool),
  },
});

Released under the MIT License.