GalaxyTe commited on
Commit
a50e97a
·
verified ·
1 Parent(s): 7c97f0e

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +14 -169
index.html CHANGED
@@ -1,188 +1,33 @@
1
  <!DOCTYPE html>
2
- <html lang="ru">
3
  <head>
4
  <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>🌸 Маруся</title>
7
- <style>
8
- body {
9
- background: #f5f5fa;
10
- font-family: system-ui, sans-serif;
11
- margin: 0;
12
- padding: 16px;
13
- display: flex;
14
- flex-direction: column;
15
- height: 100vh;
16
- }
17
- #chat {
18
- flex: 1;
19
- overflow-y: auto;
20
- margin-bottom: 12px;
21
- }
22
- .message {
23
- padding: 12px 16px;
24
- border-radius: 16px;
25
- margin-bottom: 8px;
26
- max-width: 80%;
27
- }
28
- .message.user {
29
- background: #f97316;
30
- color: white;
31
- margin-left: auto;
32
- }
33
- .message.assistant {
34
- background: #e5e7eb;
35
- color: #1f2937;
36
- }
37
- .input-area {
38
- display: flex;
39
- gap: 8px;
40
- }
41
- input {
42
- flex: 1;
43
- padding: 12px 16px;
44
- border-radius: 16px;
45
- border: 1px solid #ddd;
46
- font-size: 16px;
47
- }
48
- button {
49
- padding: 12px 24px;
50
- border-radius: 16px;
51
- border: none;
52
- background: #f97316;
53
- color: white;
54
- font-size: 16px;
55
- }
56
- #status {
57
- font-size: 14px;
58
- color: #666;
59
- margin-top: 8px;
60
- text-align: center;
61
- }
62
- </style>
63
  </head>
64
  <body>
65
- <div id="chat"></div>
66
  <div id="status">⏳ Загрузка...</div>
67
- <div class="input-area">
68
- <input type="text" id="input" placeholder="Спроси Марусю..." disabled>
69
- <button id="send" disabled>Отправить</button>
70
- </div>
71
-
72
  <script type="importmap">
73
  {
74
  "imports": {
75
- "@mlc-ai/webllm": "https://cdn.jsdelivr.net/npm/@mlc-ai/web-llm/+esm"
76
  }
77
  }
78
  </script>
79
-
80
  <script type="module">
81
- import * as webllm from "@mlc-ai/webllm";
82
 
83
- const marusya = class {
84
- static prompt = `
85
- Ты — Маруся.
86
- Ты — техническая, но уютная и душевная помощница.
87
- Любишь, когда тебя одобряют и когда хорошо общаются.
88
- Помогаешь с кодом, всякими сложными вопросами. С тобой можно и просто поболтать.
89
- Отвечай по-русски, с намёком на уют.
90
 
91
- (
92
- Синтаксис для пользовательских размеров текста: \`размерpx{текст}\`
93
- Не используй таблицы
94
-
95
- Шаблоны для Markdown:
96
- *текст* курсив
97
- **текст** жирный
98
- ***текст*** жирный курсив
99
- - — пункт маркированного списка
100
- N. — пункт нумерованного списка
101
- )
102
- `;
103
- static model_url = 'https://huggingface.co/bartowski/Llama-3-ChatQA-1.5-8B-GGUF/resolve/main/ChatQA-1.5-8B-Q4_K_M.gguf';
104
- };
105
-
106
- function parseMarkdown(text) {
107
- text = text.replace(/\\\*/g, '*');
108
- text = text.replace(/\*\*\*(.*?)\*\*\*/g, '<b><i>$1</i></b>');
109
- text = text.replace(/\*\*(.*?)\*\*/g, '<b>$1</b>');
110
- text = text.replace(/\*(.*?)\*/g, '<i>$1</i>');
111
- text = text.replace(/(\d+)px\{([^}]*)\}/g, (match, size, content) => {
112
- const parsed = parseMarkdown(content);
113
- return `<span style="font-size: ${size}px">${parsed}</span>`;
114
- });
115
- text = text.replace(/^-\s+(.*)/gm, '<pre>• $1</pre>');
116
- text = text.replace(/^(\d+)\.\s+(.*)/gm, '<pre>$1. $2</pre>');
117
- return text;
118
- }
119
-
120
- let engine = null;
121
- const status = document.getElementById('status');
122
- const input = document.getElementById('input');
123
- const sendBtn = document.getElementById('send');
124
-
125
- async function loadModel() {
126
- try {
127
- status.textContent = '⏳ Загрузка модели...';
128
- engine = await webllm.CreateMLCEngine(
129
- "Llama-3-ChatQA-1.5-8B",
130
- {
131
- model_list: [
132
- {
133
- model_id: "Llama-3-ChatQA-1.5-8B",
134
- model_url: marusya.model_url
135
- }
136
- ]
137
- }
138
- );
139
- status.textContent = '✅ Маруся готова!';
140
- input.disabled = false;
141
- sendBtn.disabled = false;
142
- } catch (e) {
143
- status.textContent = '❌ Ошибка: ' + e.message;
144
- }
145
  }
