@ai-sdk/huggingface 2.0.0-beta.23 → 2.0.0-beta.24
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/CHANGELOG.md +13 -0
- package/dist/index.js +238 -249
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
- package/dist/index.d.mts +0 -59
- package/dist/index.mjs +0 -980
- package/dist/index.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,50 +1,38 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
createHuggingFace: () => createHuggingFace,
|
|
24
|
-
huggingface: () => huggingface
|
|
25
|
-
});
|
|
26
|
-
module.exports = __toCommonJS(index_exports);
|
|
27
|
-
|
|
28
1
|
// src/huggingface-provider.ts
|
|
29
|
-
|
|
30
|
-
|
|
2
|
+
import {
|
|
3
|
+
NoSuchModelError
|
|
4
|
+
} from "@ai-sdk/provider";
|
|
5
|
+
import {
|
|
6
|
+
generateId as generateId2,
|
|
7
|
+
loadApiKey,
|
|
8
|
+
withoutTrailingSlash
|
|
9
|
+
} from "@ai-sdk/provider-utils";
|
|
31
10
|
|
|
32
11
|
// src/responses/huggingface-responses-language-model.ts
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
12
|
+
import {
|
|
13
|
+
APICallError
|
|
14
|
+
} from "@ai-sdk/provider";
|
|
15
|
+
import {
|
|
16
|
+
combineHeaders,
|
|
17
|
+
createEventSourceResponseHandler,
|
|
18
|
+
createJsonResponseHandler,
|
|
19
|
+
generateId,
|
|
20
|
+
parseProviderOptions,
|
|
21
|
+
postJsonToApi
|
|
22
|
+
} from "@ai-sdk/provider-utils";
|
|
23
|
+
import { z as z2 } from "zod/v4";
|
|
36
24
|
|
|
37
25
|
// src/huggingface-error.ts
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
var huggingfaceErrorDataSchema =
|
|
41
|
-
error:
|
|
42
|
-
message:
|
|
43
|
-
type:
|
|
44
|
-
code:
|
|
26
|
+
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
27
|
+
import { z } from "zod/v4";
|
|
28
|
+
var huggingfaceErrorDataSchema = z.object({
|
|
29
|
+
error: z.object({
|
|
30
|
+
message: z.string(),
|
|
31
|
+
type: z.string().optional(),
|
|
32
|
+
code: z.string().optional()
|
|
45
33
|
})
|
|
46
34
|
});
|
|
47
|
-
var huggingfaceFailedResponseHandler =
|
|
35
|
+
var huggingfaceFailedResponseHandler = createJsonErrorResponseHandler({
|
|
48
36
|
errorSchema: huggingfaceErrorDataSchema,
|
|
49
37
|
errorToMessage: (data) => data.error.message
|
|
50
38
|
});
|
|
@@ -89,8 +77,10 @@ function convertHuggingFaceResponsesUsage(usage) {
|
|
|
89
77
|
}
|
|
90
78
|
|
|
91
79
|
// src/responses/convert-to-huggingface-responses-messages.ts
|
|
92
|
-
|
|
93
|
-
|
|
80
|
+
import {
|
|
81
|
+
UnsupportedFunctionalityError
|
|
82
|
+
} from "@ai-sdk/provider";
|
|
83
|
+
import { isProviderReference } from "@ai-sdk/provider-utils";
|
|
94
84
|
async function convertToHuggingFaceResponsesMessages({
|
|
95
85
|
prompt
|
|
96
86
|
}) {
|
|
@@ -111,8 +101,8 @@ async function convertToHuggingFaceResponsesMessages({
|
|
|
111
101
|
return { type: "input_text", text: part.text };
|
|
112
102
|
}
|
|
113
103
|
case "file": {
|
|
114
|
-
if (
|
|
115
|
-
throw new
|
|
104
|
+
if (isProviderReference(part.data)) {
|
|
105
|
+
throw new UnsupportedFunctionalityError({
|
|
116
106
|
functionality: "file parts with provider references"
|
|
117
107
|
});
|
|
118
108
|
}
|
|
@@ -123,7 +113,7 @@ async function convertToHuggingFaceResponsesMessages({
|
|
|
123
113
|
image_url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${part.data}`
|
|
124
114
|
};
|
|
125
115
|
} else {
|
|
126
|
-
throw new
|
|
116
|
+
throw new UnsupportedFunctionalityError({
|
|
127
117
|
functionality: `file part media type ${part.mediaType}`
|
|
128
118
|
});
|
|
129
119
|
}
|
|
@@ -307,7 +297,7 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
307
297
|
prompt
|
|
308
298
|
});
|
|
309
299
|
warnings.push(...messageWarnings);
|
|
310
|
-
const huggingfaceOptions = await
|
|
300
|
+
const huggingfaceOptions = await parseProviderOptions({
|
|
311
301
|
provider: "huggingface",
|
|
312
302
|
providerOptions,
|
|
313
303
|
schema: huggingfaceResponsesProviderOptionsSchema
|
|
@@ -368,19 +358,19 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
368
358
|
value: response,
|
|
369
359
|
responseHeaders,
|
|
370
360
|
rawValue: rawResponse
|
|
371
|
-
} = await
|
|
361
|
+
} = await postJsonToApi({
|
|
372
362
|
url,
|
|
373
|
-
headers:
|
|
363
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
374
364
|
body,
|
|
375
365
|
failedResponseHandler: huggingfaceFailedResponseHandler,
|
|
376
|
-
successfulResponseHandler:
|
|
366
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
377
367
|
huggingfaceResponsesResponseSchema
|
|
378
368
|
),
|
|
379
369
|
abortSignal: options.abortSignal,
|
|
380
370
|
fetch: this.config.fetch
|
|
381
371
|
});
|
|
382
372
|
if (response.error) {
|
|
383
|
-
throw new
|
|
373
|
+
throw new APICallError({
|
|
384
374
|
message: response.error.message,
|
|
385
375
|
url,
|
|
386
376
|
requestBodyValues: body,
|
|
@@ -409,7 +399,7 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
409
399
|
content.push({
|
|
410
400
|
type: "source",
|
|
411
401
|
sourceType: "url",
|
|
412
|
-
id: (_c = (_b = (_a = this.config).generateId) == null ? void 0 : _b.call(_a)) != null ? _c :
|
|
402
|
+
id: (_c = (_b = (_a = this.config).generateId) == null ? void 0 : _b.call(_a)) != null ? _c : generateId(),
|
|
413
403
|
url: annotation.url,
|
|
414
404
|
title: annotation.title
|
|
415
405
|
});
|
|
@@ -521,15 +511,15 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
521
511
|
...args,
|
|
522
512
|
stream: true
|
|
523
513
|
};
|
|
524
|
-
const { value: response, responseHeaders } = await
|
|
514
|
+
const { value: response, responseHeaders } = await postJsonToApi({
|
|
525
515
|
url: this.config.url({
|
|
526
516
|
path: "/responses",
|
|
527
517
|
modelId: this.modelId
|
|
528
518
|
}),
|
|
529
|
-
headers:
|
|
519
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
530
520
|
body,
|
|
531
521
|
failedResponseHandler: huggingfaceFailedResponseHandler,
|
|
532
|
-
successfulResponseHandler:
|
|
522
|
+
successfulResponseHandler: createEventSourceResponseHandler(
|
|
533
523
|
huggingfaceResponsesChunkSchema
|
|
534
524
|
),
|
|
535
525
|
abortSignal: options.abortSignal,
|
|
@@ -682,231 +672,231 @@ var HuggingFaceResponsesLanguageModel = class {
|
|
|
682
672
|
};
|
|
683
673
|
}
|
|
684
674
|
};
|
|
685
|
-
var huggingfaceResponsesProviderOptionsSchema =
|
|
686
|
-
metadata:
|
|
687
|
-
instructions:
|
|
688
|
-
strictJsonSchema:
|
|
689
|
-
reasoningEffort:
|
|
675
|
+
var huggingfaceResponsesProviderOptionsSchema = z2.object({
|
|
676
|
+
metadata: z2.record(z2.string(), z2.string()).optional(),
|
|
677
|
+
instructions: z2.string().optional(),
|
|
678
|
+
strictJsonSchema: z2.boolean().optional(),
|
|
679
|
+
reasoningEffort: z2.string().optional()
|
|
690
680
|
});
|
|
691
|
-
var huggingfaceResponsesOutputSchema =
|
|
692
|
-
|
|
693
|
-
type:
|
|
694
|
-
id:
|
|
695
|
-
role:
|
|
696
|
-
status:
|
|
697
|
-
content:
|
|
698
|
-
|
|
699
|
-
type:
|
|
700
|
-
text:
|
|
701
|
-
annotations:
|
|
681
|
+
var huggingfaceResponsesOutputSchema = z2.discriminatedUnion("type", [
|
|
682
|
+
z2.object({
|
|
683
|
+
type: z2.literal("message"),
|
|
684
|
+
id: z2.string(),
|
|
685
|
+
role: z2.string().optional(),
|
|
686
|
+
status: z2.string().optional(),
|
|
687
|
+
content: z2.array(
|
|
688
|
+
z2.object({
|
|
689
|
+
type: z2.literal("output_text"),
|
|
690
|
+
text: z2.string(),
|
|
691
|
+
annotations: z2.array(z2.any()).optional()
|
|
702
692
|
})
|
|
703
693
|
)
|
|
704
694
|
}),
|
|
705
|
-
|
|
706
|
-
type:
|
|
707
|
-
id:
|
|
708
|
-
status:
|
|
709
|
-
content:
|
|
710
|
-
|
|
711
|
-
type:
|
|
712
|
-
text:
|
|
695
|
+
z2.object({
|
|
696
|
+
type: z2.literal("reasoning"),
|
|
697
|
+
id: z2.string(),
|
|
698
|
+
status: z2.string().optional(),
|
|
699
|
+
content: z2.array(
|
|
700
|
+
z2.object({
|
|
701
|
+
type: z2.literal("reasoning_text"),
|
|
702
|
+
text: z2.string()
|
|
713
703
|
})
|
|
714
704
|
),
|
|
715
|
-
summary:
|
|
716
|
-
|
|
717
|
-
type:
|
|
718
|
-
text:
|
|
705
|
+
summary: z2.array(
|
|
706
|
+
z2.object({
|
|
707
|
+
type: z2.literal("reasoning_summary"),
|
|
708
|
+
text: z2.string()
|
|
719
709
|
}).optional()
|
|
720
710
|
).optional()
|
|
721
711
|
}),
|
|
722
|
-
|
|
723
|
-
type:
|
|
724
|
-
id:
|
|
725
|
-
call_id:
|
|
726
|
-
name:
|
|
727
|
-
arguments:
|
|
728
|
-
output:
|
|
729
|
-
status:
|
|
712
|
+
z2.object({
|
|
713
|
+
type: z2.literal("function_call"),
|
|
714
|
+
id: z2.string(),
|
|
715
|
+
call_id: z2.string(),
|
|
716
|
+
name: z2.string(),
|
|
717
|
+
arguments: z2.string(),
|
|
718
|
+
output: z2.string().optional(),
|
|
719
|
+
status: z2.string().optional()
|
|
730
720
|
}),
|
|
731
|
-
|
|
732
|
-
type:
|
|
733
|
-
id:
|
|
734
|
-
name:
|
|
735
|
-
arguments:
|
|
736
|
-
output:
|
|
737
|
-
status:
|
|
721
|
+
z2.object({
|
|
722
|
+
type: z2.literal("mcp_call"),
|
|
723
|
+
id: z2.string(),
|
|
724
|
+
name: z2.string(),
|
|
725
|
+
arguments: z2.string(),
|
|
726
|
+
output: z2.string().optional(),
|
|
727
|
+
status: z2.string().optional()
|
|
738
728
|
}),
|
|
739
|
-
|
|
740
|
-
type:
|
|
741
|
-
id:
|
|
742
|
-
server_label:
|
|
743
|
-
tools:
|
|
744
|
-
status:
|
|
729
|
+
z2.object({
|
|
730
|
+
type: z2.literal("mcp_list_tools"),
|
|
731
|
+
id: z2.string(),
|
|
732
|
+
server_label: z2.string(),
|
|
733
|
+
tools: z2.array(z2.any()).optional(),
|
|
734
|
+
status: z2.string().optional()
|
|
745
735
|
})
|
|
746
736
|
]);
|
|
747
|
-
var huggingfaceResponsesResponseSchema =
|
|
748
|
-
id:
|
|
749
|
-
model:
|
|
750
|
-
object:
|
|
751
|
-
created_at:
|
|
752
|
-
status:
|
|
753
|
-
error:
|
|
754
|
-
instructions:
|
|
755
|
-
max_output_tokens:
|
|
756
|
-
metadata:
|
|
757
|
-
tool_choice:
|
|
758
|
-
tools:
|
|
759
|
-
temperature:
|
|
760
|
-
top_p:
|
|
761
|
-
incomplete_details:
|
|
762
|
-
reason:
|
|
737
|
+
var huggingfaceResponsesResponseSchema = z2.object({
|
|
738
|
+
id: z2.string(),
|
|
739
|
+
model: z2.string(),
|
|
740
|
+
object: z2.string(),
|
|
741
|
+
created_at: z2.number(),
|
|
742
|
+
status: z2.string(),
|
|
743
|
+
error: z2.any().nullable(),
|
|
744
|
+
instructions: z2.any().nullable(),
|
|
745
|
+
max_output_tokens: z2.any().nullable(),
|
|
746
|
+
metadata: z2.any().nullable(),
|
|
747
|
+
tool_choice: z2.any(),
|
|
748
|
+
tools: z2.array(z2.any()),
|
|
749
|
+
temperature: z2.number(),
|
|
750
|
+
top_p: z2.number(),
|
|
751
|
+
incomplete_details: z2.object({
|
|
752
|
+
reason: z2.string()
|
|
763
753
|
}).nullable().optional(),
|
|
764
|
-
usage:
|
|
765
|
-
input_tokens:
|
|
766
|
-
input_tokens_details:
|
|
767
|
-
cached_tokens:
|
|
754
|
+
usage: z2.object({
|
|
755
|
+
input_tokens: z2.number(),
|
|
756
|
+
input_tokens_details: z2.object({
|
|
757
|
+
cached_tokens: z2.number()
|
|
768
758
|
}).optional(),
|
|
769
|
-
output_tokens:
|
|
770
|
-
output_tokens_details:
|
|
771
|
-
reasoning_tokens:
|
|
759
|
+
output_tokens: z2.number(),
|
|
760
|
+
output_tokens_details: z2.object({
|
|
761
|
+
reasoning_tokens: z2.number()
|
|
772
762
|
}).optional(),
|
|
773
|
-
total_tokens:
|
|
763
|
+
total_tokens: z2.number()
|
|
774
764
|
}).nullable().optional(),
|
|
775
|
-
output:
|
|
776
|
-
output_text:
|
|
765
|
+
output: z2.array(huggingfaceResponsesOutputSchema),
|
|
766
|
+
output_text: z2.string().nullable().optional()
|
|
777
767
|
});
|
|
778
|
-
var responseOutputItemAddedSchema =
|
|
779
|
-
type:
|
|
780
|
-
output_index:
|
|
781
|
-
item:
|
|
782
|
-
|
|
783
|
-
type:
|
|
784
|
-
id:
|
|
785
|
-
role:
|
|
786
|
-
status:
|
|
787
|
-
content:
|
|
768
|
+
var responseOutputItemAddedSchema = z2.object({
|
|
769
|
+
type: z2.literal("response.output_item.added"),
|
|
770
|
+
output_index: z2.number(),
|
|
771
|
+
item: z2.discriminatedUnion("type", [
|
|
772
|
+
z2.object({
|
|
773
|
+
type: z2.literal("message"),
|
|
774
|
+
id: z2.string(),
|
|
775
|
+
role: z2.string().optional(),
|
|
776
|
+
status: z2.string().optional(),
|
|
777
|
+
content: z2.array(z2.any()).optional()
|
|
788
778
|
}),
|
|
789
|
-
|
|
790
|
-
type:
|
|
791
|
-
id:
|
|
792
|
-
status:
|
|
793
|
-
content:
|
|
794
|
-
summary:
|
|
779
|
+
z2.object({
|
|
780
|
+
type: z2.literal("reasoning"),
|
|
781
|
+
id: z2.string(),
|
|
782
|
+
status: z2.string().optional(),
|
|
783
|
+
content: z2.array(z2.any()).optional(),
|
|
784
|
+
summary: z2.array(z2.any()).optional()
|
|
795
785
|
}),
|
|
796
|
-
|
|
797
|
-
type:
|
|
798
|
-
id:
|
|
799
|
-
server_label:
|
|
800
|
-
tools:
|
|
801
|
-
error:
|
|
786
|
+
z2.object({
|
|
787
|
+
type: z2.literal("mcp_list_tools"),
|
|
788
|
+
id: z2.string(),
|
|
789
|
+
server_label: z2.string(),
|
|
790
|
+
tools: z2.array(z2.any()).optional(),
|
|
791
|
+
error: z2.string().optional()
|
|
802
792
|
}),
|
|
803
|
-
|
|
804
|
-
type:
|
|
805
|
-
id:
|
|
806
|
-
server_label:
|
|
807
|
-
name:
|
|
808
|
-
arguments:
|
|
809
|
-
output:
|
|
810
|
-
error:
|
|
793
|
+
z2.object({
|
|
794
|
+
type: z2.literal("mcp_call"),
|
|
795
|
+
id: z2.string(),
|
|
796
|
+
server_label: z2.string(),
|
|
797
|
+
name: z2.string(),
|
|
798
|
+
arguments: z2.string(),
|
|
799
|
+
output: z2.string().optional(),
|
|
800
|
+
error: z2.string().optional()
|
|
811
801
|
}),
|
|
812
|
-
|
|
813
|
-
type:
|
|
814
|
-
id:
|
|
815
|
-
call_id:
|
|
816
|
-
name:
|
|
817
|
-
arguments:
|
|
818
|
-
output:
|
|
819
|
-
error:
|
|
802
|
+
z2.object({
|
|
803
|
+
type: z2.literal("function_call"),
|
|
804
|
+
id: z2.string(),
|
|
805
|
+
call_id: z2.string(),
|
|
806
|
+
name: z2.string(),
|
|
807
|
+
arguments: z2.string(),
|
|
808
|
+
output: z2.string().optional(),
|
|
809
|
+
error: z2.string().optional()
|
|
820
810
|
})
|
|
821
811
|
]),
|
|
822
|
-
sequence_number:
|
|
812
|
+
sequence_number: z2.number()
|
|
823
813
|
});
|
|
824
|
-
var responseOutputItemDoneSchema =
|
|
825
|
-
type:
|
|
826
|
-
output_index:
|
|
827
|
-
item:
|
|
828
|
-
|
|
829
|
-
type:
|
|
830
|
-
id:
|
|
831
|
-
role:
|
|
832
|
-
status:
|
|
833
|
-
content:
|
|
814
|
+
var responseOutputItemDoneSchema = z2.object({
|
|
815
|
+
type: z2.literal("response.output_item.done"),
|
|
816
|
+
output_index: z2.number(),
|
|
817
|
+
item: z2.discriminatedUnion("type", [
|
|
818
|
+
z2.object({
|
|
819
|
+
type: z2.literal("message"),
|
|
820
|
+
id: z2.string(),
|
|
821
|
+
role: z2.string().optional(),
|
|
822
|
+
status: z2.string().optional(),
|
|
823
|
+
content: z2.array(z2.any()).optional()
|
|
834
824
|
}),
|
|
835
|
-
|
|
836
|
-
type:
|
|
837
|
-
id:
|
|
838
|
-
server_label:
|
|
839
|
-
tools:
|
|
840
|
-
error:
|
|
825
|
+
z2.object({
|
|
826
|
+
type: z2.literal("mcp_list_tools"),
|
|
827
|
+
id: z2.string(),
|
|
828
|
+
server_label: z2.string(),
|
|
829
|
+
tools: z2.array(z2.any()).optional(),
|
|
830
|
+
error: z2.string().optional()
|
|
841
831
|
}),
|
|
842
|
-
|
|
843
|
-
type:
|
|
844
|
-
id:
|
|
845
|
-
server_label:
|
|
846
|
-
name:
|
|
847
|
-
arguments:
|
|
848
|
-
output:
|
|
849
|
-
error:
|
|
832
|
+
z2.object({
|
|
833
|
+
type: z2.literal("mcp_call"),
|
|
834
|
+
id: z2.string(),
|
|
835
|
+
server_label: z2.string(),
|
|
836
|
+
name: z2.string(),
|
|
837
|
+
arguments: z2.string(),
|
|
838
|
+
output: z2.string().optional(),
|
|
839
|
+
error: z2.string().optional()
|
|
850
840
|
}),
|
|
851
|
-
|
|
852
|
-
type:
|
|
853
|
-
id:
|
|
854
|
-
call_id:
|
|
855
|
-
name:
|
|
856
|
-
arguments:
|
|
857
|
-
output:
|
|
858
|
-
error:
|
|
841
|
+
z2.object({
|
|
842
|
+
type: z2.literal("function_call"),
|
|
843
|
+
id: z2.string(),
|
|
844
|
+
call_id: z2.string(),
|
|
845
|
+
name: z2.string(),
|
|
846
|
+
arguments: z2.string(),
|
|
847
|
+
output: z2.string().optional(),
|
|
848
|
+
error: z2.string().optional()
|
|
859
849
|
}),
|
|
860
|
-
|
|
861
|
-
type:
|
|
862
|
-
id:
|
|
863
|
-
status:
|
|
864
|
-
content:
|
|
865
|
-
summary:
|
|
850
|
+
z2.object({
|
|
851
|
+
type: z2.literal("reasoning"),
|
|
852
|
+
id: z2.string(),
|
|
853
|
+
status: z2.string().optional(),
|
|
854
|
+
content: z2.array(z2.any()).optional(),
|
|
855
|
+
summary: z2.array(z2.any()).optional()
|
|
866
856
|
})
|
|
867
857
|
]),
|
|
868
|
-
sequence_number:
|
|
858
|
+
sequence_number: z2.number()
|
|
869
859
|
});
|
|
870
|
-
var textDeltaChunkSchema =
|
|
871
|
-
type:
|
|
872
|
-
item_id:
|
|
873
|
-
output_index:
|
|
874
|
-
content_index:
|
|
875
|
-
delta:
|
|
876
|
-
sequence_number:
|
|
860
|
+
var textDeltaChunkSchema = z2.object({
|
|
861
|
+
type: z2.literal("response.output_text.delta"),
|
|
862
|
+
item_id: z2.string(),
|
|
863
|
+
output_index: z2.number(),
|
|
864
|
+
content_index: z2.number(),
|
|
865
|
+
delta: z2.string(),
|
|
866
|
+
sequence_number: z2.number()
|
|
877
867
|
});
|
|
878
|
-
var reasoningTextDeltaChunkSchema =
|
|
879
|
-
type:
|
|
880
|
-
item_id:
|
|
881
|
-
output_index:
|
|
882
|
-
content_index:
|
|
883
|
-
delta:
|
|
884
|
-
sequence_number:
|
|
868
|
+
var reasoningTextDeltaChunkSchema = z2.object({
|
|
869
|
+
type: z2.literal("response.reasoning_text.delta"),
|
|
870
|
+
item_id: z2.string(),
|
|
871
|
+
output_index: z2.number(),
|
|
872
|
+
content_index: z2.number(),
|
|
873
|
+
delta: z2.string(),
|
|
874
|
+
sequence_number: z2.number()
|
|
885
875
|
});
|
|
886
|
-
var reasoningTextEndChunkSchema =
|
|
887
|
-
type:
|
|
888
|
-
item_id:
|
|
889
|
-
output_index:
|
|
890
|
-
content_index:
|
|
891
|
-
text:
|
|
892
|
-
sequence_number:
|
|
876
|
+
var reasoningTextEndChunkSchema = z2.object({
|
|
877
|
+
type: z2.literal("response.reasoning_text.done"),
|
|
878
|
+
item_id: z2.string(),
|
|
879
|
+
output_index: z2.number(),
|
|
880
|
+
content_index: z2.number(),
|
|
881
|
+
text: z2.string(),
|
|
882
|
+
sequence_number: z2.number()
|
|
893
883
|
});
|
|
894
|
-
var responseCompletedChunkSchema =
|
|
895
|
-
type:
|
|
884
|
+
var responseCompletedChunkSchema = z2.object({
|
|
885
|
+
type: z2.literal("response.completed"),
|
|
896
886
|
response: huggingfaceResponsesResponseSchema,
|
|
897
|
-
sequence_number:
|
|
887
|
+
sequence_number: z2.number()
|
|
898
888
|
});
|
|
899
|
-
var responseCreatedChunkSchema =
|
|
900
|
-
type:
|
|
901
|
-
response:
|
|
902
|
-
id:
|
|
903
|
-
object:
|
|
904
|
-
created_at:
|
|
905
|
-
status:
|
|
906
|
-
model:
|
|
889
|
+
var responseCreatedChunkSchema = z2.object({
|
|
890
|
+
type: z2.literal("response.created"),
|
|
891
|
+
response: z2.object({
|
|
892
|
+
id: z2.string(),
|
|
893
|
+
object: z2.string(),
|
|
894
|
+
created_at: z2.number(),
|
|
895
|
+
status: z2.string(),
|
|
896
|
+
model: z2.string()
|
|
907
897
|
})
|
|
908
898
|
});
|
|
909
|
-
var huggingfaceResponsesChunkSchema =
|
|
899
|
+
var huggingfaceResponsesChunkSchema = z2.union([
|
|
910
900
|
responseOutputItemAddedSchema,
|
|
911
901
|
responseOutputItemDoneSchema,
|
|
912
902
|
reasoningTextDeltaChunkSchema,
|
|
@@ -914,7 +904,7 @@ var huggingfaceResponsesChunkSchema = import_v42.z.union([
|
|
|
914
904
|
textDeltaChunkSchema,
|
|
915
905
|
responseCompletedChunkSchema,
|
|
916
906
|
responseCreatedChunkSchema,
|
|
917
|
-
|
|
907
|
+
z2.object({ type: z2.string() }).loose()
|
|
918
908
|
// fallback for unknown chunks
|
|
919
909
|
]);
|
|
920
910
|
function isResponseOutputItemAddedChunk(chunk) {
|
|
@@ -942,9 +932,9 @@ function isResponseCreatedChunk(chunk) {
|
|
|
942
932
|
// src/huggingface-provider.ts
|
|
943
933
|
function createHuggingFace(options = {}) {
|
|
944
934
|
var _a;
|
|
945
|
-
const baseURL = (_a =
|
|
935
|
+
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://router.huggingface.co/v1";
|
|
946
936
|
const getHeaders = () => ({
|
|
947
|
-
Authorization: `Bearer ${
|
|
937
|
+
Authorization: `Bearer ${loadApiKey({
|
|
948
938
|
apiKey: options.apiKey,
|
|
949
939
|
environmentVariableName: "HUGGINGFACE_API_KEY",
|
|
950
940
|
description: "Hugging Face"
|
|
@@ -958,7 +948,7 @@ function createHuggingFace(options = {}) {
|
|
|
958
948
|
url: ({ path }) => `${baseURL}${path}`,
|
|
959
949
|
headers: getHeaders,
|
|
960
950
|
fetch: options.fetch,
|
|
961
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
|
951
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : generateId2
|
|
962
952
|
});
|
|
963
953
|
};
|
|
964
954
|
const provider = (modelId) => createResponsesModel(modelId);
|
|
@@ -966,7 +956,7 @@ function createHuggingFace(options = {}) {
|
|
|
966
956
|
provider.languageModel = createResponsesModel;
|
|
967
957
|
provider.responses = createResponsesModel;
|
|
968
958
|
provider.embeddingModel = (modelId) => {
|
|
969
|
-
throw new
|
|
959
|
+
throw new NoSuchModelError({
|
|
970
960
|
modelId,
|
|
971
961
|
modelType: "embeddingModel",
|
|
972
962
|
message: "Hugging Face Responses API does not support text embeddings. Use the Hugging Face Inference API directly for embeddings."
|
|
@@ -974,7 +964,7 @@ function createHuggingFace(options = {}) {
|
|
|
974
964
|
};
|
|
975
965
|
provider.textEmbeddingModel = provider.embeddingModel;
|
|
976
966
|
provider.imageModel = (modelId) => {
|
|
977
|
-
throw new
|
|
967
|
+
throw new NoSuchModelError({
|
|
978
968
|
modelId,
|
|
979
969
|
modelType: "imageModel",
|
|
980
970
|
message: "Hugging Face Responses API does not support image generation. Use the Hugging Face Inference API directly for image models."
|
|
@@ -983,9 +973,8 @@ function createHuggingFace(options = {}) {
|
|
|
983
973
|
return provider;
|
|
984
974
|
}
|
|
985
975
|
var huggingface = createHuggingFace();
|
|
986
|
-
|
|
987
|
-
0 && (module.exports = {
|
|
976
|
+
export {
|
|
988
977
|
createHuggingFace,
|
|
989
978
|
huggingface
|
|
990
|
-
}
|
|
979
|
+
};
|
|
991
980
|
//# sourceMappingURL=index.js.map
|