Download frontend/src/components/CIOChat.jsx from bhuvi3/CIOAgent: direct link, hf CLI and curl.
- Browser
- Download file 2.73 kB
-
https://huggingface.co/spaces/bhuvi3/CIOAgent/resolve/main/frontend/src/components/CIOChat.jsx
- Command line
-
hf download hf://spaces/bhuvi3/CIOAgent/frontend/src/components/CIOChat.jsx
-
curl -L -o CIOChat.jsx https://huggingface.co/spaces/bhuvi3/CIOAgent/resolve/main/frontend/src/components/CIOChat.jsx
2.73 kB
| import React, { useState } from "react"; | |
| import ReactMarkdown from "react-markdown"; | |
| import remarkGfm from "remark-gfm"; | |
| import { askCIO } from "../api"; | |
| export default function CIOChat({ | |
| metrics, | |
| inferences, | |
| frontierSummary, | |
| userProfile, | |
| goalProjection, | |
| chatHistory, | |
| onChatUpdate, | |
| }) { | |
| const [input, setInput] = useState(""); | |
| const [loading, setLoading] = useState(false); | |
| const messages = chatHistory || []; | |
| const send = async () => { | |
| const q = input.trim(); | |
| if (!q || loading) return; | |
| const userMsg = { role: "user", content: q }; | |
| const updated = [...messages, userMsg]; | |
| onChatUpdate(updated); | |
| setInput(""); | |
| setLoading(true); | |
| try { | |
| const data = await askCIO(q, metrics, inferences, frontierSummary, userProfile, goalProjection); | |
| const withReply = [...updated, { role: "assistant", content: data.answer }]; | |
| onChatUpdate(withReply); | |
| } catch (e) { | |
| const withError = [...updated, { role: "assistant", content: `Error: ${e.message}` }]; | |
| onChatUpdate(withError); | |
| } finally { | |
| setLoading(false); | |
| } | |
| }; | |
| const handleKeyDown = (e) => { | |
| if (e.key === "Enter" && !e.shiftKey) { | |
| e.preventDefault(); | |
| send(); | |
| } | |
| }; | |
| return ( | |
| <section className="section"> | |
| <h2>Ask the CIO</h2> | |
| <div className="chat-container"> | |
| <div className="chat-messages"> | |
| {messages.length === 0 && ( | |
| <p className="caption"> | |
| Ask about allocation, risk, performance, efficient frontier, your | |
| risk profile... | |
| </p> | |
| )} | |
| {messages.map((m, i) => ( | |
| <div key={i} className={`chat-msg ${m.role}`}> | |
| <span className="chat-role"> | |
| {m.role === "user" ? "You" : "CIO"} | |
| </span> | |
| <div className="chat-text markdown-body"> | |
| <ReactMarkdown remarkPlugins={[remarkGfm]}>{m.content}</ReactMarkdown> | |
| </div> | |
| </div> | |
| ))} | |
| {loading && ( | |
| <div className="chat-msg assistant"> | |
| <span className="chat-role">CIO</span> | |
| <span className="chat-text thinking">Thinking...</span> | |
| </div> | |
| )} | |
| </div> | |
| <div className="chat-input-row"> | |
| <input | |
| className="chat-input" | |
| value={input} | |
| onChange={(e) => setInput(e.target.value)} | |
| onKeyDown={handleKeyDown} | |
| placeholder="Ask about your portfolio..." | |
| disabled={loading} | |
| /> | |
| <button className="btn primary" onClick={send} disabled={loading}> | |
| Send | |
| </button> | |
| </div> | |
| </div> | |
| </section> | |
| ); | |
| } | |