@huggingface/tasks 0.9.1 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/README.md +12 -14
  2. package/dist/index.cjs +91 -18
  3. package/dist/index.js +90 -18
  4. package/dist/scripts/inference-codegen.d.ts +2 -0
  5. package/dist/scripts/inference-codegen.d.ts.map +1 -0
  6. package/dist/scripts/inference-tgi-import.d.ts +2 -0
  7. package/dist/scripts/inference-tgi-import.d.ts.map +1 -0
  8. package/dist/src/default-widget-inputs.d.ts +6 -0
  9. package/dist/src/default-widget-inputs.d.ts.map +1 -0
  10. package/dist/src/index.d.ts +17 -0
  11. package/dist/src/index.d.ts.map +1 -0
  12. package/dist/src/library-to-tasks.d.ts +11 -0
  13. package/dist/src/library-to-tasks.d.ts.map +1 -0
  14. package/dist/src/local-apps.d.ts +104 -0
  15. package/dist/src/local-apps.d.ts.map +1 -0
  16. package/dist/src/model-data.d.ts +144 -0
  17. package/dist/src/model-data.d.ts.map +1 -0
  18. package/dist/src/model-libraries-downloads.d.ts +26 -0
  19. package/dist/src/model-libraries-downloads.d.ts.map +1 -0
  20. package/dist/src/model-libraries-snippets.d.ts +43 -0
  21. package/dist/src/model-libraries-snippets.d.ts.map +1 -0
  22. package/dist/src/model-libraries.d.ts +501 -0
  23. package/dist/src/model-libraries.d.ts.map +1 -0
  24. package/dist/src/pipelines.d.ts +404 -0
  25. package/dist/src/pipelines.d.ts.map +1 -0
  26. package/dist/src/snippets/curl.d.ts +9 -0
  27. package/dist/src/snippets/curl.d.ts.map +1 -0
  28. package/dist/src/snippets/index.d.ts +6 -0
  29. package/dist/src/snippets/index.d.ts.map +1 -0
  30. package/dist/src/snippets/inputs.d.ts +3 -0
  31. package/dist/src/snippets/inputs.d.ts.map +1 -0
  32. package/dist/src/snippets/js.d.ts +11 -0
  33. package/dist/src/snippets/js.d.ts.map +1 -0
  34. package/dist/src/snippets/python.d.ts +14 -0
  35. package/dist/src/snippets/python.d.ts.map +1 -0
  36. package/dist/src/snippets/types.d.ts +8 -0
  37. package/dist/src/snippets/types.d.ts.map +1 -0
  38. package/dist/src/tasks/audio-classification/data.d.ts +4 -0
  39. package/dist/src/tasks/audio-classification/data.d.ts.map +1 -0
  40. package/dist/src/tasks/audio-classification/inference.d.ts +52 -0
  41. package/dist/src/tasks/audio-classification/inference.d.ts.map +1 -0
  42. package/dist/src/tasks/audio-to-audio/data.d.ts +4 -0
  43. package/dist/src/tasks/audio-to-audio/data.d.ts.map +1 -0
  44. package/dist/src/tasks/automatic-speech-recognition/data.d.ts +4 -0
  45. package/dist/src/tasks/automatic-speech-recognition/data.d.ts.map +1 -0
  46. package/dist/src/tasks/automatic-speech-recognition/inference.d.ts +154 -0
  47. package/dist/src/tasks/automatic-speech-recognition/inference.d.ts.map +1 -0
  48. package/dist/src/tasks/chat-completion/inference.d.ts +254 -0
  49. package/dist/src/tasks/chat-completion/inference.d.ts.map +1 -0
  50. package/dist/src/tasks/depth-estimation/data.d.ts +4 -0
  51. package/dist/src/tasks/depth-estimation/data.d.ts.map +1 -0
  52. package/dist/src/tasks/depth-estimation/inference.d.ts +36 -0
  53. package/dist/src/tasks/depth-estimation/inference.d.ts.map +1 -0
  54. package/dist/src/tasks/document-question-answering/data.d.ts +4 -0
  55. package/dist/src/tasks/document-question-answering/data.d.ts.map +1 -0
  56. package/dist/src/tasks/document-question-answering/inference.d.ts +111 -0
  57. package/dist/src/tasks/document-question-answering/inference.d.ts.map +1 -0
  58. package/dist/src/tasks/feature-extraction/data.d.ts +4 -0
  59. package/dist/src/tasks/feature-extraction/data.d.ts.map +1 -0
  60. package/dist/src/tasks/feature-extraction/inference.d.ts +23 -0
  61. package/dist/src/tasks/feature-extraction/inference.d.ts.map +1 -0
  62. package/dist/src/tasks/fill-mask/data.d.ts +4 -0
  63. package/dist/src/tasks/fill-mask/data.d.ts.map +1 -0
  64. package/dist/src/tasks/fill-mask/inference.d.ts +63 -0
  65. package/dist/src/tasks/fill-mask/inference.d.ts.map +1 -0
  66. package/dist/src/tasks/image-classification/data.d.ts +4 -0
  67. package/dist/src/tasks/image-classification/data.d.ts.map +1 -0
  68. package/dist/src/tasks/image-classification/inference.d.ts +52 -0
  69. package/dist/src/tasks/image-classification/inference.d.ts.map +1 -0
  70. package/dist/src/tasks/image-feature-extraction/data.d.ts +4 -0
  71. package/dist/src/tasks/image-feature-extraction/data.d.ts.map +1 -0
  72. package/dist/src/tasks/image-segmentation/data.d.ts +4 -0
  73. package/dist/src/tasks/image-segmentation/data.d.ts.map +1 -0
  74. package/dist/src/tasks/image-segmentation/inference.d.ts +66 -0
  75. package/dist/src/tasks/image-segmentation/inference.d.ts.map +1 -0
  76. package/dist/src/tasks/image-to-image/data.d.ts +4 -0
  77. package/dist/src/tasks/image-to-image/data.d.ts.map +1 -0
  78. package/dist/src/tasks/image-to-image/inference.d.ts +64 -0
  79. package/dist/src/tasks/image-to-image/inference.d.ts.map +1 -0
  80. package/dist/src/tasks/image-to-text/data.d.ts +4 -0
  81. package/dist/src/tasks/image-to-text/data.d.ts.map +1 -0
  82. package/dist/src/tasks/image-to-text/inference.d.ts +139 -0
  83. package/dist/src/tasks/image-to-text/inference.d.ts.map +1 -0
  84. package/dist/src/tasks/index.d.ts +87 -0
  85. package/dist/src/tasks/index.d.ts.map +1 -0
  86. package/dist/src/tasks/mask-generation/data.d.ts +4 -0
  87. package/dist/src/tasks/mask-generation/data.d.ts.map +1 -0
  88. package/dist/src/tasks/object-detection/data.d.ts +4 -0
  89. package/dist/src/tasks/object-detection/data.d.ts.map +1 -0
  90. package/dist/src/tasks/object-detection/inference.d.ts +63 -0
  91. package/dist/src/tasks/object-detection/inference.d.ts.map +1 -0
  92. package/dist/src/tasks/placeholder/data.d.ts +4 -0
  93. package/dist/src/tasks/placeholder/data.d.ts.map +1 -0
  94. package/dist/src/tasks/question-answering/data.d.ts +4 -0
  95. package/dist/src/tasks/question-answering/data.d.ts.map +1 -0
  96. package/dist/src/tasks/question-answering/inference.d.ts +100 -0
  97. package/dist/src/tasks/question-answering/inference.d.ts.map +1 -0
  98. package/dist/src/tasks/reinforcement-learning/data.d.ts +4 -0
  99. package/dist/src/tasks/reinforcement-learning/data.d.ts.map +1 -0
  100. package/dist/src/tasks/sentence-similarity/data.d.ts +4 -0
  101. package/dist/src/tasks/sentence-similarity/data.d.ts.map +1 -0
  102. package/dist/src/tasks/sentence-similarity/inference.d.ts +32 -0
  103. package/dist/src/tasks/sentence-similarity/inference.d.ts.map +1 -0
  104. package/dist/src/tasks/summarization/data.d.ts +4 -0
  105. package/dist/src/tasks/summarization/data.d.ts.map +1 -0
  106. package/dist/src/tasks/summarization/inference.d.ts +55 -0
  107. package/dist/src/tasks/summarization/inference.d.ts.map +1 -0
  108. package/dist/src/tasks/table-question-answering/data.d.ts +4 -0
  109. package/dist/src/tasks/table-question-answering/data.d.ts.map +1 -0
  110. package/dist/src/tasks/table-question-answering/inference.d.ts +62 -0
  111. package/dist/src/tasks/table-question-answering/inference.d.ts.map +1 -0
  112. package/dist/src/tasks/tabular-classification/data.d.ts +4 -0
  113. package/dist/src/tasks/tabular-classification/data.d.ts.map +1 -0
  114. package/dist/src/tasks/tabular-regression/data.d.ts +4 -0
  115. package/dist/src/tasks/tabular-regression/data.d.ts.map +1 -0
  116. package/dist/src/tasks/text-classification/data.d.ts +4 -0
  117. package/dist/src/tasks/text-classification/data.d.ts.map +1 -0
  118. package/dist/src/tasks/text-classification/inference.d.ts +52 -0
  119. package/dist/src/tasks/text-classification/inference.d.ts.map +1 -0
  120. package/dist/src/tasks/text-generation/data.d.ts +4 -0
  121. package/dist/src/tasks/text-generation/data.d.ts.map +1 -0
  122. package/dist/src/tasks/text-generation/inference.d.ts +126 -0
  123. package/dist/src/tasks/text-generation/inference.d.ts.map +1 -0
  124. package/dist/src/tasks/text-to-audio/inference.d.ts +139 -0
  125. package/dist/src/tasks/text-to-audio/inference.d.ts.map +1 -0
  126. package/dist/src/tasks/text-to-image/data.d.ts +4 -0
  127. package/dist/src/tasks/text-to-image/data.d.ts.map +1 -0
  128. package/dist/src/tasks/text-to-image/inference.d.ts +68 -0
  129. package/dist/src/tasks/text-to-image/inference.d.ts.map +1 -0
  130. package/dist/src/tasks/text-to-speech/data.d.ts +4 -0
  131. package/dist/src/tasks/text-to-speech/data.d.ts.map +1 -0
  132. package/dist/src/tasks/text-to-speech/inference.d.ts +143 -0
  133. package/dist/src/tasks/text-to-speech/inference.d.ts.map +1 -0
  134. package/dist/src/tasks/text-to-video/data.d.ts +4 -0
  135. package/dist/src/tasks/text-to-video/data.d.ts.map +1 -0
  136. package/dist/src/tasks/text2text-generation/inference.d.ts +54 -0
  137. package/dist/src/tasks/text2text-generation/inference.d.ts.map +1 -0
  138. package/dist/src/tasks/token-classification/data.d.ts +4 -0
  139. package/dist/src/tasks/token-classification/data.d.ts.map +1 -0
  140. package/dist/src/tasks/token-classification/inference.d.ts +83 -0
  141. package/dist/src/tasks/token-classification/inference.d.ts.map +1 -0
  142. package/dist/src/tasks/translation/data.d.ts +4 -0
  143. package/dist/src/tasks/translation/data.d.ts.map +1 -0
  144. package/dist/src/tasks/translation/inference.d.ts +55 -0
  145. package/dist/src/tasks/translation/inference.d.ts.map +1 -0
  146. package/dist/src/tasks/unconditional-image-generation/data.d.ts +4 -0
  147. package/dist/src/tasks/unconditional-image-generation/data.d.ts.map +1 -0
  148. package/dist/src/tasks/video-classification/data.d.ts +4 -0
  149. package/dist/src/tasks/video-classification/data.d.ts.map +1 -0
  150. package/dist/src/tasks/video-classification/inference.d.ts +60 -0
  151. package/dist/src/tasks/video-classification/inference.d.ts.map +1 -0
  152. package/dist/src/tasks/visual-question-answering/data.d.ts +4 -0
  153. package/dist/src/tasks/visual-question-answering/data.d.ts.map +1 -0
  154. package/dist/src/tasks/visual-question-answering/inference.d.ts +64 -0
  155. package/dist/src/tasks/visual-question-answering/inference.d.ts.map +1 -0
  156. package/dist/src/tasks/zero-shot-classification/data.d.ts +4 -0
  157. package/dist/src/tasks/zero-shot-classification/data.d.ts.map +1 -0
  158. package/dist/src/tasks/zero-shot-classification/inference.d.ts +68 -0
  159. package/dist/src/tasks/zero-shot-classification/inference.d.ts.map +1 -0
  160. package/dist/src/tasks/zero-shot-image-classification/data.d.ts +4 -0
  161. package/dist/src/tasks/zero-shot-image-classification/data.d.ts.map +1 -0
  162. package/dist/src/tasks/zero-shot-image-classification/inference.d.ts +62 -0
  163. package/dist/src/tasks/zero-shot-image-classification/inference.d.ts.map +1 -0
  164. package/dist/src/tasks/zero-shot-object-detection/data.d.ts +4 -0
  165. package/dist/src/tasks/zero-shot-object-detection/data.d.ts.map +1 -0
  166. package/dist/src/tasks/zero-shot-object-detection/inference.d.ts +67 -0
  167. package/dist/src/tasks/zero-shot-object-detection/inference.d.ts.map +1 -0
  168. package/dist/src/tokenizer-data.d.ts +26 -0
  169. package/dist/src/tokenizer-data.d.ts.map +1 -0
  170. package/dist/src/widget-example.d.ts +86 -0
  171. package/dist/src/widget-example.d.ts.map +1 -0
  172. package/package.json +8 -6
  173. package/src/index.ts +3 -0
  174. package/src/local-apps.ts +119 -0
  175. package/src/model-data.ts +1 -5
  176. package/src/model-libraries-snippets.ts +21 -18
  177. package/src/model-libraries.ts +9 -0
  178. package/src/tasks/chat-completion/inference.ts +204 -85
  179. package/src/tasks/chat-completion/spec/input.json +198 -34
  180. package/src/tasks/chat-completion/spec/output.json +178 -40
  181. package/src/tasks/chat-completion/spec/stream_output.json +170 -0
  182. package/src/tasks/index.ts +7 -8
  183. package/src/tasks/text-generation/inference.ts +58 -170
  184. package/src/tasks/text-generation/spec/input.json +130 -29
  185. package/src/tasks/text-generation/spec/output.json +104 -90
  186. package/src/tasks/text-generation/spec/stream_output.json +97 -0
  187. package/tsconfig.json +3 -1
  188. package/dist/index.d.ts +0 -3542
  189. package/src/tasks/chat-completion/spec/output_stream.json +0 -48
  190. package/src/tasks/text-generation/spec/output_stream.json +0 -47
