Skip to content

Documentation v1.0.0


Documentation / @openassistant/plots / boxplot

Variable: boxplot

const boxplot: OpenAssistantTool<BoxplotToolArgs, BoxplotLlmResult, BoxplotAdditionalData, EChartsToolContext>

Defined in: echarts/boxplot/tool.ts:54

The boxplot tool is used to create a box plot for a given dataset and variable.

Example user prompts:

  • "Can you create a box plot of the revenue per capita for each location in dataset myVenues?"
  • "Can you show a box plot of the revenue per capita for each location in dataset myVenues?"

Example

typescript
import { boxplot, BoxplotTool } 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 boxplot using <BoxplotComponentContainer props={additionalData} />
};

const boxplotTool: BoxplotTool = {
  ...boxplot,
  context: toolContext,
  onToolCompleted,
};

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

Released under the MIT License.