@node-llm/core 0.6.0 → 0.8.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 +89 -458
- package/dist/chat/Chat.d.ts.map +1 -1
- package/dist/chat/Chat.js +5 -3
- package/dist/chat/ChatResponse.d.ts +2 -1
- package/dist/chat/ChatResponse.d.ts.map +1 -1
- package/dist/chat/ChatResponse.js +3 -1
- package/dist/chat/Stream.d.ts.map +1 -1
- package/dist/chat/Stream.js +7 -1
- package/dist/config.d.ts +31 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +12 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/llm.d.ts +16 -9
- package/dist/llm.d.ts.map +1 -1
- package/dist/llm.js +41 -20
- package/dist/models/ModelRegistry.d.ts +0 -3
- package/dist/models/ModelRegistry.d.ts.map +1 -1
- package/dist/models/ModelRegistry.js +0 -3
- package/dist/models/models.d.ts.map +1 -1
- package/dist/models/models.js +386 -0
- package/dist/models/types.d.ts +2 -2
- package/dist/models/types.d.ts.map +1 -1
- package/dist/providers/Provider.d.ts +3 -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/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.map +1 -1
- 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/index.d.ts.map +1 -1
- package/dist/providers/gemini/index.js +3 -2
- package/dist/providers/ollama/Capabilities.d.ts +13 -0
- package/dist/providers/ollama/Capabilities.d.ts.map +1 -0
- package/dist/providers/ollama/Capabilities.js +50 -0
- package/dist/providers/ollama/Embedding.d.ts +6 -0
- package/dist/providers/ollama/Embedding.d.ts.map +1 -0
- package/dist/providers/ollama/Embedding.js +12 -0
- package/dist/providers/ollama/Models.d.ts +8 -0
- package/dist/providers/ollama/Models.d.ts.map +1 -0
- package/dist/providers/ollama/Models.js +31 -0
- package/dist/providers/ollama/OllamaProvider.d.ts +8 -0
- package/dist/providers/ollama/OllamaProvider.d.ts.map +1 -0
- package/dist/providers/ollama/OllamaProvider.js +28 -0
- package/dist/providers/ollama/index.d.ts +9 -0
- package/dist/providers/ollama/index.d.ts.map +1 -0
- package/dist/providers/ollama/index.js +17 -0
- 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 +10 -2
- package/dist/providers/openai/Embedding.d.ts +4 -2
- package/dist/providers/openai/Embedding.d.ts.map +1 -1
- package/dist/providers/openai/Embedding.js +13 -8
- package/dist/providers/openai/Models.d.ts +12 -2
- package/dist/providers/openai/Models.d.ts.map +1 -1
- package/dist/providers/openai/Models.js +50 -16
- package/dist/providers/openai/OpenAIProvider.d.ts +17 -9
- package/dist/providers/openai/OpenAIProvider.d.ts.map +1 -1
- package/dist/providers/openai/OpenAIProvider.js +2 -1
- package/dist/providers/openai/index.d.ts.map +1 -1
- package/dist/providers/openai/index.js +4 -3
- package/package.json +1 -1
|
@@ -9,7 +9,8 @@ export declare class Capabilities {
|
|
|
9
9
|
static supportsImageGeneration(modelId: string): boolean;
|
|
10
10
|
static supportsTranscription(modelId: string): boolean;
|
|
11
11
|
static supportsModeration(modelId: string): boolean;
|
|
12
|
-
static
|
|
12
|
+
static supportsReasoning(modelId: string): boolean;
|
|
13
|
+
static getModelType(modelId: string): "embeddings" | "audio" | "moderation" | "image" | "chat" | "audio_transcription" | "audio_speech";
|
|
13
14
|
static getModalities(modelId: string): {
|
|
14
15
|
input: string[];
|
|
15
16
|
output: 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,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAO9C,MAAM,CAAC,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAOzD,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIjD,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAOnD,MAAM,CAAC,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AAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE;IAiB5E,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAoBjD,MAAM,CAAC,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI;IAMxG,MAAM,CAAC,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAOjD,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG;CAcxC"}
|
|
@@ -30,7 +30,7 @@ export class Capabilities {
|
|
|
30
30
|
}
|
|
31
31
|
static supportsTools(modelId) {
|
|
32
32
|
const model = ModelRegistry.find(modelId, "openai");
|
|
33
|
-
if (model?.capabilities?.includes("function_calling"))
|
|
33
|
+
if (model?.capabilities?.includes("function_calling") || model?.capabilities?.includes("tools"))
|
|
34
34
|
return true;
|
|
35
35
|
return !/embedding|moderation|dall-e|tts|whisper/.test(modelId);
|
|
36
36
|
}
|
|
@@ -67,11 +67,19 @@ export class Capabilities {
|
|
|
67
67
|
return true;
|
|
68
68
|
return /moderation/.test(modelId);
|
|
69
69
|
}
|
|
70
|
+
static supportsReasoning(modelId) {
|
|
71
|
+
const model = ModelRegistry.find(modelId, "openai");
|
|
72
|
+
if (model?.capabilities?.includes("reasoning"))
|
|
73
|
+
return true;
|
|
74
|
+
return /o\d|gpt-5/.test(modelId);
|
|
75
|
+
}
|
|
70
76
|
static getModelType(modelId) {
|
|
77
|
+
if (this.supportsEmbeddings(modelId))
|
|
78
|
+
return "embeddings";
|
|
71
79
|
if (/moderation/.test(modelId))
|
|
72
80
|
return "moderation";
|
|
73
81
|
if (/embedding/.test(modelId))
|
|
74
|
-
return "
|
|
82
|
+
return "embeddings";
|
|
75
83
|
if (/dall-e|image/.test(modelId))
|
|
76
84
|
return "image";
|
|
77
85
|
if (/whisper|transcribe/.test(modelId))
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { EmbeddingRequest, EmbeddingResponse } from "../Embedding.js";
|
|
2
2
|
export declare class OpenAIEmbedding {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
protected readonly baseUrl: string;
|
|
4
|
+
protected readonly apiKey: string;
|
|
5
5
|
constructor(baseUrl: string, apiKey: string);
|
|
6
|
+
protected getProviderName(): string;
|
|
7
|
+
protected validateModel(model: string): void;
|
|
6
8
|
execute(request: EmbeddingRequest): Promise<EmbeddingResponse>;
|
|
7
9
|
}
|
|
8
10
|
//# sourceMappingURL=Embedding.d.ts.map
|
|
@@ -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,iBAAiB,CAAC;AAMtE,qBAAa,eAAe;IAExB,
|
|
1
|
+
{"version":3,"file":"Embedding.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Embedding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAMtE,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;CA2CrE"}
|
|
@@ -9,12 +9,17 @@ export class OpenAIEmbedding {
|
|
|
9
9
|
this.baseUrl = baseUrl;
|
|
10
10
|
this.apiKey = apiKey;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
getProviderName() {
|
|
13
|
+
return "openai";
|
|
14
|
+
}
|
|
15
|
+
validateModel(model) {
|
|
16
|
+
if (Capabilities.getModelType(model) !== "embeddings") {
|
|
16
17
|
throw new Error(`Model ${model} does not support embeddings.`);
|
|
17
18
|
}
|
|
19
|
+
}
|
|
20
|
+
async execute(request) {
|
|
21
|
+
const model = request.model || DEFAULT_MODELS.EMBEDDING;
|
|
22
|
+
this.validateModel(model);
|
|
18
23
|
const body = {
|
|
19
24
|
input: request.input,
|
|
20
25
|
model,
|
|
@@ -36,13 +41,13 @@ export class OpenAIEmbedding {
|
|
|
36
41
|
if (!response.ok) {
|
|
37
42
|
await handleOpenAIError(response, request.model || DEFAULT_MODELS.EMBEDDING);
|
|
38
43
|
}
|
|
39
|
-
const
|
|
44
|
+
const { data, model: responseModel, usage } = await response.json();
|
|
40
45
|
// Extract vectors from the response
|
|
41
|
-
const vectors =
|
|
46
|
+
const vectors = data.map((item) => item.embedding);
|
|
42
47
|
return {
|
|
43
48
|
vectors,
|
|
44
|
-
model:
|
|
45
|
-
input_tokens:
|
|
49
|
+
model: responseModel,
|
|
50
|
+
input_tokens: usage.prompt_tokens,
|
|
46
51
|
dimensions: vectors[0]?.length || 0,
|
|
47
52
|
};
|
|
48
53
|
}
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { ModelInfo } from "../Provider.js";
|
|
2
2
|
export declare class OpenAIModels {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
protected readonly baseUrl: string;
|
|
4
|
+
protected readonly apiKey: string;
|
|
5
5
|
constructor(baseUrl: string, apiKey: string);
|
|
6
|
+
protected getProviderName(): string;
|
|
7
|
+
protected formatDisplayName(modelId: string): string;
|
|
8
|
+
protected getContextWindow(modelId: string): number | null;
|
|
9
|
+
protected getMaxOutputTokens(modelId: string): number | null;
|
|
10
|
+
protected getModalities(modelId: string): {
|
|
11
|
+
input: string[];
|
|
12
|
+
output: string[];
|
|
13
|
+
};
|
|
14
|
+
protected getCapabilities(modelId: string): string[];
|
|
15
|
+
protected getPricing(modelId: string): any;
|
|
6
16
|
execute(): Promise<ModelInfo[]>;
|
|
7
17
|
find(modelId: string): import("../../models/types.js").Model | undefined;
|
|
8
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Models.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Models.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/Models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAK3C,qBAAa,YAAY;IAErB,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,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAMpD,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAI1D,SAAS,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAI5D,SAAS,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM;;;;IAKvC,SAAS,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAKpD,SAAS,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM;IAK9B,OAAO,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAwDrC,IAAI,CAAC,OAAO,EAAE,MAAM;CAGrB"}
|
|
@@ -8,7 +8,35 @@ export class OpenAIModels {
|
|
|
8
8
|
this.baseUrl = baseUrl;
|
|
9
9
|
this.apiKey = apiKey;
|
|
10
10
|
}
|
|
11
|
+
getProviderName() {
|
|
12
|
+
return "openai";
|
|
13
|
+
}
|
|
14
|
+
formatDisplayName(modelId) {
|
|
15
|
+
const model = ModelRegistry.find(modelId, this.getProviderName());
|
|
16
|
+
if (model?.name && model.name !== modelId)
|
|
17
|
+
return model.name;
|
|
18
|
+
return Capabilities.formatDisplayName(modelId);
|
|
19
|
+
}
|
|
20
|
+
getContextWindow(modelId) {
|
|
21
|
+
return ModelRegistry.getContextWindow(modelId, this.getProviderName()) || Capabilities.getContextWindow(modelId) || null;
|
|
22
|
+
}
|
|
23
|
+
getMaxOutputTokens(modelId) {
|
|
24
|
+
return ModelRegistry.getMaxOutputTokens(modelId, this.getProviderName()) || Capabilities.getMaxOutputTokens(modelId) || null;
|
|
25
|
+
}
|
|
26
|
+
getModalities(modelId) {
|
|
27
|
+
const model = ModelRegistry.find(modelId, this.getProviderName());
|
|
28
|
+
return model?.modalities || Capabilities.getModalities(modelId);
|
|
29
|
+
}
|
|
30
|
+
getCapabilities(modelId) {
|
|
31
|
+
const model = ModelRegistry.find(modelId, this.getProviderName());
|
|
32
|
+
return model?.capabilities || Capabilities.getCapabilities(modelId);
|
|
33
|
+
}
|
|
34
|
+
getPricing(modelId) {
|
|
35
|
+
const model = ModelRegistry.find(modelId, this.getProviderName());
|
|
36
|
+
return model?.pricing || Capabilities.getPricing(modelId);
|
|
37
|
+
}
|
|
11
38
|
async execute() {
|
|
39
|
+
const provider = this.getProviderName();
|
|
12
40
|
try {
|
|
13
41
|
const response = await fetch(buildUrl(this.baseUrl, '/models'), {
|
|
14
42
|
method: "GET",
|
|
@@ -21,39 +49,45 @@ export class OpenAIModels {
|
|
|
21
49
|
const { data } = await response.json();
|
|
22
50
|
return data.map(m => {
|
|
23
51
|
const modelId = m.id;
|
|
24
|
-
const registryModel = ModelRegistry.find(modelId,
|
|
25
|
-
|
|
52
|
+
const registryModel = ModelRegistry.find(modelId, provider);
|
|
53
|
+
return {
|
|
26
54
|
id: modelId,
|
|
27
|
-
name:
|
|
28
|
-
provider:
|
|
55
|
+
name: this.formatDisplayName(modelId),
|
|
56
|
+
provider: provider,
|
|
29
57
|
family: registryModel?.family || modelId,
|
|
30
|
-
context_window:
|
|
31
|
-
max_output_tokens:
|
|
32
|
-
modalities:
|
|
33
|
-
capabilities:
|
|
34
|
-
pricing:
|
|
58
|
+
context_window: this.getContextWindow(modelId),
|
|
59
|
+
max_output_tokens: this.getMaxOutputTokens(modelId),
|
|
60
|
+
modalities: this.getModalities(modelId),
|
|
61
|
+
capabilities: this.getCapabilities(modelId),
|
|
62
|
+
pricing: this.getPricing(modelId),
|
|
35
63
|
metadata: {
|
|
36
64
|
...(registryModel?.metadata || {}),
|
|
37
65
|
created: m.created,
|
|
38
66
|
owned_by: m.owned_by
|
|
39
67
|
}
|
|
40
68
|
};
|
|
41
|
-
return info;
|
|
42
69
|
});
|
|
43
70
|
}
|
|
44
71
|
}
|
|
45
72
|
catch (_error) {
|
|
46
|
-
// Fallback to registry if API call fails
|
|
73
|
+
// Fallback to registry if API call fails
|
|
47
74
|
}
|
|
48
75
|
// Fallback to registry data
|
|
49
76
|
return ModelRegistry.all()
|
|
50
|
-
.filter(m => m.provider ===
|
|
51
|
-
.map(m => ({
|
|
52
|
-
|
|
53
|
-
|
|
77
|
+
.filter((m) => m.provider === provider)
|
|
78
|
+
.map((m) => ({
|
|
79
|
+
id: m.id,
|
|
80
|
+
name: m.name,
|
|
81
|
+
family: m.family || m.id,
|
|
82
|
+
provider: provider,
|
|
83
|
+
context_window: m.context_window ?? null,
|
|
84
|
+
capabilities: m.capabilities,
|
|
85
|
+
modalities: m.modalities,
|
|
86
|
+
max_output_tokens: m.max_output_tokens ?? null,
|
|
87
|
+
pricing: m.pricing || {}
|
|
54
88
|
}));
|
|
55
89
|
}
|
|
56
90
|
find(modelId) {
|
|
57
|
-
return ModelRegistry.find(modelId,
|
|
91
|
+
return ModelRegistry.find(modelId, this.getProviderName());
|
|
58
92
|
}
|
|
59
93
|
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { Provider, ChatRequest, ChatResponse, ModelInfo, ChatChunk, ImageRequest, ImageResponse, ModerationRequest, ModerationResponse } from "../Provider.js";
|
|
2
|
+
import { OpenAIChat } from "./Chat.js";
|
|
3
|
+
import { OpenAIStreaming } from "./Streaming.js";
|
|
4
|
+
import { OpenAIModels } from "./Models.js";
|
|
5
|
+
import { OpenAIImage } from "./Image.js";
|
|
6
|
+
import { OpenAITranscription } from "./Transcription.js";
|
|
7
|
+
import { OpenAIModeration } from "./Moderation.js";
|
|
8
|
+
import { OpenAIEmbedding } from "./Embedding.js";
|
|
2
9
|
import { TranscriptionRequest, TranscriptionResponse } from "../Provider.js";
|
|
3
10
|
import { EmbeddingRequest, EmbeddingResponse } from "../Embedding.js";
|
|
4
11
|
export interface OpenAIProviderOptions {
|
|
@@ -6,15 +13,15 @@ export interface OpenAIProviderOptions {
|
|
|
6
13
|
baseUrl?: string;
|
|
7
14
|
}
|
|
8
15
|
export declare class OpenAIProvider implements Provider {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
protected readonly options: OpenAIProviderOptions;
|
|
17
|
+
protected baseUrl: string;
|
|
18
|
+
protected chatHandler: OpenAIChat;
|
|
19
|
+
protected streamingHandler: OpenAIStreaming;
|
|
20
|
+
protected modelsHandler: OpenAIModels;
|
|
21
|
+
protected imageHandler: OpenAIImage;
|
|
22
|
+
protected transcriptionHandler: OpenAITranscription;
|
|
23
|
+
protected moderationHandler: OpenAIModeration;
|
|
24
|
+
protected embeddingHandler: OpenAIEmbedding;
|
|
18
25
|
capabilities: {
|
|
19
26
|
supportsVision: (model: string) => boolean;
|
|
20
27
|
supportsTools: (model: string) => boolean;
|
|
@@ -23,6 +30,7 @@ export declare class OpenAIProvider implements Provider {
|
|
|
23
30
|
supportsImageGeneration: (model: string) => boolean;
|
|
24
31
|
supportsTranscription: (model: string) => boolean;
|
|
25
32
|
supportsModeration: (model: string) => boolean;
|
|
33
|
+
supportsReasoning: (model: string) => boolean;
|
|
26
34
|
getContextWindow: (model: string) => number | null;
|
|
27
35
|
};
|
|
28
36
|
constructor(options: OpenAIProviderOptions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenAIProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/OpenAIProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"OpenAIProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/OpenAIProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAE/J,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,i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 export class OpenAIProvider {
|
|
|
24
24
|
supportsImageGeneration: (model) => Capabilities.supportsImageGeneration(model),
|
|
25
25
|
supportsTranscription: (model) => Capabilities.supportsTranscription(model),
|
|
26
26
|
supportsModeration: (model) => Capabilities.supportsModeration(model),
|
|
27
|
-
|
|
27
|
+
supportsReasoning: (model) => Capabilities.supportsReasoning(model),
|
|
28
|
+
getContextWindow: (model) => Capabilities.getContextWindow(model) || null,
|
|
28
29
|
};
|
|
29
30
|
constructor(options) {
|
|
30
31
|
this.options = options;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/openai/index.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,wBAAgB,sBAAsB,SAerC;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB,+BAAyB,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { config } from "../../config.js";
|
|
1
2
|
import { providerRegistry } from "../registry.js";
|
|
2
3
|
import { OpenAIProvider } from "./OpenAIProvider.js";
|
|
3
4
|
let registered = false;
|
|
@@ -9,10 +10,10 @@ export function registerOpenAIProvider() {
|
|
|
9
10
|
if (registered)
|
|
10
11
|
return;
|
|
11
12
|
providerRegistry.register("openai", () => {
|
|
12
|
-
const apiKey =
|
|
13
|
-
const baseUrl =
|
|
13
|
+
const apiKey = config.openaiApiKey;
|
|
14
|
+
const baseUrl = config.openaiApiBase;
|
|
14
15
|
if (!apiKey) {
|
|
15
|
-
throw new Error("
|
|
16
|
+
throw new Error("openaiApiKey is not set in config or OPENAI_API_KEY environment variable");
|
|
16
17
|
}
|
|
17
18
|
return new OpenAIProvider({ apiKey, baseUrl });
|
|
18
19
|
});
|