File size: 1,035 Bytes
3c7203e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html>
<head>
    <title>Ollama Chat</title>
</head>
<body>
    <div>
        <h1>Ollama Chat Test</h1>
        <div>
            <textarea id="prompt" rows="4" cols="50"></textarea>
        </div>
        <button onclick="sendMessage()">Send</button>
        <div id="response"></div>
    </div>

    <script>
        async function sendMessage() {
            const prompt = document.getElementById('prompt').value;
            const response = document.getElementById('response');
            response.textContent = 'Loading...';

            try {
                const res = await fetch('/testchat', {
                    method: 'POST',
                    headers: {'Content-Type': 'application/json'},
                    body: JSON.stringify({prompt})
                });
                const data = await res.json();
                response.textContent = data.response;
            } catch (err) {
                response.textContent = 'Error: ' + err;
            }
        }
    </script>
</body>
</html>