@ai-sdk/deepseek 3.0.0-beta.8 → 3.0.0-canary.34
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 +228 -0
- package/README.md +2 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +135 -220
- package/dist/index.js.map +1 -1
- package/docs/30-deepseek.mdx +14 -14
- package/package.json +11 -9
- package/src/chat/convert-to-deepseek-chat-messages.ts +11 -5
- package/src/chat/convert-to-deepseek-usage.ts +1 -1
- package/src/chat/{deepseek-chat-options.ts → deepseek-chat-language-model-options.ts} +3 -3
- package/src/chat/deepseek-chat-language-model.ts +38 -147
- package/src/chat/deepseek-prepare-tools.ts +5 -2
- package/src/chat/map-deepseek-finish-reason.ts +1 -1
- package/src/deepseek-provider.ts +5 -5
- package/src/index.ts +12 -5
- package/dist/index.d.mts +0 -68
- package/dist/index.mjs +0 -821
- package/dist/index.mjs.map +0 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
APICallError,
|
|
3
|
-
InvalidResponseDataError,
|
|
4
3
|
LanguageModelV4,
|
|
5
4
|
LanguageModelV4CallOptions,
|
|
6
5
|
LanguageModelV4Content,
|
|
@@ -14,35 +13,38 @@ import {
|
|
|
14
13
|
createEventSourceResponseHandler,
|
|
15
14
|
createJsonErrorResponseHandler,
|
|
16
15
|
createJsonResponseHandler,
|
|
17
|
-
FetchFunction,
|
|
18
16
|
generateId,
|
|
19
|
-
InferSchema,
|
|
20
17
|
isCustomReasoning,
|
|
21
|
-
isParsableJson,
|
|
22
18
|
parseProviderOptions,
|
|
23
|
-
ParseResult,
|
|
24
19
|
postJsonToApi,
|
|
25
|
-
|
|
20
|
+
serializeModelOptions,
|
|
21
|
+
StreamingToolCallTracker,
|
|
22
|
+
WORKFLOW_SERIALIZE,
|
|
23
|
+
WORKFLOW_DESERIALIZE,
|
|
24
|
+
type FetchFunction,
|
|
25
|
+
type InferSchema,
|
|
26
|
+
type ParseResult,
|
|
27
|
+
type ResponseHandler,
|
|
26
28
|
} from '@ai-sdk/provider-utils';
|
|
27
29
|
import { convertToDeepSeekChatMessages } from './convert-to-deepseek-chat-messages';
|
|
28
30
|
import { convertDeepSeekUsage } from './convert-to-deepseek-usage';
|
|
29
31
|
import {
|
|
30
32
|
deepseekChatChunkSchema,
|
|
31
33
|
deepseekChatResponseSchema,
|
|
32
|
-
DeepSeekChatTokenUsage,
|
|
33
34
|
deepSeekErrorSchema,
|
|
35
|
+
type DeepSeekChatTokenUsage,
|
|
34
36
|
} from './deepseek-chat-api-types';
|
|
35
37
|
import {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
} from './deepseek-chat-options';
|
|
38
|
+
deepseekLanguageModelChatOptions,
|
|
39
|
+
type DeepSeekChatModelId,
|
|
40
|
+
} from './deepseek-chat-language-model-options';
|
|
39
41
|
import { prepareTools } from './deepseek-prepare-tools';
|
|
40
42
|
import { getResponseMetadata } from './get-response-metadata';
|
|
41
43
|
import { mapDeepSeekFinishReason } from './map-deepseek-finish-reason';
|
|
42
44
|
|
|
43
45
|
export type DeepSeekChatConfig = {
|
|
44
46
|
provider: string;
|
|
45
|
-
headers
|
|
47
|
+
headers?: () => Record<string, string | undefined>;
|
|
46
48
|
url: (options: { modelId: string; path: string }) => string;
|
|
47
49
|
fetch?: FetchFunction;
|
|
48
50
|
};
|
|
@@ -56,6 +58,20 @@ export class DeepSeekChatLanguageModel implements LanguageModelV4 {
|
|
|
56
58
|
private readonly config: DeepSeekChatConfig;
|
|
57
59
|
private readonly failedResponseHandler: ResponseHandler<APICallError>;
|
|
58
60
|
|
|
61
|
+
static [WORKFLOW_SERIALIZE](model: DeepSeekChatLanguageModel) {
|
|
62
|
+
return serializeModelOptions({
|
|
63
|
+
modelId: model.modelId,
|
|
64
|
+
config: model.config,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static [WORKFLOW_DESERIALIZE](options: {
|
|
69
|
+
modelId: DeepSeekChatModelId;
|
|
70
|
+
config: DeepSeekChatConfig;
|
|
71
|
+
}) {
|
|
72
|
+
return new DeepSeekChatLanguageModel(options.modelId, options.config);
|
|
73
|
+
}
|
|
74
|
+
|
|
59
75
|
constructor(modelId: DeepSeekChatModelId, config: DeepSeekChatConfig) {
|
|
60
76
|
this.modelId = modelId;
|
|
61
77
|
this.config = config;
|
|
@@ -95,12 +111,13 @@ export class DeepSeekChatLanguageModel implements LanguageModelV4 {
|
|
|
95
111
|
(await parseProviderOptions({
|
|
96
112
|
provider: this.providerOptionsName,
|
|
97
113
|
providerOptions,
|
|
98
|
-
schema:
|
|
114
|
+
schema: deepseekLanguageModelChatOptions,
|
|
99
115
|
})) ?? {};
|
|
100
116
|
|
|
101
117
|
const { messages, warnings } = convertToDeepSeekChatMessages({
|
|
102
118
|
prompt,
|
|
103
119
|
responseFormat,
|
|
120
|
+
modelId: this.modelId,
|
|
104
121
|
});
|
|
105
122
|
|
|
106
123
|
if (topK != null) {
|
|
@@ -159,7 +176,7 @@ export class DeepSeekChatLanguageModel implements LanguageModelV4 {
|
|
|
159
176
|
path: '/chat/completions',
|
|
160
177
|
modelId: this.modelId,
|
|
161
178
|
}),
|
|
162
|
-
headers: combineHeaders(this.config.headers(), options.headers),
|
|
179
|
+
headers: combineHeaders(this.config.headers?.(), options.headers),
|
|
163
180
|
body: args,
|
|
164
181
|
failedResponseHandler: this.failedResponseHandler,
|
|
165
182
|
successfulResponseHandler: createJsonResponseHandler(
|
|
@@ -238,7 +255,7 @@ export class DeepSeekChatLanguageModel implements LanguageModelV4 {
|
|
|
238
255
|
path: '/chat/completions',
|
|
239
256
|
modelId: this.modelId,
|
|
240
257
|
}),
|
|
241
|
-
headers: combineHeaders(this.config.headers(), options.headers),
|
|
258
|
+
headers: combineHeaders(this.config.headers?.(), options.headers),
|
|
242
259
|
body,
|
|
243
260
|
failedResponseHandler: this.failedResponseHandler,
|
|
244
261
|
successfulResponseHandler: createEventSourceResponseHandler(
|
|
@@ -248,15 +265,7 @@ export class DeepSeekChatLanguageModel implements LanguageModelV4 {
|
|
|
248
265
|
fetch: this.config.fetch,
|
|
249
266
|
});
|
|
250
267
|
|
|
251
|
-
|
|
252
|
-
id: string;
|
|
253
|
-
type: 'function';
|
|
254
|
-
function: {
|
|
255
|
-
name: string;
|
|
256
|
-
arguments: string;
|
|
257
|
-
};
|
|
258
|
-
hasFinished: boolean;
|
|
259
|
-
}> = [];
|
|
268
|
+
let toolCallTracker: StreamingToolCallTracker;
|
|
260
269
|
|
|
261
270
|
let finishReason: LanguageModelV4FinishReason = {
|
|
262
271
|
unified: 'other',
|
|
@@ -275,6 +284,9 @@ export class DeepSeekChatLanguageModel implements LanguageModelV4 {
|
|
|
275
284
|
LanguageModelV4StreamPart
|
|
276
285
|
>({
|
|
277
286
|
start(controller) {
|
|
287
|
+
toolCallTracker = new StreamingToolCallTracker(controller, {
|
|
288
|
+
generateId,
|
|
289
|
+
});
|
|
278
290
|
controller.enqueue({ type: 'stream-start', warnings });
|
|
279
291
|
},
|
|
280
292
|
|
|
@@ -378,113 +390,7 @@ export class DeepSeekChatLanguageModel implements LanguageModelV4 {
|
|
|
378
390
|
}
|
|
379
391
|
|
|
380
392
|
for (const toolCallDelta of delta.tool_calls) {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
if (toolCalls[index] == null) {
|
|
384
|
-
if (toolCallDelta.id == null) {
|
|
385
|
-
throw new InvalidResponseDataError({
|
|
386
|
-
data: toolCallDelta,
|
|
387
|
-
message: `Expected 'id' to be a string.`,
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
if (toolCallDelta.function?.name == null) {
|
|
392
|
-
throw new InvalidResponseDataError({
|
|
393
|
-
data: toolCallDelta,
|
|
394
|
-
message: `Expected 'function.name' to be a string.`,
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
controller.enqueue({
|
|
399
|
-
type: 'tool-input-start',
|
|
400
|
-
id: toolCallDelta.id,
|
|
401
|
-
toolName: toolCallDelta.function.name,
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
toolCalls[index] = {
|
|
405
|
-
id: toolCallDelta.id,
|
|
406
|
-
type: 'function',
|
|
407
|
-
function: {
|
|
408
|
-
name: toolCallDelta.function.name,
|
|
409
|
-
arguments: toolCallDelta.function.arguments ?? '',
|
|
410
|
-
},
|
|
411
|
-
hasFinished: false,
|
|
412
|
-
};
|
|
413
|
-
|
|
414
|
-
const toolCall = toolCalls[index];
|
|
415
|
-
|
|
416
|
-
if (
|
|
417
|
-
toolCall.function?.name != null &&
|
|
418
|
-
toolCall.function?.arguments != null
|
|
419
|
-
) {
|
|
420
|
-
// send delta if the argument text has already started:
|
|
421
|
-
if (toolCall.function.arguments.length > 0) {
|
|
422
|
-
controller.enqueue({
|
|
423
|
-
type: 'tool-input-delta',
|
|
424
|
-
id: toolCall.id,
|
|
425
|
-
delta: toolCall.function.arguments,
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
// check if tool call is complete
|
|
430
|
-
// (some providers send the full tool call in one chunk):
|
|
431
|
-
if (isParsableJson(toolCall.function.arguments)) {
|
|
432
|
-
controller.enqueue({
|
|
433
|
-
type: 'tool-input-end',
|
|
434
|
-
id: toolCall.id,
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
controller.enqueue({
|
|
438
|
-
type: 'tool-call',
|
|
439
|
-
toolCallId: toolCall.id ?? generateId(),
|
|
440
|
-
toolName: toolCall.function.name,
|
|
441
|
-
input: toolCall.function.arguments,
|
|
442
|
-
});
|
|
443
|
-
toolCall.hasFinished = true;
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
continue;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
// existing tool call, merge if not finished
|
|
451
|
-
const toolCall = toolCalls[index];
|
|
452
|
-
|
|
453
|
-
if (toolCall.hasFinished) {
|
|
454
|
-
continue;
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
if (toolCallDelta.function?.arguments != null) {
|
|
458
|
-
toolCall.function!.arguments +=
|
|
459
|
-
toolCallDelta.function?.arguments ?? '';
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
// send delta
|
|
463
|
-
controller.enqueue({
|
|
464
|
-
type: 'tool-input-delta',
|
|
465
|
-
id: toolCall.id,
|
|
466
|
-
delta: toolCallDelta.function.arguments ?? '',
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
// check if tool call is complete
|
|
470
|
-
if (
|
|
471
|
-
toolCall.function?.name != null &&
|
|
472
|
-
toolCall.function?.arguments != null &&
|
|
473
|
-
isParsableJson(toolCall.function.arguments)
|
|
474
|
-
) {
|
|
475
|
-
controller.enqueue({
|
|
476
|
-
type: 'tool-input-end',
|
|
477
|
-
id: toolCall.id,
|
|
478
|
-
});
|
|
479
|
-
|
|
480
|
-
controller.enqueue({
|
|
481
|
-
type: 'tool-call',
|
|
482
|
-
toolCallId: toolCall.id ?? generateId(),
|
|
483
|
-
toolName: toolCall.function.name,
|
|
484
|
-
input: toolCall.function.arguments,
|
|
485
|
-
});
|
|
486
|
-
toolCall.hasFinished = true;
|
|
487
|
-
}
|
|
393
|
+
toolCallTracker.processDelta(toolCallDelta);
|
|
488
394
|
}
|
|
489
395
|
}
|
|
490
396
|
},
|
|
@@ -498,22 +404,7 @@ export class DeepSeekChatLanguageModel implements LanguageModelV4 {
|
|
|
498
404
|
controller.enqueue({ type: 'text-end', id: 'txt-0' });
|
|
499
405
|
}
|
|
500
406
|
|
|
501
|
-
|
|
502
|
-
for (const toolCall of toolCalls.filter(
|
|
503
|
-
toolCall => !toolCall.hasFinished,
|
|
504
|
-
)) {
|
|
505
|
-
controller.enqueue({
|
|
506
|
-
type: 'tool-input-end',
|
|
507
|
-
id: toolCall.id,
|
|
508
|
-
});
|
|
509
|
-
|
|
510
|
-
controller.enqueue({
|
|
511
|
-
type: 'tool-call',
|
|
512
|
-
toolCallId: toolCall.id ?? generateId(),
|
|
513
|
-
toolName: toolCall.function.name,
|
|
514
|
-
input: toolCall.function.arguments,
|
|
515
|
-
});
|
|
516
|
-
}
|
|
407
|
+
toolCallTracker.flush();
|
|
517
408
|
|
|
518
409
|
controller.enqueue({
|
|
519
410
|
type: 'finish',
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
LanguageModelV4CallOptions,
|
|
3
|
+
SharedV4Warning,
|
|
4
|
+
} from '@ai-sdk/provider';
|
|
5
|
+
import type {
|
|
3
6
|
DeepSeekFunctionTool,
|
|
4
7
|
DeepSeekToolChoice,
|
|
5
8
|
} from './deepseek-chat-api-types';
|
package/src/deepseek-provider.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
LanguageModelV4,
|
|
3
2
|
NoSuchModelError,
|
|
4
|
-
|
|
3
|
+
type LanguageModelV4,
|
|
4
|
+
type ProviderV4,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import {
|
|
7
|
-
FetchFunction,
|
|
8
7
|
loadApiKey,
|
|
9
8
|
withoutTrailingSlash,
|
|
10
9
|
withUserAgentSuffix,
|
|
10
|
+
type FetchFunction,
|
|
11
11
|
} from '@ai-sdk/provider-utils';
|
|
12
|
-
import { DeepSeekChatModelId } from './chat/deepseek-chat-options';
|
|
12
|
+
import type { DeepSeekChatModelId } from './chat/deepseek-chat-language-model-options';
|
|
13
13
|
import { DeepSeekChatLanguageModel } from './chat/deepseek-chat-language-model';
|
|
14
14
|
import { VERSION } from './version';
|
|
15
15
|
|
|
@@ -105,4 +105,4 @@ export function createDeepSeek(
|
|
|
105
105
|
return provider;
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
export const
|
|
108
|
+
export const deepSeek = createDeepSeek();
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {
|
|
2
|
+
createDeepSeek,
|
|
3
|
+
deepSeek,
|
|
4
|
+
/** @deprecated Use `deepSeek` instead. */
|
|
5
|
+
deepSeek as deepseek,
|
|
6
|
+
} from './deepseek-provider';
|
|
2
7
|
export type {
|
|
3
8
|
DeepSeekProvider,
|
|
4
9
|
DeepSeekProviderSettings,
|
|
5
10
|
} from './deepseek-provider';
|
|
6
11
|
export { VERSION } from './version';
|
|
7
12
|
export type {
|
|
8
|
-
|
|
9
|
-
/** @deprecated Use `
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
DeepSeekLanguageModelChatOptions,
|
|
14
|
+
/** @deprecated Use `DeepSeekLanguageModelChatOptions` instead. */
|
|
15
|
+
DeepSeekLanguageModelChatOptions as DeepSeekLanguageModelOptions,
|
|
16
|
+
/** @deprecated Use `DeepSeekLanguageModelChatOptions` instead. */
|
|
17
|
+
DeepSeekLanguageModelChatOptions as DeepSeekChatOptions,
|
|
18
|
+
} from './chat/deepseek-chat-language-model-options';
|
|
12
19
|
export type { DeepSeekErrorData } from './chat/deepseek-chat-api-types';
|
package/dist/index.d.mts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { ProviderV4, LanguageModelV4 } from '@ai-sdk/provider';
|
|
2
|
-
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
-
import { z } from 'zod/v4';
|
|
4
|
-
|
|
5
|
-
type DeepSeekChatModelId = 'deepseek-chat' | 'deepseek-reasoner' | (string & {});
|
|
6
|
-
declare const deepseekLanguageModelOptions: z.ZodObject<{
|
|
7
|
-
thinking: z.ZodOptional<z.ZodObject<{
|
|
8
|
-
type: z.ZodOptional<z.ZodEnum<{
|
|
9
|
-
enabled: "enabled";
|
|
10
|
-
disabled: "disabled";
|
|
11
|
-
}>>;
|
|
12
|
-
}, z.core.$strip>>;
|
|
13
|
-
}, z.core.$strip>;
|
|
14
|
-
type DeepSeekLanguageModelOptions = z.infer<typeof deepseekLanguageModelOptions>;
|
|
15
|
-
|
|
16
|
-
interface DeepSeekProviderSettings {
|
|
17
|
-
/**
|
|
18
|
-
* DeepSeek API key.
|
|
19
|
-
*/
|
|
20
|
-
apiKey?: string;
|
|
21
|
-
/**
|
|
22
|
-
* Base URL for the API calls.
|
|
23
|
-
*/
|
|
24
|
-
baseURL?: string;
|
|
25
|
-
/**
|
|
26
|
-
* Custom headers to include in the requests.
|
|
27
|
-
*/
|
|
28
|
-
headers?: Record<string, string>;
|
|
29
|
-
/**
|
|
30
|
-
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
31
|
-
* or to provide a custom fetch implementation for e.g. testing.
|
|
32
|
-
*/
|
|
33
|
-
fetch?: FetchFunction;
|
|
34
|
-
}
|
|
35
|
-
interface DeepSeekProvider extends ProviderV4 {
|
|
36
|
-
/**
|
|
37
|
-
* Creates a DeepSeek model for text generation.
|
|
38
|
-
*/
|
|
39
|
-
(modelId: DeepSeekChatModelId): LanguageModelV4;
|
|
40
|
-
/**
|
|
41
|
-
* Creates a DeepSeek model for text generation.
|
|
42
|
-
*/
|
|
43
|
-
languageModel(modelId: DeepSeekChatModelId): LanguageModelV4;
|
|
44
|
-
/**
|
|
45
|
-
* Creates a DeepSeek chat model for text generation.
|
|
46
|
-
*/
|
|
47
|
-
chat(modelId: DeepSeekChatModelId): LanguageModelV4;
|
|
48
|
-
/**
|
|
49
|
-
* @deprecated Use `embeddingModel` instead.
|
|
50
|
-
*/
|
|
51
|
-
textEmbeddingModel(modelId: string): never;
|
|
52
|
-
}
|
|
53
|
-
declare function createDeepSeek(options?: DeepSeekProviderSettings): DeepSeekProvider;
|
|
54
|
-
declare const deepseek: DeepSeekProvider;
|
|
55
|
-
|
|
56
|
-
declare const VERSION: string;
|
|
57
|
-
|
|
58
|
-
declare const deepSeekErrorSchema: z.ZodObject<{
|
|
59
|
-
error: z.ZodObject<{
|
|
60
|
-
message: z.ZodString;
|
|
61
|
-
type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
62
|
-
param: z.ZodOptional<z.ZodNullable<z.ZodAny>>;
|
|
63
|
-
code: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
|
|
64
|
-
}, z.core.$strip>;
|
|
65
|
-
}, z.core.$strip>;
|
|
66
|
-
type DeepSeekErrorData = z.infer<typeof deepSeekErrorSchema>;
|
|
67
|
-
|
|
68
|
-
export { type DeepSeekLanguageModelOptions as DeepSeekChatOptions, type DeepSeekErrorData, type DeepSeekLanguageModelOptions, type DeepSeekProvider, type DeepSeekProviderSettings, VERSION, createDeepSeek, deepseek };
|