Skip to content

Commit 399f484

Browse files
committed
Factorize generate parameters
1 parent bf48f5e commit 399f484

File tree

8 files changed

+123
-13
lines changed

8 files changed

+123
-13
lines changed

packages/tasks/src/scripts/inference-codegen.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ async function generateTypescript(inputData: InputData): Promise<SerializedRende
7474
* And writes that to the `inference.ts` file
7575
*
7676
*/
77-
7877
async function postProcessOutput(path2generated: string, outputSpec: Record<string, unknown>): Promise<void> {
7978
const source = ts.createSourceFile(
8079
path.basename(path2generated),
@@ -149,9 +148,12 @@ async function main() {
149148
.filter((entry) => entry.name !== "placeholder")
150149
.map(async (entry) => ({ task: entry.name, dirPath: path.join(entry.path, entry.name) }))
151150
);
152-
const allSpecFiles = allTasks
153-
.flatMap(({ dirPath }) => [path.join(dirPath, "spec", "input.json"), path.join(dirPath, "spec", "output.json")])
154-
.filter((filepath) => pathExists(filepath));
151+
const allSpecFiles = [
152+
path.join(tasksDir, "schema-utils.json"),
153+
...allTasks
154+
.flatMap(({ dirPath }) => [path.join(dirPath, "spec", "input.json"), path.join(dirPath, "spec", "output.json")])
155+
.filter((filepath) => pathExists(filepath)),
156+
];
155157

156158
for (const { task, dirPath } of allTasks) {
157159
const taskSpecDir = path.join(dirPath, "spec");

packages/tasks/src/tasks/automatic-speech-recognition/inference.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,35 @@ export interface AutomaticSpeechRecognitionInput {
1414
/**
1515
* Additional inference parameters
1616
*/
17-
parameters?: {
18-
[key: string]: unknown;
19-
};
17+
parameters?: AutomaticSpeechRecognitionParameters;
18+
[property: string]: unknown;
19+
}
20+
/**
21+
* Additional inference parameters
22+
*
23+
* Additional inference parameters for Automatic Speech Recognition
24+
*/
25+
export interface AutomaticSpeechRecognitionParameters {
26+
/**
27+
* Parametrization of the text generation process
28+
*/
29+
generate?: GenerationParameters;
30+
/**
31+
* Whether to output corresponding timestamps with the generated text
32+
*/
33+
returnTimestamps?: boolean;
34+
[property: string]: unknown;
35+
}
36+
/**
37+
* Parametrization of the text generation process
38+
*
39+
* Ad-hoc parametrization of the text generation process
40+
*/
41+
export interface GenerationParameters {
42+
/**
43+
* I can be the papa you'd be the mama
44+
*/
45+
temperature?: number;
2046
[property: string]: unknown;
2147
}
2248
export type AutomaticSpeechRecognitionOutput = AutomaticSpeechRecognitionOutputElement[];

packages/tasks/src/tasks/automatic-speech-recognition/spec/input.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,16 @@
1818
"title": "AutomaticSpeechRecognitionParameters",
1919
"description": "Additional inference parameters for Automatic Speech Recognition",
2020
"type": "object",
21-
"properties": {}
21+
"properties": {
22+
"returnTimestamps": {
23+
"type": "boolean",
24+
"description": "Whether to output corresponding timestamps with the generated text"
25+
},
26+
"generate": {
27+
"description": "Parametrization of the text generation process",
28+
"$ref": "/inference/schemas/schema-utils.json#/definitions/GenerationParameters"
29+
}
30+
}
2231
}
2332
},
2433
"required": ["data"]

packages/tasks/src/tasks/image-to-text/inference.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,28 @@ export interface ImageToTextInput {
2323
* Additional inference parameters for Image To Text
2424
*/
2525
export interface ImageToTextParameters {
26+
/**
27+
* Parametrization of the text generation process
28+
*/
29+
generate?: GenerationParameters;
2630
/**
2731
* The amount of maximum tokens to generate.
2832
*/
2933
maxNewTokens?: number;
3034
[property: string]: unknown;
3135
}
36+
/**
37+
* Parametrization of the text generation process
38+
*
39+
* Ad-hoc parametrization of the text generation process
40+
*/
41+
export interface GenerationParameters {
42+
/**
43+
* I can be the papa you'd be the mama
44+
*/
45+
temperature?: number;
46+
[property: string]: unknown;
47+
}
3248
export type ImageToTextOutput = ImageToTextOutputElement[];
3349
/**
3450
* Outputs of inference for the Image To Text task

packages/tasks/src/tasks/image-to-text/spec/input.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
"maxNewTokens": {
2323
"type": "integer",
2424
"description": "The amount of maximum tokens to generate."
25+
},
26+
"generate": {
27+
"description": "Parametrization of the text generation process",
28+
"$ref": "/inference/schemas/schema-utils.json#/definitions/GenerationParameters"
2529
}
2630
}
2731
}

packages/tasks/src/tasks/text-to-audio/inference.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,31 @@ export interface TextToAudioInput {
1414
/**
1515
* Additional inference parameters
1616
*/
17-
parameters?: {
18-
[key: string]: unknown;
19-
};
17+
parameters?: TextToAudioParameters;
18+
[property: string]: unknown;
19+
}
20+
/**
21+
* Additional inference parameters
22+
*
23+
* Additional inference parameters for Text To Audio
24+
*/
25+
export interface TextToAudioParameters {
26+
/**
27+
* Parametrization of the text generation process
28+
*/
29+
generate?: GenerationParameters;
30+
[property: string]: unknown;
31+
}
32+
/**
33+
* Parametrization of the text generation process
34+
*
35+
* Ad-hoc parametrization of the text generation process
36+
*/
37+
export interface GenerationParameters {
38+
/**
39+
* I can be the papa you'd be the mama
40+
*/
41+
temperature?: number;
2042
[property: string]: unknown;
2143
}
2244
export type TextToAudioOutput = TextToAudioOutputElement[];

packages/tasks/src/tasks/text-to-audio/spec/input.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
"title": "TextToAudioParameters",
2020
"description": "Additional inference parameters for Text To Audio",
2121
"type": "object",
22-
"properties": {}
22+
"properties": {
23+
"generate": {
24+
"description": "Parametrization of the text generation process",
25+
"$ref": "/inference/schemas/schema-utils.json#/definitions/GenerationParameters"
26+
}
27+
}
2328
}
2429
},
2530
"required": ["data"]

packages/tasks/src/tasks/text-to-speech/inference.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,33 @@ export interface TextToSpeechInput {
1717
/**
1818
* Additional inference parameters
1919
*/
20-
parameters?: { [key: string]: unknown };
20+
parameters?: TextToAudioParameters;
21+
[property: string]: unknown;
22+
}
23+
24+
/**
25+
* Additional inference parameters
26+
*
27+
* Additional inference parameters for Text To Audio
28+
*/
29+
export interface TextToAudioParameters {
30+
/**
31+
* Parametrization of the text generation process
32+
*/
33+
generate?: GenerationParameters;
34+
[property: string]: unknown;
35+
}
36+
37+
/**
38+
* Parametrization of the text generation process
39+
*
40+
* Ad-hoc parametrization of the text generation process
41+
*/
42+
export interface GenerationParameters {
43+
/**
44+
* I can be the papa you'd be the mama
45+
*/
46+
temperature?: number;
2147
[property: string]: unknown;
2248
}
2349

0 commit comments

Comments
 (0)