radames commited on
Commit
c6e4b96
1 Parent(s): 9934aaf

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +14 -12
index.html CHANGED
@@ -7,19 +7,18 @@
7
  </head>
8
  <body class="container mx-auto p-3 max-w-xl">
9
  <script type="module">
10
- import { HfInference } from "https://cdn.skypack.dev/@huggingface/inference@2.6.3";
11
  async function* textStreamRes(hf, controller, input) {
12
  let tokens = [];
13
  for await (const output of hf.textGenerationStream(
14
  {
15
  model: "mistralai/Mistral-7B-Instruct-v0.1",
16
- inputs: input,
17
  parameters: { max_new_tokens: 1000 },
18
  },
19
  {
20
  use_cache: false,
21
- fetch: (url, options) =>
22
- fetch(url, { ...options, signal: controller.signal }),
23
  }
24
  )) {
25
  tokens.push(output);
@@ -38,12 +37,15 @@
38
 
39
  const gen = document.querySelector("#generation");
40
  gen.innerHTML = "";
41
- const textStream = textStreamRes(hf, controller, input);
42
- for await (const tokens of textStream) {
43
- const lastToken = tokens[tokens.length - 1];
44
- const span = document.createElement("span");
45
- span.innerText = lastToken.token.text;
46
- gen.appendChild(span);
 
 
 
47
  }
48
  }
49
  document.addEventListener("DOMContentLoaded", () => {
@@ -78,7 +80,7 @@
78
  >
79
  Write an essay about Sartre</textarea
80
  >
81
- <div class="flex">
82
  <button
83
  id="run"
84
  class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
@@ -95,4 +97,4 @@
95
  </div>
96
  <div id="generation" class="py-3"></div>
97
  </body>
98
- </html>
 
7
  </head>
8
  <body class="container mx-auto p-3 max-w-xl">
9
  <script type="module">
10
+ import { HfInference } from "https://cdn.skypack.dev/@huggingface/inference@2.6.4";
11
  async function* textStreamRes(hf, controller, input) {
12
  let tokens = [];
13
  for await (const output of hf.textGenerationStream(
14
  {
15
  model: "mistralai/Mistral-7B-Instruct-v0.1",
16
+ inputs: "<s>[INST]Write an essay about Sartre[/INST]",
17
  parameters: { max_new_tokens: 1000 },
18
  },
19
  {
20
  use_cache: false,
21
+ signal: controller.signal,
 
22
  }
23
  )) {
24
  tokens.push(output);
 
37
 
38
  const gen = document.querySelector("#generation");
39
  gen.innerHTML = "";
40
+ try {
41
+ for await (const tokens of textStreamRes(hf, controller, input)) {
42
+ const lastToken = tokens[tokens.length - 1];
43
+ const span = document.createElement("span");
44
+ span.innerText = lastToken.token.text;
45
+ gen.appendChild(span);
46
+ }
47
+ } catch (e) {
48
+ console.log("aborted");
49
  }
50
  }
51
  document.addEventListener("DOMContentLoaded", () => {
 
80
  >
81
  Write an essay about Sartre</textarea
82
  >
83
+ <div class="flex gap-2">
84
  <button
85
  id="run"
86
  class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
 
97
  </div>
98
  <div id="generation" class="py-3"></div>
99
  </body>
100
+ </html>