Skip to content

Commit 1aae6ac

Browse files
authored
Update TGI specs (+ define TextToSpeech independently) (#915)
This PR pulls latest changes from TGI specs. In particular: - updated `ChatCompletionInputMessageContent` => now supports single message (as before), array of messages and **sending image as input** (in case of VLMs) - new input: `stream_options` - tools input have been updated - more documented fields **Note:** TGI specs have a `guideline` input parameter for chat completion. I removed it from the official specs as it's a very specific parameter and subject to deletion in the near future (it was there to fix a chat template issue for `ShieldGemma` models). More context [here](https://huggingface.slack.com/archives/C05CFK1HM0T/p1726822675255589?thread_ts=1724852501.099809&cid=C05CFK1HM0T) (internal). **Note:** I also took the opportunity to define `TextToSpeech` specs independently from `TextToAudio` (otherwise the semi-automatic scripts are not working properly). Nothing has changed in the specs. I'll open a related PR on `huggingface_hub` side to reflect this change.
1 parent 5a92211 commit 1aae6ac

File tree

12 files changed

+444
-105
lines changed

12 files changed

+444
-105
lines changed

packages/tasks/scripts/inference-tei-import.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ async function _extractAndAdapt(task: string, mainComponentName: string, type: "
7373
}
7474

7575
// Add reference to components to export (and scan it too)
76-
const newRef = camelFullName + ref.replace(camelName, "");
76+
let newRef = camelFullName + ref.replace(camelName, "");
77+
// remove duplicated InputInput or OutputOutput in naming
78+
newRef = newRef.replace("InputInput", "Input").replace("OutputOutput", "Output");
7779
if (!filteredComponents[newRef]) {
7880
components[ref]["title"] = newRef; // Rename title to avoid conflicts
7981
filteredComponents[newRef] = components[ref];

packages/tasks/scripts/inference-tgi-import.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ async function _extractAndAdapt(task: string, mainComponentName: string, type: "
6666
}
6767

6868
// Add reference to components to export (and scan it too)
69-
const newRef = camelFullName + ref.replace(camelName, "");
69+
let newRef = camelFullName + ref.replace(camelName, "");
70+
// remove duplicated InputInput or OutputOutput in naming
71+
newRef = newRef.replace("InputInput", "Input").replace("OutputOutput", "Output");
7072
if (!filteredComponents[newRef]) {
7173
components[ref]["title"] = newRef; // Rename title to avoid conflicts
7274
filteredComponents[newRef] = components[ref];

packages/tasks/src/tasks/chat-completion/inference.ts

Lines changed: 66 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export interface ChatCompletionInput {
4949
* [UNUSED] ID of the model to use. See the model endpoint compatibility table for details
5050
* on which models work with the Chat API.
5151
*/
52-
model: string;
52+
model?: string;
5353
/**
5454
* UNUSED
5555
* How many chat completion choices to generate for each input message. Note that you will
@@ -63,12 +63,14 @@ export interface ChatCompletionInput {
6363
* increasing the model's likelihood to talk about new topics
6464
*/
6565
presence_penalty?: number;
66+
response_format?: ChatCompletionInputGrammarType;
6667
seed?: number;
6768
/**
6869
* Up to 4 sequences where the API will stop generating further tokens.
6970
*/
7071
stop?: string[];
7172
stream?: boolean;
73+
stream_options?: ChatCompletionInputStreamOptions;
7274
/**
7375
* What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the
7476
* output more random, while
@@ -77,7 +79,7 @@ export interface ChatCompletionInput {
7779
* We generally recommend altering this or `top_p` but not both.
7880
*/
7981
temperature?: number;
80-
tool_choice?: ChatCompletionInputToolType;
82+
tool_choice?: ChatCompletionInputTool;
8183
/**
8284
* A prompt to be appended before the tools
8385
*/
@@ -87,7 +89,7 @@ export interface ChatCompletionInput {
8789
* Use this to provide a list of
8890
* functions the model may generate JSON inputs for.
8991
*/
90-
tools?: ChatCompletionInputTool[];
92+
tools?: ToolElement[];
9193
/**
9294
* An integer between 0 and 5 specifying the number of most likely tokens to return at each
9395
* token position, each with
@@ -105,40 +107,78 @@ export interface ChatCompletionInput {
105107
}
106108

107109
export interface ChatCompletionInputMessage {
108-
content?: string;
110+
content: ChatCompletionInputMessageContent;
109111
name?: string;
110112
role: string;
111-
tool_calls?: ChatCompletionInputToolCall[];
112113
[property: string]: unknown;
113114
}
114115

115-
export interface ChatCompletionInputToolCall {
116-
function: ChatCompletionInputFunctionDefinition;
117-
id: number;
118-
type: string;
116+
export type ChatCompletionInputMessageContent = ChatCompletionInputMessageChunk[] | string;
117+
118+
export interface ChatCompletionInputMessageChunk {
119+
image_url?: ChatCompletionInputURL;
120+
text?: string;
121+
type: ChatCompletionInputMessageChunkType;
119122
[property: string]: unknown;
120123
}
121124

122-
export interface ChatCompletionInputFunctionDefinition {
123-
arguments: unknown;
124-
description?: string;
125-
name: string;
125+
export interface ChatCompletionInputURL {
126+
url: string;
126127
[property: string]: unknown;
127128
}
128129

129-
export type ChatCompletionInputToolType = "OneOf" | ChatCompletionInputToolTypeObject;
130+
export type ChatCompletionInputMessageChunkType = "text" | "image_url";
130131

131-
export interface ChatCompletionInputToolTypeObject {
132-
FunctionName: string;
132+
export interface ChatCompletionInputGrammarType {
133+
type: ChatCompletionInputGrammarTypeType;
134+
/**
135+
* A string that represents a [JSON Schema](https://json-schema.org/).
136+
*
137+
* JSON Schema is a declarative language that allows to annotate JSON documents
138+
* with types and descriptions.
139+
*/
140+
value: unknown;
141+
[property: string]: unknown;
142+
}
143+
144+
export type ChatCompletionInputGrammarTypeType = "json" | "regex";
145+
146+
export interface ChatCompletionInputStreamOptions {
147+
/**
148+
* If set, an additional chunk will be streamed before the data: [DONE] message. The usage
149+
* field on this chunk shows the token usage statistics for the entire request, and the
150+
* choices field will always be an empty array. All other chunks will also include a usage
151+
* field, but with a null value.
152+
*/
153+
include_usage: boolean;
133154
[property: string]: unknown;
134155
}
135156

136-
export interface ChatCompletionInputTool {
157+
export type ChatCompletionInputTool = ChatCompletionInputToolType | string;
158+
159+
export interface ChatCompletionInputToolType {
160+
function?: ChatCompletionInputFunctionName;
161+
[property: string]: unknown;
162+
}
163+
164+
export interface ChatCompletionInputFunctionName {
165+
name: string;
166+
[property: string]: unknown;
167+
}
168+
169+
export interface ToolElement {
137170
function: ChatCompletionInputFunctionDefinition;
138171
type: string;
139172
[property: string]: unknown;
140173
}
141174

175+
export interface ChatCompletionInputFunctionDefinition {
176+
arguments: unknown;
177+
description?: string;
178+
name: string;
179+
[property: string]: unknown;
180+
}
181+
142182
/**
143183
* Chat Completion Output.
144184
*
@@ -151,7 +191,6 @@ export interface ChatCompletionOutput {
151191
created: number;
152192
id: string;
153193
model: string;
154-
object: string;
155194
system_fingerprint: string;
156195
usage: ChatCompletionOutputUsage;
157196
[property: string]: unknown;
@@ -185,15 +224,14 @@ export interface ChatCompletionOutputTopLogprob {
185224

186225
export interface ChatCompletionOutputMessage {
187226
content?: string;
188-
name?: string;
189227
role: string;
190228
tool_calls?: ChatCompletionOutputToolCall[];
191229
[property: string]: unknown;
192230
}
193231

194232
export interface ChatCompletionOutputToolCall {
195233
function: ChatCompletionOutputFunctionDefinition;
196-
id: number;
234+
id: string;
197235
type: string;
198236
[property: string]: unknown;
199237
}
@@ -224,8 +262,8 @@ export interface ChatCompletionStreamOutput {
224262
created: number;
225263
id: string;
226264
model: string;
227-
object: string;
228265
system_fingerprint: string;
266+
usage?: ChatCompletionStreamOutputUsage;
229267
[property: string]: unknown;
230268
}
231269

@@ -275,3 +313,10 @@ export interface ChatCompletionStreamOutputTopLogprob {
275313
token: string;
276314
[property: string]: unknown;
277315
}
316+
317+
export interface ChatCompletionStreamOutputUsage {
318+
completion_tokens: number;
319+
prompt_tokens: number;
320+
total_tokens: number;
321+
[property: string]: unknown;
322+
}

0 commit comments

Comments
 (0)