bentebbutt commited on
Commit
cc7f6c2
·
verified ·
1 Parent(s): f182217

Update frontend/src/components/playground.tsx

Browse files
frontend/src/components/playground.tsx CHANGED
@@ -1,85 +1,82 @@
1
- import { useState } from "react";
2
  import { Input } from "@/components/ui/input";
3
  import { Button } from "@/components/ui/button";
4
  import { v4 as uuidv4 } from "uuid";
 
5
  import {
6
- useChatInteract,
7
- useChatMessages,
8
- IStep,
9
  } from "@chainlit/react-client";
10
-
11
-
12
 
13
  export function Playground() {
14
- const [inputValue, setInputValue] = useState("");
15
- const { sendMessage } = useChatInteract();
16
- const { messages } = useChatMessages();
17
 
18
- const handleSendMessage = () => {
19
- const content = inputValue.trim();
20
- if (content) {
21
- const message: IStep = {
22
- id: uuidv4(),
23
- name: "user",
24
- type: "user_message",
25
- output: content,
26
- createdAt: new Date().toISOString(),
27
- };
28
- sendMessage(message, []);
29
- setInputValue("");
30
- }
31
- };
32
 
33
- const renderMessage = (message: IStep) => {
34
- const dateOptions: Intl.DateTimeFormatOptions = {
35
- hour: "2-digit",
36
- minute: "2-digit",
37
- };
38
- const date = new Date(message.createdAt).toLocaleTimeString(undefined, dateOptions);
39
- return (
40
- <div key={message.id} className="flex items-start space-x-2">
41
- <div className="w-20 text-sm text-green-500">{message.name}</div>
42
- <div className="flex-1 border rounded-lg p-2">
43
- <p className="text-black dark:text-white">{message.output}</p>
44
- <small className="text-xs text-gray-500">{date}</small>
45
- </div>
46
- </div>
47
- );
48
  };
49
-
 
 
 
50
  return (
51
- // Apply the scrollable container to the entire Playground
52
- <div className="playground-container bg-gray-100 dark:bg-gray-900 flex flex-col" style={{ borderRadius: '10px' }}>
53
-
54
- <div style={{ backgroundColor: '#d00404', height: '50px' }}>
55
- {/* Add your content for the red section here */}
56
- </div>
57
-
58
- <div className="flex-1 overflow-auto p-6">
59
- <div className="space-y-4">
60
- {messages.map((message) => renderMessage(message))}
61
- </div>
62
- </div>
63
- <div className="border-t p-4 bg-white dark:bg-gray-800">
64
- <div className="flex items-center space-x-2">
65
- <Input
66
- autoFocus
67
- className="flex-1"
68
- id="message-input"
69
- placeholder="Type a message"
70
- value={inputValue}
71
- onChange={(e) => setInputValue(e.target.value)}
72
- onKeyUp={(e) => {
73
- if (e.key === "Enter") {
74
- handleSendMessage();
75
- }
76
- }}
77
- />
78
- <Button onClick={handleSendMessage} type="submit">
79
- Send
80
- </Button>
81
- </div>
82
- </div>
83
  </div>
 
84
  );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  }
 
1
+
2
  import { Input } from "@/components/ui/input";
3
  import { Button } from "@/components/ui/button";
4
  import { v4 as uuidv4 } from "uuid";
5
+
6
  import {
7
+ useChatInteract,
8
+ useChatMessages,
9
+ IStep,
10
  } from "@chainlit/react-client";
11
+ import { useState } from "react";
 
12
 
13
  export function Playground() {
14
+ const [inputValue, setInputValue] = useState("");
15
+ const { sendMessage } = useChatInteract();
16
+ const { messages } = useChatMessages();
17
 
18
+ const handleSendMessage = () => {
19
+ const content = inputValue.trim();
20
+ if (content) {
21
+ const message: IStep = {
22
+ id: uuidv4(),
23
+ name: "user",
24
+ type: "user_message",
25
+ output: content,
26
+ createdAt: new Date().toISOString(),
27
+ };
28
+ sendMessage(message, []);
29
+ setInputValue("");
30
+ }
31
+ };
32
 
33
+ const renderMessage = (message: IStep) => {
34
+ const dateOptions: Intl.DateTimeFormatOptions = {
35
+ hour: "2-digit",
36
+ minute: "2-digit",
 
 
 
 
 
 
 
 
 
 
 
37
  };
38
+ const date = new Date(message.createdAt).toLocaleTimeString(
39
+ undefined,
40
+ dateOptions
41
+ );
42
  return (
43
+ <div key={message.id} className="flex items-start space-x-2">
44
+ <div className="w-20 text-sm text-green-500">{message.name}</div>
45
+ <div className="flex-1 border rounded-lg p-2">
46
+ <p className="text-black dark:text-white">{message.output}</p>
47
+ <small className="text-xs text-gray-500">{date}</small>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  </div>
49
+ </div>
50
  );
51
+ };
52
+
53
+ return (
54
+ <div className="min-h-screen bg-gray-100 dark:bg-gray-900 flex flex-col">
55
+ <div className="flex-1 overflow-auto p-6">
56
+ <div className="space-y-4">
57
+ {messages.map((message) => renderMessage(message))}
58
+ </div>
59
+ </div>
60
+ <div className="border-t p-4 bg-white dark:bg-gray-800">
61
+ <div className="flex items-center space-x-2">
62
+ <Input
63
+ autoFocus
64
+ className="flex-1"
65
+ id="message-input"
66
+ placeholder="Type a message"
67
+ value={inputValue}
68
+ onChange={(e) => setInputValue(e.target.value)}
69
+ onKeyUp={(e) => {
70
+ if (e.key === "Enter") {
71
+ handleSendMessage();
72
+ }
73
+ }}
74
+ />
75
+ <Button onClick={handleSendMessage} type="submit">
76
+ Send
77
+ </Button>
78
+ </div>
79
+ </div>
80
+ </div>
81
+ );
82
  }