/** * ============================================================================= * CHAT EXAMPLE - Basic Chat Completion * ============================================================================= * * Demonstrates basic chat completion with Mistral. * * INTERVIEW NOTES: * - Simple request/response pattern * - Shows loading and error states * - Good for single-turn interactions */ import { useState } from 'react'; import { useMistralChat } from '@/hooks'; export default function ChatExample() { const [input, setInput] = useState(''); const { chat, data, loading, error, reset } = useMistralChat(); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!input.trim()) return; await chat([ { role: 'system', content: 'You are a helpful assistant. Be concise and clear.', }, { role: 'user', content: input }, ]); }; return (
{data.content}
{`const { chat, data, loading, error } = useMistralChat();
await chat([
{ role: 'system', content: 'You are helpful.' },
{ role: 'user', content: 'Hello!' }
]);
// data.content contains the response`}