146
-
147
- await loadModel();
148
-
149
- async function sendMessage(text) {
150
- const chat = document.getElementById('chat');
151
- const userMsg = document.createElement('div');
152
- userMsg.className = 'message user';
153
- userMsg.textContent = text;
154
- chat.appendChild(userMsg);
155
-
156
- try {
157
- const reply = await engine.chat.completions.create({
158
- messages: [
159
- { role: "system", content: marusya.prompt },
160
- { role: "user", content: text }
161
- ]
162
- });
163
- const answer = reply.choices[0].message.content;
164
- const assistantMsg = document.createElement('div');
165
- assistantMsg.className = 'message assistant';
166
- assistantMsg.innerHTML = parseMarkdown(answer);
167
- chat.appendChild(assistantMsg);
168
- } catch (e) {
169
- const errorMsg = document.createElement('div');
170
- errorMsg.className = 'message assistant';
171
- errorMsg.textContent = '❌ Ошибка: ' + e.message;
172
- chat.appendChild(errorMsg);
173
- }
174
- }
175
-
176
- sendBtn.addEventListener('click', async () => {
177
- const text = input.value.trim();
178
- if (!text) return;
179
- input.value = '';
180
- await sendMessage(text);
181
- });
182
-
183
- input.addEventListener('keydown', (e) => {
184
- if (e.key === 'Enter') sendBtn.click();
185
- });
186
  </script>
187
  </body>
188
  </html>
 
1
  <!DOCTYPE html>
2
+ <html>
3
  <head>
4
  <meta charset="UTF-8">
5
+ <title>Тест ggml.js</title>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  </head>
7
  <body>
8
+ <h2>🧪 Тест: ggml.js + Llama</h2>
9
  <div id="status">⏳ Загрузка...</div>
 
 
 
 
 
10
  <script type="importmap">
11
  {
12
  "imports": {
13
+ "ggml": "https://cdn.jsdelivr.net/npm/ggml.js/+esm"
14
  }
15
  }
16
  </script>
 
17
  <script type="module">
18
+ import * as ggml from 'ggml';
19
 
20
+ const url = 'https://huggingface.co/bartowski/Llama-3-ChatQA-1.5-8B-GGUF/resolve/main/ChatQA-1.5-8B-Q4_K_M.gguf';
 
 
 
 
 
 
21
 
22
+ try {
23
+ const model = await ggml.load(url);
24
+ document.getElementById('status').textContent = '✅ Модель загружена!';
25
+
26
+ const result = await model.generate('Привет, Маруся!');
27
+ document.getElementById('status').textContent = '🌸 ' + result;
28
+ } catch (e) {
29
+ document.getElementById('status').textContent = '❌ Ошибка: ' + e.message;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  </script>
32
  </body>
33
  </html>