@ai-sdk/deepseek 3.0.28 → 3.0.30
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 +14 -0
- package/dist/index.d.ts +14 -4
- package/dist/index.js +180 -13
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +4 -2
- package/dist/internal/index.js +56 -8
- package/dist/internal/index.js.map +1 -1
- package/docs/30-deepseek.mdx +45 -4
- package/package.json +2 -2
- package/src/chat/convert-to-deepseek-chat-messages.ts +66 -3
- package/src/chat/deepseek-chat-api-types.ts +21 -1
- package/src/chat/deepseek-chat-language-model-options.ts +1 -0
- package/src/chat/deepseek-chat-language-model.ts +5 -2
- package/src/deepseek-provider.ts +19 -3
- package/src/files/deepseek-files-api.ts +16 -0
- package/src/files/deepseek-files-options.ts +22 -0
- package/src/files/deepseek-files.ts +109 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
lazySchema,
|
|
3
|
+
zodSchema,
|
|
4
|
+
type InferSchema,
|
|
5
|
+
} from '@ai-sdk/provider-utils';
|
|
6
|
+
import { z } from 'zod/v4';
|
|
7
|
+
|
|
8
|
+
export const deepSeekFilesOptionsSchema = lazySchema(() =>
|
|
9
|
+
zodSchema(
|
|
10
|
+
z.object({
|
|
11
|
+
/**
|
|
12
|
+
* Number of seconds after creation before the file expires.
|
|
13
|
+
* Must be between 1 hour and 30 days.
|
|
14
|
+
*/
|
|
15
|
+
expiresAfter: z.number().int().min(3600).max(2592000).optional(),
|
|
16
|
+
}),
|
|
17
|
+
),
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export type DeepSeekFilesOptions = InferSchema<
|
|
21
|
+
typeof deepSeekFilesOptionsSchema
|
|
22
|
+
>;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FilesV4,
|
|
3
|
+
FilesV4UploadFileCallOptions,
|
|
4
|
+
FilesV4UploadFileResult,
|
|
5
|
+
} from '@ai-sdk/provider';
|
|
6
|
+
import {
|
|
7
|
+
combineHeaders,
|
|
8
|
+
convertInlineFileDataToUint8Array,
|
|
9
|
+
createJsonErrorResponseHandler,
|
|
10
|
+
createJsonResponseHandler,
|
|
11
|
+
parseProviderOptions,
|
|
12
|
+
postFormDataToApi,
|
|
13
|
+
type FetchFunction,
|
|
14
|
+
type InferSchema,
|
|
15
|
+
} from '@ai-sdk/provider-utils';
|
|
16
|
+
import { deepSeekErrorSchema } from '../chat/deepseek-chat-api-types';
|
|
17
|
+
import { deepSeekFilesResponseSchema } from './deepseek-files-api';
|
|
18
|
+
import {
|
|
19
|
+
deepSeekFilesOptionsSchema,
|
|
20
|
+
type DeepSeekFilesOptions,
|
|
21
|
+
} from './deepseek-files-options';
|
|
22
|
+
|
|
23
|
+
interface DeepSeekFilesConfig {
|
|
24
|
+
provider: string;
|
|
25
|
+
baseURL: string;
|
|
26
|
+
headers: () => Record<string, string | undefined>;
|
|
27
|
+
fetch?: FetchFunction;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const deepSeekFailedResponseHandler = createJsonErrorResponseHandler({
|
|
31
|
+
errorSchema: deepSeekErrorSchema,
|
|
32
|
+
errorToMessage: (error: InferSchema<typeof deepSeekErrorSchema>) =>
|
|
33
|
+
error.error.message,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export class DeepSeekFiles implements FilesV4 {
|
|
37
|
+
readonly specificationVersion = 'v4';
|
|
38
|
+
|
|
39
|
+
get provider(): string {
|
|
40
|
+
return this.config.provider;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
constructor(private readonly config: DeepSeekFilesConfig) {}
|
|
44
|
+
|
|
45
|
+
async uploadFile({
|
|
46
|
+
data,
|
|
47
|
+
mediaType,
|
|
48
|
+
filename,
|
|
49
|
+
providerOptions,
|
|
50
|
+
}: FilesV4UploadFileCallOptions): Promise<FilesV4UploadFileResult> {
|
|
51
|
+
const deepSeekOptions = (await parseProviderOptions({
|
|
52
|
+
provider: 'deepseek',
|
|
53
|
+
providerOptions,
|
|
54
|
+
schema: deepSeekFilesOptionsSchema,
|
|
55
|
+
})) as DeepSeekFilesOptions | undefined;
|
|
56
|
+
|
|
57
|
+
const fileBytes = convertInlineFileDataToUint8Array(data);
|
|
58
|
+
const blob = new Blob([fileBytes], { type: mediaType });
|
|
59
|
+
|
|
60
|
+
const formData = new FormData();
|
|
61
|
+
if (filename != null) {
|
|
62
|
+
formData.append('file', blob, filename);
|
|
63
|
+
} else {
|
|
64
|
+
formData.append('file', blob);
|
|
65
|
+
}
|
|
66
|
+
formData.append('purpose', 'user_data');
|
|
67
|
+
|
|
68
|
+
if (deepSeekOptions?.expiresAfter != null) {
|
|
69
|
+
formData.append('expires_after[anchor]', 'created_at');
|
|
70
|
+
formData.append(
|
|
71
|
+
'expires_after[seconds]',
|
|
72
|
+
String(deepSeekOptions.expiresAfter),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const { value: response } = await postFormDataToApi({
|
|
77
|
+
url: `${this.config.baseURL}/files`,
|
|
78
|
+
headers: combineHeaders(this.config.headers()),
|
|
79
|
+
formData,
|
|
80
|
+
failedResponseHandler: deepSeekFailedResponseHandler,
|
|
81
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
82
|
+
deepSeekFilesResponseSchema,
|
|
83
|
+
),
|
|
84
|
+
fetch: this.config.fetch,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
warnings: [],
|
|
89
|
+
providerReference: { deepseek: response.id },
|
|
90
|
+
...((response.filename ?? filename)
|
|
91
|
+
? { filename: response.filename ?? filename }
|
|
92
|
+
: {}),
|
|
93
|
+
...(mediaType != null ? { mediaType } : {}),
|
|
94
|
+
providerMetadata: {
|
|
95
|
+
deepseek: {
|
|
96
|
+
...(response.filename != null ? { filename: response.filename } : {}),
|
|
97
|
+
...(response.purpose != null ? { purpose: response.purpose } : {}),
|
|
98
|
+
...(response.bytes != null ? { bytes: response.bytes } : {}),
|
|
99
|
+
...(response.created_at != null
|
|
100
|
+
? { createdAt: response.created_at }
|
|
101
|
+
: {}),
|
|
102
|
+
...(response.expires_at != null
|
|
103
|
+
? { expiresAt: response.expires_at }
|
|
104
|
+
: {}),
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -17,3 +17,4 @@ export type {
|
|
|
17
17
|
DeepSeekLanguageModelChatOptions as DeepSeekChatOptions,
|
|
18
18
|
} from './chat/deepseek-chat-language-model-options';
|
|
19
19
|
export type { DeepSeekErrorData } from './chat/deepseek-chat-api-types';
|
|
20
|
+
export type { DeepSeekFilesOptions } from './files/deepseek-files-options';
|