@huggingface/inference 3.6.2 → 3.7.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.
- package/README.md +0 -25
- package/dist/index.cjs +1232 -898
- package/dist/index.js +1234 -900
- package/dist/src/config.d.ts +1 -0
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/lib/getProviderHelper.d.ts +37 -0
- package/dist/src/lib/getProviderHelper.d.ts.map +1 -0
- package/dist/src/lib/makeRequestOptions.d.ts +0 -2
- package/dist/src/lib/makeRequestOptions.d.ts.map +1 -1
- package/dist/src/providers/black-forest-labs.d.ts +14 -18
- package/dist/src/providers/black-forest-labs.d.ts.map +1 -1
- package/dist/src/providers/cerebras.d.ts +4 -2
- package/dist/src/providers/cerebras.d.ts.map +1 -1
- package/dist/src/providers/cohere.d.ts +5 -2
- package/dist/src/providers/cohere.d.ts.map +1 -1
- package/dist/src/providers/fal-ai.d.ts +50 -3
- package/dist/src/providers/fal-ai.d.ts.map +1 -1
- package/dist/src/providers/fireworks-ai.d.ts +5 -2
- package/dist/src/providers/fireworks-ai.d.ts.map +1 -1
- package/dist/src/providers/hf-inference.d.ts +125 -2
- package/dist/src/providers/hf-inference.d.ts.map +1 -1
- package/dist/src/providers/hyperbolic.d.ts +31 -2
- package/dist/src/providers/hyperbolic.d.ts.map +1 -1
- package/dist/src/providers/nebius.d.ts +20 -18
- package/dist/src/providers/nebius.d.ts.map +1 -1
- package/dist/src/providers/novita.d.ts +21 -18
- package/dist/src/providers/novita.d.ts.map +1 -1
- package/dist/src/providers/openai.d.ts +4 -2
- package/dist/src/providers/openai.d.ts.map +1 -1
- package/dist/src/providers/providerHelper.d.ts +182 -0
- package/dist/src/providers/providerHelper.d.ts.map +1 -0
- package/dist/src/providers/replicate.d.ts +23 -19
- package/dist/src/providers/replicate.d.ts.map +1 -1
- package/dist/src/providers/sambanova.d.ts +4 -2
- package/dist/src/providers/sambanova.d.ts.map +1 -1
- package/dist/src/providers/together.d.ts +32 -2
- package/dist/src/providers/together.d.ts.map +1 -1
- package/dist/src/snippets/getInferenceSnippets.d.ts.map +1 -1
- package/dist/src/tasks/audio/audioClassification.d.ts.map +1 -1
- package/dist/src/tasks/audio/automaticSpeechRecognition.d.ts.map +1 -1
- package/dist/src/tasks/audio/textToSpeech.d.ts.map +1 -1
- package/dist/src/tasks/audio/utils.d.ts +2 -1
- package/dist/src/tasks/audio/utils.d.ts.map +1 -1
- package/dist/src/tasks/custom/request.d.ts +1 -2
- package/dist/src/tasks/custom/request.d.ts.map +1 -1
- package/dist/src/tasks/custom/streamingRequest.d.ts +1 -2
- package/dist/src/tasks/custom/streamingRequest.d.ts.map +1 -1
- package/dist/src/tasks/cv/imageClassification.d.ts.map +1 -1
- package/dist/src/tasks/cv/imageSegmentation.d.ts.map +1 -1
- package/dist/src/tasks/cv/imageToImage.d.ts.map +1 -1
- package/dist/src/tasks/cv/imageToText.d.ts.map +1 -1
- package/dist/src/tasks/cv/objectDetection.d.ts +1 -1
- package/dist/src/tasks/cv/objectDetection.d.ts.map +1 -1
- package/dist/src/tasks/cv/textToImage.d.ts.map +1 -1
- package/dist/src/tasks/cv/textToVideo.d.ts +1 -1
- package/dist/src/tasks/cv/textToVideo.d.ts.map +1 -1
- package/dist/src/tasks/cv/zeroShotImageClassification.d.ts +1 -1
- package/dist/src/tasks/cv/zeroShotImageClassification.d.ts.map +1 -1
- package/dist/src/tasks/index.d.ts +6 -6
- package/dist/src/tasks/index.d.ts.map +1 -1
- package/dist/src/tasks/multimodal/documentQuestionAnswering.d.ts +1 -1
- package/dist/src/tasks/multimodal/documentQuestionAnswering.d.ts.map +1 -1
- package/dist/src/tasks/multimodal/visualQuestionAnswering.d.ts.map +1 -1
- package/dist/src/tasks/nlp/chatCompletion.d.ts +1 -1
- package/dist/src/tasks/nlp/chatCompletion.d.ts.map +1 -1
- package/dist/src/tasks/nlp/chatCompletionStream.d.ts +1 -1
- package/dist/src/tasks/nlp/chatCompletionStream.d.ts.map +1 -1
- package/dist/src/tasks/nlp/featureExtraction.d.ts.map +1 -1
- package/dist/src/tasks/nlp/fillMask.d.ts.map +1 -1
- package/dist/src/tasks/nlp/questionAnswering.d.ts.map +1 -1
- package/dist/src/tasks/nlp/sentenceSimilarity.d.ts.map +1 -1
- package/dist/src/tasks/nlp/summarization.d.ts.map +1 -1
- package/dist/src/tasks/nlp/tableQuestionAnswering.d.ts.map +1 -1
- package/dist/src/tasks/nlp/textClassification.d.ts.map +1 -1
- package/dist/src/tasks/nlp/textGeneration.d.ts.map +1 -1
- package/dist/src/tasks/nlp/tokenClassification.d.ts.map +1 -1
- package/dist/src/tasks/nlp/translation.d.ts.map +1 -1
- package/dist/src/tasks/nlp/zeroShotClassification.d.ts.map +1 -1
- package/dist/src/tasks/tabular/tabularClassification.d.ts.map +1 -1
- package/dist/src/tasks/tabular/tabularRegression.d.ts.map +1 -1
- package/dist/src/types.d.ts +10 -13
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/request.d.ts +27 -0
- package/dist/src/utils/request.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/config.ts +1 -0
- package/src/lib/getProviderHelper.ts +270 -0
- package/src/lib/makeRequestOptions.ts +36 -90
- package/src/providers/black-forest-labs.ts +73 -22
- package/src/providers/cerebras.ts +6 -27
- package/src/providers/cohere.ts +9 -28
- package/src/providers/fal-ai.ts +195 -77
- package/src/providers/fireworks-ai.ts +8 -29
- package/src/providers/hf-inference.ts +555 -34
- package/src/providers/hyperbolic.ts +107 -29
- package/src/providers/nebius.ts +65 -29
- package/src/providers/novita.ts +68 -32
- package/src/providers/openai.ts +6 -32
- package/src/providers/providerHelper.ts +354 -0
- package/src/providers/replicate.ts +124 -34
- package/src/providers/sambanova.ts +5 -30
- package/src/providers/together.ts +92 -28
- package/src/snippets/getInferenceSnippets.ts +16 -9
- package/src/snippets/templates.exported.ts +2 -2
- package/src/tasks/audio/audioClassification.ts +6 -9
- package/src/tasks/audio/audioToAudio.ts +5 -28
- package/src/tasks/audio/automaticSpeechRecognition.ts +7 -6
- package/src/tasks/audio/textToSpeech.ts +6 -30
- package/src/tasks/audio/utils.ts +2 -1
- package/src/tasks/custom/request.ts +7 -34
- package/src/tasks/custom/streamingRequest.ts +5 -87
- package/src/tasks/cv/imageClassification.ts +5 -9
- package/src/tasks/cv/imageSegmentation.ts +5 -10
- package/src/tasks/cv/imageToImage.ts +5 -8
- package/src/tasks/cv/imageToText.ts +8 -13
- package/src/tasks/cv/objectDetection.ts +6 -21
- package/src/tasks/cv/textToImage.ts +10 -138
- package/src/tasks/cv/textToVideo.ts +11 -59
- package/src/tasks/cv/zeroShotImageClassification.ts +7 -12
- package/src/tasks/index.ts +6 -6
- package/src/tasks/multimodal/documentQuestionAnswering.ts +10 -26
- package/src/tasks/multimodal/visualQuestionAnswering.ts +6 -12
- package/src/tasks/nlp/chatCompletion.ts +7 -23
- package/src/tasks/nlp/chatCompletionStream.ts +4 -5
- package/src/tasks/nlp/featureExtraction.ts +5 -20
- package/src/tasks/nlp/fillMask.ts +5 -18
- package/src/tasks/nlp/questionAnswering.ts +5 -23
- package/src/tasks/nlp/sentenceSimilarity.ts +5 -18
- package/src/tasks/nlp/summarization.ts +5 -8
- package/src/tasks/nlp/tableQuestionAnswering.ts +5 -29
- package/src/tasks/nlp/textClassification.ts +8 -14
- package/src/tasks/nlp/textGeneration.ts +13 -80
- package/src/tasks/nlp/textGenerationStream.ts +2 -2
- package/src/tasks/nlp/tokenClassification.ts +8 -24
- package/src/tasks/nlp/translation.ts +5 -8
- package/src/tasks/nlp/zeroShotClassification.ts +8 -22
- package/src/tasks/tabular/tabularClassification.ts +5 -8
- package/src/tasks/tabular/tabularRegression.ts +5 -8
- package/src/types.ts +11 -14
- package/src/utils/request.ts +161 -0
|
@@ -14,35 +14,113 @@
|
|
|
14
14
|
*
|
|
15
15
|
* Thanks!
|
|
16
16
|
*/
|
|
17
|
-
import type {
|
|
17
|
+
import type { ChatCompletionOutput, TextGenerationOutput } from "@huggingface/tasks";
|
|
18
|
+
import { InferenceOutputError } from "../lib/InferenceOutputError";
|
|
19
|
+
import type { BodyParams, UrlParams } from "../types";
|
|
20
|
+
import { omit } from "../utils/omit";
|
|
21
|
+
import {
|
|
22
|
+
BaseConversationalTask,
|
|
23
|
+
BaseTextGenerationTask,
|
|
24
|
+
TaskProviderHelper,
|
|
25
|
+
type TextToImageTaskHelper,
|
|
26
|
+
} from "./providerHelper";
|
|
18
27
|
|
|
19
28
|
const HYPERBOLIC_API_BASE_URL = "https://api.hyperbolic.xyz";
|
|
20
29
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
30
|
+
export interface HyperbolicTextCompletionOutput extends Omit<ChatCompletionOutput, "choices"> {
|
|
31
|
+
choices: Array<{
|
|
32
|
+
message: { content: string };
|
|
33
|
+
}>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface HyperbolicTextToImageOutput {
|
|
37
|
+
images: Array<{ image: string }>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export class HyperbolicConversationalTask extends BaseConversationalTask {
|
|
41
|
+
constructor() {
|
|
42
|
+
super("hyperbolic", HYPERBOLIC_API_BASE_URL);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export class HyperbolicTextGenerationTask extends BaseTextGenerationTask {
|
|
47
|
+
constructor() {
|
|
48
|
+
super("hyperbolic", HYPERBOLIC_API_BASE_URL);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
override makeRoute(): string {
|
|
52
|
+
return "v1/chat/completions";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
override preparePayload(params: BodyParams): Record<string, unknown> {
|
|
56
|
+
return {
|
|
57
|
+
messages: [{ content: params.args.inputs, role: "user" }],
|
|
58
|
+
...(params.args.parameters
|
|
59
|
+
? {
|
|
60
|
+
max_tokens: (params.args.parameters as Record<string, unknown>).max_new_tokens,
|
|
61
|
+
...omit(params.args.parameters as Record<string, unknown>, "max_new_tokens"),
|
|
62
|
+
}
|
|
63
|
+
: undefined),
|
|
64
|
+
...omit(params.args, ["inputs", "parameters"]),
|
|
65
|
+
model: params.model,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
override async getResponse(response: HyperbolicTextCompletionOutput): Promise<TextGenerationOutput> {
|
|
70
|
+
if (
|
|
71
|
+
typeof response === "object" &&
|
|
72
|
+
"choices" in response &&
|
|
73
|
+
Array.isArray(response?.choices) &&
|
|
74
|
+
typeof response?.model === "string"
|
|
75
|
+
) {
|
|
76
|
+
const completion = response.choices[0];
|
|
77
|
+
return {
|
|
78
|
+
generated_text: completion.message.content,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
throw new InferenceOutputError("Expected Hyperbolic text generation response format");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export class HyperbolicTextToImageTask extends TaskProviderHelper implements TextToImageTaskHelper {
|
|
87
|
+
constructor() {
|
|
88
|
+
super("hyperbolic", HYPERBOLIC_API_BASE_URL);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
makeRoute(params: UrlParams): string {
|
|
92
|
+
void params;
|
|
93
|
+
return `/v1/images/generations`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
preparePayload(params: BodyParams): Record<string, unknown> {
|
|
97
|
+
return {
|
|
98
|
+
...omit(params.args, ["inputs", "parameters"]),
|
|
99
|
+
...(params.args.parameters as Record<string, unknown>),
|
|
100
|
+
prompt: params.args.inputs,
|
|
101
|
+
model_name: params.model,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async getResponse(
|
|
106
|
+
response: HyperbolicTextToImageOutput,
|
|
107
|
+
url?: string,
|
|
108
|
+
headers?: HeadersInit,
|
|
109
|
+
outputType?: "url" | "blob"
|
|
110
|
+
): Promise<string | Blob> {
|
|
111
|
+
if (
|
|
112
|
+
typeof response === "object" &&
|
|
113
|
+
"images" in response &&
|
|
114
|
+
Array.isArray(response.images) &&
|
|
115
|
+
response.images[0] &&
|
|
116
|
+
typeof response.images[0].image === "string"
|
|
117
|
+
) {
|
|
118
|
+
if (outputType === "url") {
|
|
119
|
+
return `data:image/jpeg;base64,${response.images[0].image}`;
|
|
120
|
+
}
|
|
121
|
+
return fetch(`data:image/jpeg;base64,${response.images[0].image}`).then((res) => res.blob());
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
throw new InferenceOutputError("Expected Hyperbolic text-to-image response format");
|
|
125
|
+
}
|
|
126
|
+
}
|
package/src/providers/nebius.ts
CHANGED
|
@@ -14,41 +14,77 @@
|
|
|
14
14
|
*
|
|
15
15
|
* Thanks!
|
|
16
16
|
*/
|
|
17
|
-
import
|
|
17
|
+
import { InferenceOutputError } from "../lib/InferenceOutputError";
|
|
18
|
+
import type { BodyParams, UrlParams } from "../types";
|
|
19
|
+
import { omit } from "../utils/omit";
|
|
20
|
+
import {
|
|
21
|
+
BaseConversationalTask,
|
|
22
|
+
BaseTextGenerationTask,
|
|
23
|
+
TaskProviderHelper,
|
|
24
|
+
type TextToImageTaskHelper,
|
|
25
|
+
} from "./providerHelper";
|
|
18
26
|
|
|
19
27
|
const NEBIUS_API_BASE_URL = "https://api.studio.nebius.ai";
|
|
20
28
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
29
|
+
interface NebiusBase64ImageGeneration {
|
|
30
|
+
data: Array<{
|
|
31
|
+
b64_json: string;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
24
34
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
35
|
+
export class NebiusConversationalTask extends BaseConversationalTask {
|
|
36
|
+
constructor() {
|
|
37
|
+
super("nebius", NEBIUS_API_BASE_URL);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
31
40
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
41
|
+
export class NebiusTextGenerationTask extends BaseTextGenerationTask {
|
|
42
|
+
constructor() {
|
|
43
|
+
super("nebius", NEBIUS_API_BASE_URL);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
35
46
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
47
|
+
export class NebiusTextToImageTask extends TaskProviderHelper implements TextToImageTaskHelper {
|
|
48
|
+
constructor() {
|
|
49
|
+
super("nebius", NEBIUS_API_BASE_URL);
|
|
39
50
|
}
|
|
40
|
-
|
|
41
|
-
|
|
51
|
+
|
|
52
|
+
preparePayload(params: BodyParams): Record<string, unknown> {
|
|
53
|
+
return {
|
|
54
|
+
...omit(params.args, ["inputs", "parameters"]),
|
|
55
|
+
...(params.args.parameters as Record<string, unknown>),
|
|
56
|
+
response_format: "b64_json",
|
|
57
|
+
prompt: params.args.inputs,
|
|
58
|
+
model: params.model,
|
|
59
|
+
};
|
|
42
60
|
}
|
|
43
|
-
|
|
44
|
-
|
|
61
|
+
|
|
62
|
+
makeRoute(params: UrlParams): string {
|
|
63
|
+
void params;
|
|
64
|
+
return "v1/images/generations";
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async getResponse(
|
|
68
|
+
response: NebiusBase64ImageGeneration,
|
|
69
|
+
url?: string,
|
|
70
|
+
headers?: HeadersInit,
|
|
71
|
+
outputType?: "url" | "blob"
|
|
72
|
+
): Promise<string | Blob> {
|
|
73
|
+
if (
|
|
74
|
+
typeof response === "object" &&
|
|
75
|
+
"data" in response &&
|
|
76
|
+
Array.isArray(response.data) &&
|
|
77
|
+
response.data.length > 0 &&
|
|
78
|
+
"b64_json" in response.data[0] &&
|
|
79
|
+
typeof response.data[0].b64_json === "string"
|
|
80
|
+
) {
|
|
81
|
+
const base64Data = response.data[0].b64_json;
|
|
82
|
+
if (outputType === "url") {
|
|
83
|
+
return `data:image/jpeg;base64,${base64Data}`;
|
|
84
|
+
}
|
|
85
|
+
return fetch(`data:image/jpeg;base64,${base64Data}`).then((res) => res.blob());
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
throw new InferenceOutputError("Expected Nebius text-to-image response format");
|
|
45
89
|
}
|
|
46
|
-
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export const NEBIUS_CONFIG: ProviderConfig = {
|
|
50
|
-
makeBaseUrl,
|
|
51
|
-
makeBody,
|
|
52
|
-
makeHeaders,
|
|
53
|
-
makeUrl,
|
|
54
|
-
};
|
|
90
|
+
}
|
package/src/providers/novita.ts
CHANGED
|
@@ -14,38 +14,74 @@
|
|
|
14
14
|
*
|
|
15
15
|
* Thanks!
|
|
16
16
|
*/
|
|
17
|
-
import
|
|
17
|
+
import { InferenceOutputError } from "../lib/InferenceOutputError";
|
|
18
|
+
import { isUrl } from "../lib/isUrl";
|
|
19
|
+
import type { BodyParams, UrlParams } from "../types";
|
|
20
|
+
import { omit } from "../utils/omit";
|
|
21
|
+
import {
|
|
22
|
+
BaseConversationalTask,
|
|
23
|
+
BaseTextGenerationTask,
|
|
24
|
+
TaskProviderHelper,
|
|
25
|
+
type TextToVideoTaskHelper,
|
|
26
|
+
} from "./providerHelper";
|
|
18
27
|
|
|
19
28
|
const NOVITA_API_BASE_URL = "https://api.novita.ai";
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
const makeBody = (params: BodyParams): Record<string, unknown> => {
|
|
25
|
-
return {
|
|
26
|
-
...params.args,
|
|
27
|
-
...(params.chatCompletion ? { model: params.model } : undefined),
|
|
29
|
+
export interface NovitaOutput {
|
|
30
|
+
video: {
|
|
31
|
+
video_url: string;
|
|
28
32
|
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
33
|
+
}
|
|
34
|
+
export class NovitaTextGenerationTask extends BaseTextGenerationTask {
|
|
35
|
+
constructor() {
|
|
36
|
+
super("novita", NOVITA_API_BASE_URL);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
override makeRoute(): string {
|
|
40
|
+
return "/v3/openai/chat/completions";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class NovitaConversationalTask extends BaseConversationalTask {
|
|
45
|
+
constructor() {
|
|
46
|
+
super("novita", NOVITA_API_BASE_URL);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
override makeRoute(): string {
|
|
50
|
+
return "/v3/openai/chat/completions";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export class NovitaTextToVideoTask extends TaskProviderHelper implements TextToVideoTaskHelper {
|
|
54
|
+
constructor() {
|
|
55
|
+
super("novita", NOVITA_API_BASE_URL);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
makeRoute(params: UrlParams): string {
|
|
59
|
+
return `/v3/hf/${params.model}`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
preparePayload(params: BodyParams): Record<string, unknown> {
|
|
63
|
+
return {
|
|
64
|
+
...omit(params.args, ["inputs", "parameters"]),
|
|
65
|
+
...(params.args.parameters as Record<string, unknown>),
|
|
66
|
+
prompt: params.args.inputs,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
override async getResponse(response: NovitaOutput): Promise<Blob> {
|
|
70
|
+
const isValidOutput =
|
|
71
|
+
typeof response === "object" &&
|
|
72
|
+
!!response &&
|
|
73
|
+
"video" in response &&
|
|
74
|
+
typeof response.video === "object" &&
|
|
75
|
+
!!response.video &&
|
|
76
|
+
"video_url" in response.video &&
|
|
77
|
+
typeof response.video.video_url === "string" &&
|
|
78
|
+
isUrl(response.video.video_url);
|
|
79
|
+
|
|
80
|
+
if (!isValidOutput) {
|
|
81
|
+
throw new InferenceOutputError("Expected { video: { video_url: string } }");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const urlResponse = await fetch(response.video.video_url);
|
|
85
|
+
return await urlResponse.blob();
|
|
86
|
+
}
|
|
87
|
+
}
|
package/src/providers/openai.ts
CHANGED
|
@@ -1,39 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Special case: provider configuration for a private models provider (OpenAI in this case).
|
|
3
3
|
*/
|
|
4
|
-
import
|
|
4
|
+
import { BaseConversationalTask } from "./providerHelper";
|
|
5
5
|
|
|
6
6
|
const OPENAI_API_BASE_URL = "https://api.openai.com";
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const makeBody = (params: BodyParams): Record<string, unknown> => {
|
|
13
|
-
if (!params.chatCompletion) {
|
|
14
|
-
throw new Error("OpenAI only supports chat completions.");
|
|
8
|
+
export class OpenAIConversationalTask extends BaseConversationalTask {
|
|
9
|
+
constructor() {
|
|
10
|
+
// Pass clientSideRoutingOnly: true to the constructor
|
|
11
|
+
super("openai", OPENAI_API_BASE_URL, true);
|
|
15
12
|
}
|
|
16
|
-
|
|
17
|
-
...params.args,
|
|
18
|
-
model: params.model,
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const makeHeaders = (params: HeaderParams): Record<string, string> => {
|
|
23
|
-
return { Authorization: `Bearer ${params.accessToken}` };
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const makeUrl = (params: UrlParams): string => {
|
|
27
|
-
if (!params.chatCompletion) {
|
|
28
|
-
throw new Error("OpenAI only supports chat completions.");
|
|
29
|
-
}
|
|
30
|
-
return `${params.baseUrl}/v1/chat/completions`;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const OPENAI_CONFIG: ProviderConfig = {
|
|
34
|
-
makeBaseUrl,
|
|
35
|
-
makeBody,
|
|
36
|
-
makeHeaders,
|
|
37
|
-
makeUrl,
|
|
38
|
-
clientSideRoutingOnly: true,
|
|
39
|
-
};
|
|
13
|
+
}
|