@node-llm/core 1.5.2 → 1.6.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 +84 -110
- package/dist/aliases.js +239 -239
- package/dist/chat/Chat.d.ts +18 -17
- package/dist/chat/Chat.d.ts.map +1 -1
- package/dist/chat/Chat.js +63 -42
- package/dist/chat/ChatOptions.d.ts +8 -9
- package/dist/chat/ChatOptions.d.ts.map +1 -1
- package/dist/chat/ChatResponse.d.ts +1 -1
- package/dist/chat/ChatResponse.d.ts.map +1 -1
- package/dist/chat/ChatResponse.js +22 -8
- package/dist/chat/ChatStream.d.ts.map +1 -1
- package/dist/chat/ChatStream.js +16 -22
- package/dist/chat/Content.d.ts +3 -3
- package/dist/chat/Content.d.ts.map +1 -1
- package/dist/chat/Content.js +3 -6
- package/dist/chat/Message.d.ts +3 -1
- package/dist/chat/Message.d.ts.map +1 -1
- package/dist/chat/Role.d.ts.map +1 -1
- package/dist/chat/Tool.d.ts +15 -15
- package/dist/chat/Tool.d.ts.map +1 -1
- package/dist/chat/Tool.js +9 -7
- package/dist/chat/ToolHandler.d.ts +4 -3
- package/dist/chat/ToolHandler.d.ts.map +1 -1
- package/dist/chat/ToolHandler.js +10 -14
- package/dist/chat/Validation.d.ts.map +1 -1
- package/dist/chat/Validation.js +13 -6
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +80 -25
- package/dist/constants.js +1 -1
- package/dist/errors/index.d.ts +21 -7
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +14 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/llm.d.ts +44 -46
- package/dist/llm.d.ts.map +1 -1
- package/dist/llm.js +206 -134
- package/dist/model_aliases.d.ts.map +1 -1
- package/dist/models/ModelRegistry.d.ts.map +1 -1
- package/dist/models/ModelRegistry.js +12 -10
- package/dist/models/PricingRegistry.d.ts +31 -0
- package/dist/models/PricingRegistry.d.ts.map +1 -0
- package/dist/models/PricingRegistry.js +101 -0
- package/dist/models/models.d.ts.map +1 -1
- package/dist/models/models.js +5954 -7352
- package/dist/models/types.d.ts +37 -34
- package/dist/models/types.d.ts.map +1 -1
- package/dist/moderation/Moderation.d.ts.map +1 -1
- package/dist/moderation/Moderation.js +15 -5
- package/dist/providers/BaseProvider.d.ts +12 -8
- package/dist/providers/BaseProvider.d.ts.map +1 -1
- package/dist/providers/BaseProvider.js +17 -7
- package/dist/providers/Provider.d.ts +20 -5
- package/dist/providers/Provider.d.ts.map +1 -1
- package/dist/providers/anthropic/AnthropicProvider.d.ts +1 -1
- package/dist/providers/anthropic/AnthropicProvider.d.ts.map +1 -1
- package/dist/providers/anthropic/AnthropicProvider.js +3 -3
- package/dist/providers/anthropic/Capabilities.d.ts +2 -1
- package/dist/providers/anthropic/Capabilities.d.ts.map +1 -1
- package/dist/providers/anthropic/Capabilities.js +3 -20
- package/dist/providers/anthropic/Chat.d.ts.map +1 -1
- package/dist/providers/anthropic/Chat.js +27 -17
- package/dist/providers/anthropic/Errors.d.ts.map +1 -1
- package/dist/providers/anthropic/Errors.js +5 -2
- package/dist/providers/anthropic/Models.d.ts.map +1 -1
- package/dist/providers/anthropic/Models.js +6 -6
- package/dist/providers/anthropic/Streaming.d.ts.map +1 -1
- package/dist/providers/anthropic/Streaming.js +17 -12
- package/dist/providers/anthropic/Utils.js +8 -5
- package/dist/providers/anthropic/index.d.ts.map +1 -1
- package/dist/providers/anthropic/index.js +4 -3
- package/dist/providers/anthropic/types.d.ts +11 -4
- package/dist/providers/anthropic/types.d.ts.map +1 -1
- package/dist/providers/deepseek/Capabilities.d.ts +7 -5
- package/dist/providers/deepseek/Capabilities.d.ts.map +1 -1
- package/dist/providers/deepseek/Capabilities.js +9 -5
- package/dist/providers/deepseek/Chat.d.ts.map +1 -1
- package/dist/providers/deepseek/Chat.js +10 -9
- package/dist/providers/deepseek/DeepSeekProvider.d.ts +1 -1
- package/dist/providers/deepseek/DeepSeekProvider.d.ts.map +1 -1
- package/dist/providers/deepseek/DeepSeekProvider.js +4 -4
- package/dist/providers/deepseek/Models.d.ts.map +1 -1
- package/dist/providers/deepseek/Models.js +7 -7
- package/dist/providers/deepseek/Streaming.d.ts.map +1 -1
- package/dist/providers/deepseek/Streaming.js +11 -8
- package/dist/providers/deepseek/index.d.ts.map +1 -1
- package/dist/providers/deepseek/index.js +5 -4
- package/dist/providers/gemini/Capabilities.d.ts +5 -33
- package/dist/providers/gemini/Capabilities.d.ts.map +1 -1
- package/dist/providers/gemini/Capabilities.js +7 -30
- package/dist/providers/gemini/Chat.d.ts.map +1 -1
- package/dist/providers/gemini/Chat.js +24 -19
- package/dist/providers/gemini/ChatUtils.d.ts.map +1 -1
- package/dist/providers/gemini/ChatUtils.js +10 -10
- package/dist/providers/gemini/Embeddings.d.ts.map +1 -1
- package/dist/providers/gemini/Embeddings.js +2 -2
- package/dist/providers/gemini/Errors.d.ts.map +1 -1
- package/dist/providers/gemini/Errors.js +5 -2
- package/dist/providers/gemini/GeminiProvider.d.ts +1 -1
- package/dist/providers/gemini/GeminiProvider.d.ts.map +1 -1
- package/dist/providers/gemini/GeminiProvider.js +3 -3
- package/dist/providers/gemini/Image.d.ts.map +1 -1
- package/dist/providers/gemini/Image.js +8 -8
- package/dist/providers/gemini/Models.d.ts.map +1 -1
- package/dist/providers/gemini/Models.js +6 -6
- package/dist/providers/gemini/Streaming.d.ts.map +1 -1
- package/dist/providers/gemini/Streaming.js +18 -14
- package/dist/providers/gemini/Transcription.d.ts.map +1 -1
- package/dist/providers/gemini/Transcription.js +11 -11
- package/dist/providers/gemini/index.d.ts +1 -1
- package/dist/providers/gemini/index.d.ts.map +1 -1
- package/dist/providers/gemini/index.js +5 -4
- package/dist/providers/gemini/types.d.ts +4 -4
- package/dist/providers/gemini/types.d.ts.map +1 -1
- package/dist/providers/ollama/Capabilities.d.ts.map +1 -1
- package/dist/providers/ollama/Capabilities.js +6 -2
- package/dist/providers/ollama/Models.js +1 -1
- package/dist/providers/ollama/OllamaProvider.d.ts +1 -1
- package/dist/providers/ollama/OllamaProvider.d.ts.map +1 -1
- package/dist/providers/ollama/OllamaProvider.js +2 -2
- package/dist/providers/ollama/index.d.ts +1 -1
- package/dist/providers/ollama/index.d.ts.map +1 -1
- package/dist/providers/ollama/index.js +7 -3
- package/dist/providers/openai/Capabilities.d.ts +2 -1
- package/dist/providers/openai/Capabilities.d.ts.map +1 -1
- package/dist/providers/openai/Capabilities.js +9 -21
- package/dist/providers/openai/Chat.d.ts.map +1 -1
- package/dist/providers/openai/Chat.js +18 -14
- package/dist/providers/openai/Embedding.d.ts.map +1 -1
- package/dist/providers/openai/Embedding.js +11 -7
- package/dist/providers/openai/Errors.d.ts.map +1 -1
- package/dist/providers/openai/Errors.js +5 -2
- package/dist/providers/openai/Image.d.ts.map +1 -1
- package/dist/providers/openai/Image.js +6 -6
- package/dist/providers/openai/Models.d.ts +1 -1
- package/dist/providers/openai/Models.d.ts.map +1 -1
- package/dist/providers/openai/Models.js +12 -8
- package/dist/providers/openai/Moderation.d.ts.map +1 -1
- package/dist/providers/openai/Moderation.js +6 -6
- package/dist/providers/openai/OpenAIProvider.d.ts +2 -3
- package/dist/providers/openai/OpenAIProvider.d.ts.map +1 -1
- package/dist/providers/openai/OpenAIProvider.js +4 -4
- package/dist/providers/openai/Streaming.d.ts.map +1 -1
- package/dist/providers/openai/Streaming.js +18 -13
- package/dist/providers/openai/Transcription.d.ts.map +1 -1
- package/dist/providers/openai/Transcription.js +15 -12
- package/dist/providers/openai/index.d.ts +1 -1
- package/dist/providers/openai/index.d.ts.map +1 -1
- package/dist/providers/openai/index.js +6 -5
- package/dist/providers/openai/types.d.ts +1 -1
- package/dist/providers/openai/utils.js +2 -2
- package/dist/providers/openrouter/Capabilities.d.ts +3 -3
- package/dist/providers/openrouter/Capabilities.d.ts.map +1 -1
- package/dist/providers/openrouter/Capabilities.js +21 -24
- package/dist/providers/openrouter/Models.d.ts.map +1 -1
- package/dist/providers/openrouter/Models.js +20 -16
- package/dist/providers/openrouter/OpenRouterProvider.d.ts.map +1 -1
- package/dist/providers/openrouter/OpenRouterProvider.js +1 -1
- package/dist/providers/openrouter/index.d.ts +1 -1
- package/dist/providers/openrouter/index.d.ts.map +1 -1
- package/dist/providers/openrouter/index.js +6 -5
- package/dist/providers/registry.d.ts +18 -2
- package/dist/providers/registry.d.ts.map +1 -1
- package/dist/providers/registry.js +17 -2
- package/dist/providers/utils.js +1 -1
- package/dist/schema/Schema.d.ts +3 -3
- package/dist/schema/Schema.d.ts.map +1 -1
- package/dist/schema/Schema.js +2 -2
- package/dist/schema/to-json-schema.d.ts +1 -1
- package/dist/schema/to-json-schema.d.ts.map +1 -1
- package/dist/streaming/Stream.d.ts.map +1 -1
- package/dist/streaming/Stream.js +3 -3
- package/dist/utils/Binary.d.ts.map +1 -1
- package/dist/utils/Binary.js +32 -23
- package/dist/utils/FileLoader.d.ts.map +1 -1
- package/dist/utils/FileLoader.js +25 -4
- package/dist/utils/audio.js +2 -2
- package/dist/utils/fetch.d.ts.map +1 -1
- package/dist/utils/fetch.js +14 -4
- package/dist/utils/logger.d.ts +3 -3
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +2 -2
- package/package.json +1 -1
|
@@ -19,8 +19,10 @@ export class AnthropicStreaming {
|
|
|
19
19
|
let system = systemPrompt;
|
|
20
20
|
if (request.response_format) {
|
|
21
21
|
let schemaText = "";
|
|
22
|
-
if (request.response_format.type === "json_schema" &&
|
|
23
|
-
|
|
22
|
+
if (request.response_format.type === "json_schema" &&
|
|
23
|
+
request.response_format.json_schema?.schema) {
|
|
24
|
+
schemaText =
|
|
25
|
+
"\nSchema:\n" + JSON.stringify(request.response_format.json_schema.schema, null, 2);
|
|
24
26
|
}
|
|
25
27
|
const instruction = `CRITICAL: Respond ONLY with a valid JSON object matching the requested schema.${schemaText}\n\nDo not include any other text or explanation.`;
|
|
26
28
|
system = system ? `${system}\n\n${instruction}` : instruction;
|
|
@@ -30,25 +32,25 @@ export class AnthropicStreaming {
|
|
|
30
32
|
messages: messages,
|
|
31
33
|
max_tokens: maxTokens,
|
|
32
34
|
system: system,
|
|
33
|
-
stream: true
|
|
35
|
+
stream: true
|
|
34
36
|
};
|
|
35
37
|
if (request.temperature !== undefined) {
|
|
36
38
|
body.temperature = request.temperature;
|
|
37
39
|
}
|
|
38
40
|
if (request.tools && request.tools.length > 0) {
|
|
39
|
-
body.tools = request.tools.map(tool => ({
|
|
41
|
+
body.tools = request.tools.map((tool) => ({
|
|
40
42
|
name: tool.function.name,
|
|
41
43
|
description: tool.function.description,
|
|
42
44
|
input_schema: tool.function.parameters
|
|
43
45
|
}));
|
|
44
46
|
}
|
|
45
47
|
// Check if any message contains PDF content to add beta header
|
|
46
|
-
const hasPdf = messages.some(msg => Array.isArray(msg.content) && msg.content.some(block => block.type === "document"));
|
|
48
|
+
const hasPdf = messages.some((msg) => Array.isArray(msg.content) && msg.content.some((block) => block.type === "document"));
|
|
47
49
|
const headers = {
|
|
48
50
|
"x-api-key": this.apiKey,
|
|
49
51
|
"anthropic-version": "2023-06-01",
|
|
50
52
|
"content-type": "application/json",
|
|
51
|
-
...request.headers
|
|
53
|
+
...request.headers
|
|
52
54
|
};
|
|
53
55
|
if (hasPdf) {
|
|
54
56
|
headers["anthropic-beta"] = "pdfs-2024-09-25";
|
|
@@ -64,12 +66,15 @@ export class AnthropicStreaming {
|
|
|
64
66
|
method: "POST",
|
|
65
67
|
headers: headers,
|
|
66
68
|
body: JSON.stringify(body),
|
|
67
|
-
signal: abortController.signal
|
|
69
|
+
signal: abortController.signal
|
|
68
70
|
}, request.requestTimeout);
|
|
69
71
|
if (!response.ok) {
|
|
70
72
|
await handleAnthropicError(response, model);
|
|
71
73
|
}
|
|
72
|
-
logger.debug("Anthropic streaming started", {
|
|
74
|
+
logger.debug("Anthropic streaming started", {
|
|
75
|
+
status: response.status,
|
|
76
|
+
statusText: response.statusText
|
|
77
|
+
});
|
|
73
78
|
if (!response.body) {
|
|
74
79
|
throw new Error("No response body for streaming");
|
|
75
80
|
}
|
|
@@ -87,7 +92,7 @@ export class AnthropicStreaming {
|
|
|
87
92
|
for (const line of lines) {
|
|
88
93
|
let trimmed = line.trim();
|
|
89
94
|
// Handle carriage returns
|
|
90
|
-
if (trimmed.endsWith(
|
|
95
|
+
if (trimmed.endsWith("\r")) {
|
|
91
96
|
trimmed = trimmed.substring(0, trimmed.length - 1);
|
|
92
97
|
}
|
|
93
98
|
if (!trimmed.startsWith("event: "))
|
|
@@ -97,7 +102,7 @@ export class AnthropicStreaming {
|
|
|
97
102
|
// data: json
|
|
98
103
|
const parts = trimmed.split("\n");
|
|
99
104
|
const eventLine = parts[0];
|
|
100
|
-
const dataLine = parts.find(p => p.startsWith("data: "));
|
|
105
|
+
const dataLine = parts.find((p) => p.startsWith("data: "));
|
|
101
106
|
if (!dataLine || !eventLine)
|
|
102
107
|
continue;
|
|
103
108
|
const eventType = eventLine.replace("event: ", "").trim();
|
|
@@ -142,7 +147,7 @@ export class AnthropicStreaming {
|
|
|
142
147
|
// Update usage or stop reason
|
|
143
148
|
if (data.delta?.stop_reason === "end_turn" && toolCallsMap.size > 0) {
|
|
144
149
|
// Yield accumulated tool calls
|
|
145
|
-
const toolCalls = Array.from(toolCallsMap.values()).map(tc => ({
|
|
150
|
+
const toolCalls = Array.from(toolCallsMap.values()).map((tc) => ({
|
|
146
151
|
id: tc.id,
|
|
147
152
|
type: "function",
|
|
148
153
|
function: {
|
|
@@ -172,7 +177,7 @@ export class AnthropicStreaming {
|
|
|
172
177
|
}
|
|
173
178
|
catch (e) {
|
|
174
179
|
// Graceful exit on abort
|
|
175
|
-
if (e instanceof Error && e.name ===
|
|
180
|
+
if (e instanceof Error && e.name === "AbortError") {
|
|
176
181
|
return;
|
|
177
182
|
}
|
|
178
183
|
throw e;
|
|
@@ -8,7 +8,7 @@ export function formatSystemPrompt(messages) {
|
|
|
8
8
|
else if (Array.isArray(msg.content)) {
|
|
9
9
|
systemPrompt = msg.content
|
|
10
10
|
.filter((p) => p.type === "text")
|
|
11
|
-
.map(p => p.text)
|
|
11
|
+
.map((p) => p.text)
|
|
12
12
|
.join("\n");
|
|
13
13
|
}
|
|
14
14
|
else if (msg.content) {
|
|
@@ -27,7 +27,7 @@ export function formatMessages(requestMessages) {
|
|
|
27
27
|
const lastMsg = messages[messages.length - 1];
|
|
28
28
|
if (lastMsg && lastMsg.role === formatted.role) {
|
|
29
29
|
// Merge content
|
|
30
|
-
|
|
30
|
+
const existingContent = Array.isArray(lastMsg.content)
|
|
31
31
|
? lastMsg.content
|
|
32
32
|
: [{ type: "text", text: lastMsg.content }];
|
|
33
33
|
const newContent = Array.isArray(formatted.content)
|
|
@@ -47,11 +47,14 @@ function formatSingleMessage(msg) {
|
|
|
47
47
|
if (msg.role === "tool") {
|
|
48
48
|
return {
|
|
49
49
|
role: "user",
|
|
50
|
-
content: [
|
|
50
|
+
content: [
|
|
51
|
+
{
|
|
51
52
|
type: "tool_result",
|
|
52
53
|
tool_use_id: msg.tool_call_id,
|
|
53
|
-
content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content)
|
|
54
|
-
|
|
54
|
+
content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content),
|
|
55
|
+
is_error: msg.isError
|
|
56
|
+
}
|
|
57
|
+
]
|
|
55
58
|
};
|
|
56
59
|
}
|
|
57
60
|
// Handle Assistant Messages (which might have tool_calls)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/index.ts"],"names":[],"mappings":"AAIA,wBAAgB,yBAAyB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/index.ts"],"names":[],"mappings":"AAIA,wBAAgB,yBAAyB,SAWxC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { config } from "../../config.js";
|
|
1
|
+
import { config as globalConfig } from "../../config.js";
|
|
2
2
|
import { providerRegistry } from "../registry.js";
|
|
3
3
|
import { AnthropicProvider } from "./AnthropicProvider.js";
|
|
4
4
|
export function registerAnthropicProvider() {
|
|
5
|
-
providerRegistry.register("anthropic", () => {
|
|
6
|
-
const
|
|
5
|
+
providerRegistry.register("anthropic", (config) => {
|
|
6
|
+
const cfg = config || globalConfig;
|
|
7
|
+
const apiKey = cfg.anthropicApiKey;
|
|
7
8
|
if (!apiKey) {
|
|
8
9
|
throw new Error("anthropicApiKey is not set in config or ANTHROPIC_API_KEY environment variable");
|
|
9
10
|
}
|
|
@@ -12,7 +12,7 @@ export interface AnthropicContentBlock {
|
|
|
12
12
|
};
|
|
13
13
|
id?: string;
|
|
14
14
|
name?: string;
|
|
15
|
-
input?:
|
|
15
|
+
input?: Record<string, unknown>;
|
|
16
16
|
tool_use_id?: string;
|
|
17
17
|
content?: string | Array<AnthropicContentBlock>;
|
|
18
18
|
is_error?: boolean;
|
|
@@ -22,14 +22,21 @@ export interface AnthropicMessageRequest {
|
|
|
22
22
|
messages: AnthropicMessage[];
|
|
23
23
|
max_tokens: number;
|
|
24
24
|
system?: string;
|
|
25
|
-
metadata?:
|
|
25
|
+
metadata?: Record<string, unknown>;
|
|
26
26
|
stop_sequences?: string[];
|
|
27
27
|
stream?: boolean;
|
|
28
28
|
temperature?: number;
|
|
29
29
|
top_p?: number;
|
|
30
30
|
top_k?: number;
|
|
31
|
-
tools?:
|
|
32
|
-
|
|
31
|
+
tools?: Array<{
|
|
32
|
+
name: string;
|
|
33
|
+
description?: string;
|
|
34
|
+
input_schema?: Record<string, unknown>;
|
|
35
|
+
}>;
|
|
36
|
+
tool_choice?: {
|
|
37
|
+
type: string;
|
|
38
|
+
name?: string;
|
|
39
|
+
};
|
|
33
40
|
}
|
|
34
41
|
export interface AnthropicUsage {
|
|
35
42
|
input_tokens: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC,qBAAqB,CAAC,CAAC;CAChD;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,aAAa,GAAG,UAAU,CAAC;IACjE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE;QACP,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC,qBAAqB,CAAC,CAAC;CAChD;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,aAAa,GAAG,UAAU,CAAC;IACjE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE;QACP,IAAI,EAAE,QAAQ,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,GAA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MAAM,GAAG,IAAI,CAAC;IAC7B,KAAK,EAAE,cAAc,CAAC;CACvB;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH"}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
import { ModelPricing } from "../../models/types.js";
|
|
1
2
|
export declare class Capabilities {
|
|
2
3
|
static getCapabilities(modelId: string): string[];
|
|
3
4
|
static getContextWindow(modelId: string): number | null;
|
|
4
5
|
static getMaxOutputTokens(modelId: string): number | null;
|
|
5
|
-
static supportsVision(
|
|
6
|
+
static supportsVision(_modelId: string): boolean;
|
|
6
7
|
static supportsTools(modelId: string): boolean;
|
|
7
8
|
static supportsStructuredOutput(modelId: string): boolean;
|
|
8
|
-
static supportsEmbeddings(
|
|
9
|
-
static supportsImageGeneration(
|
|
10
|
-
static supportsTranscription(
|
|
11
|
-
static supportsModeration(
|
|
9
|
+
static supportsEmbeddings(_modelId: string): boolean;
|
|
10
|
+
static supportsImageGeneration(_modelId: string): boolean;
|
|
11
|
+
static supportsTranscription(_modelId: string): boolean;
|
|
12
|
+
static supportsModeration(_modelId: string): boolean;
|
|
12
13
|
static supportsReasoning(modelId: string): boolean;
|
|
14
|
+
static getPricing(modelId: string): ModelPricing | undefined;
|
|
13
15
|
}
|
|
14
16
|
//# sourceMappingURL=Capabilities.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Capabilities.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/Capabilities.ts"],"names":[],"mappings":"AAEA,qBAAa,YAAY;IACvB,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAcjD,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAUvD,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAOzD,MAAM,CAAC,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"Capabilities.d.ts","sourceRoot":"","sources":["../../../src/providers/deepseek/Capabilities.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAGrD,qBAAa,YAAY;IACvB,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAcjD,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAUvD,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAOzD,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIhD,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAI9C,MAAM,CAAC,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIzD,MAAM,CAAC,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIpD,MAAM,CAAC,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIzD,MAAM,CAAC,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIvD,MAAM,CAAC,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIpD,MAAM,CAAC,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIlD,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;CAG7D"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ModelRegistry } from "../../models/ModelRegistry.js";
|
|
2
|
+
import { PricingRegistry } from "../../models/PricingRegistry.js";
|
|
2
3
|
export class Capabilities {
|
|
3
4
|
static getCapabilities(modelId) {
|
|
4
5
|
const caps = ["streaming"];
|
|
@@ -25,7 +26,7 @@ export class Capabilities {
|
|
|
25
26
|
}
|
|
26
27
|
return 4_096;
|
|
27
28
|
}
|
|
28
|
-
static supportsVision(
|
|
29
|
+
static supportsVision(_modelId) {
|
|
29
30
|
return false;
|
|
30
31
|
}
|
|
31
32
|
static supportsTools(modelId) {
|
|
@@ -34,19 +35,22 @@ export class Capabilities {
|
|
|
34
35
|
static supportsStructuredOutput(modelId) {
|
|
35
36
|
return /deepseek-(?:chat|reasoner)/.test(modelId);
|
|
36
37
|
}
|
|
37
|
-
static supportsEmbeddings(
|
|
38
|
+
static supportsEmbeddings(_modelId) {
|
|
38
39
|
return false;
|
|
39
40
|
}
|
|
40
|
-
static supportsImageGeneration(
|
|
41
|
+
static supportsImageGeneration(_modelId) {
|
|
41
42
|
return false;
|
|
42
43
|
}
|
|
43
|
-
static supportsTranscription(
|
|
44
|
+
static supportsTranscription(_modelId) {
|
|
44
45
|
return false;
|
|
45
46
|
}
|
|
46
|
-
static supportsModeration(
|
|
47
|
+
static supportsModeration(_modelId) {
|
|
47
48
|
return false;
|
|
48
49
|
}
|
|
49
50
|
static supportsReasoning(modelId) {
|
|
50
51
|
return /deepseek-reasoner/.test(modelId);
|
|
51
52
|
}
|
|
53
|
+
static getPricing(modelId) {
|
|
54
|
+
return PricingRegistry.getPricing(modelId, "deepseek");
|
|
55
|
+
}
|
|
52
56
|
}
|
|
@@ -1 +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;
|
|
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;AAgClE,qBAAa,YAAY;IAErB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;IAG3B,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CA2G3D"}
|
|
@@ -10,7 +10,7 @@ export class DeepSeekChat {
|
|
|
10
10
|
this.apiKey = apiKey;
|
|
11
11
|
}
|
|
12
12
|
async execute(request) {
|
|
13
|
-
const { model, messages, tools, max_tokens, response_format, headers, requestTimeout, ...rest } = request;
|
|
13
|
+
const { model, messages, tools, max_tokens, response_format, headers: _headers, requestTimeout, ...rest } = request;
|
|
14
14
|
const mappedMessages = mapSystemMessages(messages, false);
|
|
15
15
|
const body = {
|
|
16
16
|
model,
|
|
@@ -31,16 +31,17 @@ export class DeepSeekChat {
|
|
|
31
31
|
body.response_format = { type: "json_object" };
|
|
32
32
|
// Append schema instructions to the system prompt or convert to a new system message
|
|
33
33
|
const schema = response_format.json_schema;
|
|
34
|
-
const schemaString = JSON.stringify(schema
|
|
34
|
+
const schemaString = JSON.stringify(schema?.schema, null, 2);
|
|
35
35
|
const instruction = `\n\nIMPORTANT: You must output strictly valid JSON conforming to the following schema:\n${schemaString}\n\nOutput only the JSON object.`;
|
|
36
36
|
// Find system message or append to last user message
|
|
37
|
-
const
|
|
37
|
+
const messagesList = body.messages;
|
|
38
|
+
const systemMessage = messagesList.find((m) => m.role === "system" || m.role === "developer");
|
|
38
39
|
if (systemMessage) {
|
|
39
40
|
systemMessage.content += instruction;
|
|
40
41
|
}
|
|
41
42
|
else {
|
|
42
43
|
// Insert system message at the beginning
|
|
43
|
-
|
|
44
|
+
messagesList.unshift({
|
|
44
45
|
role: "system",
|
|
45
46
|
content: "You are a helpful assistant." + instruction
|
|
46
47
|
});
|
|
@@ -55,11 +56,11 @@ export class DeepSeekChat {
|
|
|
55
56
|
const response = await fetchWithTimeout(url, {
|
|
56
57
|
method: "POST",
|
|
57
58
|
headers: {
|
|
58
|
-
|
|
59
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
59
60
|
"Content-Type": "application/json",
|
|
60
|
-
...request.headers
|
|
61
|
+
...request.headers
|
|
61
62
|
},
|
|
62
|
-
body: JSON.stringify(body)
|
|
63
|
+
body: JSON.stringify(body)
|
|
63
64
|
}, requestTimeout);
|
|
64
65
|
if (!response.ok) {
|
|
65
66
|
const errorText = await response.text();
|
|
@@ -73,11 +74,11 @@ export class DeepSeekChat {
|
|
|
73
74
|
const usage = {
|
|
74
75
|
input_tokens: json.usage.prompt_tokens,
|
|
75
76
|
output_tokens: json.usage.completion_tokens,
|
|
76
|
-
total_tokens: json.usage.total_tokens
|
|
77
|
+
total_tokens: json.usage.total_tokens
|
|
77
78
|
};
|
|
78
79
|
const toolCalls = message?.tool_calls?.map((tc) => ({
|
|
79
80
|
id: tc.id,
|
|
80
|
-
type:
|
|
81
|
+
type: "function",
|
|
81
82
|
function: {
|
|
82
83
|
name: tc.function.name,
|
|
83
84
|
arguments: tc.function.arguments
|
|
@@ -26,7 +26,7 @@ export declare class DeepSeekProvider extends BaseProvider implements Provider {
|
|
|
26
26
|
apiBase(): string;
|
|
27
27
|
headers(): Record<string, string>;
|
|
28
28
|
protected providerName(): string;
|
|
29
|
-
defaultModel(
|
|
29
|
+
defaultModel(_feature?: string): string;
|
|
30
30
|
chat(request: ChatRequest): Promise<ChatResponse>;
|
|
31
31
|
stream(request: ChatRequest): AsyncGenerator<ChatChunk>;
|
|
32
32
|
listModels(): Promise<ModelInfo[]>;
|
|
@@ -1 +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;AAC3F,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC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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;wCACD,MAAM;kCACZ,MAAM;MAChC;gBAE2B,OAAO,EAAE,uBAAuB;IAQtD,OAAO,IAAI,MAAM;IAIjB,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAOxC,SAAS,CAAC,YAAY,IAAI,MAAM;IAIhB,YAAY,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM;IAIjD,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;CAKzC"}
|
|
@@ -19,7 +19,7 @@ export class DeepSeekProvider extends BaseProvider {
|
|
|
19
19
|
supportsModeration: (model) => Capabilities.supportsModeration(model),
|
|
20
20
|
supportsReasoning: (model) => Capabilities.supportsReasoning(model),
|
|
21
21
|
supportsDeveloperRole: (_model) => false,
|
|
22
|
-
getContextWindow: (model) => Capabilities.getContextWindow(model)
|
|
22
|
+
getContextWindow: (model) => Capabilities.getContextWindow(model)
|
|
23
23
|
};
|
|
24
24
|
constructor(options) {
|
|
25
25
|
super();
|
|
@@ -34,14 +34,14 @@ export class DeepSeekProvider extends BaseProvider {
|
|
|
34
34
|
}
|
|
35
35
|
headers() {
|
|
36
36
|
return {
|
|
37
|
-
|
|
38
|
-
"Content-Type": "application/json"
|
|
37
|
+
Authorization: `Bearer ${this.options.apiKey}`,
|
|
38
|
+
"Content-Type": "application/json"
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
providerName() {
|
|
42
42
|
return "DeepSeek";
|
|
43
43
|
}
|
|
44
|
-
defaultModel(
|
|
44
|
+
defaultModel(_feature) {
|
|
45
45
|
return "deepseek-chat";
|
|
46
46
|
}
|
|
47
47
|
async chat(request) {
|
|
@@ -1 +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;
|
|
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;IAEvB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;IAG3B,OAAO,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;CA+DtC"}
|
|
@@ -11,14 +11,14 @@ export class DeepSeekModels {
|
|
|
11
11
|
const response = await fetch(`${this.baseUrl}/models`, {
|
|
12
12
|
method: "GET",
|
|
13
13
|
headers: {
|
|
14
|
-
|
|
15
|
-
}
|
|
14
|
+
Authorization: `Bearer ${this.apiKey}`
|
|
15
|
+
}
|
|
16
16
|
});
|
|
17
17
|
if (!response.ok) {
|
|
18
18
|
// Fallback to local registry
|
|
19
19
|
const localModels = ModelRegistry.all()
|
|
20
|
-
.filter(m => m.provider === "deepseek")
|
|
21
|
-
.map(m => ({
|
|
20
|
+
.filter((m) => m.provider === "deepseek")
|
|
21
|
+
.map((m) => ({
|
|
22
22
|
id: m.id,
|
|
23
23
|
name: m.name,
|
|
24
24
|
provider: "deepseek",
|
|
@@ -33,10 +33,10 @@ export class DeepSeekModels {
|
|
|
33
33
|
return localModels;
|
|
34
34
|
}
|
|
35
35
|
const json = (await response.json());
|
|
36
|
-
const localRegistry = ModelRegistry.all().filter(m => m.provider === "deepseek");
|
|
37
|
-
return json.data.map(m => {
|
|
36
|
+
const localRegistry = ModelRegistry.all().filter((m) => m.provider === "deepseek");
|
|
37
|
+
return json.data.map((m) => {
|
|
38
38
|
// Try to find in local registry for enriched data (pricing, limits)
|
|
39
|
-
const local = localRegistry.find(l => l.id === m.id);
|
|
39
|
+
const local = localRegistry.find((l) => l.id === m.id);
|
|
40
40
|
if (local) {
|
|
41
41
|
return {
|
|
42
42
|
id: local.id,
|
|
@@ -1 +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;AAMxD,qBAAa,iBAAiB;
|
|
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;AAMxD,qBAAa,iBAAiB;IAE1B,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;IAG1B,OAAO,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,eAAe,GAAG,cAAc,CAAC,SAAS,CAAC;CAgL9F"}
|
|
@@ -11,7 +11,7 @@ export class DeepSeekStreaming {
|
|
|
11
11
|
}
|
|
12
12
|
async *execute(request, controller) {
|
|
13
13
|
const abortController = controller || new AbortController();
|
|
14
|
-
const { model, messages, tools, max_tokens, response_format, headers, requestTimeout, ...rest } = request;
|
|
14
|
+
const { model, messages, tools, max_tokens, response_format, headers: _headers, requestTimeout, ...rest } = request;
|
|
15
15
|
const mappedMessages = mapSystemMessages(messages, false);
|
|
16
16
|
const body = {
|
|
17
17
|
model,
|
|
@@ -34,18 +34,21 @@ export class DeepSeekStreaming {
|
|
|
34
34
|
const response = await fetchWithTimeout(url, {
|
|
35
35
|
method: "POST",
|
|
36
36
|
headers: {
|
|
37
|
-
|
|
37
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
38
38
|
"Content-Type": "application/json",
|
|
39
|
-
...request.headers
|
|
39
|
+
...request.headers
|
|
40
40
|
},
|
|
41
41
|
body: JSON.stringify(body),
|
|
42
|
-
signal: abortController.signal
|
|
42
|
+
signal: abortController.signal
|
|
43
43
|
}, requestTimeout);
|
|
44
44
|
if (!response.ok) {
|
|
45
45
|
const errorText = await response.text();
|
|
46
46
|
throw new Error(`DeepSeek API error: ${response.status} - ${errorText}`);
|
|
47
47
|
}
|
|
48
|
-
logger.debug("DeepSeek streaming started", {
|
|
48
|
+
logger.debug("DeepSeek streaming started", {
|
|
49
|
+
status: response.status,
|
|
50
|
+
statusText: response.statusText
|
|
51
|
+
});
|
|
49
52
|
if (!response.body) {
|
|
50
53
|
throw new Error("No response body for streaming");
|
|
51
54
|
}
|
|
@@ -63,7 +66,7 @@ export class DeepSeekStreaming {
|
|
|
63
66
|
for (const line of lines) {
|
|
64
67
|
let trimmed = line.trim();
|
|
65
68
|
// Handle carriage returns
|
|
66
|
-
if (trimmed.endsWith(
|
|
69
|
+
if (trimmed.endsWith("\r")) {
|
|
67
70
|
trimmed = trimmed.substring(0, trimmed.length - 1);
|
|
68
71
|
}
|
|
69
72
|
if (!trimmed.startsWith("data: "))
|
|
@@ -73,7 +76,7 @@ export class DeepSeekStreaming {
|
|
|
73
76
|
done = true;
|
|
74
77
|
// Yield final tool calls if any were accumulated
|
|
75
78
|
if (toolCallsMap.size > 0) {
|
|
76
|
-
const toolCalls = Array.from(toolCallsMap.values()).map(tc => ({
|
|
79
|
+
const toolCalls = Array.from(toolCallsMap.values()).map((tc) => ({
|
|
77
80
|
id: tc.id,
|
|
78
81
|
type: "function",
|
|
79
82
|
function: {
|
|
@@ -140,7 +143,7 @@ export class DeepSeekStreaming {
|
|
|
140
143
|
}
|
|
141
144
|
catch (e) {
|
|
142
145
|
// Graceful exit on abort
|
|
143
|
-
if (e instanceof Error && e.name ===
|
|
146
|
+
if (e instanceof Error && e.name === "AbortError") {
|
|
144
147
|
return;
|
|
145
148
|
}
|
|
146
149
|
throw e;
|
|
@@ -1 +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,
|
|
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,SAkBvC;AAED,eAAO,MAAM,wBAAwB,iCAA2B,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { config } from "../../config.js";
|
|
1
|
+
import { config as globalConfig } from "../../config.js";
|
|
2
2
|
import { providerRegistry } from "../registry.js";
|
|
3
3
|
import { DeepSeekProvider } from "./DeepSeekProvider.js";
|
|
4
4
|
export * from "./DeepSeekProvider.js";
|
|
@@ -9,9 +9,10 @@ let registered = false;
|
|
|
9
9
|
export function registerDeepSeekProvider() {
|
|
10
10
|
if (registered)
|
|
11
11
|
return;
|
|
12
|
-
providerRegistry.register("deepseek", () => {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
12
|
+
providerRegistry.register("deepseek", (config) => {
|
|
13
|
+
const cfg = config || globalConfig;
|
|
14
|
+
const apiKey = cfg.deepseekApiKey;
|
|
15
|
+
const baseUrl = cfg.deepseekApiBase; // Optional override
|
|
15
16
|
if (!apiKey) {
|
|
16
17
|
throw new Error("deepseek_api_key is not set in config or DEEPSEEK_API_KEY environment variable");
|
|
17
18
|
}
|
|
@@ -1,51 +1,23 @@
|
|
|
1
|
+
import { ModelPricing } from "../../models/types.js";
|
|
1
2
|
export declare class Capabilities {
|
|
2
3
|
static getContextWindow(modelId: string): number | null;
|
|
3
4
|
static getMaxOutputTokens(modelId: string): number | null;
|
|
4
5
|
static supportsVision(modelId: string): boolean;
|
|
5
6
|
static supportsTools(modelId: string): boolean;
|
|
6
7
|
static supportsStructuredOutput(modelId: string): boolean;
|
|
7
|
-
static supportsSystemInstructions(
|
|
8
|
+
static supportsSystemInstructions(_modelId: string): boolean;
|
|
8
9
|
static supportsJsonMode(modelId: string): boolean;
|
|
9
10
|
static supportsEmbeddings(modelId: string): boolean;
|
|
10
11
|
static supportsImageGeneration(modelId: string): boolean;
|
|
11
12
|
static supportsTranscription(modelId: string): boolean;
|
|
12
|
-
static supportsModeration(
|
|
13
|
-
static normalizeTemperature(temperature: number | undefined,
|
|
13
|
+
static supportsModeration(_modelId: string): boolean;
|
|
14
|
+
static normalizeTemperature(temperature: number | undefined, _model: string): number | undefined;
|
|
14
15
|
static getModalities(modelId: string): {
|
|
15
16
|
input: string[];
|
|
16
17
|
output: string[];
|
|
17
18
|
};
|
|
18
19
|
static getCapabilities(modelId: string): string[];
|
|
19
|
-
static getPricing(modelId: string):
|
|
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;
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
};
|
|
20
|
+
static getPricing(modelId: string): ModelPricing | undefined;
|
|
49
21
|
private static normalizeModelId;
|
|
50
22
|
}
|
|
51
23
|
//# sourceMappingURL=Capabilities.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
1
|
+
{"version":3,"file":"Capabilities.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Capabilities.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,qBAAa,YAAY;IACvB,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IA2BvD,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAwBzD,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,QAAQ,EAAE,MAAM,GAAG,OAAO;IAI5D,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,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