@@ -43,9 +43,8 @@ export type {
43
43
  ChatCompletionInput,
44
44
  ChatCompletionInputMessage,
45
45
  ChatCompletionOutput,
46
- ChatCompletionOutputChoice,
47
- ChatCompletionFinishReason,
48
- ChatCompletionOutputChoiceMessage,
46
+ ChatCompletionOutputComplete,
47
+ ChatCompletionOutputMessage,
49
48
  ChatCompletionStreamOutput,
50
49
  ChatCompletionStreamOutputChoice,
51
50
  ChatCompletionStreamOutputDelta,
@@ -85,15 +84,15 @@ export type {
85
84
  TextClassificationParameters,
86
85
  } from "./text-classification/inference";
87
86
  export type {
88
- TextGenerationFinishReason,
89
- TextGenerationPrefillToken,
87
+ TextGenerationOutputFinishReason,
88
+ TextGenerationOutputPrefillToken,
90
89
  TextGenerationInput,
91
90
  TextGenerationOutput,
92
91
  TextGenerationOutputDetails,
93
- TextGenerationParameters,
94
- TextGenerationOutputSequenceDetails,
92
+ TextGenerationInputGenerateParameters,
93
+ TextGenerationOutputBestOfSequence,
95
94
  TextGenerationOutputToken,
96
- TextGenerationStreamDetails,
95
+ TextGenerationStreamOutputStreamDetails,
97
96
  TextGenerationStreamOutput,
98
97
  } from "./text-generation/inference";
99
98
  export type * from "./video-classification/inference";
@@ -5,246 +5,134 @@
5
5
  */
6
6
 
7
7
  /**
8
- * Inputs for Text Generation inference
8
+ * Text Generation Input.
9
+ *
10
+ * Auto-generated from TGI specs.
11
+ * For more details, check out
12
+ * https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-tgi-import.ts.
9
13
  */
10
14
  export interface TextGenerationInput {
11
- /**
12
- * The text to initialize generation with
13
- */
14
15
  inputs: string;
15
- /**
16
- * Additional inference parameters
17
- */
18
- parameters?: TextGenerationParameters;
19
- /**
20
- * Whether to stream output tokens
21
- */
16
+ parameters?: TextGenerationInputGenerateParameters;
22
17
  stream?: boolean;
23
18
  [property: string]: unknown;
24
19
  }
25
20
 
26
- /**
27
- * Additional inference parameters
28
- *
29
- * Additional inference parameters for Text Generation
30
- */
31
- export interface TextGenerationParameters {
32
- /**
33
- * The number of sampling queries to run. Only the best one (in terms of total logprob) will
34
- * be returned.
35
- */
21
+ export interface TextGenerationInputGenerateParameters {
36
22
  best_of?: number;
37
- /**
38
- * Whether or not to output decoder input details
39
- */
40
23
  decoder_input_details?: boolean;
41
- /**
42
- * Whether or not to output details
43
- */
44
24
  details?: boolean;
45
- /**
46
- * Whether to use logits sampling instead of greedy decoding when generating new tokens.
47
- */
48
25
  do_sample?: boolean;
49
- /**
50
- * The maximum number of tokens to generate.
51
- */
26
+ frequency_penalty?: number;
27
+ grammar?: TextGenerationInputGrammarType;
52
28
  max_new_tokens?: number;
53
- /**
54
- * The parameter for repetition penalty. A value of 1.0 means no penalty. See [this
55
- * paper](https://hf.co/papers/1909.05858) for more details.
56
- */
57
29
  repetition_penalty?: number;
58
- /**
59
- * Whether to prepend the prompt to the generated text.
60
- */
61
30
  return_full_text?: boolean;
62
- /**
63
- * The random sampling seed.
64
- */
65
31
  seed?: number;
66
- /**
67
- * Stop generating tokens if a member of `stop_sequences` is generated.
68
- */
69
- stop_sequences?: string[];
70
- /**
71
- * The value used to modulate the logits distribution.
72
- */
32
+ stop?: string[];
73
33
  temperature?: number;
74
- /**
75
- * The number of highest probability vocabulary tokens to keep for top-k-filtering.
76
- */
77
34
  top_k?: number;
78
- /**
79
- * If set to < 1, only the smallest set of most probable tokens with probabilities that add
80
- * up to `top_p` or higher are kept for generation.
81
- */
35
+ top_n_tokens?: number;
82
36
  top_p?: number;
83
- /**
84
- * Truncate input tokens to the given size.
85
- */
86
37
  truncate?: number;
87
- /**
88
- * Typical Decoding mass. See [Typical Decoding for Natural Language
89
- * Generation](https://hf.co/papers/2202.00666) for more information
90
- */
91
38
  typical_p?: number;
39
+ watermark?: boolean;
40
+ [property: string]: unknown;
41
+ }
42
+
43
+ export interface TextGenerationInputGrammarType {
44
+ type: Type;
92
45
  /**
93
- * Watermarking with [A Watermark for Large Language Models](https://hf.co/papers/2301.10226)
46
+ * A string that represents a [JSON Schema](https://json-schema.org/).
47
+ *
48
+ * JSON Schema is a declarative language that allows to annotate JSON documents
49
+ * with types and descriptions.
94
50
  */
95
- watermark?: boolean;
51
+ value: unknown;
96
52
  [property: string]: unknown;
97
53
  }
98
54
 
55
+ export type Type = "json" | "regex";
56
+
99
57
  /**
100
- * Outputs for Text Generation inference
58
+ * Text Generation Output.
59
+ *
60
+ * Auto-generated from TGI specs.
61
+ * For more details, check out
62
+ * https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-tgi-import.ts.
101
63
  */
102
64
  export interface TextGenerationOutput {
103
- /**
104
- * When enabled, details about the generation
105
- */
106
65
  details?: TextGenerationOutputDetails;
107
- /**
108
- * The generated text
109
- */
110
66
  generated_text: string;
111
67
  [property: string]: unknown;
112
68
  }
113
69
 
114
- /**
115
- * When enabled, details about the generation
116
- */
117
70
  export interface TextGenerationOutputDetails {
118
- /**
119
- * Details about additional sequences when best_of is provided
120
- */
121
- best_of_sequences?: TextGenerationOutputSequenceDetails[];
122
- /**
123
- * The reason why the generation was stopped.
124
- */
125
- finish_reason: TextGenerationFinishReason;
126
- /**
127
- * The number of generated tokens
128
- */
71
+ best_of_sequences?: TextGenerationOutputBestOfSequence[];
72
+ finish_reason: TextGenerationOutputFinishReason;
129
73
  generated_tokens: number;
130
- prefill: TextGenerationPrefillToken[];
131
- /**
132
- * The random seed used for generation
133
- */
74
+ prefill: TextGenerationOutputPrefillToken[];
134
75
  seed?: number;
135
- /**
136
- * The generated tokens and associated details
137
- */
138
76
  tokens: TextGenerationOutputToken[];
139
- /**
140
- * Most likely tokens
141
- */
142
77
  top_tokens?: Array<TextGenerationOutputToken[]>;
143
78
  [property: string]: unknown;
144
79
  }
145
80
 
146
- export interface TextGenerationOutputSequenceDetails {
147
- finish_reason: TextGenerationFinishReason;
148
- /**
149
- * The generated text
150
- */
81
+ export interface TextGenerationOutputBestOfSequence {
82
+ finish_reason: TextGenerationOutputFinishReason;
151
83
  generated_text: string;
152
- /**
153
- * The number of generated tokens
154
- */
155
84
  generated_tokens: number;
156
- prefill: TextGenerationPrefillToken[];
157
- /**
158
- * The random seed used for generation
159
- */
85
+ prefill: TextGenerationOutputPrefillToken[];
160
86
  seed?: number;
161
- /**
162
- * The generated tokens and associated details
163
- */
164
87
  tokens: TextGenerationOutputToken[];
165
- /**
166
- * Most likely tokens
167
- */
168
88
  top_tokens?: Array<TextGenerationOutputToken[]>;
169
89
  [property: string]: unknown;
170
90
  }
171
91
 
172
- /**
173
- * The reason why the generation was stopped.
174
- *
175
- * length: The generated sequence reached the maximum allowed length
176
- *
177
- * eos_token: The model generated an end-of-sentence (EOS) token
178
- *
179
- * stop_sequence: One of the sequence in stop_sequences was generated
180
- */
181
- export type TextGenerationFinishReason = "length" | "eos_token" | "stop_sequence";
92
+ export type TextGenerationOutputFinishReason = "length" | "eos_token" | "stop_sequence";
182
93
 
183
- export interface TextGenerationPrefillToken {
94
+ export interface TextGenerationOutputPrefillToken {
184
95
  id: number;
185
96
  logprob: number;
186
- /**
187
- * The text associated with that token
188
- */
189
97
  text: string;
190
98
  [property: string]: unknown;
191
99
  }
192
100
 
193
- /**
194
- * Generated token.
195
- */
196
101
  export interface TextGenerationOutputToken {
197
102
  id: number;
198
- logprob?: number;
199
- /**
200
- * Whether or not that token is a special one
201
- */
103
+ logprob: number;
202
104
  special: boolean;
203
- /**
204
- * The text associated with that token
205
- */
206
105
  text: string;
207
106
  [property: string]: unknown;
208
107
  }
209
108
 
210
109
  /**
211
- * Text Generation Stream Output
110
+ * Text Generation Stream Output.
111
+ *
112
+ * Auto-generated from TGI specs.
113
+ * For more details, check out
114
+ * https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-tgi-import.ts.
212
115
  */
213
116
  export interface TextGenerationStreamOutput {
214
- /**
215
- * Generation details. Only available when the generation is finished.
216
- */
217
- details?: TextGenerationStreamDetails;
218
- /**
219
- * The complete generated text. Only available when the generation is finished.
220
- */
117
+ details?: TextGenerationStreamOutputStreamDetails;
221
118
  generated_text?: string;
222
- /**
223
- * The token index within the stream. Optional to support older clients that omit it.
224
- */
225
- index?: number;
226
- /**
227
- * Generated token.
228
- */
229
- token: TextGenerationOutputToken;
119
+ index: number;
120
+ token: TextGenerationStreamOutputToken;
121
+ top_tokens?: TextGenerationStreamOutputToken[];
230
122
  [property: string]: unknown;
231
123
  }
232
124
 
233
- /**
234
- * Generation details. Only available when the generation is finished.
235
- */
236
- export interface TextGenerationStreamDetails {
237
- /**
238
- * The reason why the generation was stopped.
239
- */
240
- finish_reason: TextGenerationFinishReason;
241
- /**
242
- * The number of generated tokens
243
- */
125
+ export interface TextGenerationStreamOutputStreamDetails {
126
+ finish_reason: TextGenerationOutputFinishReason;
244
127
  generated_tokens: number;
245
- /**
246
- * The random seed used for generation
247
- */
248
- seed: number;
128
+ seed?: number;
129
+ [property: string]: unknown;
130
+ }
131
+
132
+ export interface TextGenerationStreamOutputToken {
133
+ id: number;
134
+ logprob: number;
135
+ special: boolean;
136
+ text: string;
249
137
  [property: string]: unknown;
250
138
  }
@@ -1,94 +1,195 @@
1
1
  {
2
2
  "$id": "/inference/schemas/text-generation/input.json",
3
3
  "$schema": "http://json-schema.org/draft-06/schema#",
4
- "description": "Inputs for Text Generation inference",
4
+ "description": "Text Generation Input.\n\nAuto-generated from TGI specs.\nFor more details, check out https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/scripts/inference-tgi-import.ts.",
5
5
  "title": "TextGenerationInput",
6
6
  "type": "object",
7
+ "required": ["inputs"],
7
8
  "properties": {
8
9
  "inputs": {
9
- "description": "The text to initialize generation with",
10
- "type": "string"
10
+ "type": "string",
11
+ "example": "My name is Olivier and I"
11
12
  },
12
13
  "parameters": {
13
- "description": "Additional inference parameters",
14
- "$ref": "#/$defs/TextGenerationParameters"
14
+ "$ref": "#/$defs/TextGenerationInputGenerateParameters"
15
15
  },
16
16
  "stream": {
17
- "description": "Whether to stream output tokens",
18
- "type": "boolean"
17
+ "type": "boolean",
18
+ "default": "false"
19
19
  }
20
20
  },
21
21
  "$defs": {
22
- "TextGenerationParameters": {
23
- "title": "TextGenerationParameters",
24
- "description": "Additional inference parameters for Text Generation",
22
+ "TextGenerationInputGenerateParameters": {
25
23
  "type": "object",
26
24
  "properties": {
27
25
  "best_of": {
28
26
  "type": "integer",
29
- "description": "The number of sampling queries to run. Only the best one (in terms of total logprob) will be returned."
27
+ "default": "null",
28
+ "example": 1,
29
+ "nullable": true,
30
+ "minimum": 0,
31
+ "exclusiveMinimum": 0
30
32
  },
31
33
  "decoder_input_details": {
32
34
  "type": "boolean",
33
- "description": "Whether or not to output decoder input details"
35
+ "default": "false"
34
36
  },
35
37
  "details": {
36
38
  "type": "boolean",
37
- "description": "Whether or not to output details"
39
+ "default": "true"
38
40
  },
39
41
  "do_sample": {
40
42
  "type": "boolean",
41
- "description": "Whether to use logits sampling instead of greedy decoding when generating new tokens."
43
+ "default": "false",
44
+ "example": true
45
+ },
46
+ "frequency_penalty": {
47
+ "type": "number",
48
+ "format": "float",
49
+ "default": "null",
50
+ "example": 0.1,
51
+ "nullable": true,
52
+ "exclusiveMinimum": -2
53
+ },
54
+ "grammar": {
55
+ "allOf": [
56
+ {
57
+ "$ref": "#/$defs/TextGenerationInputGrammarType"
58
+ }
59
+ ],
60
+ "default": "null",
61
+ "nullable": true
42
62
  },
43
63
  "max_new_tokens": {
44
64
  "type": "integer",
45
- "description": "The maximum number of tokens to generate."
65
+ "format": "int32",
66
+ "default": "100",
67
+ "example": "20",
68
+ "nullable": true,
69
+ "minimum": 0
46
70
  },
47
71
  "repetition_penalty": {
48
72
  "type": "number",
49
- "description": "The parameter for repetition penalty. A value of 1.0 means no penalty. See [this paper](https://hf.co/papers/1909.05858) for more details."
73
+ "format": "float",
74
+ "default": "null",
75
+ "example": 1.03,
76
+ "nullable": true,
77
+ "exclusiveMinimum": 0
50
78
  },
51
79
  "return_full_text": {
52
80
  "type": "boolean",
53
- "description": "Whether to prepend the prompt to the generated text."
81
+ "default": "null",
82
+ "example": false,
83
+ "nullable": true
54
84
  },
55
85
  "seed": {
56
86
  "type": "integer",
57
- "description": "The random sampling seed."
87
+ "format": "int64",
88
+ "default": "null",
89
+ "example": "null",
90
+ "nullable": true,
91
+ "minimum": 0,
92
+ "exclusiveMinimum": 0
58
93
  },
59
- "stop_sequences": {
94
+ "stop": {
60
95
  "type": "array",
61
96
  "items": {
62
97
  "type": "string"
63
98
  },
64
- "description": "Stop generating tokens if a member of `stop_sequences` is generated."
99
+ "example": ["photographer"],
100
+ "maxItems": 4
65
101
  },
66
102
  "temperature": {
67
103
  "type": "number",
68
- "description": "The value used to modulate the logits distribution."
104
+ "format": "float",
105
+ "default": "null",
106
+ "example": 0.5,
107
+ "nullable": true,
108
+ "exclusiveMinimum": 0
69
109
  },
70
110
  "top_k": {
71
111
  "type": "integer",
72
- "description": "The number of highest probability vocabulary tokens to keep for top-k-filtering."
112
+ "format": "int32",
113
+ "default": "null",
114
+ "example": 10,
115
+ "nullable": true,
116
+ "exclusiveMinimum": 0
117
+ },
118
+ "top_n_tokens": {
119
+ "type": "integer",
120
+ "format": "int32",
121
+ "default": "null",
122
+ "example": 5,
123
+ "nullable": true,
124
+ "minimum": 0,
125
+ "exclusiveMinimum": 0
73
126
  },
74
127
  "top_p": {
75
128
  "type": "number",
76
- "description": "If set to < 1, only the smallest set of most probable tokens with probabilities that add up to `top_p` or higher are kept for generation."
129
+ "format": "float",
130
+ "default": "null",
131
+ "example": 0.95,
132
+ "nullable": true,
133
+ "maximum": 1,
134
+ "exclusiveMinimum": 0
77
135
  },
78
136
  "truncate": {
79
137
  "type": "integer",
80
- "description": "Truncate input tokens to the given size."
138
+ "default": "null",
139
+ "example": "null",
140
+ "nullable": true,
141
+ "minimum": 0
81
142
  },
82
143
  "typical_p": {
83
144
  "type": "number",
84
- "description": "Typical Decoding mass. See [Typical Decoding for Natural Language Generation](https://hf.co/papers/2202.00666) for more information"
145
+ "format": "float",
146
+ "default": "null",
147
+ "example": 0.95,
148
+ "nullable": true,
149
+ "maximum": 1,
150
+ "exclusiveMinimum": 0
85
151
  },
86
152
  "watermark": {
87
153
  "type": "boolean",
88
- "description": "Watermarking with [A Watermark for Large Language Models](https://hf.co/papers/2301.10226)"
154
+ "default": "false",
155
+ "example": true
89
156
  }
90
- }
157
+ },
158
+ "title": "TextGenerationInputGenerateParameters"
159
+ },
160
+ "TextGenerationInputGrammarType": {
161
+ "oneOf": [
162
+ {
163
+ "type": "object",
164
+ "required": ["type", "value"],
165
+ "properties": {
166
+ "type": {
167
+ "type": "string",
168
+ "enum": ["json"]
169
+ },
170
+ "value": {
171
+ "description": "A string that represents a [JSON Schema](https://json-schema.org/).\n\nJSON Schema is a declarative language that allows to annotate JSON documents\nwith types and descriptions."
172
+ }
173
+ }
174
+ },
175
+ {
176
+ "type": "object",
177
+ "required": ["type", "value"],
178
+ "properties": {
179
+ "type": {
180
+ "type": "string",
181
+ "enum": ["regex"]
182
+ },
183
+ "value": {
184
+ "type": "string"
185
+ }
186
+ }
187
+ }
188
+ ],
189
+ "discriminator": {
190
+ "propertyName": "type"
191
+ },
192
+ "title": "TextGenerationInputGrammarType"
91
193
  }
92
- },
93
- "required": ["inputs"]
194
+ }
94
195
  }