MCPcopy Create free account
hub / github.com/CommandCodeAI/BaseAI / ChatAdvancedExample

Function ChatAdvancedExample

examples/astro/src/components/chat-advanced.tsx:6–151  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4import {usePipe} from '@baseai/core/react';
5
6const ChatAdvancedExample: React.FC = () => {
7 const handleResponse = useCallback(
8 (message: {role: string; content: string}) => {
9 console.log(
10 'Received response:',
11 message.content.slice(0, 50) + '...',
12 );
13 },
14 [],
15 );
16
17 const handleFinish = useCallback(
18 (messages: {role: string; content: string}[]) => {
19 console.log(
20 `Conversation finished. Total messages: ${messages.length}`,
21 );
22 },
23 [],
24 );
25
26 const handleError = useCallback((error: Error) => {
27 console.error('An error occurred:', error);
28 }, []);
29
30 const {
31 messages,
32 input,
33 handleInputChange,
34 handleSubmit,
35 isLoading,
36 error,
37 regenerate,
38 stop,
39 setMessages,
40 threadId,
41 sendMessage,
42 } = usePipe({
43 stream: true,
44 apiRoute: '/api/langbase/pipes/run-stream',
45 onResponse: handleResponse,
46 onFinish: handleFinish,
47 onError: handleError,
48 // initialMessages: [
49 // {role: 'assistant', content: 'Hello! How can I help you?'},
50 // {role: 'user', content: 'Who is an AI engineer?'},
51 // ], // You can set initial messages here if needed
52 // You can set a threadId here if needed to change the thread manually,
53 // otherwise it will be generated automatically persistented in the browser.
54 // threadId: '',
55 });
56
57 const handleClearChat = () => {
58 setMessages([]);
59 };
60
61 const handleRegenerateWithOptions = () => {
62 regenerate({
63 headers: {'Custom-Header': 'Regenerate'},

Callers

nothing calls this directly

Calls 3

usePipeFunction · 0.90
logMethod · 0.80
handleSubmitFunction · 0.70

Tested by

no test coverage detected