Skip to content

Documentation v1.0.0


Documentation / @openassistant/plots / histogram

Variable: histogram

const histogram: OpenAssistantTool<HistogramToolArgs, HistogramLlmResult, HistogramAdditionalData, EChartsToolContext>

Defined in: echarts/histogram/tool.ts:49

The histogram tool is used to create a histogram chart for a given dataset and variable.

Example

typescript
import { histogram, HistogramTool } from '@openassistant/plots';
import { convertToVercelAiTool } from '@openassistant/utils';
import { generateText } from 'ai';

const toolContext = {
  getValues: async (datasetName: string, variableName: string) => {
    // get the values of the variable from dataset, e.g.
    return SAMPLE_DATASETS[datasetName].map((item) => item[variableName]);
  },
};

const onToolCompleted = (toolCallId: string, additionalData?: unknown) => {
  console.log('Tool call completed:', toolCallId, additionalData);
  // render the histogram using <HistogramComponentContainer props={additionalData} />
};

const histogramTool: HistogramTool = {
  ...histogram,
  context: toolContext,
  onToolCompleted,
};

generateText({
  model: openai('gpt-4.1', { apiKey: key }),
  prompt: 'Can you create a histogram of the revenue per capita for each location in dataset myVenues?',
  tools: {
    histogram: convertToVercelAiTool(histogramTool),
  },
});

Released under the MIT License.