@node-llm/core 0.5.0 → 0.7.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/README.md +83 -421
- package/dist/chat/Chat.d.ts +5 -0
- package/dist/chat/Chat.d.ts.map +1 -1
- package/dist/chat/Chat.js +31 -7
- package/dist/chat/ChatOptions.d.ts +3 -0
- package/dist/chat/ChatOptions.d.ts.map +1 -1
- package/dist/chat/ChatResponse.d.ts +5 -1
- package/dist/chat/ChatResponse.d.ts.map +1 -1
- package/dist/chat/ChatResponse.js +6 -1
- package/dist/chat/Stream.d.ts.map +1 -1
- package/dist/chat/Stream.js +7 -1
- package/dist/config.d.ts +29 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +11 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/llm.d.ts +20 -10
- package/dist/llm.d.ts.map +1 -1
- package/dist/llm.js +52 -23
- package/dist/models/ModelRegistry.d.ts +39 -12
- package/dist/models/ModelRegistry.d.ts.map +1 -1
- package/dist/models/ModelRegistry.js +50 -40
- package/dist/models/models.d.ts +972 -0
- package/dist/models/models.d.ts.map +1 -0
- package/dist/models/models.js +7076 -0
- package/dist/models/types.d.ts +50 -0
- package/dist/models/types.d.ts.map +1 -0
- package/dist/models/types.js +1 -0
- package/dist/providers/Provider.d.ts +7 -0
- package/dist/providers/Provider.d.ts.map +1 -1
- package/dist/providers/anthropic/AnthropicProvider.d.ts +1 -0
- package/dist/providers/anthropic/AnthropicProvider.d.ts.map +1 -1
- package/dist/providers/anthropic/AnthropicProvider.js +2 -3
- package/dist/providers/anthropic/Capabilities.d.ts +1 -37
- package/dist/providers/anthropic/Capabilities.d.ts.map +1 -1
- package/dist/providers/anthropic/Capabilities.js +59 -130
- package/dist/providers/anthropic/Chat.d.ts.map +1 -1
- package/dist/providers/anthropic/Chat.js +6 -2
- package/dist/providers/anthropic/Models.d.ts +1 -0
- package/dist/providers/anthropic/Models.d.ts.map +1 -1
- package/dist/providers/anthropic/Models.js +36 -41
- package/dist/providers/anthropic/Streaming.d.ts.map +1 -1
- package/dist/providers/anthropic/Streaming.js +10 -1
- package/dist/providers/anthropic/index.d.ts.map +1 -1
- package/dist/providers/anthropic/index.js +3 -2
- package/dist/providers/deepseek/Capabilities.d.ts +14 -0
- package/dist/providers/deepseek/Capabilities.d.ts.map +1 -0
- package/dist/providers/deepseek/Capabilities.js +52 -0
- package/dist/providers/deepseek/Chat.d.ts +8 -0
- package/dist/providers/deepseek/Chat.d.ts.map +1 -0
- package/dist/providers/deepseek/Chat.js +89 -0
- package/dist/providers/deepseek/DeepSeekProvider.d.ts +28 -0
- package/dist/providers/deepseek/DeepSeekProvider.d.ts.map +1 -0
- package/dist/providers/deepseek/DeepSeekProvider.js +38 -0
- package/dist/providers/deepseek/Models.d.ts +8 -0
- package/dist/providers/deepseek/Models.d.ts.map +1 -0
- package/dist/providers/deepseek/Models.js +67 -0
- package/dist/providers/deepseek/Streaming.d.ts +8 -0
- package/dist/providers/deepseek/Streaming.d.ts.map +1 -0
- package/dist/providers/deepseek/Streaming.js +74 -0
- package/dist/providers/deepseek/index.d.ts +7 -0
- package/dist/providers/deepseek/index.d.ts.map +1 -0
- package/dist/providers/deepseek/index.js +22 -0
- package/dist/providers/gemini/Capabilities.d.ts +28 -7
- package/dist/providers/gemini/Capabilities.d.ts.map +1 -1
- package/dist/providers/gemini/Capabilities.js +32 -20
- package/dist/providers/gemini/Chat.d.ts.map +1 -1
- package/dist/providers/gemini/Chat.js +9 -11
- package/dist/providers/gemini/GeminiProvider.d.ts +1 -0
- package/dist/providers/gemini/GeminiProvider.d.ts.map +1 -1
- package/dist/providers/gemini/GeminiProvider.js +1 -0
- package/dist/providers/gemini/Models.d.ts +1 -0
- package/dist/providers/gemini/Models.d.ts.map +1 -1
- package/dist/providers/gemini/Models.js +46 -26
- package/dist/providers/gemini/index.d.ts.map +1 -1
- package/dist/providers/gemini/index.js +3 -2
- package/dist/providers/openai/Capabilities.d.ts +4 -11
- package/dist/providers/openai/Capabilities.d.ts.map +1 -1
- package/dist/providers/openai/Capabilities.js +124 -121
- package/dist/providers/openai/Chat.d.ts.map +1 -1
- package/dist/providers/openai/Chat.js +19 -17
- package/dist/providers/openai/Embedding.d.ts.map +1 -1
- package/dist/providers/openai/Embedding.js +2 -1
- package/dist/providers/openai/Image.d.ts.map +1 -1
- package/dist/providers/openai/Image.js +2 -1
- package/dist/providers/openai/ModelDefinitions.d.ts +1 -24
- package/dist/providers/openai/ModelDefinitions.d.ts.map +1 -1
- package/dist/providers/openai/ModelDefinitions.js +1 -211
- package/dist/providers/openai/Models.d.ts +1 -0
- package/dist/providers/openai/Models.d.ts.map +1 -1
- package/dist/providers/openai/Models.js +46 -22
- package/dist/providers/openai/Moderation.d.ts.map +1 -1
- package/dist/providers/openai/Moderation.js +2 -1
- package/dist/providers/openai/OpenAIProvider.d.ts +1 -0
- package/dist/providers/openai/OpenAIProvider.d.ts.map +1 -1
- package/dist/providers/openai/OpenAIProvider.js +1 -0
- package/dist/providers/openai/Streaming.d.ts.map +1 -1
- package/dist/providers/openai/Streaming.js +5 -1
- package/dist/providers/openai/Transcription.d.ts.map +1 -1
- package/dist/providers/openai/Transcription.js +3 -2
- package/dist/providers/openai/index.d.ts.map +1 -1
- package/dist/providers/openai/index.js +5 -3
- package/dist/providers/openai/utils.d.ts +20 -0
- package/dist/providers/openai/utils.d.ts.map +1 -0
- package/dist/providers/openai/utils.js +25 -0
- package/package.json +1 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ModelRegistry } from "../../models/ModelRegistry.js";
|
|
2
|
+
export class Capabilities {
|
|
3
|
+
static getCapabilities(modelId) {
|
|
4
|
+
const caps = ["streaming"];
|
|
5
|
+
if (/deepseek-chat/.test(modelId)) {
|
|
6
|
+
caps.push("function_calling");
|
|
7
|
+
}
|
|
8
|
+
if (/deepseek-reasoner/.test(modelId)) {
|
|
9
|
+
caps.push("reasoning");
|
|
10
|
+
}
|
|
11
|
+
return caps;
|
|
12
|
+
}
|
|
13
|
+
static getContextWindow(modelId) {
|
|
14
|
+
const val = ModelRegistry.getContextWindow(modelId, "deepseek");
|
|
15
|
+
if (val)
|
|
16
|
+
return val;
|
|
17
|
+
if (/deepseek-(?:chat|reasoner)/.test(modelId)) {
|
|
18
|
+
return 64_000;
|
|
19
|
+
}
|
|
20
|
+
return 32_768;
|
|
21
|
+
}
|
|
22
|
+
static getMaxOutputTokens(modelId) {
|
|
23
|
+
if (/deepseek-(?:chat|reasoner)/.test(modelId)) {
|
|
24
|
+
return 8_192;
|
|
25
|
+
}
|
|
26
|
+
return 4_096;
|
|
27
|
+
}
|
|
28
|
+
static supportsVision(modelId) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
static supportsTools(modelId) {
|
|
32
|
+
return /deepseek-chat/.test(modelId);
|
|
33
|
+
}
|
|
34
|
+
static supportsStructuredOutput(modelId) {
|
|
35
|
+
return /deepseek-(?:chat|reasoner)/.test(modelId);
|
|
36
|
+
}
|
|
37
|
+
static supportsEmbeddings(modelId) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
static supportsImageGeneration(modelId) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
static supportsTranscription(modelId) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
static supportsModeration(modelId) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
static supportsReasoning(modelId) {
|
|
50
|
+
return /deepseek-reasoner/.test(modelId);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ChatRequest, ChatResponse } from "../Provider.js";
|
|
2
|
+
export declare class DeepSeekChat {
|
|
3
|
+
private readonly baseUrl;
|
|
4
|
+
private readonly apiKey;
|
|
5
|
+
constructor(baseUrl: string, apiKey: string);
|
|
6
|
+
execute(request: ChatRequest): Promise<ChatResponse>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=Chat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAS,MAAM,gBAAgB,CAAC;AAqBlE,qBAAa,YAAY;IACX,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CAwF3D"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { ModelRegistry } from "../../models/ModelRegistry.js";
|
|
2
|
+
export class DeepSeekChat {
|
|
3
|
+
baseUrl;
|
|
4
|
+
apiKey;
|
|
5
|
+
constructor(baseUrl, apiKey) {
|
|
6
|
+
this.baseUrl = baseUrl;
|
|
7
|
+
this.apiKey = apiKey;
|
|
8
|
+
}
|
|
9
|
+
async execute(request) {
|
|
10
|
+
const { model, messages, tools, max_tokens, response_format, headers, ...rest } = request;
|
|
11
|
+
const body = {
|
|
12
|
+
model,
|
|
13
|
+
messages,
|
|
14
|
+
...rest
|
|
15
|
+
};
|
|
16
|
+
if (max_tokens)
|
|
17
|
+
body.max_tokens = max_tokens;
|
|
18
|
+
if (tools && tools.length > 0)
|
|
19
|
+
body.tools = tools;
|
|
20
|
+
if (max_tokens)
|
|
21
|
+
body.max_tokens = max_tokens;
|
|
22
|
+
if (tools && tools.length > 0)
|
|
23
|
+
body.tools = tools;
|
|
24
|
+
// Handle structured output for DeepSeek
|
|
25
|
+
if (response_format) {
|
|
26
|
+
if (response_format.type === "json_schema") {
|
|
27
|
+
body.response_format = { type: "json_object" };
|
|
28
|
+
// Append schema instructions to the system prompt or convert to a new system message
|
|
29
|
+
const schema = response_format.json_schema;
|
|
30
|
+
const schemaString = JSON.stringify(schema.schema, null, 2);
|
|
31
|
+
const instruction = `\n\nIMPORTANT: You must output strictly valid JSON conforming to the following schema:\n${schemaString}\n\nOutput only the JSON object.`;
|
|
32
|
+
// Find system message or append to last user message
|
|
33
|
+
const systemMessage = body.messages.find((m) => m.role === "system");
|
|
34
|
+
if (systemMessage) {
|
|
35
|
+
systemMessage.content += instruction;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
// Insert system message at the beginning
|
|
39
|
+
body.messages.unshift({
|
|
40
|
+
role: "system",
|
|
41
|
+
content: "You are a helpful assistant." + instruction
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
body.response_format = response_format;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (process.env.NODELLM_DEBUG === "true") {
|
|
50
|
+
console.log(`[DeepSeek Request] ${JSON.stringify(body, null, 2)}`);
|
|
51
|
+
}
|
|
52
|
+
const response = await fetch(`${this.baseUrl}/chat/completions`, {
|
|
53
|
+
method: "POST",
|
|
54
|
+
headers: {
|
|
55
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
56
|
+
"Content-Type": "application/json",
|
|
57
|
+
...request.headers,
|
|
58
|
+
},
|
|
59
|
+
body: JSON.stringify(body),
|
|
60
|
+
});
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
const errorText = await response.text();
|
|
63
|
+
throw new Error(`DeepSeek API error: ${response.status} - ${errorText}`);
|
|
64
|
+
}
|
|
65
|
+
const json = (await response.json());
|
|
66
|
+
const message = json.choices[0]?.message;
|
|
67
|
+
const content = message?.content ?? null;
|
|
68
|
+
const reasoning = message?.reasoning_content ?? null;
|
|
69
|
+
const usage = {
|
|
70
|
+
input_tokens: json.usage.prompt_tokens,
|
|
71
|
+
output_tokens: json.usage.completion_tokens,
|
|
72
|
+
total_tokens: json.usage.total_tokens,
|
|
73
|
+
};
|
|
74
|
+
const toolCalls = message?.tool_calls?.map((tc) => ({
|
|
75
|
+
id: tc.id,
|
|
76
|
+
type: tc.type,
|
|
77
|
+
function: {
|
|
78
|
+
name: tc.function.name,
|
|
79
|
+
arguments: tc.function.arguments
|
|
80
|
+
}
|
|
81
|
+
}));
|
|
82
|
+
if (!content && !reasoning && (!toolCalls || toolCalls.length === 0)) {
|
|
83
|
+
throw new Error("DeepSeek returned empty response");
|
|
84
|
+
}
|
|
85
|
+
// deepseek cost calculation if needed, otherwise just return usage
|
|
86
|
+
const calculatedUsage = ModelRegistry.calculateCost(usage, model, "deepseek");
|
|
87
|
+
return { content, reasoning, usage: calculatedUsage, tool_calls: toolCalls };
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Provider, ChatRequest, ChatResponse, ModelInfo, ChatChunk } from "../Provider.js";
|
|
2
|
+
export interface DeepSeekProviderOptions {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare class DeepSeekProvider implements Provider {
|
|
7
|
+
private readonly options;
|
|
8
|
+
private readonly baseUrl;
|
|
9
|
+
private readonly chatHandler;
|
|
10
|
+
private readonly streamingHandler;
|
|
11
|
+
private readonly modelsHandler;
|
|
12
|
+
capabilities: {
|
|
13
|
+
supportsVision: (model: string) => boolean;
|
|
14
|
+
supportsTools: (model: string) => boolean;
|
|
15
|
+
supportsStructuredOutput: (model: string) => boolean;
|
|
16
|
+
supportsEmbeddings: (model: string) => boolean;
|
|
17
|
+
supportsImageGeneration: (model: string) => boolean;
|
|
18
|
+
supportsTranscription: (model: string) => boolean;
|
|
19
|
+
supportsModeration: (model: string) => boolean;
|
|
20
|
+
supportsReasoning: (model: string) => boolean;
|
|
21
|
+
getContextWindow: (model: string) => number | null;
|
|
22
|
+
};
|
|
23
|
+
constructor(options: DeepSeekProviderOptions);
|
|
24
|
+
chat(request: ChatRequest): Promise<ChatResponse>;
|
|
25
|
+
stream(request: ChatRequest): AsyncGenerator<ChatChunk>;
|
|
26
|
+
listModels(): Promise<ModelInfo[]>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=DeepSeekProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeepSeekProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/DeepSeekProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAM3F,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,gBAAiB,YAAW,QAAQ;IAkBnC,OAAO,CAAC,QAAQ,CAAC,OAAO;IAjBpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAe;IAC3C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAoB;IACrD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiB;IAExC,YAAY;gCACO,MAAM;+BACP,MAAM;0CACK,MAAM;oCACZ,MAAM;yCACD,MAAM;uCACR,MAAM;oCACT,MAAM;mCACP,MAAM;kCACP,MAAM;MAChC;gBAE2B,OAAO,EAAE,uBAAuB;IAOvD,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAIhD,MAAM,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CAAC,SAAS,CAAC;IAIxD,UAAU,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;CAGzC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { DeepSeekChat } from "./Chat.js";
|
|
2
|
+
import { DeepSeekModels } from "./Models.js";
|
|
3
|
+
import { DeepSeekStreaming } from "./Streaming.js";
|
|
4
|
+
import { Capabilities } from "./Capabilities.js";
|
|
5
|
+
export class DeepSeekProvider {
|
|
6
|
+
options;
|
|
7
|
+
baseUrl;
|
|
8
|
+
chatHandler;
|
|
9
|
+
streamingHandler;
|
|
10
|
+
modelsHandler;
|
|
11
|
+
capabilities = {
|
|
12
|
+
supportsVision: (model) => Capabilities.supportsVision(model),
|
|
13
|
+
supportsTools: (model) => Capabilities.supportsTools(model),
|
|
14
|
+
supportsStructuredOutput: (model) => Capabilities.supportsStructuredOutput(model),
|
|
15
|
+
supportsEmbeddings: (model) => Capabilities.supportsEmbeddings(model),
|
|
16
|
+
supportsImageGeneration: (model) => Capabilities.supportsImageGeneration(model),
|
|
17
|
+
supportsTranscription: (model) => Capabilities.supportsTranscription(model),
|
|
18
|
+
supportsModeration: (model) => Capabilities.supportsModeration(model),
|
|
19
|
+
supportsReasoning: (model) => Capabilities.supportsReasoning(model),
|
|
20
|
+
getContextWindow: (model) => Capabilities.getContextWindow(model),
|
|
21
|
+
};
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.options = options;
|
|
24
|
+
this.baseUrl = options.baseUrl ?? "https://api.deepseek.com";
|
|
25
|
+
this.chatHandler = new DeepSeekChat(this.baseUrl, options.apiKey);
|
|
26
|
+
this.streamingHandler = new DeepSeekStreaming(this.baseUrl, options.apiKey);
|
|
27
|
+
this.modelsHandler = new DeepSeekModels(this.baseUrl, options.apiKey);
|
|
28
|
+
}
|
|
29
|
+
async chat(request) {
|
|
30
|
+
return this.chatHandler.execute(request);
|
|
31
|
+
}
|
|
32
|
+
async *stream(request) {
|
|
33
|
+
yield* this.streamingHandler.execute(request);
|
|
34
|
+
}
|
|
35
|
+
async listModels() {
|
|
36
|
+
return this.modelsHandler.execute();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Models.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/Models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAe3C,qBAAa,cAAc;IACb,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;CA+DtC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Capabilities } from "./Capabilities.js";
|
|
2
|
+
import { ModelRegistry } from "../../models/ModelRegistry.js";
|
|
3
|
+
export class DeepSeekModels {
|
|
4
|
+
baseUrl;
|
|
5
|
+
apiKey;
|
|
6
|
+
constructor(baseUrl, apiKey) {
|
|
7
|
+
this.baseUrl = baseUrl;
|
|
8
|
+
this.apiKey = apiKey;
|
|
9
|
+
}
|
|
10
|
+
async execute() {
|
|
11
|
+
const response = await fetch(`${this.baseUrl}/models`, {
|
|
12
|
+
method: "GET",
|
|
13
|
+
headers: {
|
|
14
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
if (!response.ok) {
|
|
18
|
+
// Fallback to local registry
|
|
19
|
+
const localModels = ModelRegistry.all()
|
|
20
|
+
.filter(m => m.provider === "deepseek")
|
|
21
|
+
.map(m => ({
|
|
22
|
+
id: m.id,
|
|
23
|
+
name: m.name,
|
|
24
|
+
provider: "deepseek",
|
|
25
|
+
family: m.family ?? "deepseek",
|
|
26
|
+
context_window: m.context_window ?? null,
|
|
27
|
+
max_output_tokens: m.max_output_tokens ?? null,
|
|
28
|
+
modalities: m.modalities,
|
|
29
|
+
capabilities: m.capabilities,
|
|
30
|
+
pricing: m.pricing,
|
|
31
|
+
metadata: m.metadata
|
|
32
|
+
}));
|
|
33
|
+
return localModels;
|
|
34
|
+
}
|
|
35
|
+
const json = (await response.json());
|
|
36
|
+
const localRegistry = ModelRegistry.all().filter(m => m.provider === "deepseek");
|
|
37
|
+
return json.data.map(m => {
|
|
38
|
+
// Try to find in local registry for enriched data (pricing, limits)
|
|
39
|
+
const local = localRegistry.find(l => l.id === m.id);
|
|
40
|
+
if (local) {
|
|
41
|
+
return {
|
|
42
|
+
id: local.id,
|
|
43
|
+
name: local.name,
|
|
44
|
+
provider: "deepseek", // Ensure literal type
|
|
45
|
+
family: local.family ?? "deepseek", // Handle missing family
|
|
46
|
+
context_window: local.context_window ?? null,
|
|
47
|
+
max_output_tokens: local.max_output_tokens ?? null,
|
|
48
|
+
modalities: local.modalities,
|
|
49
|
+
capabilities: local.capabilities,
|
|
50
|
+
pricing: local.pricing,
|
|
51
|
+
metadata: local.metadata
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
id: m.id,
|
|
56
|
+
name: m.id,
|
|
57
|
+
provider: "deepseek",
|
|
58
|
+
family: "deepseek",
|
|
59
|
+
context_window: Capabilities.getContextWindow(m.id),
|
|
60
|
+
max_output_tokens: Capabilities.getMaxOutputTokens(m.id),
|
|
61
|
+
modalities: { input: ["text"], output: ["text"] },
|
|
62
|
+
capabilities: Capabilities.getCapabilities(m.id),
|
|
63
|
+
pricing: {}
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ChatRequest, ChatChunk } from "../Provider.js";
|
|
2
|
+
export declare class DeepSeekStreaming {
|
|
3
|
+
private readonly baseUrl;
|
|
4
|
+
private readonly apiKey;
|
|
5
|
+
constructor(baseUrl: string, apiKey: string);
|
|
6
|
+
execute(request: ChatRequest): AsyncGenerator<ChatChunk>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=Streaming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAExD,qBAAa,iBAAiB;IAChB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEtE,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CAAC,SAAS,CAAC;CAwEhE"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export class DeepSeekStreaming {
|
|
2
|
+
baseUrl;
|
|
3
|
+
apiKey;
|
|
4
|
+
constructor(baseUrl, apiKey) {
|
|
5
|
+
this.baseUrl = baseUrl;
|
|
6
|
+
this.apiKey = apiKey;
|
|
7
|
+
}
|
|
8
|
+
async *execute(request) {
|
|
9
|
+
const { model, messages, tools, max_tokens, response_format, headers, ...rest } = request;
|
|
10
|
+
const body = {
|
|
11
|
+
model,
|
|
12
|
+
messages,
|
|
13
|
+
stream: true,
|
|
14
|
+
...rest
|
|
15
|
+
};
|
|
16
|
+
if (max_tokens)
|
|
17
|
+
body.max_tokens = max_tokens;
|
|
18
|
+
if (tools && tools.length > 0)
|
|
19
|
+
body.tools = tools;
|
|
20
|
+
if (response_format)
|
|
21
|
+
body.response_format = response_format;
|
|
22
|
+
const response = await fetch(`${this.baseUrl}/chat/completions`, {
|
|
23
|
+
method: "POST",
|
|
24
|
+
headers: {
|
|
25
|
+
"Authorization": `Bearer ${this.apiKey}`,
|
|
26
|
+
"Content-Type": "application/json",
|
|
27
|
+
...request.headers,
|
|
28
|
+
},
|
|
29
|
+
body: JSON.stringify(body),
|
|
30
|
+
});
|
|
31
|
+
if (!response.ok) {
|
|
32
|
+
const errorText = await response.text();
|
|
33
|
+
throw new Error(`DeepSeek API error: ${response.status} - ${errorText}`);
|
|
34
|
+
}
|
|
35
|
+
if (!response.body) {
|
|
36
|
+
throw new Error("No response body for streaming");
|
|
37
|
+
}
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
const reader = response.body.getReader();
|
|
40
|
+
const decoder = new TextDecoder();
|
|
41
|
+
let buffer = "";
|
|
42
|
+
while (true) {
|
|
43
|
+
const { value, done } = await reader.read();
|
|
44
|
+
if (done)
|
|
45
|
+
break;
|
|
46
|
+
const chunk = decoder.decode(value, { stream: true });
|
|
47
|
+
buffer += chunk;
|
|
48
|
+
const lines = buffer.split("\n\n");
|
|
49
|
+
buffer = lines.pop() || "";
|
|
50
|
+
for (const line of lines) {
|
|
51
|
+
const trimmed = line.trim();
|
|
52
|
+
if (!trimmed.startsWith("data: "))
|
|
53
|
+
continue;
|
|
54
|
+
const data = trimmed.replace("data: ", "").trim();
|
|
55
|
+
if (data === "[DONE]")
|
|
56
|
+
return;
|
|
57
|
+
try {
|
|
58
|
+
const json = JSON.parse(data);
|
|
59
|
+
const deltaContent = json.choices?.[0]?.delta?.content;
|
|
60
|
+
const deltaReasoning = json.choices?.[0]?.delta?.reasoning_content;
|
|
61
|
+
if (deltaContent || deltaReasoning) {
|
|
62
|
+
yield {
|
|
63
|
+
content: deltaContent || "",
|
|
64
|
+
reasoning: deltaReasoning || ""
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
// ignore
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./DeepSeekProvider.js";
|
|
2
|
+
export * from "./Chat.js";
|
|
3
|
+
export * from "./Models.js";
|
|
4
|
+
export * from "./Capabilities.js";
|
|
5
|
+
export declare function registerDeepSeekProvider(): void;
|
|
6
|
+
export declare const ensureDeepSeekRegistered: typeof registerDeepSeekProvider;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/index.ts"],"names":[],"mappings":"AAIA,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAIlC,wBAAgB,wBAAwB,SAevC;AAED,eAAO,MAAM,wBAAwB,iCAA2B,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { config } from "../../config.js";
|
|
2
|
+
import { providerRegistry } from "../registry.js";
|
|
3
|
+
import { DeepSeekProvider } from "./DeepSeekProvider.js";
|
|
4
|
+
export * from "./DeepSeekProvider.js";
|
|
5
|
+
export * from "./Chat.js";
|
|
6
|
+
export * from "./Models.js";
|
|
7
|
+
export * from "./Capabilities.js";
|
|
8
|
+
let registered = false;
|
|
9
|
+
export function registerDeepSeekProvider() {
|
|
10
|
+
if (registered)
|
|
11
|
+
return;
|
|
12
|
+
providerRegistry.register("deepseek", () => {
|
|
13
|
+
const apiKey = config.deepseekApiKey;
|
|
14
|
+
const baseUrl = config.deepseekApiBase; // Optional override
|
|
15
|
+
if (!apiKey) {
|
|
16
|
+
throw new Error("deepseek_api_key is not set in config or DEEPSEEK_API_KEY environment variable");
|
|
17
|
+
}
|
|
18
|
+
return new DeepSeekProvider({ apiKey, baseUrl });
|
|
19
|
+
});
|
|
20
|
+
registered = true;
|
|
21
|
+
}
|
|
22
|
+
export const ensureDeepSeekRegistered = registerDeepSeekProvider;
|
|
@@ -4,27 +4,48 @@ export declare class Capabilities {
|
|
|
4
4
|
static supportsVision(modelId: string): boolean;
|
|
5
5
|
static supportsTools(modelId: string): boolean;
|
|
6
6
|
static supportsStructuredOutput(modelId: string): boolean;
|
|
7
|
+
static supportsSystemInstructions(modelId: string): boolean;
|
|
7
8
|
static supportsJsonMode(modelId: string): boolean;
|
|
8
9
|
static supportsEmbeddings(modelId: string): boolean;
|
|
9
10
|
static supportsImageGeneration(modelId: string): boolean;
|
|
10
11
|
static supportsTranscription(modelId: string): boolean;
|
|
11
12
|
static supportsModeration(modelId: string): boolean;
|
|
12
|
-
static normalizeTemperature(temperature: number | undefined,
|
|
13
|
-
static getFamily(modelId: string): string;
|
|
13
|
+
static normalizeTemperature(temperature: number | undefined, model: string): number | undefined;
|
|
14
14
|
static getModalities(modelId: string): {
|
|
15
15
|
input: string[];
|
|
16
16
|
output: string[];
|
|
17
17
|
};
|
|
18
18
|
static getCapabilities(modelId: string): string[];
|
|
19
19
|
static getPricing(modelId: string): {
|
|
20
|
-
text_tokens
|
|
21
|
-
standard
|
|
22
|
-
input_per_million
|
|
23
|
-
|
|
20
|
+
text_tokens?: {
|
|
21
|
+
standard?: {
|
|
22
|
+
input_per_million?: number;
|
|
23
|
+
cached_input_per_million?: number;
|
|
24
|
+
output_per_million?: number;
|
|
25
|
+
reasoning_output_per_million?: number;
|
|
26
|
+
};
|
|
27
|
+
batch?: {
|
|
28
|
+
input_per_million?: number;
|
|
29
|
+
output_per_million?: number;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
images?: {
|
|
33
|
+
standard?: {
|
|
34
|
+
input?: number;
|
|
35
|
+
output?: number;
|
|
36
|
+
};
|
|
37
|
+
batch?: {
|
|
38
|
+
input?: number;
|
|
39
|
+
output?: number;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
audio_tokens?: {
|
|
43
|
+
standard?: {
|
|
44
|
+
input_per_million?: number;
|
|
45
|
+
output_per_million?: number;
|
|
24
46
|
};
|
|
25
47
|
};
|
|
26
48
|
};
|
|
27
|
-
static formatDisplayName(modelId: string): string;
|
|
28
49
|
private static normalizeModelId;
|
|
29
50
|
}
|
|
30
51
|
//# sourceMappingURL=Capabilities.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Capabilities.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Capabilities.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Capabilities.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Capabilities.ts"],"names":[],"mappings":"AAEA,qBAAa,YAAY;IACvB,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAuBvD,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAoBzD,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAW/C,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAW9C,MAAM,CAAC,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAWzD,MAAM,CAAC,0BAA0B,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAI3D,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIjD,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAQnD,MAAM,CAAC,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAQxD,MAAM,CAAC,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAQtD,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAInD,MAAM,CAAC,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAI/F,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE;IAY5E,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAUjD,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM;;oBArI2D,CAAC;iCAA6B,CAAC;wCAGrH,CAAC;kCACH,CAAC;4CAEgB,CAAC;;iBACd,CAAC;iCAEG,CAAC;kCAAoC,CAAC;;;;oBAG3B,CAAC;qBACV,CAAC;sBAEF,CAAC;;iBAGM,CAAC;qBAAiB,CAAC;sBACrC,CAAA;;;;oBAA6D,CAAC;iCACxC,CAAC;kCAEpB,CAAC;;;;IA4IN,OAAO,CAAC,MAAM,CAAC,gBAAgB;CAGhC"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { ModelRegistry } from "../../models/ModelRegistry.js";
|
|
1
2
|
export class Capabilities {
|
|
2
3
|
static getContextWindow(modelId) {
|
|
4
|
+
const val = ModelRegistry.getContextWindow(modelId, "gemini");
|
|
5
|
+
if (val !== undefined && val !== null)
|
|
6
|
+
return val;
|
|
3
7
|
const id = this.normalizeModelId(modelId);
|
|
4
8
|
if (id.match(/gemini-2\.5-pro-exp-03-25|gemini-2\.0-flash|gemini-2\.0-flash-lite|gemini-1\.5-flash|gemini-1\.5-flash-8b/)) {
|
|
5
9
|
return 1_048_576;
|
|
@@ -19,6 +23,9 @@ export class Capabilities {
|
|
|
19
23
|
return 32_768;
|
|
20
24
|
}
|
|
21
25
|
static getMaxOutputTokens(modelId) {
|
|
26
|
+
const val = ModelRegistry.getMaxOutputTokens(modelId, "gemini");
|
|
27
|
+
if (val !== undefined && val !== null)
|
|
28
|
+
return val;
|
|
22
29
|
const id = this.normalizeModelId(modelId);
|
|
23
30
|
if (id.match(/gemini-2\.5-pro-exp-03-25/)) {
|
|
24
31
|
return 64_000;
|
|
@@ -35,6 +42,9 @@ export class Capabilities {
|
|
|
35
42
|
return 4_096;
|
|
36
43
|
}
|
|
37
44
|
static supportsVision(modelId) {
|
|
45
|
+
const model = ModelRegistry.find(modelId, "gemini");
|
|
46
|
+
if (model?.modalities?.input?.includes("image"))
|
|
47
|
+
return true;
|
|
38
48
|
const id = this.normalizeModelId(modelId);
|
|
39
49
|
if (id.match(/text-embedding|embedding-001|aqa/)) {
|
|
40
50
|
return false;
|
|
@@ -42,6 +52,9 @@ export class Capabilities {
|
|
|
42
52
|
return !!id.match(/gemini|flash|pro|imagen/);
|
|
43
53
|
}
|
|
44
54
|
static supportsTools(modelId) {
|
|
55
|
+
const model = ModelRegistry.find(modelId, "gemini");
|
|
56
|
+
if (model?.capabilities?.includes("function_calling"))
|
|
57
|
+
return true;
|
|
45
58
|
const id = this.normalizeModelId(modelId);
|
|
46
59
|
if (id.match(/text-embedding|embedding-001|aqa|flash-lite|imagen|gemini-2\.0-flash-lite/)) {
|
|
47
60
|
return false;
|
|
@@ -49,49 +62,48 @@ export class Capabilities {
|
|
|
49
62
|
return !!id.match(/gemini|pro|flash/);
|
|
50
63
|
}
|
|
51
64
|
static supportsStructuredOutput(modelId) {
|
|
65
|
+
const model = ModelRegistry.find(modelId, "gemini");
|
|
66
|
+
if (model?.capabilities?.includes("structured_output"))
|
|
67
|
+
return true;
|
|
52
68
|
const id = this.normalizeModelId(modelId);
|
|
53
69
|
if (id.match(/text-embedding|embedding-001|aqa|imagen/)) {
|
|
54
70
|
return false;
|
|
55
71
|
}
|
|
56
72
|
return true;
|
|
57
73
|
}
|
|
74
|
+
static supportsSystemInstructions(modelId) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
58
77
|
static supportsJsonMode(modelId) {
|
|
59
78
|
return this.supportsStructuredOutput(modelId);
|
|
60
79
|
}
|
|
61
80
|
static supportsEmbeddings(modelId) {
|
|
81
|
+
const model = ModelRegistry.find(modelId, "gemini");
|
|
82
|
+
if (model?.modalities?.output?.includes("embeddings"))
|
|
83
|
+
return true;
|
|
62
84
|
const id = this.normalizeModelId(modelId);
|
|
63
85
|
return !!id.match(/text-embedding|embedding|gemini-embedding/);
|
|
64
86
|
}
|
|
65
87
|
static supportsImageGeneration(modelId) {
|
|
88
|
+
const model = ModelRegistry.find(modelId, "gemini");
|
|
89
|
+
if (model?.capabilities?.includes("image_generation") || model?.modalities?.output?.includes("image"))
|
|
90
|
+
return true;
|
|
66
91
|
const id = this.normalizeModelId(modelId);
|
|
67
92
|
return !!id.match(/imagen/);
|
|
68
93
|
}
|
|
69
94
|
static supportsTranscription(modelId) {
|
|
95
|
+
const model = ModelRegistry.find(modelId, "gemini");
|
|
96
|
+
if (model?.modalities?.input?.includes("audio"))
|
|
97
|
+
return true;
|
|
70
98
|
const id = this.normalizeModelId(modelId);
|
|
71
99
|
return !!id.match(/gemini|flash|pro/);
|
|
72
100
|
}
|
|
73
101
|
static supportsModeration(modelId) {
|
|
74
102
|
return false;
|
|
75
103
|
}
|
|
76
|
-
static normalizeTemperature(temperature,
|
|
104
|
+
static normalizeTemperature(temperature, model) {
|
|
77
105
|
return temperature;
|
|
78
106
|
}
|
|
79
|
-
static getFamily(modelId) {
|
|
80
|
-
const id = this.normalizeModelId(modelId);
|
|
81
|
-
if (id.startsWith("gemini-1.5-pro"))
|
|
82
|
-
return "gemini-1.5-pro";
|
|
83
|
-
if (id.startsWith("gemini-1.5-flash"))
|
|
84
|
-
return "gemini-1.5-flash";
|
|
85
|
-
if (id.startsWith("gemini-2.0-flash"))
|
|
86
|
-
return "gemini-2.0-flash";
|
|
87
|
-
if (id.startsWith("gemini-2.0-flash-lite"))
|
|
88
|
-
return "gemini-2.0-flash-lite";
|
|
89
|
-
if (id.startsWith("text-embedding"))
|
|
90
|
-
return "text-embedding";
|
|
91
|
-
if (id.startsWith("imagen"))
|
|
92
|
-
return "imagen";
|
|
93
|
-
return "other";
|
|
94
|
-
}
|
|
95
107
|
static getModalities(modelId) {
|
|
96
108
|
const input = ["text"];
|
|
97
109
|
const output = ["text"];
|
|
@@ -118,6 +130,9 @@ export class Capabilities {
|
|
|
118
130
|
return caps;
|
|
119
131
|
}
|
|
120
132
|
static getPricing(modelId) {
|
|
133
|
+
const model = ModelRegistry.find(modelId, "gemini");
|
|
134
|
+
if (model?.pricing)
|
|
135
|
+
return model.pricing;
|
|
121
136
|
const id = this.normalizeModelId(modelId);
|
|
122
137
|
let input = 0;
|
|
123
138
|
let output = 0;
|
|
@@ -142,9 +157,6 @@ export class Capabilities {
|
|
|
142
157
|
}
|
|
143
158
|
};
|
|
144
159
|
}
|
|
145
|
-
static formatDisplayName(modelId) {
|
|
146
|
-
return modelId.replace("models/", "").replace(/-/g, " ").replace(/\b\w/g, l => l.toUpperCase());
|
|
147
|
-
}
|
|
148
160
|
static normalizeModelId(modelId) {
|
|
149
161
|
return modelId.replace("models/", "");
|
|
150
162
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAS,MAAM,gBAAgB,CAAC;AAOlE,qBAAa,UAAU;IACT,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAyF1D,OAAO,CAAC,cAAc;CAwBvB"}
|