-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
156 lines (143 loc) · 4.1 KB
/
App.tsx
File metadata and controls
156 lines (143 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/**
* Example React app using dedalus-react
*
* This is a minimal example showing how to use the useChat hook.
*/
import { useState } from "react";
import { useChat } from "../../src/react";
export function App() {
const [input, setInput] = useState("");
const { messages, sendMessage, status, error, stop } = useChat({
transport: {
api: "http://localhost:3001/api/chat",
},
});
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!input.trim() || status === "streaming") return;
const message = input;
setInput("");
await sendMessage(message);
};
return (
<div
style={{
minHeight: "100vh",
backgroundColor: "#000705",
color: "#FFDB6B",
}}
>
<div style={{ maxWidth: 600, margin: "0 auto", padding: 20 }}>
<h1 style={{ marginBottom: 16 }}> <img
src="https://www.firmware.ai/api/media/file/dedalus-logo-gold.svg"
alt="Dedalus Labs"
style={{ height: 24, paddingRight: 8}}
/>Dedalus Chat</h1>
{/* Messages */}
<div
style={{
padding: 16,
minHeight: 300,
marginBottom: 16,
backgroundColor: "#000705",
}}
>
{messages.map((msg, i) => (
<div
key={i}
style={{
marginBottom: 12,
padding: 8,
borderRadius: 4,
backgroundColor: msg.role === "user" ? "#3b3a35" : "#1a1a18",
color: "#FFDB6B",
}}
>
<strong>{msg.role === "user" ? "You" : "Assistant"}:</strong>
<p style={{ margin: "4px 0 0", color: "#FFDB6B" }}>
{msg.content as string}
</p>
</div>
))}
{status === "streaming" && (
<p style={{ color: "#FFDB6B", fontStyle: "italic", opacity: 0.7 }}>
Typing...
</p>
)}
</div>
{/* Error display */}
{error && (
<div
style={{
padding: 8,
marginBottom: 16,
backgroundColor: "#3b3a35",
borderRadius: 4,
color: "#ff6b6b",
border: "1px solid #ff6b6b",
}}
>
Error: {error.message}
</div>
)}
{/* Input form */}
<form onSubmit={handleSubmit} style={{ display: "flex", gap: 8 }}>
<input
type="text"
value={input}
onChange={(e) => setInput(e.target.value)}
placeholder="Type a message..."
disabled={status === "streaming"}
style={{
flex: 1,
padding: "8px 12px",
borderRadius: 4,
border: "1px solid #3b3a35",
backgroundColor: "#000705",
color: "#FFDB6B",
}}
/>
{status === "streaming" ? (
<button
type="button"
onClick={stop}
style={{
padding: "8px 16px",
borderRadius: 4,
border: "none",
backgroundColor: "#ff6b6b",
color: "#000705",
cursor: "pointer",
fontWeight: "bold",
}}
>
Stop
</button>
) : (
<button
type="submit"
disabled={!input.trim()}
style={{
padding: "8px 16px",
borderRadius: 4,
border: "none",
backgroundColor: "#FFDB6B",
color: "#000705",
cursor: input.trim() ? "pointer" : "not-allowed",
opacity: input.trim() ? 1 : 0.5,
fontWeight: "bold",
}}
>
Send
</button>
)}
</form>
{/* Status indicator */}
<p style={{ marginTop: 16, fontSize: 12, color: "#3b3a35" }}>
Status: {status}
</p>
</div>
</div>
);
}
export default App;