File size: 2,800 Bytes
a618bb4
dfd6c0b
a618bb4
dfd6c0b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a618bb4
 
dfd6c0b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da32240
 
 
 
 
dfd6c0b
e045f7a
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Chat Interface</title>
    <style>
        #chat-container {
            display: flex;
            flex-direction: column;
            width: 300px;
            margin: 0 auto;
        }
        #chat-box {
            border: 1px solid #ccc;
            padding: 10px;
            height: 200px;
            overflow-y: scroll;
            margin-bottom: 10px;
        }
        #console-output {
            border: 1px solid #ccc;
            padding: 10px;
            height: 200px;
            overflow-y: scroll;
            margin-top: 20px;
        }
    </style>
</head>
<body>
    <h1>Chat Interface</h1>
    <div id="chat-container">
        <div id="chat-box"></div>
        <input type="text" id="chat-input" placeholder="Type your message here...">
        <button id="send-button">Send</button>
    </div>
    <h2>Console Output</h2>
    <div id="console-output"></div>
    <script>
        const chatBox = document.getElementById('chat-box');
        const chatInput = document.getElementById('chat-input');
        const sendButton = document.getElementById('send-button');
        const consoleOutput = document.getElementById('console-output');

        sendButton.addEventListener('click', () => {
            const message = chatInput.value;
            if (message) {
                fetch('/api/generate', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({ prompt: message })
                })
                .then(response => response.json())
                .then(data => {
                    const responseMessage = document.createElement('div');
                    responseMessage.textContent = `Bot: ${data.response}`;
                    chatBox.appendChild(responseMessage);
                });
                const userMessage = document.createElement('div');
                userMessage.textContent = `You: ${message}`;
                chatBox.appendChild(userMessage);
                chatInput.value = '';
            }
        });

        const eventSource = new EventSource('/logs');
        eventSource.onmessage = function(event) {
            const logMessage = document.createElement('div');
            logMessage.textContent = event.data;
            consoleOutput.appendChild(logMessage);
        };
        eventSource.onmessage = function(event) {
            const logMessage = document.createElement('div');
            logMessage.textContent = event.data;
            consoleOutput.appendChild(logMessage);
        };
    </script>
</body>
</html>