# AI chat example

A chat where each answer is a chart. The model is given the schema of your data and returns a JSON spec; `ChartFromSpec` turns the spec into a live component, and each click comes back as a sentence to send as the next message. This is the whole message component; the interactive chat is in the browser at [/examples/ai-chat](/examples/ai-chat).

```tsx title="AssistantMessage.tsx"
import { ChartFromSpec, intentToPrompt } from 'em-kit';
import type { ChartSpec } from 'em-kit';

type Props = {
  message: { text: string; spec?: ChartSpec };
  sendMessage: (text: string) => void;
};

export function AssistantMessage({ message, sendMessage }: Props) {
  return (
    <div className="bubble">
      <p>{message.text}</p>
      {message.spec && (
        <ChartFromSpec
          spec={message.spec}
          chrome="bare"
          height={260}
          onIntent={(intent) => sendMessage(intentToPrompt(intent))}
        />
      )}
    </div>
  );
}
```

See [Charts from a model](/docs/charts-from-a-model.md) for the tool definition, the schema and the prompt, and [the dashboard example](/examples.md) for the other example app.
