machineuser commited on
Commit
4a43f6f
1 Parent(s): e816e9d

Sync widgets demo

Browse files
packages/tasks/src/index.ts CHANGED
@@ -17,7 +17,7 @@ export {
17
  export { ALL_DISPLAY_MODEL_LIBRARY_KEYS, ALL_MODEL_LIBRARY_KEYS, MODEL_LIBRARIES_UI_ELEMENTS } from "./model-libraries";
18
  export type { LibraryUiElement, ModelLibraryKey } from "./model-libraries";
19
  export type { ModelData, TransformersInfo } from "./model-data";
20
- export type { SpecialTokensMap, TokenizerConfig } from "./tokenizer-data";
21
  export type {
22
  ChatMessage,
23
  WidgetExample,
 
17
  export { ALL_DISPLAY_MODEL_LIBRARY_KEYS, ALL_MODEL_LIBRARY_KEYS, MODEL_LIBRARIES_UI_ELEMENTS } from "./model-libraries";
18
  export type { LibraryUiElement, ModelLibraryKey } from "./model-libraries";
19
  export type { ModelData, TransformersInfo } from "./model-data";
20
+ export type { AddedToken, SpecialTokensMap, TokenizerConfig } from "./tokenizer-data";
21
  export type {
22
  ChatMessage,
23
  WidgetExample,
packages/tasks/src/tokenizer-data.ts CHANGED
@@ -12,8 +12,16 @@ export const SPECIAL_TOKENS_ATTRIBUTES = [
12
  /**
13
  * Public interface for a tokenizer's special tokens mapping
14
  */
 
 
 
 
 
 
 
 
15
  export type SpecialTokensMap = {
16
- [key in (typeof SPECIAL_TOKENS_ATTRIBUTES)[number]]?: string;
17
  };
18
  /**
19
  * Public interface for tokenizer config
 
12
  /**
13
  * Public interface for a tokenizer's special tokens mapping
14
  */
15
+ export interface AddedToken {
16
+ __type: "AddedToken";
17
+ content?: string;
18
+ lstrip?: boolean;
19
+ normalized?: boolean;
20
+ rstrip?: boolean;
21
+ single_word?: boolean;
22
+ }
23
  export type SpecialTokensMap = {
24
+ [key in (typeof SPECIAL_TOKENS_ATTRIBUTES)[number]]?: string | AddedToken;
25
  };
26
  /**
27
  * Public interface for tokenizer config
packages/widgets/src/lib/components/InferenceWidget/widgets/ConversationalWidget/ConversationalWidget.svelte CHANGED
@@ -10,6 +10,7 @@
10
  WidgetExampleOutputText,
11
  WidgetExampleChatInput,
12
  WidgetExample,
 
13
  } from "@huggingface/tasks";
14
  import { SPECIAL_TOKENS_ATTRIBUTES } from "@huggingface/tasks";
15
  import { HfInference } from "@huggingface/inference";
@@ -186,6 +187,8 @@
186
  const value = tokenizerConfig[key];
187
  if (typeof value === "string") {
188
  specialTokensMap[key] = value;
 
 
189
  }
190
  }
191
  return specialTokensMap;
 
10
  WidgetExampleOutputText,
11
  WidgetExampleChatInput,
12
  WidgetExample,
13
+ AddedToken,
14
  } from "@huggingface/tasks";
15
  import { SPECIAL_TOKENS_ATTRIBUTES } from "@huggingface/tasks";
16
  import { HfInference } from "@huggingface/inference";
 
187
  const value = tokenizerConfig[key];
188
  if (typeof value === "string") {
189
  specialTokensMap[key] = value;
190
+ } else if (typeof value === "object" && value.__type === "AddedToken" && value.content) {
191
+ specialTokensMap[key] = (value as AddedToken).content;
192
  }
193
  }
194
  return specialTokensMap;