@node-llm/core 1.4.2 → 1.5.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 +87 -19
- package/dist/chat/Chat.d.ts +51 -0
- package/dist/chat/Chat.d.ts.map +1 -1
- package/dist/chat/Chat.js +189 -55
- package/dist/chat/ChatOptions.d.ts +11 -2
- package/dist/chat/ChatOptions.d.ts.map +1 -1
- package/dist/chat/ChatResponse.d.ts +7 -1
- package/dist/chat/ChatResponse.d.ts.map +1 -1
- package/dist/chat/ChatResponse.js +9 -1
- package/dist/chat/ChatStream.d.ts +15 -1
- package/dist/chat/ChatStream.d.ts.map +1 -1
- package/dist/chat/ChatStream.js +122 -36
- package/dist/chat/Role.d.ts +1 -1
- package/dist/chat/Role.d.ts.map +1 -1
- package/dist/config.d.ts +11 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +7 -1
- package/dist/constants.d.ts +11 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +12 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/llm.d.ts +4 -0
- package/dist/llm.d.ts.map +1 -1
- package/dist/llm.js +10 -0
- package/dist/providers/Provider.d.ts +6 -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 +1 -0
- package/dist/providers/anthropic/Chat.d.ts.map +1 -1
- package/dist/providers/anthropic/Chat.js +4 -3
- package/dist/providers/anthropic/Streaming.d.ts.map +1 -1
- package/dist/providers/anthropic/Streaming.js +3 -2
- package/dist/providers/anthropic/Utils.js +2 -2
- package/dist/providers/deepseek/Chat.d.ts.map +1 -1
- package/dist/providers/deepseek/Chat.js +8 -5
- package/dist/providers/deepseek/DeepSeekProvider.d.ts +1 -0
- package/dist/providers/deepseek/DeepSeekProvider.d.ts.map +1 -1
- package/dist/providers/deepseek/DeepSeekProvider.js +1 -0
- package/dist/providers/deepseek/Streaming.d.ts.map +1 -1
- package/dist/providers/deepseek/Streaming.js +7 -4
- package/dist/providers/gemini/Chat.d.ts.map +1 -1
- package/dist/providers/gemini/Chat.js +4 -3
- package/dist/providers/gemini/ChatUtils.js +5 -5
- 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/Streaming.d.ts.map +1 -1
- package/dist/providers/gemini/Streaming.js +3 -2
- package/dist/providers/ollama/OllamaProvider.d.ts.map +1 -1
- package/dist/providers/ollama/OllamaProvider.js +1 -0
- package/dist/providers/openai/Capabilities.d.ts +1 -0
- package/dist/providers/openai/Capabilities.d.ts.map +1 -1
- package/dist/providers/openai/Capabilities.js +3 -0
- package/dist/providers/openai/Chat.d.ts +4 -2
- package/dist/providers/openai/Chat.d.ts.map +1 -1
- package/dist/providers/openai/Chat.js +16 -7
- package/dist/providers/openai/Embedding.d.ts.map +1 -1
- package/dist/providers/openai/Embedding.js +3 -2
- package/dist/providers/openai/Image.d.ts.map +1 -1
- package/dist/providers/openai/Image.js +3 -2
- package/dist/providers/openai/Moderation.d.ts.map +1 -1
- package/dist/providers/openai/Moderation.js +3 -2
- 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 +3 -2
- package/dist/providers/openai/Streaming.d.ts +4 -2
- package/dist/providers/openai/Streaming.d.ts.map +1 -1
- package/dist/providers/openai/Streaming.js +15 -6
- package/dist/providers/openai/Transcription.d.ts.map +1 -1
- package/dist/providers/openai/Transcription.js +5 -4
- package/dist/providers/openrouter/OpenRouterProvider.d.ts +1 -0
- package/dist/providers/openrouter/OpenRouterProvider.d.ts.map +1 -1
- package/dist/providers/openrouter/OpenRouterProvider.js +1 -0
- package/dist/providers/utils.d.ts +8 -0
- package/dist/providers/utils.d.ts.map +1 -0
- package/dist/providers/utils.js +16 -0
- package/dist/utils/fetch.d.ts +12 -0
- package/dist/utils/fetch.d.ts.map +1 -0
- package/dist/utils/fetch.js +34 -0
- package/package.json +11 -12
- package/dist/aliases.json +0 -132
- package/dist/utils/sanitize.d.ts +0 -21
- package/dist/utils/sanitize.d.ts.map +0 -1
- package/dist/utils/sanitize.js +0 -76
|
@@ -19,6 +19,7 @@ export declare class AnthropicProvider extends BaseProvider implements Provider
|
|
|
19
19
|
supportsTranscription: (_model: string) => boolean;
|
|
20
20
|
supportsModeration: (_model: string) => boolean;
|
|
21
21
|
supportsReasoning: (_model: string) => boolean;
|
|
22
|
+
supportsDeveloperRole: (_model: string) => boolean;
|
|
22
23
|
getContextWindow: (model: string) => number | null;
|
|
23
24
|
};
|
|
24
25
|
constructor(options: AnthropicProviderOptions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnthropicProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/AnthropicProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAwJ,MAAM,gBAAgB,CAAC;AACjP,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAMlD,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,iBAAkB,SAAQ,YAAa,YAAW,QAAQ;
|
|
1
|
+
{"version":3,"file":"AnthropicProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/AnthropicProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAwJ,MAAM,gBAAgB,CAAC;AACjP,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAMlD,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,iBAAkB,SAAQ,YAAa,YAAW,QAAQ;IAmBzD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAlBpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAgB;IAC5C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAqB;IACnD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAkB;IAEzC,YAAY;gCACO,MAAM;+BACP,MAAM;0CACK,MAAM;qCACX,MAAM;0CACD,MAAM;wCACR,MAAM;qCACT,MAAM;oCACP,MAAM;wCACF,MAAM;kCACZ,MAAM;MAChC;gBAE2B,OAAO,EAAE,wBAAwB;IAQvD,OAAO,IAAI,MAAM;IAIjB,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAQxC,SAAS,CAAC,YAAY,IAAI,MAAM;IAIhB,YAAY,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM;IAIhD,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"}
|
|
@@ -18,6 +18,7 @@ export class AnthropicProvider extends BaseProvider {
|
|
|
18
18
|
supportsTranscription: (_model) => false,
|
|
19
19
|
supportsModeration: (_model) => false,
|
|
20
20
|
supportsReasoning: (_model) => false,
|
|
21
|
+
supportsDeveloperRole: (_model) => true,
|
|
21
22
|
getContextWindow: (model) => Capabilities.getContextWindow(model),
|
|
22
23
|
};
|
|
23
24
|
constructor(options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/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/anthropic/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAS,MAAM,gBAAgB,CAAC;AAYlE,qBAAa,aAAa;IACZ,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;CA4G3D"}
|
|
@@ -2,6 +2,7 @@ import { Capabilities } from "./Capabilities.js";
|
|
|
2
2
|
import { handleAnthropicError } from "./Errors.js";
|
|
3
3
|
import { ModelRegistry } from "../../models/ModelRegistry.js";
|
|
4
4
|
import { logger } from "../../utils/logger.js";
|
|
5
|
+
import { fetchWithTimeout } from "../../utils/fetch.js";
|
|
5
6
|
import { formatSystemPrompt, formatMessages } from "./Utils.js";
|
|
6
7
|
export class AnthropicChat {
|
|
7
8
|
baseUrl;
|
|
@@ -24,7 +25,7 @@ export class AnthropicChat {
|
|
|
24
25
|
const instruction = `CRITICAL: Respond ONLY with a valid JSON object matching the requested schema.${schemaText}\n\nDo not include any other text or explanation.`;
|
|
25
26
|
system = system ? `${system}\n\n${instruction}` : instruction;
|
|
26
27
|
}
|
|
27
|
-
const { model: _model, messages: _messages, tools: _tools, temperature: _temp, max_tokens: _max, response_format: _format, headers: _headers, ...rest } = request;
|
|
28
|
+
const { model: _model, messages: _messages, tools: _tools, temperature: _temp, max_tokens: _max, response_format: _format, headers: _headers, requestTimeout, ...rest } = request;
|
|
28
29
|
const body = {
|
|
29
30
|
model: model,
|
|
30
31
|
messages: messages,
|
|
@@ -57,11 +58,11 @@ export class AnthropicChat {
|
|
|
57
58
|
}
|
|
58
59
|
const url = `${this.baseUrl}/messages`;
|
|
59
60
|
logger.logRequest("Anthropic", "POST", url, body);
|
|
60
|
-
const response = await
|
|
61
|
+
const response = await fetchWithTimeout(url, {
|
|
61
62
|
method: "POST",
|
|
62
63
|
headers: headers,
|
|
63
64
|
body: JSON.stringify(body),
|
|
64
|
-
});
|
|
65
|
+
}, requestTimeout);
|
|
65
66
|
if (!response.ok) {
|
|
66
67
|
await handleAnthropicError(response, model);
|
|
67
68
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAQxD,qBAAa,kBAAkB;IACjB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEtE,OAAO,CACZ,OAAO,EAAE,WAAW,EACpB,UAAU,CAAC,EAAE,eAAe,GAC3B,cAAc,CAAC,SAAS,CAAC;CAqM7B"}
|
|
@@ -2,6 +2,7 @@ import { Capabilities } from "./Capabilities.js";
|
|
|
2
2
|
import { handleAnthropicError } from "./Errors.js";
|
|
3
3
|
import { formatSystemPrompt, formatMessages } from "./Utils.js";
|
|
4
4
|
import { logger } from "../../utils/logger.js";
|
|
5
|
+
import { fetchWithTimeout } from "../../utils/fetch.js";
|
|
5
6
|
export class AnthropicStreaming {
|
|
6
7
|
baseUrl;
|
|
7
8
|
apiKey;
|
|
@@ -59,12 +60,12 @@ export class AnthropicStreaming {
|
|
|
59
60
|
try {
|
|
60
61
|
const url = `${this.baseUrl}/messages`;
|
|
61
62
|
logger.logRequest("Anthropic", "POST", url, body);
|
|
62
|
-
const response = await
|
|
63
|
+
const response = await fetchWithTimeout(url, {
|
|
63
64
|
method: "POST",
|
|
64
65
|
headers: headers,
|
|
65
66
|
body: JSON.stringify(body),
|
|
66
67
|
signal: abortController.signal,
|
|
67
|
-
});
|
|
68
|
+
}, request.requestTimeout);
|
|
68
69
|
if (!response.ok) {
|
|
69
70
|
await handleAnthropicError(response, model);
|
|
70
71
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export function formatSystemPrompt(messages) {
|
|
2
2
|
let systemPrompt;
|
|
3
3
|
for (const msg of messages) {
|
|
4
|
-
if (msg.role === "system") {
|
|
4
|
+
if (msg.role === "system" || msg.role === "developer") {
|
|
5
5
|
if (typeof msg.content === "string") {
|
|
6
6
|
systemPrompt = msg.content;
|
|
7
7
|
}
|
|
@@ -21,7 +21,7 @@ export function formatSystemPrompt(messages) {
|
|
|
21
21
|
export function formatMessages(requestMessages) {
|
|
22
22
|
const messages = [];
|
|
23
23
|
for (const msg of requestMessages) {
|
|
24
|
-
if (msg.role === "system")
|
|
24
|
+
if (msg.role === "system" || msg.role === "developer")
|
|
25
25
|
continue;
|
|
26
26
|
const formatted = formatSingleMessage(msg);
|
|
27
27
|
const lastMsg = messages[messages.length - 1];
|
|
@@ -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;AAwBlE,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;CA2F3D"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ModelRegistry } from "../../models/ModelRegistry.js";
|
|
2
2
|
import { logger } from "../../utils/logger.js";
|
|
3
|
+
import { mapSystemMessages } from "../utils.js";
|
|
4
|
+
import { fetchWithTimeout } from "../../utils/fetch.js";
|
|
3
5
|
export class DeepSeekChat {
|
|
4
6
|
baseUrl;
|
|
5
7
|
apiKey;
|
|
@@ -8,10 +10,11 @@ export class DeepSeekChat {
|
|
|
8
10
|
this.apiKey = apiKey;
|
|
9
11
|
}
|
|
10
12
|
async execute(request) {
|
|
11
|
-
const { model, messages, tools, max_tokens, response_format, headers, ...rest } = request;
|
|
13
|
+
const { model, messages, tools, max_tokens, response_format, headers, requestTimeout, ...rest } = request;
|
|
14
|
+
const mappedMessages = mapSystemMessages(messages, false);
|
|
12
15
|
const body = {
|
|
13
16
|
model,
|
|
14
|
-
messages,
|
|
17
|
+
messages: mappedMessages,
|
|
15
18
|
...rest
|
|
16
19
|
};
|
|
17
20
|
if (max_tokens)
|
|
@@ -31,7 +34,7 @@ export class DeepSeekChat {
|
|
|
31
34
|
const schemaString = JSON.stringify(schema.schema, null, 2);
|
|
32
35
|
const instruction = `\n\nIMPORTANT: You must output strictly valid JSON conforming to the following schema:\n${schemaString}\n\nOutput only the JSON object.`;
|
|
33
36
|
// Find system message or append to last user message
|
|
34
|
-
const systemMessage = body.messages.find((m) => m.role === "system");
|
|
37
|
+
const systemMessage = body.messages.find((m) => m.role === "system" || m.role === "developer");
|
|
35
38
|
if (systemMessage) {
|
|
36
39
|
systemMessage.content += instruction;
|
|
37
40
|
}
|
|
@@ -49,7 +52,7 @@ export class DeepSeekChat {
|
|
|
49
52
|
}
|
|
50
53
|
const url = `${this.baseUrl}/chat/completions`;
|
|
51
54
|
logger.logRequest("DeepSeek", "POST", url, body);
|
|
52
|
-
const response = await
|
|
55
|
+
const response = await fetchWithTimeout(url, {
|
|
53
56
|
method: "POST",
|
|
54
57
|
headers: {
|
|
55
58
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
@@ -57,7 +60,7 @@ export class DeepSeekChat {
|
|
|
57
60
|
...request.headers,
|
|
58
61
|
},
|
|
59
62
|
body: JSON.stringify(body),
|
|
60
|
-
});
|
|
63
|
+
}, requestTimeout);
|
|
61
64
|
if (!response.ok) {
|
|
62
65
|
const errorText = await response.text();
|
|
63
66
|
throw new Error(`DeepSeek API error: ${response.status} - ${errorText}`);
|
|
@@ -19,6 +19,7 @@ export declare class DeepSeekProvider extends BaseProvider implements Provider {
|
|
|
19
19
|
supportsTranscription: (model: string) => boolean;
|
|
20
20
|
supportsModeration: (model: string) => boolean;
|
|
21
21
|
supportsReasoning: (model: string) => boolean;
|
|
22
|
+
supportsDeveloperRole: (_model: string) => boolean;
|
|
22
23
|
getContextWindow: (model: string) => number | null;
|
|
23
24
|
};
|
|
24
25
|
constructor(options: DeepSeekProviderOptions);
|
|
@@ -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;AAMlD,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,gBAAiB,SAAQ,YAAa,YAAW,QAAQ;
|
|
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;AAMlD,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,gBAAiB,SAAQ,YAAa,YAAW,QAAQ;IAmBxD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAlBpC,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;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,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM;IAIhD,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"}
|
|
@@ -18,6 +18,7 @@ export class DeepSeekProvider extends BaseProvider {
|
|
|
18
18
|
supportsTranscription: (model) => Capabilities.supportsTranscription(model),
|
|
19
19
|
supportsModeration: (model) => Capabilities.supportsModeration(model),
|
|
20
20
|
supportsReasoning: (model) => Capabilities.supportsReasoning(model),
|
|
21
|
+
supportsDeveloperRole: (_model) => false,
|
|
21
22
|
getContextWindow: (model) => Capabilities.getContextWindow(model),
|
|
22
23
|
};
|
|
23
24
|
constructor(options) {
|
|
@@ -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;
|
|
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;IAChB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEtE,OAAO,CACZ,OAAO,EAAE,WAAW,EACpB,UAAU,CAAC,EAAE,eAAe,GAC3B,cAAc,CAAC,SAAS,CAAC;CAiK7B"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { APIError } from "../../errors/index.js";
|
|
2
2
|
import { logger } from "../../utils/logger.js";
|
|
3
|
+
import { mapSystemMessages } from "../utils.js";
|
|
4
|
+
import { fetchWithTimeout } from "../../utils/fetch.js";
|
|
3
5
|
export class DeepSeekStreaming {
|
|
4
6
|
baseUrl;
|
|
5
7
|
apiKey;
|
|
@@ -9,10 +11,11 @@ export class DeepSeekStreaming {
|
|
|
9
11
|
}
|
|
10
12
|
async *execute(request, controller) {
|
|
11
13
|
const abortController = controller || new AbortController();
|
|
12
|
-
const { model, messages, tools, max_tokens, response_format, headers, ...rest } = request;
|
|
14
|
+
const { model, messages, tools, max_tokens, response_format, headers, requestTimeout, ...rest } = request;
|
|
15
|
+
const mappedMessages = mapSystemMessages(messages, false);
|
|
13
16
|
const body = {
|
|
14
17
|
model,
|
|
15
|
-
messages,
|
|
18
|
+
messages: mappedMessages,
|
|
16
19
|
stream: true,
|
|
17
20
|
...rest
|
|
18
21
|
};
|
|
@@ -28,7 +31,7 @@ export class DeepSeekStreaming {
|
|
|
28
31
|
try {
|
|
29
32
|
const url = `${this.baseUrl}/chat/completions`;
|
|
30
33
|
logger.logRequest("DeepSeek", "POST", url, body);
|
|
31
|
-
const response = await
|
|
34
|
+
const response = await fetchWithTimeout(url, {
|
|
32
35
|
method: "POST",
|
|
33
36
|
headers: {
|
|
34
37
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
@@ -37,7 +40,7 @@ export class DeepSeekStreaming {
|
|
|
37
40
|
},
|
|
38
41
|
body: JSON.stringify(body),
|
|
39
42
|
signal: abortController.signal,
|
|
40
|
-
});
|
|
43
|
+
}, requestTimeout);
|
|
41
44
|
if (!response.ok) {
|
|
42
45
|
const errorText = await response.text();
|
|
43
46
|
throw new Error(`DeepSeek API error: ${response.status} - ${errorText}`);
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AASlE,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;IA4F1D,OAAO,CAAC,cAAc;CAwBvB"}
|
|
@@ -3,6 +3,7 @@ import { handleGeminiError } from "./Errors.js";
|
|
|
3
3
|
import { GeminiChatUtils } from "./ChatUtils.js";
|
|
4
4
|
import { ModelRegistry } from "../../models/ModelRegistry.js";
|
|
5
5
|
import { logger } from "../../utils/logger.js";
|
|
6
|
+
import { fetchWithTimeout } from "../../utils/fetch.js";
|
|
6
7
|
export class GeminiChat {
|
|
7
8
|
baseUrl;
|
|
8
9
|
apiKey;
|
|
@@ -27,7 +28,7 @@ export class GeminiChat {
|
|
|
27
28
|
generationConfig.responseSchema = this.sanitizeSchema(request.response_format.json_schema.schema);
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
|
-
const { model: _model, messages: _messages, tools: _tools, temperature: _temp, max_tokens: _max, response_format: _format, headers: _headers, ...rest } = request;
|
|
31
|
+
const { model: _model, messages: _messages, tools: _tools, temperature: _temp, max_tokens: _max, response_format: _format, headers: _headers, requestTimeout, ...rest } = request;
|
|
31
32
|
const payload = {
|
|
32
33
|
contents,
|
|
33
34
|
generationConfig: {
|
|
@@ -51,13 +52,13 @@ export class GeminiChat {
|
|
|
51
52
|
];
|
|
52
53
|
}
|
|
53
54
|
logger.logRequest("Gemini", "POST", url, payload);
|
|
54
|
-
const response = await
|
|
55
|
+
const response = await fetchWithTimeout(url, {
|
|
55
56
|
method: "POST",
|
|
56
57
|
headers: {
|
|
57
58
|
"Content-Type": "application/json",
|
|
58
59
|
},
|
|
59
60
|
body: JSON.stringify(payload),
|
|
60
|
-
});
|
|
61
|
+
}, requestTimeout);
|
|
61
62
|
if (!response.ok) {
|
|
62
63
|
await handleGeminiError(response, request.model);
|
|
63
64
|
}
|
|
@@ -4,9 +4,9 @@ export class GeminiChatUtils {
|
|
|
4
4
|
const contents = [];
|
|
5
5
|
const systemInstructionParts = [];
|
|
6
6
|
for (const msg of messages) {
|
|
7
|
-
if (msg.role === "system") {
|
|
8
|
-
if (
|
|
9
|
-
systemInstructionParts.push({ text: msg.content });
|
|
7
|
+
if (msg.role === "system" || msg.role === "developer") {
|
|
8
|
+
if (msg.content) {
|
|
9
|
+
systemInstructionParts.push({ text: String(msg.content) });
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
else if (msg.role === "user" || msg.role === "assistant" || msg.role === "tool") {
|
|
@@ -22,8 +22,8 @@ export class GeminiChatUtils {
|
|
|
22
22
|
}
|
|
23
23
|
else {
|
|
24
24
|
const role = msg.role === "assistant" ? "model" : "user";
|
|
25
|
-
if (typeof msg.content === "string"
|
|
26
|
-
parts.push({ text: msg.content });
|
|
25
|
+
if (msg.content && (typeof msg.content === "string" || msg.content instanceof String)) {
|
|
26
|
+
parts.push({ text: String(msg.content) });
|
|
27
27
|
}
|
|
28
28
|
else if (Array.isArray(msg.content)) {
|
|
29
29
|
for (const part of msg.content) {
|
|
@@ -22,6 +22,7 @@ export declare class GeminiProvider extends BaseProvider implements Provider {
|
|
|
22
22
|
supportsTranscription: (model: string) => boolean;
|
|
23
23
|
supportsModeration: (model: string) => boolean;
|
|
24
24
|
supportsReasoning: (_model: string) => boolean;
|
|
25
|
+
supportsDeveloperRole: (_model: string) => boolean;
|
|
25
26
|
getContextWindow: (model: string) => number | null;
|
|
26
27
|
};
|
|
27
28
|
constructor(options: GeminiProviderOptions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeminiProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/GeminiProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,SAAS,EACT,SAAS,EACT,YAAY,EACZ,aAAa,EACb,oBAAoB,EACpB,qBAAqB,EAGrB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AASlD,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC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MAAM;IAIhD,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;IAIlC,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAIpD,KAAK,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAI5D,UAAU,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAKhF"}
|
|
@@ -24,6 +24,7 @@ export class GeminiProvider extends BaseProvider {
|
|
|
24
24
|
supportsTranscription: (model) => Capabilities.supportsTranscription(model),
|
|
25
25
|
supportsModeration: (model) => Capabilities.supportsModeration(model),
|
|
26
26
|
supportsReasoning: (_model) => false,
|
|
27
|
+
supportsDeveloperRole: (_model) => true,
|
|
27
28
|
getContextWindow: (model) => Capabilities.getContextWindow(model),
|
|
28
29
|
};
|
|
29
30
|
constructor(options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Streaming.d.ts","sourceRoot":"","sources":["../../../src/providers/gemini/Streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAQxD,qBAAa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEtE,OAAO,CACZ,OAAO,EAAE,WAAW,EACpB,UAAU,CAAC,EAAE,eAAe,GAC3B,cAAc,CAAC,SAAS,CAAC;IAyI5B,OAAO,CAAC,cAAc;CAwBvB"}
|
|
@@ -2,6 +2,7 @@ import { Capabilities } from "./Capabilities.js";
|
|
|
2
2
|
import { handleGeminiError } from "./Errors.js";
|
|
3
3
|
import { GeminiChatUtils } from "./ChatUtils.js";
|
|
4
4
|
import { logger } from "../../utils/logger.js";
|
|
5
|
+
import { fetchWithTimeout } from "../../utils/fetch.js";
|
|
5
6
|
export class GeminiStreaming {
|
|
6
7
|
baseUrl;
|
|
7
8
|
apiKey;
|
|
@@ -49,14 +50,14 @@ export class GeminiStreaming {
|
|
|
49
50
|
const toolCalls = [];
|
|
50
51
|
try {
|
|
51
52
|
logger.logRequest("Gemini", "POST", url, payload);
|
|
52
|
-
const response = await
|
|
53
|
+
const response = await fetchWithTimeout(url, {
|
|
53
54
|
method: "POST",
|
|
54
55
|
headers: {
|
|
55
56
|
"Content-Type": "application/json",
|
|
56
57
|
},
|
|
57
58
|
body: JSON.stringify(payload),
|
|
58
59
|
signal: abortController.signal,
|
|
59
|
-
});
|
|
60
|
+
}, request.requestTimeout);
|
|
60
61
|
if (!response.ok) {
|
|
61
62
|
await handleGeminiError(response, request.model);
|
|
62
63
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OllamaProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/ollama/OllamaProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAM7D,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,cAAe,SAAQ,cAAc;gBACpC,OAAO,GAAE,qBAA0B;
|
|
1
|
+
{"version":3,"file":"OllamaProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/ollama/OllamaProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAM7D,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,cAAe,SAAQ,cAAc;gBACpC,OAAO,GAAE,qBAA0B;IAyB/C,SAAS,CAAC,YAAY,IAAI,MAAM;IAIhB,YAAY,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM;CAGvD"}
|
|
@@ -22,6 +22,7 @@ export class OllamaProvider extends OpenAIProvider {
|
|
|
22
22
|
supportsTranscription: (modelId) => OllamaCapabilities.supportsTranscription(modelId),
|
|
23
23
|
supportsModeration: (modelId) => OllamaCapabilities.supportsModeration(modelId),
|
|
24
24
|
supportsReasoning: (modelId) => OllamaCapabilities.supportsReasoning(modelId),
|
|
25
|
+
supportsDeveloperRole: (_modelId) => false,
|
|
25
26
|
getContextWindow: (modelId) => OllamaCapabilities.getContextWindow(modelId),
|
|
26
27
|
};
|
|
27
28
|
}
|
|
@@ -10,6 +10,7 @@ export declare class Capabilities {
|
|
|
10
10
|
static supportsTranscription(modelId: string): boolean;
|
|
11
11
|
static supportsModeration(modelId: string): boolean;
|
|
12
12
|
static supportsReasoning(modelId: string): boolean;
|
|
13
|
+
static supportsDeveloperRole(modelId: string): boolean;
|
|
13
14
|
static getModelType(modelId: string): "embeddings" | "audio" | "moderation" | "image" | "chat" | "audio_transcription" | "audio_speech";
|
|
14
15
|
static getModalities(modelId: string): {
|
|
15
16
|
input: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Capabilities.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Capabilities.ts"],"names":[],"mappings":"AAEA,qBAAa,YAAY;IACvB,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAUvD,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IASzD,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAO/C,MAAM,CAAC,aA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B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAOjD,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG;CAcxC"}
|
|
@@ -73,6 +73,9 @@ export class Capabilities {
|
|
|
73
73
|
return true;
|
|
74
74
|
return /o\d|gpt-5/.test(modelId);
|
|
75
75
|
}
|
|
76
|
+
static supportsDeveloperRole(modelId) {
|
|
77
|
+
return /gpt-4o|o1|o3/.test(modelId);
|
|
78
|
+
}
|
|
76
79
|
static getModelType(modelId) {
|
|
77
80
|
if (this.supportsEmbeddings(modelId))
|
|
78
81
|
return "embeddings";
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ChatRequest, ChatResponse } from "../Provider.js";
|
|
2
|
+
import { OpenAIProvider } from "./OpenAIProvider.js";
|
|
2
3
|
export declare class OpenAIChat {
|
|
3
|
-
private readonly
|
|
4
|
+
private readonly providerOrUrl;
|
|
4
5
|
private readonly apiKey;
|
|
5
|
-
|
|
6
|
+
private readonly baseUrl;
|
|
7
|
+
constructor(providerOrUrl: OpenAIProvider | string, apiKey: string);
|
|
6
8
|
execute(request: ChatRequest): Promise<ChatResponse>;
|
|
7
9
|
}
|
|
8
10
|
//# sourceMappingURL=Chat.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/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/openai/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAS,MAAM,gBAAgB,CAAC;AASlE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,qBAAa,UAAU;IAGT,OAAO,CAAC,QAAQ,CAAC,aAAa;IAA2B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAF5F,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAEJ,aAAa,EAAE,cAAc,GAAG,MAAM,EAAmB,MAAM,EAAE,MAAM;IAI9F,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CAgE3D"}
|
|
@@ -3,19 +3,28 @@ import { handleOpenAIError } from "./Errors.js";
|
|
|
3
3
|
import { ModelRegistry } from "../../models/ModelRegistry.js";
|
|
4
4
|
import { buildUrl } from "./utils.js";
|
|
5
5
|
import { logger } from "../../utils/logger.js";
|
|
6
|
+
import { fetchWithTimeout } from "../../utils/fetch.js";
|
|
7
|
+
import { mapSystemMessages } from "../utils.js";
|
|
6
8
|
export class OpenAIChat {
|
|
7
|
-
|
|
9
|
+
providerOrUrl;
|
|
8
10
|
apiKey;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
baseUrl;
|
|
12
|
+
constructor(providerOrUrl, apiKey) {
|
|
13
|
+
this.providerOrUrl = providerOrUrl;
|
|
11
14
|
this.apiKey = apiKey;
|
|
15
|
+
this.baseUrl = typeof providerOrUrl === "string" ? providerOrUrl : providerOrUrl.apiBase();
|
|
12
16
|
}
|
|
13
17
|
async execute(request) {
|
|
14
18
|
const temperature = Capabilities.normalizeTemperature(request.temperature, request.model);
|
|
15
|
-
const
|
|
19
|
+
const isMainOpenAI = this.baseUrl.includes("api.openai.com");
|
|
20
|
+
const supportsDeveloperRole = isMainOpenAI && (typeof this.providerOrUrl === "string"
|
|
21
|
+
? Capabilities.supportsDeveloperRole(request.model)
|
|
22
|
+
: this.providerOrUrl.capabilities?.supportsDeveloperRole(request.model));
|
|
23
|
+
const { model, messages, tools, temperature: _, max_tokens, response_format, headers, requestTimeout, ...rest } = request;
|
|
24
|
+
const mappedMessages = mapSystemMessages(messages, !!supportsDeveloperRole);
|
|
16
25
|
const body = {
|
|
17
26
|
model,
|
|
18
|
-
messages,
|
|
27
|
+
messages: mappedMessages,
|
|
19
28
|
...rest
|
|
20
29
|
};
|
|
21
30
|
if (temperature !== undefined && temperature !== null)
|
|
@@ -28,7 +37,7 @@ export class OpenAIChat {
|
|
|
28
37
|
body.response_format = response_format;
|
|
29
38
|
const url = buildUrl(this.baseUrl, '/chat/completions');
|
|
30
39
|
logger.logRequest("OpenAI", "POST", url, body);
|
|
31
|
-
const response = await
|
|
40
|
+
const response = await fetchWithTimeout(url, {
|
|
32
41
|
method: "POST",
|
|
33
42
|
headers: {
|
|
34
43
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
@@ -36,7 +45,7 @@ export class OpenAIChat {
|
|
|
36
45
|
...request.headers,
|
|
37
46
|
},
|
|
38
47
|
body: JSON.stringify(body),
|
|
39
|
-
});
|
|
48
|
+
}, request.requestTimeout);
|
|
40
49
|
if (!response.ok) {
|
|
41
50
|
await handleOpenAIError(response, request.model);
|
|
42
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Embedding.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Embedding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Embedding.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Embedding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAQrE,qBAAa,eAAe;IAExB,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM;IAClC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM;gBADd,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM;IAGnC,SAAS,CAAC,eAAe,IAAI,MAAM;IAInC,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAMtC,OAAO,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CA+CrE"}
|
|
@@ -3,6 +3,7 @@ import { Capabilities } from "./Capabilities.js";
|
|
|
3
3
|
import { DEFAULT_MODELS } from "../../constants.js";
|
|
4
4
|
import { buildUrl } from "./utils.js";
|
|
5
5
|
import { logger } from "../../utils/logger.js";
|
|
6
|
+
import { fetchWithTimeout } from "../../utils/fetch.js";
|
|
6
7
|
export class OpenAIEmbedding {
|
|
7
8
|
baseUrl;
|
|
8
9
|
apiKey;
|
|
@@ -33,14 +34,14 @@ export class OpenAIEmbedding {
|
|
|
33
34
|
}
|
|
34
35
|
const url = buildUrl(this.baseUrl, '/embeddings');
|
|
35
36
|
logger.logRequest("OpenAI", "POST", url, body);
|
|
36
|
-
const response = await
|
|
37
|
+
const response = await fetchWithTimeout(url, {
|
|
37
38
|
method: "POST",
|
|
38
39
|
headers: {
|
|
39
40
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
40
41
|
"Content-Type": "application/json",
|
|
41
42
|
},
|
|
42
43
|
body: JSON.stringify(body),
|
|
43
|
-
});
|
|
44
|
+
}, request.requestTimeout);
|
|
44
45
|
if (!response.ok) {
|
|
45
46
|
await handleOpenAIError(response, request.model || DEFAULT_MODELS.EMBEDDING);
|
|
46
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Image.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Image.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAM7D,qBAAa,WAAW;IACV,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;CAuC7D"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { handleOpenAIError } from "./Errors.js";
|
|
2
2
|
import { buildUrl } from "./utils.js";
|
|
3
3
|
import { logger } from "../../utils/logger.js";
|
|
4
|
+
import { fetchWithTimeout } from "../../utils/fetch.js";
|
|
4
5
|
export class OpenAIImage {
|
|
5
6
|
baseUrl;
|
|
6
7
|
apiKey;
|
|
@@ -18,14 +19,14 @@ export class OpenAIImage {
|
|
|
18
19
|
};
|
|
19
20
|
const url = buildUrl(this.baseUrl, '/images/generations');
|
|
20
21
|
logger.logRequest("OpenAI", "POST", url, body);
|
|
21
|
-
const response = await
|
|
22
|
+
const response = await fetchWithTimeout(url, {
|
|
22
23
|
method: "POST",
|
|
23
24
|
headers: {
|
|
24
25
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
25
26
|
"Content-Type": "application/json",
|
|
26
27
|
},
|
|
27
28
|
body: JSON.stringify(body),
|
|
28
|
-
});
|
|
29
|
+
}, request.requestTimeout);
|
|
29
30
|
if (!response.ok) {
|
|
30
31
|
await handleOpenAIError(response, request.model);
|
|
31
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Moderation.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Moderation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Moderation.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Moderation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAOvE,qBAAa,gBAAgB;IACf,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;CA0BvE"}
|
|
@@ -2,6 +2,7 @@ import { handleOpenAIError } from "./Errors.js";
|
|
|
2
2
|
import { DEFAULT_MODELS } from "../../constants.js";
|
|
3
3
|
import { buildUrl } from "./utils.js";
|
|
4
4
|
import { logger } from "../../utils/logger.js";
|
|
5
|
+
import { fetchWithTimeout } from "../../utils/fetch.js";
|
|
5
6
|
export class OpenAIModeration {
|
|
6
7
|
baseUrl;
|
|
7
8
|
apiKey;
|
|
@@ -16,14 +17,14 @@ export class OpenAIModeration {
|
|
|
16
17
|
};
|
|
17
18
|
const url = buildUrl(this.baseUrl, '/moderations');
|
|
18
19
|
logger.logRequest("OpenAI", "POST", url, body);
|
|
19
|
-
const response = await
|
|
20
|
+
const response = await fetchWithTimeout(url, {
|
|
20
21
|
method: "POST",
|
|
21
22
|
headers: {
|
|
22
23
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
23
24
|
"Content-Type": "application/json",
|
|
24
25
|
},
|
|
25
26
|
body: JSON.stringify(body),
|
|
26
|
-
});
|
|
27
|
+
}, request.requestTimeout);
|
|
27
28
|
if (!response.ok) {
|
|
28
29
|
await handleOpenAIError(response, request.model || DEFAULT_MODELS.MODERATION);
|
|
29
30
|
}
|
|
@@ -31,6 +31,7 @@ export declare class OpenAIProvider extends BaseProvider implements Provider {
|
|
|
31
31
|
supportsTranscription: (model: string) => boolean;
|
|
32
32
|
supportsModeration: (model: string) => boolean;
|
|
33
33
|
supportsReasoning: (model: string) => boolean;
|
|
34
|
+
supportsDeveloperRole: (modelId: string) => boolean;
|
|
34
35
|
getContextWindow: (model: string) => number | null;
|
|
35
36
|
};
|
|
36
37
|
constructor(options: OpenAIProviderOptions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAIProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/OpenAIProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAA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,GAAG,OAAO,CAAC,YAAY,CAAC;IAIhD,MAAM,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CAAC,SAAS,CAAC;IAIxD,UAAU,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAIlC,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAIpD,UAAU,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAIzE,QAAQ,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAIjE,KAAK,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAGnE"}
|
|
@@ -26,14 +26,15 @@ export class OpenAIProvider extends BaseProvider {
|
|
|
26
26
|
supportsTranscription: (model) => Capabilities.supportsTranscription(model),
|
|
27
27
|
supportsModeration: (model) => Capabilities.supportsModeration(model),
|
|
28
28
|
supportsReasoning: (model) => Capabilities.supportsReasoning(model),
|
|
29
|
+
supportsDeveloperRole: (modelId) => this.baseUrl.includes("api.openai.com") && Capabilities.supportsDeveloperRole(modelId),
|
|
29
30
|
getContextWindow: (model) => Capabilities.getContextWindow(model) || null,
|
|
30
31
|
};
|
|
31
32
|
constructor(options) {
|
|
32
33
|
super();
|
|
33
34
|
this.options = options;
|
|
34
35
|
this.baseUrl = options.baseUrl ?? "https://api.openai.com/v1";
|
|
35
|
-
this.chatHandler = new OpenAIChat(this
|
|
36
|
-
this.streamingHandler = new OpenAIStreaming(this
|
|
36
|
+
this.chatHandler = new OpenAIChat(this, options.apiKey);
|
|
37
|
+
this.streamingHandler = new OpenAIStreaming(this, options.apiKey);
|
|
37
38
|
this.modelsHandler = new OpenAIModels(this.baseUrl, options.apiKey);
|
|
38
39
|
this.imageHandler = new OpenAIImage(this.baseUrl, options.apiKey);
|
|
39
40
|
this.transcriptionHandler = new OpenAITranscription(this.baseUrl, options.apiKey);
|