@node-llm/core 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -421
- package/dist/chat/Chat.d.ts +5 -0
- package/dist/chat/Chat.d.ts.map +1 -1
- package/dist/chat/Chat.js +31 -7
- package/dist/chat/ChatOptions.d.ts +3 -0
- package/dist/chat/ChatOptions.d.ts.map +1 -1
- package/dist/chat/ChatResponse.d.ts +5 -1
- package/dist/chat/ChatResponse.d.ts.map +1 -1
- package/dist/chat/ChatResponse.js +6 -1
- package/dist/chat/Stream.d.ts.map +1 -1
- package/dist/chat/Stream.js +7 -1
- package/dist/config.d.ts +29 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +11 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/llm.d.ts +20 -10
- package/dist/llm.d.ts.map +1 -1
- package/dist/llm.js +52 -23
- package/dist/models/ModelRegistry.d.ts +39 -12
- package/dist/models/ModelRegistry.d.ts.map +1 -1
- package/dist/models/ModelRegistry.js +50 -40
- package/dist/models/models.d.ts +972 -0
- package/dist/models/models.d.ts.map +1 -0
- package/dist/models/models.js +7076 -0
- package/dist/models/types.d.ts +50 -0
- package/dist/models/types.d.ts.map +1 -0
- package/dist/models/types.js +1 -0
- package/dist/providers/Provider.d.ts +7 -0
- package/dist/providers/Provider.d.ts.map +1 -1
- package/dist/providers/anthropic/AnthropicProvider.d.ts +1 -0
- package/dist/providers/anthropic/AnthropicProvider.d.ts.map +1 -1
- package/dist/providers/anthropic/AnthropicProvider.js +2 -3
- package/dist/providers/anthropic/Capabilities.d.ts +1 -37
- package/dist/providers/anthropic/Capabilities.d.ts.map +1 -1
- package/dist/providers/anthropic/Capabilities.js +59 -130
- package/dist/providers/anthropic/Chat.d.ts.map +1 -1
- package/dist/providers/anthropic/Chat.js +6 -2
- package/dist/providers/anthropic/Models.d.ts +1 -0
- package/dist/providers/anthropic/Models.d.ts.map +1 -1
- package/dist/providers/anthropic/Models.js +36 -41
- package/dist/providers/anthropic/Streaming.d.ts.map +1 -1
- package/dist/providers/anthropic/Streaming.js +10 -1
- package/dist/providers/anthropic/index.d.ts.map +1 -1
- package/dist/providers/anthropic/index.js +3 -2
- package/dist/providers/deepseek/Capabilities.d.ts +14 -0
- package/dist/providers/deepseek/Capabilities.d.ts.map +1 -0
- package/dist/providers/deepseek/Capabilities.js +52 -0
- package/dist/providers/deepseek/Chat.d.ts +8 -0
- package/dist/providers/deepseek/Chat.d.ts.map +1 -0
- package/dist/providers/deepseek/Chat.js +89 -0
- package/dist/providers/deepseek/DeepSeekProvider.d.ts +28 -0
- package/dist/providers/deepseek/DeepSeekProvider.d.ts.map +1 -0
- package/dist/providers/deepseek/DeepSeekProvider.js +38 -0
- package/dist/providers/deepseek/Models.d.ts +8 -0
- package/dist/providers/deepseek/Models.d.ts.map +1 -0
- package/dist/providers/deepseek/Models.js +67 -0
- package/dist/providers/deepseek/Streaming.d.ts +8 -0
- package/dist/providers/deepseek/Streaming.d.ts.map +1 -0
- package/dist/providers/deepseek/Streaming.js +74 -0
- package/dist/providers/deepseek/index.d.ts +7 -0
- package/dist/providers/deepseek/index.d.ts.map +1 -0
- package/dist/providers/deepseek/index.js +22 -0
- package/dist/providers/gemini/Capabilities.d.ts +28 -7
- package/dist/providers/gemini/Capabilities.d.ts.map +1 -1
- package/dist/providers/gemini/Capabilities.js +32 -20
- package/dist/providers/gemini/Chat.d.ts.map +1 -1
- package/dist/providers/gemini/Chat.js +9 -11
- package/dist/providers/gemini/GeminiProvider.d.ts +1 -0
- package/dist/providers/gemini/GeminiProvider.d.ts.map +1 -1
- package/dist/providers/gemini/GeminiProvider.js +1 -0
- package/dist/providers/gemini/Models.d.ts +1 -0
- package/dist/providers/gemini/Models.d.ts.map +1 -1
- package/dist/providers/gemini/Models.js +46 -26
- package/dist/providers/gemini/index.d.ts.map +1 -1
- package/dist/providers/gemini/index.js +3 -2
- package/dist/providers/openai/Capabilities.d.ts +4 -11
- package/dist/providers/openai/Capabilities.d.ts.map +1 -1
- package/dist/providers/openai/Capabilities.js +124 -121
- package/dist/providers/openai/Chat.d.ts.map +1 -1
- package/dist/providers/openai/Chat.js +19 -17
- package/dist/providers/openai/Embedding.d.ts.map +1 -1
- package/dist/providers/openai/Embedding.js +2 -1
- package/dist/providers/openai/Image.d.ts.map +1 -1
- package/dist/providers/openai/Image.js +2 -1
- package/dist/providers/openai/ModelDefinitions.d.ts +1 -24
- package/dist/providers/openai/ModelDefinitions.d.ts.map +1 -1
- package/dist/providers/openai/ModelDefinitions.js +1 -211
- package/dist/providers/openai/Models.d.ts +1 -0
- package/dist/providers/openai/Models.d.ts.map +1 -1
- package/dist/providers/openai/Models.js +46 -22
- package/dist/providers/openai/Moderation.d.ts.map +1 -1
- package/dist/providers/openai/Moderation.js +2 -1
- package/dist/providers/openai/OpenAIProvider.d.ts +1 -0
- package/dist/providers/openai/OpenAIProvider.d.ts.map +1 -1
- package/dist/providers/openai/OpenAIProvider.js +1 -0
- package/dist/providers/openai/Streaming.d.ts.map +1 -1
- package/dist/providers/openai/Streaming.js +5 -1
- package/dist/providers/openai/Transcription.d.ts.map +1 -1
- package/dist/providers/openai/Transcription.js +3 -2
- package/dist/providers/openai/index.d.ts.map +1 -1
- package/dist/providers/openai/index.js +5 -3
- package/dist/providers/openai/utils.d.ts +20 -0
- package/dist/providers/openai/utils.d.ts.map +1 -0
- package/dist/providers/openai/utils.js +25 -0
- package/package.json +1 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export interface Model {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
provider: 'openai' | 'anthropic' | 'gemini' | 'deepseek';
|
|
5
|
+
family?: string | null;
|
|
6
|
+
created_at?: string | null;
|
|
7
|
+
context_window?: number | null;
|
|
8
|
+
max_output_tokens?: number | null;
|
|
9
|
+
knowledge_cutoff?: string | null;
|
|
10
|
+
modalities: {
|
|
11
|
+
input: string[];
|
|
12
|
+
output: string[];
|
|
13
|
+
};
|
|
14
|
+
capabilities: string[];
|
|
15
|
+
pricing?: {
|
|
16
|
+
text_tokens?: {
|
|
17
|
+
standard?: {
|
|
18
|
+
input_per_million?: number;
|
|
19
|
+
cached_input_per_million?: number;
|
|
20
|
+
output_per_million?: number;
|
|
21
|
+
reasoning_output_per_million?: number;
|
|
22
|
+
};
|
|
23
|
+
batch?: {
|
|
24
|
+
input_per_million?: number;
|
|
25
|
+
output_per_million?: number;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
images?: {
|
|
29
|
+
standard?: {
|
|
30
|
+
input?: number;
|
|
31
|
+
output?: number;
|
|
32
|
+
};
|
|
33
|
+
batch?: {
|
|
34
|
+
input?: number;
|
|
35
|
+
output?: number;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
audio_tokens?: {
|
|
39
|
+
standard?: {
|
|
40
|
+
input_per_million?: number;
|
|
41
|
+
output_per_million?: number;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
metadata?: Record<string, any>;
|
|
46
|
+
}
|
|
47
|
+
export type ProviderName = 'openai' | 'anthropic' | 'gemini' | 'deepseek';
|
|
48
|
+
export type ModelCapability = 'streaming' | 'function_calling' | 'structured_output' | 'predicted_outputs' | 'distillation' | 'fine_tuning' | 'batch' | 'realtime' | 'image_generation' | 'speech_generation' | 'transcription' | 'translation' | 'citations' | 'reasoning' | 'caching' | 'moderation' | 'json_mode' | 'vision';
|
|
49
|
+
export type ModelModality = 'text' | 'image' | 'audio' | 'pdf' | 'video' | 'file' | 'embeddings' | 'moderation';
|
|
50
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/models/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,IA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;SACH,CAAC;KACH,CAAC;IACF,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAED,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,GAAG,UAAU,CAAC;AAE1E,MAAM,MAAM,eAAe,GACvB,WAAW,GACX,kBAAkB,GAClB,mBAAmB,GACnB,mBAAmB,GACnB,cAAc,GACd,aAAa,GACb,OAAO,GACP,UAAU,GACV,kBAAkB,GAClB,mBAAmB,GACnB,eAAe,GACf,aAAa,GACb,WAAW,GACX,WAAW,GACX,SAAS,GACT,YAAY,GACZ,WAAW,GACX,QAAQ,CAAC;AAEb,MAAM,MAAM,aAAa,GACrB,MAAM,GACN,OAAO,GACP,OAAO,GACP,KAAK,GACL,OAAO,GACP,MAAM,GACN,YAAY,GACZ,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -9,9 +9,11 @@ export interface ChatRequest {
|
|
|
9
9
|
max_tokens?: number;
|
|
10
10
|
response_format?: any;
|
|
11
11
|
headers?: Record<string, string>;
|
|
12
|
+
[key: string]: any;
|
|
12
13
|
}
|
|
13
14
|
export interface ChatChunk {
|
|
14
15
|
content: string;
|
|
16
|
+
reasoning?: string;
|
|
15
17
|
done?: boolean;
|
|
16
18
|
}
|
|
17
19
|
export interface Usage {
|
|
@@ -20,9 +22,13 @@ export interface Usage {
|
|
|
20
22
|
total_tokens: number;
|
|
21
23
|
cached_tokens?: number;
|
|
22
24
|
cache_creation_tokens?: number;
|
|
25
|
+
cost?: number;
|
|
26
|
+
input_cost?: number;
|
|
27
|
+
output_cost?: number;
|
|
23
28
|
}
|
|
24
29
|
export interface ChatResponse {
|
|
25
30
|
content: string | null;
|
|
31
|
+
reasoning?: string | null;
|
|
26
32
|
tool_calls?: ToolCall[];
|
|
27
33
|
usage?: Usage;
|
|
28
34
|
}
|
|
@@ -34,6 +40,7 @@ export interface ProviderCapabilities {
|
|
|
34
40
|
supportsImageGeneration(modelId: string): boolean;
|
|
35
41
|
supportsTranscription(modelId: string): boolean;
|
|
36
42
|
supportsModeration(modelId: string): boolean;
|
|
43
|
+
supportsReasoning(modelId: string): boolean;
|
|
37
44
|
getContextWindow(modelId: string): number | null;
|
|
38
45
|
}
|
|
39
46
|
export interface ModelInfo {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../src/providers/Provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAErE,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,GAAG,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../src/providers/Provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAErE,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;IACf,WAAW,CAAC,EAA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qBAAqB,CAAC,CAAC;IAC3E,QAAQ,CAAC,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACnE,KAAK,CAAC,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC9D,YAAY,CAAC,EAAE,oBAAoB,CAAC;CACrC"}
|
|
@@ -18,6 +18,7 @@ export declare class AnthropicProvider implements Provider {
|
|
|
18
18
|
supportsImageGeneration: (_model: string) => boolean;
|
|
19
19
|
supportsTranscription: (_model: string) => boolean;
|
|
20
20
|
supportsModeration: (_model: string) => boolean;
|
|
21
|
+
supportsReasoning: (_model: string) => boolean;
|
|
21
22
|
getContextWindow: (model: string) => number | null;
|
|
22
23
|
};
|
|
23
24
|
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,EAAE,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC5M,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAMtE,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,iBAAkB,YAAW,QAAQ;IAkBpC,OAAO,CAAC,QAAQ,CAAC,OAAO;IAjBpC,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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AAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAIlE,KAAK,CAAC,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAGpE"}
|
|
@@ -8,15 +8,15 @@ export class AnthropicProvider {
|
|
|
8
8
|
chatHandler;
|
|
9
9
|
streamHandler;
|
|
10
10
|
modelsHandler;
|
|
11
|
-
// Capabilities Interface Implementation
|
|
12
11
|
capabilities = {
|
|
13
12
|
supportsVision: (model) => Capabilities.supportsVision(model),
|
|
14
13
|
supportsTools: (model) => Capabilities.supportsTools(model),
|
|
15
|
-
supportsStructuredOutput: (model) => Capabilities.supportsJsonMode(model),
|
|
14
|
+
supportsStructuredOutput: (model) => Capabilities.supportsJsonMode(model),
|
|
16
15
|
supportsEmbeddings: (_model) => false,
|
|
17
16
|
supportsImageGeneration: (_model) => false,
|
|
18
17
|
supportsTranscription: (_model) => false,
|
|
19
18
|
supportsModeration: (_model) => false,
|
|
19
|
+
supportsReasoning: (_model) => false,
|
|
20
20
|
getContextWindow: (model) => Capabilities.getContextWindow(model),
|
|
21
21
|
};
|
|
22
22
|
constructor(options) {
|
|
@@ -35,7 +35,6 @@ export class AnthropicProvider {
|
|
|
35
35
|
async listModels() {
|
|
36
36
|
return this.modelsHandler.execute();
|
|
37
37
|
}
|
|
38
|
-
// Unsupported methods
|
|
39
38
|
async paint(_request) {
|
|
40
39
|
throw new Error("Anthropic doesn't support image generation");
|
|
41
40
|
}
|
|
@@ -1,47 +1,11 @@
|
|
|
1
|
-
export interface ModelPricing {
|
|
2
|
-
input?: number;
|
|
3
|
-
output?: number;
|
|
4
|
-
cache_write?: number;
|
|
5
|
-
cache_read?: number;
|
|
6
|
-
}
|
|
7
|
-
export interface ModelFeatures {
|
|
8
|
-
vision?: boolean;
|
|
9
|
-
tools?: boolean;
|
|
10
|
-
jsonMode?: boolean;
|
|
11
|
-
reasoning?: boolean;
|
|
12
|
-
citations?: boolean;
|
|
13
|
-
}
|
|
14
|
-
export type ModelType = "chat";
|
|
15
|
-
export interface ModelFamilyDefinition {
|
|
16
|
-
pattern: RegExp;
|
|
17
|
-
contextWindow: number;
|
|
18
|
-
maxOutputTokens: number;
|
|
19
|
-
pricing: ModelPricing;
|
|
20
|
-
features: ModelFeatures;
|
|
21
|
-
type: ModelType;
|
|
22
|
-
}
|
|
23
|
-
export declare const ANTHROPIC_MODELS: Record<string, ModelFamilyDefinition>;
|
|
24
1
|
export declare class Capabilities {
|
|
25
|
-
static getFamily(modelId: string): string;
|
|
26
|
-
static getDefinition(modelId: string): ModelFamilyDefinition;
|
|
27
2
|
static getContextWindow(modelId: string): number | null;
|
|
28
3
|
static getMaxOutputTokens(modelId: string): number | null;
|
|
29
4
|
static supportsVision(modelId: string): boolean;
|
|
30
5
|
static supportsTools(modelId: string): boolean;
|
|
31
6
|
static supportsJsonMode(modelId: string): boolean;
|
|
32
7
|
static supportsExtendedThinking(modelId: string): boolean;
|
|
33
|
-
static getInputPrice(modelId: string): number;
|
|
34
|
-
static getOutputPrice(modelId: string): number;
|
|
35
|
-
static getModalities(modelId: string): {
|
|
36
|
-
input: string[];
|
|
37
|
-
output: string[];
|
|
38
|
-
};
|
|
39
8
|
static getCapabilities(modelId: string): string[];
|
|
40
|
-
static getPricing(modelId: string):
|
|
41
|
-
text_tokens: {
|
|
42
|
-
standard: any;
|
|
43
|
-
batch: any;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
9
|
+
static getPricing(modelId: string): any;
|
|
46
10
|
}
|
|
47
11
|
//# sourceMappingURL=Capabilities.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Capabilities.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/Capabilities.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Capabilities.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/Capabilities.ts"],"names":[],"mappings":"AAEA,qBAAa,YAAY;IACvB,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAKvD,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAKzD,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAO/C,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAO9C,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAOjD,MAAM,CAAC,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAOzD,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAsBjD,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG;CAsBxC"}
|
|
@@ -1,152 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
claude3_7_sonnet: {
|
|
3
|
-
pattern: /claude-3-7-sonnet/,
|
|
4
|
-
contextWindow: 200_000,
|
|
5
|
-
maxOutputTokens: 8_192,
|
|
6
|
-
pricing: { input: 3.0, output: 15.0 },
|
|
7
|
-
features: { vision: true, tools: true, jsonMode: true, reasoning: true, citations: true },
|
|
8
|
-
type: "chat"
|
|
9
|
-
},
|
|
10
|
-
claude3_5_sonnet: {
|
|
11
|
-
pattern: /claude-3-5-sonnet/,
|
|
12
|
-
contextWindow: 200_000,
|
|
13
|
-
maxOutputTokens: 8_192,
|
|
14
|
-
pricing: { input: 3.0, output: 15.0 },
|
|
15
|
-
features: { vision: true, tools: true, jsonMode: true, citations: true },
|
|
16
|
-
type: "chat"
|
|
17
|
-
},
|
|
18
|
-
claude3_5_haiku: {
|
|
19
|
-
pattern: /claude-3-5-haiku/,
|
|
20
|
-
contextWindow: 200_000,
|
|
21
|
-
maxOutputTokens: 8_192,
|
|
22
|
-
pricing: { input: 0.80, output: 4.0 },
|
|
23
|
-
features: { vision: true, tools: true, jsonMode: true },
|
|
24
|
-
type: "chat"
|
|
25
|
-
},
|
|
26
|
-
claude3_opus: {
|
|
27
|
-
pattern: /claude-3-opus/,
|
|
28
|
-
contextWindow: 200_000,
|
|
29
|
-
maxOutputTokens: 4_096,
|
|
30
|
-
pricing: { input: 15.0, output: 75.0 },
|
|
31
|
-
features: { vision: true, tools: true, jsonMode: true },
|
|
32
|
-
type: "chat"
|
|
33
|
-
},
|
|
34
|
-
claude3_sonnet: {
|
|
35
|
-
pattern: /claude-3-sonnet/,
|
|
36
|
-
contextWindow: 200_000,
|
|
37
|
-
maxOutputTokens: 4_096,
|
|
38
|
-
pricing: { input: 3.0, output: 15.0 },
|
|
39
|
-
features: { vision: true, tools: true, jsonMode: true },
|
|
40
|
-
type: "chat"
|
|
41
|
-
},
|
|
42
|
-
claude3_haiku: {
|
|
43
|
-
pattern: /claude-3-haiku/,
|
|
44
|
-
contextWindow: 200_000,
|
|
45
|
-
maxOutputTokens: 4_096,
|
|
46
|
-
pricing: { input: 0.25, output: 1.25 },
|
|
47
|
-
features: { vision: true, tools: true, jsonMode: true },
|
|
48
|
-
type: "chat"
|
|
49
|
-
},
|
|
50
|
-
claude2: {
|
|
51
|
-
pattern: /claude-[12]/,
|
|
52
|
-
contextWindow: 200_000,
|
|
53
|
-
maxOutputTokens: 4_096,
|
|
54
|
-
pricing: { input: 3.0, output: 15.0 },
|
|
55
|
-
features: { vision: false, tools: false, jsonMode: false },
|
|
56
|
-
type: "chat"
|
|
57
|
-
},
|
|
58
|
-
other: {
|
|
59
|
-
pattern: /.*/,
|
|
60
|
-
contextWindow: 200_000,
|
|
61
|
-
maxOutputTokens: 4_096,
|
|
62
|
-
pricing: { input: 3.0, output: 15.0 },
|
|
63
|
-
features: { vision: false, tools: false, jsonMode: false },
|
|
64
|
-
type: "chat"
|
|
65
|
-
}
|
|
66
|
-
};
|
|
1
|
+
import { ModelRegistry } from "../../models/ModelRegistry.js";
|
|
67
2
|
export class Capabilities {
|
|
68
|
-
static getFamily(modelId) {
|
|
69
|
-
for (const [key, def] of Object.entries(ANTHROPIC_MODELS)) {
|
|
70
|
-
if (key === "other")
|
|
71
|
-
continue;
|
|
72
|
-
if (def.pattern.test(modelId)) {
|
|
73
|
-
return key;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return "other";
|
|
77
|
-
}
|
|
78
|
-
static getDefinition(modelId) {
|
|
79
|
-
const family = this.getFamily(modelId);
|
|
80
|
-
return ANTHROPIC_MODELS[family];
|
|
81
|
-
}
|
|
82
3
|
static getContextWindow(modelId) {
|
|
83
|
-
|
|
4
|
+
const val = ModelRegistry.getContextWindow(modelId, "anthropic");
|
|
5
|
+
return val ?? 200_000;
|
|
84
6
|
}
|
|
85
7
|
static getMaxOutputTokens(modelId) {
|
|
86
|
-
|
|
8
|
+
const val = ModelRegistry.getMaxOutputTokens(modelId, "anthropic");
|
|
9
|
+
return val ?? 4_096;
|
|
87
10
|
}
|
|
88
11
|
static supportsVision(modelId) {
|
|
89
|
-
|
|
12
|
+
const model = ModelRegistry.find(modelId, "anthropic");
|
|
13
|
+
if (model?.modalities?.input?.includes("image"))
|
|
14
|
+
return true;
|
|
15
|
+
return /claude-3/.test(modelId);
|
|
90
16
|
}
|
|
91
17
|
static supportsTools(modelId) {
|
|
92
|
-
|
|
18
|
+
const model = ModelRegistry.find(modelId, "anthropic");
|
|
19
|
+
if (model?.capabilities?.includes("function_calling"))
|
|
20
|
+
return true;
|
|
21
|
+
return /claude-3/.test(modelId);
|
|
93
22
|
}
|
|
94
23
|
static supportsJsonMode(modelId) {
|
|
95
|
-
|
|
24
|
+
const model = ModelRegistry.find(modelId, "anthropic");
|
|
25
|
+
if (model?.capabilities.includes("json_mode"))
|
|
26
|
+
return true;
|
|
27
|
+
return this.supportsTools(modelId);
|
|
96
28
|
}
|
|
97
29
|
static supportsExtendedThinking(modelId) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return
|
|
102
|
-
}
|
|
103
|
-
static getOutputPrice(modelId) {
|
|
104
|
-
return this.getDefinition(modelId).pricing.output || 15.0;
|
|
105
|
-
}
|
|
106
|
-
static getModalities(modelId) {
|
|
107
|
-
const modalities = {
|
|
108
|
-
input: ["text"],
|
|
109
|
-
output: ["text"]
|
|
110
|
-
};
|
|
111
|
-
if (this.supportsVision(modelId)) {
|
|
112
|
-
modalities.input.push("image", "pdf");
|
|
113
|
-
}
|
|
114
|
-
return modalities;
|
|
30
|
+
const model = ModelRegistry.find(modelId, "anthropic");
|
|
31
|
+
if (model?.capabilities.includes("reasoning"))
|
|
32
|
+
return true;
|
|
33
|
+
return /claude-3-7/.test(modelId) || /thinking/.test(modelId);
|
|
115
34
|
}
|
|
116
35
|
static getCapabilities(modelId) {
|
|
117
|
-
const
|
|
118
|
-
const
|
|
119
|
-
if (
|
|
120
|
-
capabilities.
|
|
121
|
-
|
|
36
|
+
const caps = ["streaming"];
|
|
37
|
+
const model = ModelRegistry.find(modelId, "anthropic");
|
|
38
|
+
if (model) {
|
|
39
|
+
if (model.capabilities.includes("function_calling"))
|
|
40
|
+
caps.push("function_calling");
|
|
41
|
+
if (model.capabilities.includes("reasoning"))
|
|
42
|
+
caps.push("reasoning");
|
|
43
|
+
if (model.capabilities.includes("json_mode"))
|
|
44
|
+
caps.push("json_mode");
|
|
45
|
+
model.capabilities.forEach(c => {
|
|
46
|
+
if (!caps.includes(c))
|
|
47
|
+
caps.push(c);
|
|
48
|
+
});
|
|
49
|
+
return caps;
|
|
50
|
+
}
|
|
51
|
+
if (this.supportsTools(modelId))
|
|
52
|
+
caps.push("function_calling");
|
|
53
|
+
if (this.supportsExtendedThinking(modelId))
|
|
54
|
+
caps.push("reasoning");
|
|
55
|
+
if (this.supportsJsonMode(modelId))
|
|
56
|
+
caps.push("json_mode");
|
|
122
57
|
if (/claude-3/.test(modelId))
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
capabilities.push("reasoning");
|
|
126
|
-
if (def.features.citations)
|
|
127
|
-
capabilities.push("citations");
|
|
128
|
-
return capabilities;
|
|
58
|
+
caps.push("batch");
|
|
59
|
+
return caps;
|
|
129
60
|
}
|
|
130
61
|
static getPricing(modelId) {
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
output_per_million: outputCpm
|
|
137
|
-
};
|
|
138
|
-
const batchPricing = {
|
|
139
|
-
input_per_million: inputCpm * 0.5,
|
|
140
|
-
output_per_million: outputCpm * 0.5
|
|
141
|
-
};
|
|
142
|
-
if (this.supportsExtendedThinking(modelId)) {
|
|
143
|
-
standardPricing.reasoning_output_per_million = outputCpm * 2.5;
|
|
144
|
-
batchPricing.reasoning_output_per_million = outputCpm * 1.25;
|
|
145
|
-
}
|
|
62
|
+
const model = ModelRegistry.find(modelId, "anthropic");
|
|
63
|
+
if (model?.pricing)
|
|
64
|
+
return model.pricing;
|
|
65
|
+
const inputCpm = 3.0;
|
|
66
|
+
const outputCpm = 15.0;
|
|
146
67
|
return {
|
|
147
68
|
text_tokens: {
|
|
148
|
-
standard:
|
|
149
|
-
|
|
69
|
+
standard: {
|
|
70
|
+
input_per_million: inputCpm,
|
|
71
|
+
output_per_million: outputCpm,
|
|
72
|
+
...(this.supportsExtendedThinking(modelId) ? { reasoning_output_per_million: outputCpm * 2.5 } : {})
|
|
73
|
+
},
|
|
74
|
+
batch: {
|
|
75
|
+
input_per_million: inputCpm * 0.5,
|
|
76
|
+
output_per_million: outputCpm * 0.5,
|
|
77
|
+
...(this.supportsExtendedThinking(modelId) ? { reasoning_output_per_million: outputCpm * 1.25 } : {})
|
|
78
|
+
}
|
|
150
79
|
}
|
|
151
80
|
};
|
|
152
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,
|
|
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;AAUlE,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;CAwG3D"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Capabilities } from "./Capabilities.js";
|
|
2
2
|
import { handleAnthropicError } from "./Errors.js";
|
|
3
|
+
import { ModelRegistry } from "../../models/ModelRegistry.js";
|
|
3
4
|
import { formatSystemPrompt, formatMessages } from "./Utils.js";
|
|
4
5
|
export class AnthropicChat {
|
|
5
6
|
baseUrl;
|
|
@@ -22,12 +23,14 @@ export class AnthropicChat {
|
|
|
22
23
|
const instruction = `CRITICAL: Respond ONLY with a valid JSON object matching the requested schema.${schemaText}\n\nDo not include any other text or explanation.`;
|
|
23
24
|
system = system ? `${system}\n\n${instruction}` : instruction;
|
|
24
25
|
}
|
|
26
|
+
const { model: _model, messages: _messages, tools: _tools, temperature: _temp, max_tokens: _max, response_format: _format, headers: _headers, ...rest } = request;
|
|
25
27
|
const body = {
|
|
26
28
|
model: model,
|
|
27
29
|
messages: messages,
|
|
28
30
|
max_tokens: maxTokens,
|
|
29
31
|
system: system,
|
|
30
|
-
stream: false,
|
|
32
|
+
stream: false,
|
|
33
|
+
...rest,
|
|
31
34
|
};
|
|
32
35
|
if (request.temperature !== undefined) {
|
|
33
36
|
body.temperature = request.temperature;
|
|
@@ -88,6 +91,7 @@ export class AnthropicChat {
|
|
|
88
91
|
cached_tokens: json.usage.cache_read_input_tokens,
|
|
89
92
|
cache_creation_tokens: json.usage.cache_creation_input_tokens,
|
|
90
93
|
} : undefined;
|
|
91
|
-
|
|
94
|
+
const calculatedUsage = usage ? ModelRegistry.calculateCost(usage, model, "anthropic") : undefined;
|
|
95
|
+
return { content, usage: calculatedUsage, tool_calls: toolCalls.length > 0 ? toolCalls : undefined };
|
|
92
96
|
}
|
|
93
97
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Models.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/Models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"Models.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/Models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAK3C,qBAAa,eAAe;IACd,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEvE,OAAO,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAkDrC,IAAI,CAAC,OAAO,EAAE,MAAM;CAGrB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Capabilities
|
|
1
|
+
import { Capabilities } from "./Capabilities.js";
|
|
2
|
+
import { ModelRegistry } from "../../models/ModelRegistry.js";
|
|
2
3
|
export class AnthropicModels {
|
|
3
4
|
baseUrl;
|
|
4
5
|
apiKey;
|
|
@@ -16,48 +17,42 @@ export class AnthropicModels {
|
|
|
16
17
|
"content-type": "application/json",
|
|
17
18
|
},
|
|
18
19
|
});
|
|
19
|
-
if (
|
|
20
|
-
|
|
20
|
+
if (response.ok) {
|
|
21
|
+
const { data } = await response.json();
|
|
22
|
+
return data.map(m => {
|
|
23
|
+
const modelId = m.id;
|
|
24
|
+
const registryModel = ModelRegistry.find(modelId, "anthropic");
|
|
25
|
+
const info = {
|
|
26
|
+
id: modelId,
|
|
27
|
+
name: registryModel?.name || m.display_name || modelId,
|
|
28
|
+
provider: "anthropic",
|
|
29
|
+
family: registryModel?.family || modelId,
|
|
30
|
+
context_window: registryModel?.context_window || Capabilities.getContextWindow(modelId),
|
|
31
|
+
max_output_tokens: registryModel?.max_output_tokens || Capabilities.getMaxOutputTokens(modelId),
|
|
32
|
+
modalities: registryModel?.modalities || { input: ["text"], output: ["text"] },
|
|
33
|
+
capabilities: Capabilities.getCapabilities(modelId),
|
|
34
|
+
pricing: registryModel?.pricing || Capabilities.getPricing(modelId),
|
|
35
|
+
metadata: {
|
|
36
|
+
...(registryModel?.metadata || {}),
|
|
37
|
+
display_name: m.display_name,
|
|
38
|
+
created_at: m.created_at
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
return info;
|
|
42
|
+
});
|
|
21
43
|
}
|
|
22
|
-
const data = await response.json();
|
|
23
|
-
const models = data.data || [];
|
|
24
|
-
return models.map((model) => {
|
|
25
|
-
const id = model.id;
|
|
26
|
-
const createdAt = new Date(model.created_at);
|
|
27
|
-
return {
|
|
28
|
-
id: id,
|
|
29
|
-
name: model.display_name || id,
|
|
30
|
-
provider: "anthropic",
|
|
31
|
-
family: Capabilities.getFamily(id),
|
|
32
|
-
context_window: Capabilities.getContextWindow(id),
|
|
33
|
-
max_output_tokens: Capabilities.getMaxOutputTokens(id),
|
|
34
|
-
modalities: Capabilities.getModalities(id),
|
|
35
|
-
capabilities: Capabilities.getCapabilities(id),
|
|
36
|
-
pricing: Capabilities.getPricing(id),
|
|
37
|
-
created_at: createdAt
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
44
|
}
|
|
41
|
-
catch (
|
|
42
|
-
// Fallback
|
|
43
|
-
return Object.entries(ANTHROPIC_MODELS).filter(([key]) => key !== "other").map(([key, def]) => {
|
|
44
|
-
let id = key.replace(/_/g, "-");
|
|
45
|
-
if (id.includes("claude-3-5"))
|
|
46
|
-
id = "claude-3-5-sonnet-20240620";
|
|
47
|
-
else if (id.includes("claude-3-haiku"))
|
|
48
|
-
id = "claude-3-haiku-20240307";
|
|
49
|
-
return {
|
|
50
|
-
id: id,
|
|
51
|
-
name: id,
|
|
52
|
-
provider: "anthropic",
|
|
53
|
-
family: Capabilities.getFamily(id),
|
|
54
|
-
context_window: def.contextWindow,
|
|
55
|
-
max_output_tokens: def.maxOutputTokens,
|
|
56
|
-
modalities: Capabilities.getModalities(id),
|
|
57
|
-
capabilities: Capabilities.getCapabilities(id),
|
|
58
|
-
pricing: Capabilities.getPricing(id)
|
|
59
|
-
};
|
|
60
|
-
});
|
|
45
|
+
catch (_error) {
|
|
46
|
+
// Fallback
|
|
61
47
|
}
|
|
48
|
+
return ModelRegistry.all()
|
|
49
|
+
.filter(m => m.provider === "anthropic")
|
|
50
|
+
.map(m => ({
|
|
51
|
+
...m,
|
|
52
|
+
capabilities: Capabilities.getCapabilities(m.id)
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
find(modelId) {
|
|
56
|
+
return ModelRegistry.find(modelId, "anthropic");
|
|
62
57
|
}
|
|
63
58
|
}
|
|
@@ -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;AAMxD,qBAAa,kBAAkB;IACjB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEtE,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CAAC,SAAS,CAAC;
|
|
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;AAMxD,qBAAa,kBAAkB;IACjB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAAU,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxC,OAAO,EAAE,MAAM,EAAmB,MAAM,EAAE,MAAM;IAEtE,OAAO,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CAAC,SAAS,CAAC;CA0HhE"}
|
|
@@ -13,11 +13,20 @@ export class AnthropicStreaming {
|
|
|
13
13
|
const maxTokens = request.max_tokens || Capabilities.getMaxOutputTokens(model) || 4096;
|
|
14
14
|
const systemPrompt = formatSystemPrompt(request.messages);
|
|
15
15
|
const messages = formatMessages(request.messages);
|
|
16
|
+
let system = systemPrompt;
|
|
17
|
+
if (request.response_format) {
|
|
18
|
+
let schemaText = "";
|
|
19
|
+
if (request.response_format.type === "json_schema" && request.response_format.json_schema?.schema) {
|
|
20
|
+
schemaText = "\nSchema:\n" + JSON.stringify(request.response_format.json_schema.schema, null, 2);
|
|
21
|
+
}
|
|
22
|
+
const instruction = `CRITICAL: Respond ONLY with a valid JSON object matching the requested schema.${schemaText}\n\nDo not include any other text or explanation.`;
|
|
23
|
+
system = system ? `${system}\n\n${instruction}` : instruction;
|
|
24
|
+
}
|
|
16
25
|
const body = {
|
|
17
26
|
model: model,
|
|
18
27
|
messages: messages,
|
|
19
28
|
max_tokens: maxTokens,
|
|
20
|
-
system:
|
|
29
|
+
system: system,
|
|
21
30
|
stream: true,
|
|
22
31
|
};
|
|
23
32
|
if (request.temperature !== undefined) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/index.ts"],"names":[],"mappings":"AAIA,wBAAgB,yBAAyB,SAQxC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { config } from "../../config.js";
|
|
1
2
|
import { providerRegistry } from "../registry.js";
|
|
2
3
|
import { AnthropicProvider } from "./AnthropicProvider.js";
|
|
3
4
|
export function registerAnthropicProvider() {
|
|
4
5
|
providerRegistry.register("anthropic", () => {
|
|
5
|
-
const apiKey =
|
|
6
|
+
const apiKey = config.anthropicApiKey;
|
|
6
7
|
if (!apiKey) {
|
|
7
|
-
throw new Error("
|
|
8
|
+
throw new Error("anthropicApiKey is not set in config or ANTHROPIC_API_KEY environment variable");
|
|
8
9
|
}
|
|
9
10
|
return new AnthropicProvider({ apiKey: apiKey.trim() });
|
|
10
11
|
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class Capabilities {
|
|
2
|
+
static getCapabilities(modelId: string): string[];
|
|
3
|
+
static getContextWindow(modelId: string): number | null;
|
|
4
|
+
static getMaxOutputTokens(modelId: string): number | null;
|
|
5
|
+
static supportsVision(modelId: string): boolean;
|
|
6
|
+
static supportsTools(modelId: string): boolean;
|
|
7
|
+
static supportsStructuredOutput(modelId: string): boolean;
|
|
8
|
+
static supportsEmbeddings(modelId: string): boolean;
|
|
9
|
+
static supportsImageGeneration(modelId: string): boolean;
|
|
10
|
+
static supportsTranscription(modelId: string): boolean;
|
|
11
|
+
static supportsModeration(modelId: string): boolean;
|
|
12
|
+
static supportsReasoning(modelId: string): boolean;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=Capabilities.d.ts.map
|
|
@@ -0,0 +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,OAAO,EAAE,MAAM,GAAG,OAAO;IAI/C,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAI9C,MAAM,CAAC,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIzD,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAInD,MAAM,CAAC,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIxD,MAAM,CAAC,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAItD,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAInD,MAAM,CAAC,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;CAGnD"}
|