nico-martin HF Staff commited on
Commit
cc1f67c
·
1 Parent(s): 9185156

hashchange

Browse files
dist/assets/{index-H_rCVADf.js → index-DekWw0AL.js} RENAMED
The diff for this file is too large to render. See raw diff
 
dist/assets/{textGenerationWorker-3qlqwFPf.js → textGenerationWorker-BB6zZU4k.js} RENAMED
The diff for this file is too large to render. See raw diff
 
dist/index.html CHANGED
@@ -11,7 +11,7 @@
11
  rel="stylesheet"
12
  />
13
  <title>Transformers.js TextGeneration</title>
14
- <script type="module" crossorigin src="/assets/index-H_rCVADf.js"></script>
15
  <link rel="stylesheet" crossorigin href="/assets/index-DitayMGw.css">
16
  </head>
17
  <body>
 
11
  rel="stylesheet"
12
  />
13
  <title>Transformers.js TextGeneration</title>
14
+ <script type="module" crossorigin src="/assets/index-DekWw0AL.js"></script>
15
  <link rel="stylesheet" crossorigin href="/assets/index-DitayMGw.css">
16
  </head>
17
  <body>
src/chat/Chat.tsx CHANGED
@@ -150,7 +150,10 @@ export default function Chat({ className = "" }: { className?: string }) {
150
  <div className="gap- flex flex-col border-t border-gray-300 dark:border-gray-700">
151
  {CONVERSATION_STARTERS[starterCategory].prompts.map(
152
  (prompt, index) => (
153
- <div className="border-b border-gray-300 py-1 dark:border-gray-700">
 
 
 
154
  <Button
155
  key={index}
156
  onClick={() => generate(prompt)}
 
150
  <div className="gap- flex flex-col border-t border-gray-300 dark:border-gray-700">
151
  {CONVERSATION_STARTERS[starterCategory].prompts.map(
152
  (prompt, index) => (
153
+ <div
154
+ key={prompt}
155
+ className="border-b border-gray-300 py-1 dark:border-gray-700"
156
+ >
157
  <Button
158
  key={index}
159
  onClick={() => generate(prompt)}
src/main.tsx CHANGED
@@ -1,10 +1,21 @@
1
- import { StrictMode } from 'react'
2
- import { createRoot } from 'react-dom/client'
3
- import './index.css'
4
- import App from './App.tsx'
5
 
6
- createRoot(document.getElementById('root')!).render(
 
 
 
7
  <StrictMode>
8
  <App />
9
- </StrictMode>,
10
- )
 
 
 
 
 
 
 
 
 
 
 
1
+ import { StrictMode } from "react";
2
+ import { createRoot } from "react-dom/client";
 
 
3
 
4
+ import App from "./App.tsx";
5
+ import "./index.css";
6
+
7
+ createRoot(document.getElementById("root")!).render(
8
  <StrictMode>
9
  <App />
10
+ </StrictMode>
11
+ );
12
+
13
+ window.addEventListener("hashchange", () =>
14
+ window.parent.postMessage(
15
+ {
16
+ queryString: "",
17
+ hash: window.location.hash,
18
+ },
19
+ "https://huggingface.co"
20
+ )
21
+ );
src/textGeneration/types.ts CHANGED
@@ -84,6 +84,7 @@ export interface GenerationMetadata {
84
  modelKey: keyof typeof MODELS;
85
  model: string;
86
  template: string;
 
87
  }
88
 
89
  interface ResponseGenerateTextAborted {
 
84
  modelKey: keyof typeof MODELS;
85
  model: string;
86
  template: string;
87
+ useKvCache: boolean;
88
  }
89
 
90
  interface ResponseGenerateTextAborted {
src/textGeneration/worker/textGenerationWorker.ts CHANGED
@@ -143,13 +143,13 @@ self.onmessage = async ({ data }: MessageEvent<Request>) => {
143
  });
144
 
145
  const cacheKey = MODEL.modelId + JSON.stringify(messages.slice(0, -1));
146
- const useCache = cacheKey === cache.key;
147
- console.log("useCache", useCache);
148
 
149
  const { sequences, past_key_values } = (await model.generate({
150
  ...input,
151
  max_new_tokens: 1024,
152
- //past_key_values: useCache ? cache.pastKeyValues : null,
153
  return_dict_in_generate: true,
154
  temperature: data.temperature,
155
  stopping_criteria: stoppingCriteria,
@@ -198,6 +198,7 @@ self.onmessage = async ({ data }: MessageEvent<Request>) => {
198
  modelKey: MODEL.modelId,
199
  model: MODEL.title,
200
  template,
 
201
  },
202
  interrupted: stoppingCriteria.interrupted,
203
  requestId,
 
143
  });
144
 
145
  const cacheKey = MODEL.modelId + JSON.stringify(messages.slice(0, -1));
146
+ const useCache = false; // cacheKey === cache.key;
147
+ console.log("useCache", useCache, cacheKey);
148
 
149
  const { sequences, past_key_values } = (await model.generate({
150
  ...input,
151
  max_new_tokens: 1024,
152
+ past_key_values: useCache ? cache.pastKeyValues : null,
153
  return_dict_in_generate: true,
154
  temperature: data.temperature,
155
  stopping_criteria: stoppingCriteria,
 
198
  modelKey: MODEL.modelId,
199
  model: MODEL.title,
200
  template,
201
+ useKvCache: useCache,
202
  },
203
  interrupted: stoppingCriteria.interrupted,
204
  requestId,
src/utils/context/chatSettings/ChatSettingsContextProvider.tsx CHANGED
@@ -47,7 +47,6 @@ export default function ChatSettingsContextProvider({
47
 
48
  useEffect(() => {
49
  const settings = getSettingsFromURL();
50
- console.log(settings);
51
  if (settings) {
52
  setSettings({
53
  tools: settings?.tools,
 
47
 
48
  useEffect(() => {
49
  const settings = getSettingsFromURL();
 
50
  if (settings) {
51
  setSettings({
52
  tools: settings?.tools,
src/utils/context/chatSettings/ChatSettingsModal.tsx CHANGED
@@ -48,6 +48,7 @@ export default function ChatSettingsModal({
48
  }
49
  onSubmit={handleSubmit}
50
  downloadedModels={downloadedModels}
 
51
  />
52
  </Modal>
53
  );
 
48
  }
49
  onSubmit={handleSubmit}
50
  downloadedModels={downloadedModels}
51
+ visible={isOpen}
52
  />
53
  </Modal>
54
  );
src/utils/context/chatSettings/ChatSettingsModalForm.tsx CHANGED
@@ -9,6 +9,7 @@ import {
9
  import { formatBytes } from "@utils/format.ts";
10
  import { MODELS } from "@utils/models.ts";
11
  import { TOOLS } from "@utils/tools.ts";
 
12
  import { Controller, useForm } from "react-hook-form";
13
 
14
  import type { ChatSettings } from "./types.ts";
@@ -17,11 +18,14 @@ export default function ChatSettingsModalForm({
17
  defaultValues,
18
  onSubmit,
19
  downloadedModels,
 
20
  }: {
21
  defaultValues: ChatSettings;
22
  onSubmit: (data: ChatSettings) => void;
23
  downloadedModels: Array<string>;
 
24
  }) {
 
25
  const {
26
  control,
27
  handleSubmit,
@@ -41,6 +45,15 @@ export default function ChatSettingsModalForm({
41
  description: tool.description,
42
  }));
43
 
 
 
 
 
 
 
 
 
 
44
  return (
45
  <form onSubmit={handleSubmit(onSubmit)} className="flex flex-col gap-6">
46
  <Controller
@@ -57,6 +70,7 @@ export default function ChatSettingsModalForm({
57
  options={modelOptions}
58
  required
59
  tooltip="(*) are already downloaded"
 
60
  />
61
  )}
62
  />
 
9
  import { formatBytes } from "@utils/format.ts";
10
  import { MODELS } from "@utils/models.ts";
11
  import { TOOLS } from "@utils/tools.ts";
12
+ import { useEffect, useRef } from "react";
13
  import { Controller, useForm } from "react-hook-form";
14
 
15
  import type { ChatSettings } from "./types.ts";
 
18
  defaultValues,
19
  onSubmit,
20
  downloadedModels,
21
+ visible,
22
  }: {
23
  defaultValues: ChatSettings;
24
  onSubmit: (data: ChatSettings) => void;
25
  downloadedModels: Array<string>;
26
+ visible: boolean;
27
  }) {
28
+ const selectModelRef = useRef<HTMLSelectElement>(null);
29
  const {
30
  control,
31
  handleSubmit,
 
45
  description: tool.description,
46
  }));
47
 
48
+ useEffect(() => {
49
+ if (visible && selectModelRef.current) {
50
+ // Use setTimeout to ensure the element is rendered and ready for focus
51
+ setTimeout(() => {
52
+ selectModelRef.current?.focus();
53
+ }, 200);
54
+ }
55
+ }, [visible]);
56
+
57
  return (
58
  <form onSubmit={handleSubmit(onSubmit)} className="flex flex-col gap-6">
59
  <Controller
 
70
  options={modelOptions}
71
  required
72
  tooltip="(*) are already downloaded"
73
+ ref={selectModelRef}
74
  />
75
  )}
76
  />