File size: 5,708 Bytes
5355384
e2a8ae1
 
 
 
 
 
 
 
 
5a8378b
 
e2a8ae1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5a8378b
 
 
 
 
 
 
 
dde4a7a
5a8378b
 
558cfda
 
5a8378b
 
 
59695b2
5a8378b
 
 
 
 
 
 
 
 
e2a8ae1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5a8378b
e2a8ae1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5a8378b
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Question and Answer</title>
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script>
        function sendQuestion() {
            document.getElementById("loading").classList.remove("hidden");
            document.getElementById("answer").classList.add("hidden");
        // https://baf8-34-87-104-241.ngrok-free.app/generate
        // var myHeaders = new Headers();
        // myHeaders.append("Content-Type", "application/json");
        // var q_text = document.getElementById('question').value
        // var raw = JSON.stringify({
        // "prompt": '<s>[INST] {q_text} [/INST]',
        // "max_tokens": 256,
        // "temperature": 0.1
        // });
        // var requestOptions = {
        // method: 'POST',
        // headers: myHeaders,
        // body: raw,
        // redirect: 'follow'
        // };
        // fetch("https://baf8-34-87-104-241.ngrok-free.app/generate", requestOptions)
        // .then(response => response.text())
        // .then(result => console.log(result))
        // .catch(error => console.log('error', error));
            let data = JSON.stringify({
                "prompt": "<s>[INST] ତୁମେ କିଏ? [/INST] ",
                "max_tokens": 25,
                "temperature": 0.1
            });
            let config = {
                method: 'post',
                maxBodyLength: Infinity,
                url: 'https://bbb5-34-136-146-180.ngrok-free.app/generate',
                headers: { 
                    'Content-Type': 'application/json',
                    // "Access-Control-Allow-Origin": "*",
                    // "ngrok-skip-browser-warning": 'any'
                },
                data: data
            };
            axios.request(config)
                .then((response) => {
                    console.log(JSON.stringify(response.data));
                    document.getElementById("answer").textContent = response.data;
                    document.getElementById("loading").classList.add("hidden");
                    document.getElementById("answer").classList.remove("hidden");
            })
                .catch((error) => {
                console.log(error);
            });
        // let continuation = 'The best things in life are';
        // let prompt = `<s>[INST] ${continuation} [/INST]`;
        // let counter = 0;
        // while(!continuation.includes('</s>') && counter < 5) {
        //     // Request more tokens from the server
        //     let data = { prompt: continuation, priority: 'MED' }; // 'HIGH' | 'MED' | 'LOW' | 'VLOW'
        //     try {
        //         const response = await axios.post(`http://mydomain.com/dt_llama`, data, { timeout: 10_000});
        //         if(response.data.status === 'success') {
        //             continuation += response.data.data.text;
        //             counter += 1;
        //             // Here write the continuation to your UI, or observable state etc.
        //         } else {
        //             console.error(response.data.error);
        //             break;
        //         }
        //     } catch(err) {
        //         // non-2XX/3XX response
        //         console.error(err);
        //         break;
        //     }
        // }
        // fetch(
        //     'https://baf8-34-87-104-241.ngrok-free.app/generate' +
        //     encodeURIComponent(document.getElementById('question').value)
        // )
        //     .then((response) => response.json())
        //     .then((data) => {
            // document.getElementById("answer").textContent = data.answer;
            // document.getElementById("loading").classList.add("hidden");
            // document.getElementById("answer").classList.remove("hidden");
        //     })
        //     .catch((error) => {
        //     console.error("Error fetching data:", error);
        //     document.getElementById("loading").classList.add("hidden");
        //     document.getElementById("answer").textContent = "Error: Unable to fetch data";
        //     document.getElementById("answer").classList.remove("hidden");
        //     });
        };
    </script>
    <style>
        @keyframes spin {
        to {
            transform: rotate(360deg);
        }
        }
        .animate-spin {
        animation: spin 1s linear infinite;
        }
    </style>
</head>
<body class="bg-gray-100 min-h-screen">
    <div class="container mx-auto py-8">
        <div class="bg-white shadow-lg rounded-lg p-8">
            <h1 class="text-3xl font-bold mb-4">Ask a Question</h1>
            <textarea id="answer" class="w-full h-64 p-4 bg-gray-100 mb-4" readonly></textarea>
            <!-- Loading message -->
            <!-- Loading spinner -->
            <div
            id="loading"
            class="hidden w-16 h-16 border-t-4 border-blue-500 border-solid rounded-full animate-spin mx-auto my-8"
            ></div>
            <div class="flex items-center space-x-4">
                <input id="question" type="text" placeholder="Type your question here" class="flex-grow p-4 border rounded-lg">
                <button 
                class="bg-blue-500 text-white py-3 px-6 rounded-lg"
                onclick="sendQuestion()"
            >
                Ask
            </button>
            </div>
            <div class="htmx-indicator h-2 w-2 bg-blue-500 invisible rounded-full"></div>
        </div>
    </div>
</body>
</html>