diff --git a/app/api/chat/route.ts b/app/api/chat/route.ts index 67c0944..d1d2ac3 100644 --- a/app/api/chat/route.ts +++ b/app/api/chat/route.ts @@ -43,11 +43,13 @@ Note that: // Add system message if only user message is provided const enhancedMessages = messages.length === 1 ? [{ role: "system", content: systemMessage }, ...messages] + : messages; const result = streamText({ // model: google("gemini-2.0-flash"), model: openai("gpt-4o"), + toolCallStreaming: true, messages: enhancedMessages, tools: { // Client-side tool that will be executed on the client diff --git a/components/chatPanel.tsx b/components/chatPanel.tsx index 441e66c..e26e34b 100644 --- a/components/chatPanel.tsx +++ b/components/chatPanel.tsx @@ -15,7 +15,7 @@ interface ChatPanelProps { } export default function ChatPanel({ onDisplayChart, onFetchChart }: ChatPanelProps) { - const { messages, input, handleInputChange, handleSubmit, status, error, setInput, setMessages } = useChat({ + const { messages, input, handleInputChange, handleSubmit, status, error, setInput, setMessages, data } = useChat({ maxSteps: 5, async onToolCall({ toolCall }) { console.log("Tool call:", toolCall); @@ -32,13 +32,12 @@ export default function ChatPanel({ onDisplayChart, onFetchChart }: ChatPanelPro } }) const messagesEndRef = useRef(null) - // Scroll to bottom when messages change useEffect(() => { if (messagesEndRef.current) { messagesEndRef.current.scrollIntoView({ behavior: "smooth" }) } - console.log("Messages updated:", messages); + console.log("Data updated:", data); }, [messages]) const onFormSubmit = (e: React.FormEvent) => { @@ -65,22 +64,22 @@ export default function ChatPanel({ onDisplayChart, onFetchChart }: ChatPanelPro const callId = toolInvocation.toolCallId; switch (toolInvocation.toolName) { - case 'display_flow_chart': { + case 'display_diagram': { switch (toolInvocation.state) { case 'call': case 'partial-call': return (
-
Displaying flowchart...
+
Displaying diagram...
- Tool: display_flow_chart + Tool: display_diagram
); case 'result': return (
-
Flowchart displayed
+
Diagram displayed
Result: {toolInvocation.result}
@@ -89,30 +88,6 @@ export default function ChatPanel({ onDisplayChart, onFetchChart }: ChatPanelPro } break; } - case 'fetch_flow_chart': { - switch (toolInvocation.state) { - case 'call': - case 'partial-call': - return ( -
-
Fetching current flowchart...
-
- Tool: fetch_flow_chart -
-
- ); - case 'result': - return ( -
-
Flowchart fetched
-
- Successfully retrieved current diagram -
-
- ); - } - break; - } default: return null; } @@ -134,7 +109,7 @@ export default function ChatPanel({ onDisplayChart, onFetchChart }: ChatPanelPro messages.map((message) => (
{/* Render message content based on parts if available */}