@huggingface/inference 3.7.0 → 3.8.0
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/dist/index.cjs +1369 -941
- package/dist/index.js +1371 -943
- package/dist/src/lib/getInferenceProviderMapping.d.ts +21 -0
- package/dist/src/lib/getInferenceProviderMapping.d.ts.map +1 -0
- 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 +5 -5
- 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/consts.d.ts +2 -3
- package/dist/src/providers/consts.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 +126 -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 +2 -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 +0 -2
- package/dist/src/tasks/custom/request.d.ts.map +1 -1
- package/dist/src/tasks/custom/streamingRequest.d.ts +0 -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.map +1 -1
- package/dist/src/tasks/cv/textToImage.d.ts.map +1 -1
- package/dist/src/tasks/cv/textToVideo.d.ts.map +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.map +1 -1
- package/dist/src/tasks/multimodal/visualQuestionAnswering.d.ts.map +1 -1
- package/dist/src/tasks/nlp/chatCompletion.d.ts.map +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/textGenerationStream.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 +5 -13
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/request.d.ts +3 -2
- package/dist/src/utils/request.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/lib/getInferenceProviderMapping.ts +96 -0
- package/src/lib/getProviderHelper.ts +270 -0
- package/src/lib/makeRequestOptions.ts +78 -97
- 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/consts.ts +5 -2
- package/src/providers/fal-ai.ts +224 -77
- package/src/providers/fireworks-ai.ts +8 -29
- package/src/providers/hf-inference.ts +557 -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 +39 -14
- package/src/snippets/templates.exported.ts +25 -25
- package/src/tasks/audio/audioClassification.ts +5 -8
- package/src/tasks/audio/audioToAudio.ts +4 -27
- package/src/tasks/audio/automaticSpeechRecognition.ts +5 -4
- package/src/tasks/audio/textToSpeech.ts +5 -29
- package/src/tasks/audio/utils.ts +2 -1
- package/src/tasks/custom/request.ts +3 -3
- package/src/tasks/custom/streamingRequest.ts +4 -3
- package/src/tasks/cv/imageClassification.ts +4 -8
- package/src/tasks/cv/imageSegmentation.ts +4 -9
- package/src/tasks/cv/imageToImage.ts +4 -7
- package/src/tasks/cv/imageToText.ts +4 -7
- package/src/tasks/cv/objectDetection.ts +4 -19
- package/src/tasks/cv/textToImage.ts +9 -137
- package/src/tasks/cv/textToVideo.ts +17 -64
- package/src/tasks/cv/zeroShotImageClassification.ts +4 -8
- package/src/tasks/index.ts +6 -6
- package/src/tasks/multimodal/documentQuestionAnswering.ts +4 -19
- package/src/tasks/multimodal/visualQuestionAnswering.ts +4 -12
- package/src/tasks/nlp/chatCompletion.ts +5 -20
- package/src/tasks/nlp/chatCompletionStream.ts +4 -3
- package/src/tasks/nlp/featureExtraction.ts +4 -19
- package/src/tasks/nlp/fillMask.ts +4 -17
- package/src/tasks/nlp/questionAnswering.ts +11 -26
- package/src/tasks/nlp/sentenceSimilarity.ts +4 -8
- package/src/tasks/nlp/summarization.ts +4 -7
- package/src/tasks/nlp/tableQuestionAnswering.ts +10 -30
- package/src/tasks/nlp/textClassification.ts +4 -9
- package/src/tasks/nlp/textGeneration.ts +11 -79
- package/src/tasks/nlp/textGenerationStream.ts +3 -1
- package/src/tasks/nlp/tokenClassification.ts +11 -23
- package/src/tasks/nlp/translation.ts +4 -7
- package/src/tasks/nlp/zeroShotClassification.ts +11 -21
- package/src/tasks/tabular/tabularClassification.ts +4 -7
- package/src/tasks/tabular/tabularRegression.ts +4 -7
- package/src/types.ts +5 -14
- package/src/utils/request.ts +7 -4
- package/dist/src/lib/getProviderModelId.d.ts +0 -10
- package/dist/src/lib/getProviderModelId.d.ts.map +0 -1
- package/src/lib/getProviderModelId.ts +0 -74
package/src/providers/fal-ai.ts
CHANGED
|
@@ -14,109 +14,256 @@
|
|
|
14
14
|
*
|
|
15
15
|
* Thanks!
|
|
16
16
|
*/
|
|
17
|
+
import type { AutomaticSpeechRecognitionOutput } from "@huggingface/tasks";
|
|
17
18
|
import { InferenceOutputError } from "../lib/InferenceOutputError";
|
|
18
19
|
import { isUrl } from "../lib/isUrl";
|
|
19
|
-
import type { BodyParams, HeaderParams,
|
|
20
|
+
import type { BodyParams, HeaderParams, ModelId, UrlParams } from "../types";
|
|
20
21
|
import { delay } from "../utils/delay";
|
|
22
|
+
import { omit } from "../utils/omit";
|
|
23
|
+
import {
|
|
24
|
+
type AutomaticSpeechRecognitionTaskHelper,
|
|
25
|
+
TaskProviderHelper,
|
|
26
|
+
type TextToImageTaskHelper,
|
|
27
|
+
type TextToVideoTaskHelper,
|
|
28
|
+
} from "./providerHelper";
|
|
29
|
+
import { HF_HUB_URL } from "../config";
|
|
21
30
|
|
|
22
|
-
|
|
23
|
-
|
|
31
|
+
export interface FalAiQueueOutput {
|
|
32
|
+
request_id: string;
|
|
33
|
+
status: string;
|
|
34
|
+
response_url: string;
|
|
35
|
+
}
|
|
24
36
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
37
|
+
interface FalAITextToImageOutput {
|
|
38
|
+
images: Array<{
|
|
39
|
+
url: string;
|
|
40
|
+
}>;
|
|
41
|
+
}
|
|
28
42
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
43
|
+
interface FalAIAutomaticSpeechRecognitionOutput {
|
|
44
|
+
text: string;
|
|
45
|
+
}
|
|
32
46
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
47
|
+
interface FalAITextToSpeechOutput {
|
|
48
|
+
audio: {
|
|
49
|
+
url: string;
|
|
50
|
+
content_type: string;
|
|
36
51
|
};
|
|
37
|
-
}
|
|
52
|
+
}
|
|
53
|
+
export const FAL_AI_SUPPORTED_BLOB_TYPES = ["audio/mpeg", "audio/mp4", "audio/wav", "audio/x-wav"];
|
|
38
54
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return `${baseUrl}?_subdomain=queue`;
|
|
55
|
+
abstract class FalAITask extends TaskProviderHelper {
|
|
56
|
+
constructor(url?: string) {
|
|
57
|
+
super("fal-ai", url || "https://fal.run");
|
|
43
58
|
}
|
|
44
|
-
return baseUrl;
|
|
45
|
-
};
|
|
46
59
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
60
|
+
preparePayload(params: BodyParams): Record<string, unknown> {
|
|
61
|
+
return params.args;
|
|
62
|
+
}
|
|
63
|
+
makeRoute(params: UrlParams): string {
|
|
64
|
+
return `/${params.model}`;
|
|
65
|
+
}
|
|
66
|
+
override prepareHeaders(params: HeaderParams, binary: boolean): Record<string, string> {
|
|
67
|
+
const headers: Record<string, string> = {
|
|
68
|
+
Authorization:
|
|
69
|
+
params.authMethod !== "provider-key" ? `Bearer ${params.accessToken}` : `Key ${params.accessToken}`,
|
|
70
|
+
};
|
|
71
|
+
if (!binary) {
|
|
72
|
+
headers["Content-Type"] = "application/json";
|
|
73
|
+
}
|
|
74
|
+
return headers;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
53
77
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
78
|
+
function buildLoraPath(modelId: ModelId, adapterWeightsPath: string): string {
|
|
79
|
+
return `${HF_HUB_URL}/${modelId}/resolve/main/${adapterWeightsPath}`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export class FalAITextToImageTask extends FalAITask implements TextToImageTaskHelper {
|
|
83
|
+
override preparePayload(params: BodyParams): Record<string, unknown> {
|
|
84
|
+
const payload: Record<string, unknown> = {
|
|
85
|
+
...omit(params.args, ["inputs", "parameters"]),
|
|
86
|
+
...(params.args.parameters as Record<string, unknown>),
|
|
87
|
+
sync_mode: true,
|
|
88
|
+
prompt: params.args.inputs,
|
|
89
|
+
...(params.mapping?.adapter === "lora" && params.mapping.adapterWeightsPath
|
|
90
|
+
? {
|
|
91
|
+
loras: [
|
|
92
|
+
{
|
|
93
|
+
path: buildLoraPath(params.mapping.hfModelId, params.mapping.adapterWeightsPath),
|
|
94
|
+
scale: 1,
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
}
|
|
98
|
+
: undefined),
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
if (params.mapping?.adapter === "lora" && params.mapping.adapterWeightsPath) {
|
|
102
|
+
payload.loras = [
|
|
103
|
+
{
|
|
104
|
+
path: buildLoraPath(params.mapping.hfModelId, params.mapping.adapterWeightsPath),
|
|
105
|
+
scale: 1,
|
|
106
|
+
},
|
|
107
|
+
];
|
|
108
|
+
if (params.mapping.providerId === "fal-ai/lora") {
|
|
109
|
+
payload.model_name = "stabilityai/stable-diffusion-xl-base-1.0";
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return payload;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
override async getResponse(response: FalAITextToImageOutput, outputType?: "url" | "blob"): Promise<string | Blob> {
|
|
117
|
+
if (
|
|
118
|
+
typeof response === "object" &&
|
|
119
|
+
"images" in response &&
|
|
120
|
+
Array.isArray(response.images) &&
|
|
121
|
+
response.images.length > 0 &&
|
|
122
|
+
"url" in response.images[0] &&
|
|
123
|
+
typeof response.images[0].url === "string"
|
|
124
|
+
) {
|
|
125
|
+
if (outputType === "url") {
|
|
126
|
+
return response.images[0].url;
|
|
127
|
+
}
|
|
128
|
+
const urlResponse = await fetch(response.images[0].url);
|
|
129
|
+
return await urlResponse.blob();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
throw new InferenceOutputError("Expected Fal.ai text-to-image response format");
|
|
133
|
+
}
|
|
58
134
|
}
|
|
59
135
|
|
|
60
|
-
export
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
):
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
136
|
+
export class FalAITextToVideoTask extends FalAITask implements TextToVideoTaskHelper {
|
|
137
|
+
constructor() {
|
|
138
|
+
super("https://queue.fal.run");
|
|
139
|
+
}
|
|
140
|
+
override makeRoute(params: UrlParams): string {
|
|
141
|
+
if (params.authMethod !== "provider-key") {
|
|
142
|
+
return `/${params.model}?_subdomain=queue`;
|
|
143
|
+
}
|
|
144
|
+
return `/${params.model}`;
|
|
68
145
|
}
|
|
69
|
-
|
|
146
|
+
override preparePayload(params: BodyParams): Record<string, unknown> {
|
|
147
|
+
return {
|
|
148
|
+
...omit(params.args, ["inputs", "parameters"]),
|
|
149
|
+
...(params.args.parameters as Record<string, unknown>),
|
|
150
|
+
prompt: params.args.inputs,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
override async getResponse(
|
|
155
|
+
response: FalAiQueueOutput,
|
|
156
|
+
url?: string,
|
|
157
|
+
headers?: Record<string, string>
|
|
158
|
+
): Promise<Blob> {
|
|
159
|
+
if (!url || !headers) {
|
|
160
|
+
throw new InferenceOutputError("URL and headers are required for text-to-video task");
|
|
161
|
+
}
|
|
162
|
+
const requestId = response.request_id;
|
|
163
|
+
if (!requestId) {
|
|
164
|
+
throw new InferenceOutputError("No request ID found in the response");
|
|
165
|
+
}
|
|
166
|
+
let status = response.status;
|
|
70
167
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
168
|
+
const parsedUrl = new URL(url);
|
|
169
|
+
const baseUrl = `${parsedUrl.protocol}//${parsedUrl.host}${
|
|
170
|
+
parsedUrl.host === "router.huggingface.co" ? "/fal-ai" : ""
|
|
171
|
+
}`;
|
|
75
172
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
173
|
+
// extracting the provider model id for status and result urls
|
|
174
|
+
// from the response as it might be different from the mapped model in `url`
|
|
175
|
+
const modelId = new URL(response.response_url).pathname;
|
|
176
|
+
const queryParams = parsedUrl.search;
|
|
80
177
|
|
|
81
|
-
|
|
82
|
-
|
|
178
|
+
const statusUrl = `${baseUrl}${modelId}/status${queryParams}`;
|
|
179
|
+
const resultUrl = `${baseUrl}${modelId}${queryParams}`;
|
|
83
180
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
181
|
+
while (status !== "COMPLETED") {
|
|
182
|
+
await delay(500);
|
|
183
|
+
const statusResponse = await fetch(statusUrl, { headers });
|
|
87
184
|
|
|
88
|
-
|
|
89
|
-
|
|
185
|
+
if (!statusResponse.ok) {
|
|
186
|
+
throw new InferenceOutputError("Failed to fetch response status from fal-ai API");
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
status = (await statusResponse.json()).status;
|
|
190
|
+
} catch (error) {
|
|
191
|
+
throw new InferenceOutputError("Failed to parse status response from fal-ai API");
|
|
192
|
+
}
|
|
90
193
|
}
|
|
194
|
+
|
|
195
|
+
const resultResponse = await fetch(resultUrl, { headers });
|
|
196
|
+
let result: unknown;
|
|
91
197
|
try {
|
|
92
|
-
|
|
198
|
+
result = await resultResponse.json();
|
|
93
199
|
} catch (error) {
|
|
94
|
-
throw new InferenceOutputError("Failed to parse
|
|
200
|
+
throw new InferenceOutputError("Failed to parse result response from fal-ai API");
|
|
201
|
+
}
|
|
202
|
+
if (
|
|
203
|
+
typeof result === "object" &&
|
|
204
|
+
!!result &&
|
|
205
|
+
"video" in result &&
|
|
206
|
+
typeof result.video === "object" &&
|
|
207
|
+
!!result.video &&
|
|
208
|
+
"url" in result.video &&
|
|
209
|
+
typeof result.video.url === "string" &&
|
|
210
|
+
isUrl(result.video.url)
|
|
211
|
+
) {
|
|
212
|
+
const urlResponse = await fetch(result.video.url);
|
|
213
|
+
return await urlResponse.blob();
|
|
214
|
+
} else {
|
|
215
|
+
throw new InferenceOutputError(
|
|
216
|
+
"Expected { video: { url: string } } result format, got instead: " + JSON.stringify(result)
|
|
217
|
+
);
|
|
95
218
|
}
|
|
96
219
|
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export class FalAIAutomaticSpeechRecognitionTask extends FalAITask implements AutomaticSpeechRecognitionTaskHelper {
|
|
223
|
+
override prepareHeaders(params: HeaderParams, binary: boolean): Record<string, string> {
|
|
224
|
+
const headers = super.prepareHeaders(params, binary);
|
|
225
|
+
headers["Content-Type"] = "application/json";
|
|
226
|
+
return headers;
|
|
227
|
+
}
|
|
228
|
+
override async getResponse(response: unknown): Promise<AutomaticSpeechRecognitionOutput> {
|
|
229
|
+
const res = response as FalAIAutomaticSpeechRecognitionOutput;
|
|
230
|
+
if (typeof res?.text !== "string") {
|
|
231
|
+
throw new InferenceOutputError(
|
|
232
|
+
`Expected { text: string } format from Fal.ai Automatic Speech Recognition, got: ${JSON.stringify(response)}`
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
return { text: res.text };
|
|
236
|
+
}
|
|
237
|
+
}
|
|
97
238
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
239
|
+
export class FalAITextToSpeechTask extends FalAITask {
|
|
240
|
+
override preparePayload(params: BodyParams): Record<string, unknown> {
|
|
241
|
+
return {
|
|
242
|
+
...omit(params.args, ["inputs", "parameters"]),
|
|
243
|
+
...(params.args.parameters as Record<string, unknown>),
|
|
244
|
+
lyrics: params.args.inputs,
|
|
245
|
+
};
|
|
104
246
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
"
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
247
|
+
|
|
248
|
+
override async getResponse(response: unknown): Promise<Blob> {
|
|
249
|
+
const res = response as FalAITextToSpeechOutput;
|
|
250
|
+
if (typeof res?.audio?.url !== "string") {
|
|
251
|
+
throw new InferenceOutputError(
|
|
252
|
+
`Expected { audio: { url: string } } format from Fal.ai Text-to-Speech, got: ${JSON.stringify(response)}`
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
try {
|
|
256
|
+
const urlResponse = await fetch(res.audio.url);
|
|
257
|
+
if (!urlResponse.ok) {
|
|
258
|
+
throw new Error(`Failed to fetch audio from ${res.audio.url}: ${urlResponse.statusText}`);
|
|
259
|
+
}
|
|
260
|
+
return await urlResponse.blob();
|
|
261
|
+
} catch (error) {
|
|
262
|
+
throw new InferenceOutputError(
|
|
263
|
+
`Error fetching or processing audio from Fal.ai Text-to-Speech URL: ${res.audio.url}. ${
|
|
264
|
+
error instanceof Error ? error.message : String(error)
|
|
265
|
+
}`
|
|
266
|
+
);
|
|
267
|
+
}
|
|
121
268
|
}
|
|
122
269
|
}
|
|
@@ -14,35 +14,14 @@
|
|
|
14
14
|
*
|
|
15
15
|
* Thanks!
|
|
16
16
|
*/
|
|
17
|
-
import
|
|
17
|
+
import { BaseConversationalTask } from "./providerHelper";
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return FIREWORKS_AI_API_BASE_URL;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const makeBody = (params: BodyParams): Record<string, unknown> => {
|
|
26
|
-
return {
|
|
27
|
-
...params.args,
|
|
28
|
-
...(params.chatCompletion ? { model: params.model } : undefined),
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const makeHeaders = (params: HeaderParams): Record<string, string> => {
|
|
33
|
-
return { Authorization: `Bearer ${params.accessToken}` };
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const makeUrl = (params: UrlParams): string => {
|
|
37
|
-
if (params.chatCompletion) {
|
|
38
|
-
return `${params.baseUrl}/inference/v1/chat/completions`;
|
|
19
|
+
export class FireworksConversationalTask extends BaseConversationalTask {
|
|
20
|
+
constructor() {
|
|
21
|
+
super("fireworks-ai", "https://api.fireworks.ai");
|
|
39
22
|
}
|
|
40
|
-
return `${params.baseUrl}/inference`;
|
|
41
|
-
};
|
|
42
23
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
makeUrl,
|
|
48
|
-
};
|
|
24
|
+
override makeRoute(): string {
|
|
25
|
+
return "/inference/v1/chat/completions";
|
|
26
|
+
}
|
|
27
|
+
}
|