āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā š shadcn/directory/ai-elements/sources ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
A component that allows a user to view the sources or citations used to generate a response.
The Sources component allows a user to view the sources or citations used to generate a response.
npx ai-elements@latest add sources
import {
Source,
Sources,
SourcesContent,
SourcesTrigger,
} from '@/components/ai-elements/sources';
<Sources>
<SourcesTrigger count={1} />
<SourcesContent>
<Source href="https://ai-sdk.dev" title="AI SDK" />
</SourcesContent>
</Sources>
Build a simple web search agent with Perplexity Sonar.
Add the following component to your frontend:
// app/page.tsx
'use client';
import { useChat } from '@ai-sdk/react';
import {
Source,
Sources,
SourcesContent,
SourcesTrigger,
} from '@/components/ai-elements/sources';
import {
Input,
PromptInputTextarea,
PromptInputSubmit,
} from '@/components/ai-elements/prompt-input';
import {
Conversation,
ConversationContent,
ConversationScrollButton,
} from '@/components/ai-elements/conversation';
import { Message, MessageContent } from '@/components/ai-elements/message';
import { Response } from '@/components/ai-elements/response';
import { useState } from 'react';
import { DefaultChatTransport } from 'ai';
const SourceDemo = () => {
const [input, setInput] = useState('');
const { messages, sendMessage, status } = useChat({
transport: new DefaultChatTransport({
api: '/api/sources',
}),
});
};
Add the following route to your backend:
// api/chat/route.ts
import { streamText, convertToModelMessages } from 'ai';
import { perplexity } from '@ai-sdk/perplexity';
export const maxDuration = 30;
export async function POST(req: Request) {
const { messages } = await req.json();
const result = streamText({
model: perplexity('sonar'),
messages: convertToModelMessages(messages),
});
return result.toUIMessageStreamResponse();
}
| Prop | Type | | ...props? | React.ComponentProps<typeof Accordion> |
| Prop | Type | | count? | number | string | | ...props? | React.ComponentProps<typeof AccordionTrigger> |
| Prop | Type | | ...props? | React.ComponentProps<typeof AccordionContent> |
| Prop | Type | | href? | string | | title? | string | | description? | string | | ...props? | React.ComponentProps<"a"> |
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā