@ai-sdk/huggingface 2.0.0-beta.8 → 2.0.0-canary.37
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 +278 -0
- package/README.md +2 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +296 -265
- package/dist/index.js.map +1 -1
- package/docs/170-huggingface.mdx +21 -19
- package/package.json +12 -10
- package/src/huggingface-config.ts +2 -2
- package/src/huggingface-provider.ts +5 -5
- package/src/index.ts +7 -1
- package/src/responses/convert-huggingface-responses-usage.ts +1 -1
- package/src/responses/convert-to-huggingface-responses-messages.ts +33 -19
- package/src/responses/huggingface-responses-language-model-options.ts +12 -0
- package/src/responses/huggingface-responses-language-model.ts +36 -22
- package/src/responses/huggingface-responses-prepare-tools.ts +4 -1
- package/src/responses/map-huggingface-responses-finish-reason.ts +1 -1
- package/src/version.ts +6 -0
- package/dist/index.d.mts +0 -59
- package/dist/index.mjs +0 -974
- package/dist/index.mjs.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
APICallError,
|
|
3
|
-
LanguageModelV4,
|
|
4
|
-
LanguageModelV4CallOptions,
|
|
5
|
-
LanguageModelV4Content,
|
|
6
|
-
LanguageModelV4FinishReason,
|
|
7
|
-
LanguageModelV4GenerateResult,
|
|
8
|
-
LanguageModelV4StreamPart,
|
|
9
|
-
LanguageModelV4StreamResult,
|
|
10
|
-
SharedV4Warning,
|
|
3
|
+
type LanguageModelV4,
|
|
4
|
+
type LanguageModelV4CallOptions,
|
|
5
|
+
type LanguageModelV4Content,
|
|
6
|
+
type LanguageModelV4FinishReason,
|
|
7
|
+
type LanguageModelV4GenerateResult,
|
|
8
|
+
type LanguageModelV4StreamPart,
|
|
9
|
+
type LanguageModelV4StreamResult,
|
|
10
|
+
type SharedV4Warning,
|
|
11
11
|
} from '@ai-sdk/provider';
|
|
12
12
|
import {
|
|
13
13
|
combineHeaders,
|
|
@@ -15,19 +15,23 @@ import {
|
|
|
15
15
|
createJsonResponseHandler,
|
|
16
16
|
generateId,
|
|
17
17
|
parseProviderOptions,
|
|
18
|
-
ParseResult,
|
|
19
18
|
postJsonToApi,
|
|
19
|
+
serializeModelOptions,
|
|
20
|
+
WORKFLOW_SERIALIZE,
|
|
21
|
+
WORKFLOW_DESERIALIZE,
|
|
22
|
+
type ParseResult,
|
|
20
23
|
} from '@ai-sdk/provider-utils';
|
|
21
24
|
import { z } from 'zod/v4';
|
|
22
|
-
import { HuggingFaceConfig } from '../huggingface-config';
|
|
25
|
+
import type { HuggingFaceConfig } from '../huggingface-config';
|
|
23
26
|
import { huggingfaceFailedResponseHandler } from '../huggingface-error';
|
|
24
27
|
import {
|
|
25
28
|
convertHuggingFaceResponsesUsage,
|
|
26
|
-
HuggingFaceResponsesUsage,
|
|
29
|
+
type HuggingFaceResponsesUsage,
|
|
27
30
|
} from './convert-huggingface-responses-usage';
|
|
28
31
|
import { convertToHuggingFaceResponsesMessages } from './convert-to-huggingface-responses-messages';
|
|
32
|
+
import { huggingfaceLanguageModelResponsesOptions } from './huggingface-responses-language-model-options';
|
|
29
33
|
import { prepareResponsesTools } from './huggingface-responses-prepare-tools';
|
|
30
|
-
import { HuggingFaceResponsesModelId } from './huggingface-responses-settings';
|
|
34
|
+
import type { HuggingFaceResponsesModelId } from './huggingface-responses-settings';
|
|
31
35
|
import { mapHuggingFaceResponsesFinishReason } from './map-huggingface-responses-finish-reason';
|
|
32
36
|
|
|
33
37
|
export class HuggingFaceResponsesLanguageModel implements LanguageModelV4 {
|
|
@@ -37,6 +41,23 @@ export class HuggingFaceResponsesLanguageModel implements LanguageModelV4 {
|
|
|
37
41
|
|
|
38
42
|
private readonly config: HuggingFaceConfig;
|
|
39
43
|
|
|
44
|
+
static [WORKFLOW_SERIALIZE](model: HuggingFaceResponsesLanguageModel) {
|
|
45
|
+
return serializeModelOptions({
|
|
46
|
+
modelId: model.modelId,
|
|
47
|
+
config: model.config,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static [WORKFLOW_DESERIALIZE](options: {
|
|
52
|
+
modelId: HuggingFaceResponsesModelId;
|
|
53
|
+
config: HuggingFaceConfig;
|
|
54
|
+
}) {
|
|
55
|
+
return new HuggingFaceResponsesLanguageModel(
|
|
56
|
+
options.modelId,
|
|
57
|
+
options.config,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
40
61
|
constructor(modelId: HuggingFaceResponsesModelId, config: HuggingFaceConfig) {
|
|
41
62
|
this.modelId = modelId;
|
|
42
63
|
this.config = config;
|
|
@@ -97,7 +118,7 @@ export class HuggingFaceResponsesLanguageModel implements LanguageModelV4 {
|
|
|
97
118
|
const huggingfaceOptions = await parseProviderOptions({
|
|
98
119
|
provider: 'huggingface',
|
|
99
120
|
providerOptions,
|
|
100
|
-
schema:
|
|
121
|
+
schema: huggingfaceLanguageModelResponsesOptions,
|
|
101
122
|
});
|
|
102
123
|
|
|
103
124
|
const {
|
|
@@ -170,7 +191,7 @@ export class HuggingFaceResponsesLanguageModel implements LanguageModelV4 {
|
|
|
170
191
|
rawValue: rawResponse,
|
|
171
192
|
} = await postJsonToApi({
|
|
172
193
|
url,
|
|
173
|
-
headers: combineHeaders(this.config.headers(), options.headers),
|
|
194
|
+
headers: combineHeaders(this.config.headers?.(), options.headers),
|
|
174
195
|
body,
|
|
175
196
|
failedResponseHandler: huggingfaceFailedResponseHandler,
|
|
176
197
|
successfulResponseHandler: createJsonResponseHandler(
|
|
@@ -345,7 +366,7 @@ export class HuggingFaceResponsesLanguageModel implements LanguageModelV4 {
|
|
|
345
366
|
path: '/responses',
|
|
346
367
|
modelId: this.modelId,
|
|
347
368
|
}),
|
|
348
|
-
headers: combineHeaders(this.config.headers(), options.headers),
|
|
369
|
+
headers: combineHeaders(this.config.headers?.(), options.headers),
|
|
349
370
|
body,
|
|
350
371
|
failedResponseHandler: huggingfaceFailedResponseHandler,
|
|
351
372
|
successfulResponseHandler: createEventSourceResponseHandler(
|
|
@@ -524,13 +545,6 @@ export class HuggingFaceResponsesLanguageModel implements LanguageModelV4 {
|
|
|
524
545
|
}
|
|
525
546
|
}
|
|
526
547
|
|
|
527
|
-
const huggingfaceResponsesProviderOptionsSchema = z.object({
|
|
528
|
-
metadata: z.record(z.string(), z.string()).optional(),
|
|
529
|
-
instructions: z.string().optional(),
|
|
530
|
-
strictJsonSchema: z.boolean().optional(),
|
|
531
|
-
reasoningEffort: z.string().optional(),
|
|
532
|
-
});
|
|
533
|
-
|
|
534
548
|
const huggingfaceResponsesOutputSchema = z.discriminatedUnion('type', [
|
|
535
549
|
z.object({
|
|
536
550
|
type: z.literal('message'),
|
package/src/version.ts
ADDED
package/dist/index.d.mts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { ProviderV4, LanguageModelV4 } from '@ai-sdk/provider';
|
|
2
|
-
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
-
export { OpenAICompatibleErrorData as HuggingFaceErrorData } from '@ai-sdk/openai-compatible';
|
|
4
|
-
|
|
5
|
-
type HuggingFaceResponsesModelId = 'meta-llama/Llama-3.1-8B-Instruct' | 'meta-llama/Llama-3.1-70B-Instruct' | 'meta-llama/Llama-3.1-405B-Instruct' | 'meta-llama/Llama-3.3-70B-Instruct' | 'meta-llama/Meta-Llama-3-8B-Instruct' | 'meta-llama/Meta-Llama-3-70B-Instruct' | 'meta-llama/Llama-3.2-3B-Instruct' | 'meta-llama/Llama-4-Maverick-17B-128E-Instruct' | 'meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8' | 'meta-llama/Llama-Guard-4-12B' | 'deepseek-ai/DeepSeek-V3.1' | 'deepseek-ai/DeepSeek-V3-0324' | 'deepseek-ai/DeepSeek-R1' | 'deepseek-ai/DeepSeek-R1-0528' | 'deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B' | 'deepseek-ai/DeepSeek-R1-Distill-Qwen-7B' | 'deepseek-ai/DeepSeek-R1-Distill-Qwen-14B' | 'deepseek-ai/DeepSeek-R1-Distill-Qwen-32B' | 'deepseek-ai/DeepSeek-R1-Distill-Llama-8B' | 'deepseek-ai/DeepSeek-R1-Distill-Llama-70B' | 'deepseek-ai/DeepSeek-Prover-V2-671B' | 'Qwen/Qwen3-32B' | 'Qwen/Qwen3-14B' | 'Qwen/Qwen3-8B' | 'Qwen/Qwen3-4B' | 'Qwen/Qwen3-Coder-480B-A35B-Instruct' | 'Qwen/Qwen3-Coder-480B-A35B-Instruct-FP8' | 'Qwen/Qwen3-30B-A3B' | 'Qwen/Qwen2.5-VL-7B-Instruct' | 'Qwen/Qwen2.5-7B-Instruct' | 'Qwen/Qwen2.5-Coder-7B-Instruct' | 'Qwen/Qwen2.5-Coder-32B-Instruct' | 'google/gemma-2-9b-it' | 'google/gemma-3-27b-it' | 'moonshotai/Kimi-K2-Instruct' | (string & {});
|
|
6
|
-
interface HuggingFaceResponsesSettings {
|
|
7
|
-
metadata?: Record<string, string>;
|
|
8
|
-
instructions?: string;
|
|
9
|
-
strictJsonSchema?: boolean;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface HuggingFaceProviderSettings {
|
|
13
|
-
/**
|
|
14
|
-
* Hugging Face API key.
|
|
15
|
-
*/
|
|
16
|
-
apiKey?: string;
|
|
17
|
-
/**
|
|
18
|
-
* Base URL for the API calls.
|
|
19
|
-
*/
|
|
20
|
-
baseURL?: string;
|
|
21
|
-
/**
|
|
22
|
-
* Custom headers to include in the requests.
|
|
23
|
-
*/
|
|
24
|
-
headers?: Record<string, string>;
|
|
25
|
-
/**
|
|
26
|
-
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
27
|
-
* or to provide a custom fetch implementation for e.g. testing.
|
|
28
|
-
*/
|
|
29
|
-
fetch?: FetchFunction;
|
|
30
|
-
generateId?: () => string;
|
|
31
|
-
}
|
|
32
|
-
interface HuggingFaceProvider extends ProviderV4 {
|
|
33
|
-
/**
|
|
34
|
-
* Creates a Hugging Face responses model for text generation.
|
|
35
|
-
*/
|
|
36
|
-
(modelId: HuggingFaceResponsesModelId): LanguageModelV4;
|
|
37
|
-
/**
|
|
38
|
-
* Creates a Hugging Face responses model for text generation.
|
|
39
|
-
*/
|
|
40
|
-
languageModel(modelId: HuggingFaceResponsesModelId): LanguageModelV4;
|
|
41
|
-
/**
|
|
42
|
-
* Creates a Hugging Face responses model for text generation.
|
|
43
|
-
*/
|
|
44
|
-
responses(modelId: HuggingFaceResponsesModelId): LanguageModelV4;
|
|
45
|
-
/**
|
|
46
|
-
* @deprecated Use `embeddingModel` instead.
|
|
47
|
-
*/
|
|
48
|
-
textEmbeddingModel(modelId: string): never;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Create a Hugging Face provider instance.
|
|
52
|
-
*/
|
|
53
|
-
declare function createHuggingFace(options?: HuggingFaceProviderSettings): HuggingFaceProvider;
|
|
54
|
-
/**
|
|
55
|
-
* Default Hugging Face provider instance.
|
|
56
|
-
*/
|
|
57
|
-
declare const huggingface: HuggingFaceProvider;
|
|
58
|
-
|
|
59
|
-
export { type HuggingFaceProvider, type HuggingFaceProviderSettings, type HuggingFaceResponsesModelId, type HuggingFaceResponsesSettings, createHuggingFace, huggingface };
|