Skip to content

Documentation v1.0.0


Documentation / @openassistant/osm / getUsZipcodeGeojson

Variable: getUsZipcodeGeojson

const getUsZipcodeGeojson: OpenAssistantTool<GetUsZipcodeGeojsonFunctionArgs, GetUsZipcodeGeojsonLlmResult, GetUsZipcodeGeojsonAdditionalData>

Defined in: us/zipcode.ts:75

getUsZipcodeGeojson Tool

This tool can be used to get the GeoJSON data of one or more United States zipcodes from the Github repository: https://github.com/greencoder/us-zipcode-to-geojson*

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 zipcode of 10001, 10002, 10003?"

Example user prompts:

  • "Get all zipcodes in California"
  • "Show me the zipcode boundaries of New"

INFO

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

Example

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

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

const zipcodeTool: GetUsZipcodeGeojsonTool = {
  ...getUsZipcodeGeojson,
  onToolCompleted: (toolCallId, additionalData) => {
    toolResultCache.addDataset(toolCallId, additionalData);
  },
};

generateText({
  model: openai('gpt-4.1', { apiKey: key }),
  prompt: 'Get all zipcodes in California',
  tools: {
    zipcode: convertToVercelAiTool(zipcodeTool),
  },
});

Released under the MIT License.