-
Hi, I need help with ai sdk's 'use client';
import { useChat } from 'ai/react';
import { Thread } from '@assistant-ui/react';
import { makeMarkdownText } from '@assistant-ui/react-markdown';
import { useVercelUseChatRuntime } from '@assistant-ui/react-ai-sdk';
import { GetStockPriceToolUI } from './GetStockPriceToolUI';
import { RetirementPlannerToolUI } from './RetirementFormUI';
import { ToolFallback } from './ToolFallBack';
const MarkdownText = makeMarkdownText();
export function MyAssistant() {
// const runtime = useEdgeRuntime({ api: "/api/chat" });
const chat = useChat({
api: '/api/chat',
});
const runtime = useVercelUseChatRuntime(chat);
return (
<Thread
runtime={runtime}
assistantMessage={{ components: { Text: MarkdownText, ToolFallback } }}
tools={[GetStockPriceToolUI, RetirementPlannerToolUI]} // Including the RetirementPlannerToolUI
>
</Thread>
);
} What RetirementPlannerToolUI does is basically, show retirement form for user to input. 'use client';
import { makeAssistantToolUI } from '@assistant-ui/react'
import { useState } from 'react'
import { useChat } from 'ai/react';
import { useEffect } from 'react';
const RetirementForm = ({ onSubmit }: { onSubmit: (args: RetirementPlannerArgs) => void }) => {
console.log("Handling retirement form submission");
const { messages, append, input, setInput, handleSubmit } = useChat();
useEffect(() => {
console.log('Current conversation history:', messages);
}, [messages]);
const message = 'test message'
append({
role: 'user',
content: message
});
// Set the message in the chat input
setInput(message);
// Submit the chat form
handleSubmit(e); I thought that as I wonder if I am wrong on shared state concept of |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Pass in the same |
Beta Was this translation helpful? Give feedback.
Pass in the same
id
to bothuseChat
calls to share the statehttps://sdk.vercel.ai/docs/reference/ai-sdk-ui/use-chat#id