Components
npx shadcn@latest add https://21st.dev/r/haydenbleasel/ai-inputStarting preview...
import {
AIInput,
AIInputButton,
AIInputModelSelect,
AIInputModelSelectContent,
AIInputModelSelectItem,
AIInputModelSelectTrigger,
AIInputModelSelectValue,
AIInputSubmit,
AIInputTextarea,
AIInputToolbar,
AIInputTools
} from "@/components/ui/ai-input";
import { GlobeIcon, MicIcon, PlusIcon, SendIcon } from 'lucide-react';
import { type FormEventHandler, useState } from 'react';
const models = [
{ id: 'gpt-4', name: 'GPT-4' },
{ id: 'gpt-3.5-turbo', name: 'GPT-3.5 Turbo' },
{ id: 'claude-2', name: 'Claude 2' },
{ id: 'claude-instant', name: 'Claude Instant' },
{ id: 'palm-2', name: 'PaLM 2' },
{ id: 'llama-2-70b', name: 'Llama 2 70B' },
{ id: 'llama-2-13b', name: 'Llama 2 13B' },
{ id: 'cohere-command', name: 'Command' },
{ id: 'mistral-7b', name: 'Mistral 7B' },
];
const Demo = () => {
const [model, setModel] = useState<string>(models[0].id);
const handleSubmit: FormEventHandler<HTMLFormElement> = (event) => {
event.preventDefault();
const formData = new FormData(event.currentTarget);
const message = formData.get('message');
console.log('Submitted message:', message);
};
return (
<AIInput onSubmit={handleSubmit}>
<AIInputTextarea />
<AIInputToolbar>
<AIInputTools>
<AIInputButton>
<PlusIcon size={16} />
</AIInputButton>
<AIInputButton>
<MicIcon size={16} />
</AIInputButton>
<AIInputButton>
<GlobeIcon size={16} />
<span>Search</span>
</AIInputButton>
<AIInputModelSelect value={model} onValueChange={setModel}>
<AIInputModelSelectTrigger>
<AIInputModelSelectValue />
</AIInputModelSelectTrigger>
<AIInputModelSelectContent>
{models.map((model) => (
<AIInputModelSelectItem key={model.id} value={model.id}>
{model.name}
</AIInputModelSelectItem>
))}
</AIInputModelSelectContent>
</AIInputModelSelect>
</AIInputTools>
<AIInputSubmit>
<SendIcon size={16} />
</AIInputSubmit>
</AIInputToolbar>
</AIInput>
);
}
export default { Demo }