@node-llm/core 0.4.0 → 0.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 +43 -20
- package/dist/chat/Chat.d.ts +1 -1
- package/dist/chat/Chat.d.ts.map +1 -1
- package/dist/chat/Chat.js +2 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/llm.d.ts.map +1 -1
- package/dist/llm.js +4 -0
- package/dist/providers/Provider.d.ts +1 -0
- package/dist/providers/Provider.d.ts.map +1 -1
- package/dist/providers/anthropic/AnthropicProvider.d.ts +32 -0
- package/dist/providers/anthropic/AnthropicProvider.d.ts.map +1 -0
- package/dist/providers/anthropic/AnthropicProvider.js +51 -0
- package/dist/providers/anthropic/Capabilities.d.ts +47 -0
- package/dist/providers/anthropic/Capabilities.d.ts.map +1 -0
- package/dist/providers/anthropic/Capabilities.js +153 -0
- package/dist/providers/anthropic/Chat.d.ts +8 -0
- package/dist/providers/anthropic/Chat.d.ts.map +1 -0
- package/dist/providers/anthropic/Chat.js +93 -0
- package/dist/providers/anthropic/Errors.d.ts +2 -0
- package/dist/providers/anthropic/Errors.d.ts.map +1 -0
- package/dist/providers/anthropic/Errors.js +33 -0
- package/dist/providers/anthropic/Models.d.ts +8 -0
- package/dist/providers/anthropic/Models.d.ts.map +1 -0
- package/dist/providers/anthropic/Models.js +63 -0
- package/dist/providers/anthropic/Streaming.d.ts +8 -0
- package/dist/providers/anthropic/Streaming.d.ts.map +1 -0
- package/dist/providers/anthropic/Streaming.js +104 -0
- package/dist/providers/anthropic/Utils.d.ts +5 -0
- package/dist/providers/anthropic/Utils.d.ts.map +1 -0
- package/dist/providers/anthropic/Utils.js +125 -0
- package/dist/providers/anthropic/index.d.ts +2 -0
- package/dist/providers/anthropic/index.d.ts.map +1 -0
- package/dist/providers/anthropic/index.js +11 -0
- package/dist/providers/anthropic/types.d.ts +57 -0
- package/dist/providers/anthropic/types.d.ts.map +1 -0
- package/dist/providers/anthropic/types.js +1 -0
- package/dist/providers/gemini/Capabilities.d.ts.map +1 -1
- package/dist/providers/gemini/Capabilities.js +5 -2
- package/dist/providers/gemini/Chat.d.ts +1 -0
- package/dist/providers/gemini/Chat.d.ts.map +1 -1
- package/dist/providers/gemini/Chat.js +43 -4
- package/dist/providers/gemini/GeminiProvider.d.ts +2 -1
- package/dist/providers/gemini/GeminiProvider.d.ts.map +1 -1
- package/dist/providers/gemini/GeminiProvider.js +3 -0
- package/dist/providers/gemini/Streaming.d.ts +1 -0
- package/dist/providers/gemini/Streaming.d.ts.map +1 -1
- package/dist/providers/gemini/Streaming.js +34 -4
- package/dist/providers/registry.js +1 -1
- package/dist/utils/FileLoader.d.ts.map +1 -1
- package/dist/utils/FileLoader.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,13 +12,13 @@ A provider-agnostic LLM core for Node.js, heavily inspired by the elegant design
|
|
|
12
12
|
|
|
13
13
|
## 🚀 Features
|
|
14
14
|
|
|
15
|
-
- **Provider-Agnostic**: Switch between OpenAI, Anthropic, and
|
|
15
|
+
- **Provider-Agnostic**: Switch between OpenAI (GPT-4o), Anthropic (Claude 3.5), and Gemini (2.0) with a single line of config.
|
|
16
16
|
- **Streaming-First**: Native `AsyncIterator` support for real-time token delivery.
|
|
17
|
-
- **Tool Calling**: Automatic execution loop for model-requested functions.
|
|
18
|
-
- **
|
|
19
|
-
- **Multi-modal & Smart Files**: Built-in support for Vision (images), Audio, and
|
|
20
|
-
- **Fluent API**: Chainable methods like `.withTool()` for dynamic registration.
|
|
21
|
-
- **Resilient**: Configurable retry logic
|
|
17
|
+
- **Tool Calling**: Automatic execution loop for model-requested functions (OpenAI, Anthropic, Gemini).
|
|
18
|
+
- **Structured Output**: Strict Zod-based JSON schema enforcement across all major providers.
|
|
19
|
+
- **Multi-modal & Smart Files**: Built-in support for Vision (images), Audio, and Documents (PDFs for Claude).
|
|
20
|
+
- **Fluent API**: Chainable methods like `.withTool()` and `.withSchema()` for dynamic registration.
|
|
21
|
+
- **Resilient**: Configurable retry logic and detailed error handling for API outages.
|
|
22
22
|
- **Type-Safe**: Written in TypeScript with full ESM support.
|
|
23
23
|
|
|
24
24
|
---
|
|
@@ -42,7 +42,7 @@ import { LLM } from "@node-llm/core";
|
|
|
42
42
|
import "dotenv/config";
|
|
43
43
|
|
|
44
44
|
LLM.configure({
|
|
45
|
-
provider: "openai", // or "gemini"
|
|
45
|
+
provider: "openai", // or "anthropic", "gemini"
|
|
46
46
|
retry: { attempts: 3, delayMs: 500 },
|
|
47
47
|
defaultModerationModel: "text-moderation-latest",
|
|
48
48
|
defaultTranscriptionModel: "whisper-1",
|
|
@@ -220,6 +220,7 @@ Check the [examples](../../examples) directory for focused scripts organized by
|
|
|
220
220
|
| [Lifecycle Events](../../examples/openai/chat/events.mjs) | Hooks for specific chat events (onNewMessage, onToolCall) |
|
|
221
221
|
| [Token Usage](../../examples/openai/chat/usage.mjs) | Tracking costs and token counts |
|
|
222
222
|
| [Max Tokens](../../examples/openai/chat/max-tokens.mjs) | Limiting response length with `maxTokens` |
|
|
223
|
+
| [Structured Output](../../examples/openai/chat/structured.mjs) | Zod-based JSON schema enforcement |
|
|
223
224
|
|
|
224
225
|
#### 🖼️ Multimodal
|
|
225
226
|
| Example | Description |
|
|
@@ -255,6 +256,7 @@ Check the [examples](../../examples) directory for focused scripts organized by
|
|
|
255
256
|
| [Tool Calling](../../examples/gemini/chat/tools.mjs) | Function calling with automatic execution |
|
|
256
257
|
| [Lifecycle Events](../../examples/gemini/chat/events.mjs) | Event hooks for chat interactions |
|
|
257
258
|
| [Token Usage](../../examples/gemini/chat/usage.mjs) | Tracking conversation costs |
|
|
259
|
+
| [Structured Output](../../examples/gemini/chat/structured.mjs) | Native JSON schema support |
|
|
258
260
|
|
|
259
261
|
#### 🖼️ Multimodal
|
|
260
262
|
| Example | Description |
|
|
@@ -271,8 +273,26 @@ Check the [examples](../../examples) directory for focused scripts organized by
|
|
|
271
273
|
#### 🧠 Discovery
|
|
272
274
|
| Example | Description |
|
|
273
275
|
| :--- | :--- |
|
|
274
|
-
| [Models & Capabilities](../../examples/gemini/discovery/models.mjs) | Listing models and
|
|
275
|
-
| [Embeddings](../../examples/gemini/embeddings/create.mjs) |
|
|
276
|
+
| [Models & Capabilities](../../examples/gemini/discovery/models.mjs) | Listing models and inspecting their specs |
|
|
277
|
+
| [Embeddings](../../examples/gemini/embeddings/create.mjs) | Generating semantic vector embeddings |
|
|
278
|
+
|
|
279
|
+
### Anthropic Examples
|
|
280
|
+
|
|
281
|
+
#### 💬 Chat
|
|
282
|
+
| Example | Description |
|
|
283
|
+
| :--- | :--- |
|
|
284
|
+
| [Basic & Streaming](../../examples/anthropic/chat/basic.mjs) | Chatting with Claude 3.5 Models |
|
|
285
|
+
| [Tool Calling](../../examples/anthropic/chat/tools.mjs) | Native tool use with automatic execution |
|
|
286
|
+
| [Parallel Tools](../../examples/anthropic/chat/parallel-tools.mjs) | Handling multiple tool requests in one turn |
|
|
287
|
+
| [Token Usage](../../examples/anthropic/chat/usage.mjs) | Tracking Claude-specific token metrics |
|
|
288
|
+
| [Structured Output](../../examples/anthropic/chat/structured.mjs) | Prompt-based JSON schema enforcement |
|
|
289
|
+
|
|
290
|
+
#### 🖼️ Multimodal
|
|
291
|
+
| Example | Description |
|
|
292
|
+
| :--- | :--- |
|
|
293
|
+
| [Vision Analysis](../../examples/anthropic/multimodal/vision.mjs) | Analyzing images with Claude Vision |
|
|
294
|
+
| [PDF Analysis](../../examples/anthropic/multimodal/pdf.mjs) | Native PDF document processing |
|
|
295
|
+
| [File Context](../../examples/anthropic/multimodal/files.mjs) | Passing local file contents to Claude |
|
|
276
296
|
|
|
277
297
|
|
|
278
298
|
To run an example:
|
|
@@ -316,7 +336,7 @@ Ensure the AI returns data exactly matching a specific structure. Supports stric
|
|
|
316
336
|
**Using Zod (Recommended):**
|
|
317
337
|
|
|
318
338
|
```ts
|
|
319
|
-
import { z } from "
|
|
339
|
+
import { LLM, z } from "@node-llm/core";
|
|
320
340
|
|
|
321
341
|
const personSchema = z.object({
|
|
322
342
|
name: z.string(),
|
|
@@ -437,7 +457,7 @@ console.log(model.pricing.text_tokens.standard.input_per_million); // => 0.15
|
|
|
437
457
|
| :--- | :--- | :--- |
|
|
438
458
|
| **OpenAI** | ✅ Supported | Chat, Streaming, Tools, Vision, Audio, Images, Transcription, Moderation |
|
|
439
459
|
| **Gemini** | ✅ Supported | Chat, Streaming, Tools, Vision, Audio, Video, Embeddings, Transcription |
|
|
440
|
-
| **Anthropic** |
|
|
460
|
+
| **Anthropic** | ✅ Supported | Chat, Streaming, Tools, Vision, PDF Support, Structured Output |
|
|
441
461
|
| **Azure OpenAI** | 🏗️ Roadmap | Coming soon |
|
|
442
462
|
|
|
443
463
|
---
|
|
@@ -451,19 +471,22 @@ console.log(model.pricing.text_tokens.standard.input_per_million); // => 0.15
|
|
|
451
471
|
|
|
452
472
|
---
|
|
453
473
|
|
|
454
|
-
|
|
474
|
+
`node-llm` features a comprehensive test suite including high-level integration tests and granular unit tests.
|
|
455
475
|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
- **Replay Mode (Default)**: Runs tests using recorded cassettes. Fast, deterministic, and requires no API keys.
|
|
476
|
+
- **Unit Tests**: Test core logic and provider handlers in isolation without hitting any APIs.
|
|
459
477
|
```bash
|
|
460
|
-
npm test
|
|
478
|
+
npm run test:unit
|
|
461
479
|
```
|
|
462
480
|
|
|
463
|
-
- **
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
481
|
+
- **Integration Tests (VCR)**: Uses Polly.js to record and replay real LLM interactions.
|
|
482
|
+
- **Replay Mode (Default)**: Runs against recorded cassettes. Fast and requires no API keys.
|
|
483
|
+
```bash
|
|
484
|
+
npm run test:integration
|
|
485
|
+
```
|
|
486
|
+
- **Record Mode**: Update cassettes by hitting real APIs (requires API keys).
|
|
487
|
+
```bash
|
|
488
|
+
VCR_MODE=record npm run test:integration
|
|
489
|
+
```
|
|
467
490
|
|
|
468
491
|
*All recordings are automatically scrubbed of sensitive data (API keys, org IDs) before being saved to disk.*
|
|
469
492
|
|
package/dist/chat/Chat.d.ts
CHANGED
|
@@ -86,7 +86,7 @@ export declare class Chat {
|
|
|
86
86
|
/**
|
|
87
87
|
* Ask the model a question
|
|
88
88
|
*/
|
|
89
|
-
ask(content: string, options?: AskOptions): Promise<ChatResponseString>;
|
|
89
|
+
ask(content: string | any[], options?: AskOptions): Promise<ChatResponseString>;
|
|
90
90
|
/**
|
|
91
91
|
* Streams the model's response to a user question.
|
|
92
92
|
*/
|
package/dist/chat/Chat.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../src/chat/Chat.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAI3D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,WAAW,UAAU;IACzB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,qBAAa,IAAI;IAKb,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,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E,GAAG,KAAK,IAAI,GAAG,IAAI;IAKlD,YAAY,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI;IAKlD;;OAEG;IACG,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,EAAE,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA8KrF;;OAEG;IACI,MAAM,CAAC,OAAO,EAAE,MAAM;CAI9B"}
|
package/dist/chat/Chat.js
CHANGED
|
@@ -43,9 +43,10 @@ export class Chat {
|
|
|
43
43
|
acc.output_tokens += msg.usage.output_tokens;
|
|
44
44
|
acc.total_tokens += msg.usage.total_tokens;
|
|
45
45
|
acc.cached_tokens = (acc.cached_tokens ?? 0) + (msg.usage.cached_tokens ?? 0);
|
|
46
|
+
acc.cache_creation_tokens = (acc.cache_creation_tokens ?? 0) + (msg.usage.cache_creation_tokens ?? 0);
|
|
46
47
|
}
|
|
47
48
|
return acc;
|
|
48
|
-
}, { input_tokens: 0, output_tokens: 0, total_tokens: 0, cached_tokens: 0 });
|
|
49
|
+
}, { input_tokens: 0, output_tokens: 0, total_tokens: 0, cached_tokens: 0, cache_creation_tokens: 0 });
|
|
49
50
|
}
|
|
50
51
|
/**
|
|
51
52
|
* Add a tool to the chat session (fluent API)
|
package/dist/index.d.ts
CHANGED
|
@@ -6,10 +6,12 @@ export type { Role } from "./chat/Role.js";
|
|
|
6
6
|
export type { ChatOptions } from "./chat/ChatOptions.js";
|
|
7
7
|
export type { Tool, ToolCall } from "./chat/Tool.js";
|
|
8
8
|
export type { MessageContent, ContentPart } from "./chat/Content.js";
|
|
9
|
+
export { z } from "zod";
|
|
9
10
|
export { LLM, Transcription, Moderation, Embedding } from "./llm.js";
|
|
10
11
|
export { providerRegistry } from "./providers/registry.js";
|
|
11
12
|
export { OpenAIProvider } from "./providers/openai/OpenAIProvider.js";
|
|
12
13
|
export { registerOpenAIProvider } from "./providers/openai/index.js";
|
|
14
|
+
export { registerAnthropicProvider } from "./providers/anthropic/index.js";
|
|
13
15
|
export type { ImageRequest, ImageResponse } from "./providers/Provider.js";
|
|
14
16
|
export * from "./errors/index.js";
|
|
15
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,YAAY,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC3C,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACrD,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC3E,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,YAAY,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC3C,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACrD,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC3E,cAAc,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export { Chat } from "./chat/Chat.js";
|
|
2
2
|
export { Stream } from "./chat/Stream.js";
|
|
3
3
|
export { GeneratedImage } from "./image/GeneratedImage.js";
|
|
4
|
+
export { z } from "zod";
|
|
4
5
|
export { LLM, Transcription, Moderation, Embedding } from "./llm.js";
|
|
5
6
|
export { providerRegistry } from "./providers/registry.js";
|
|
6
7
|
export { OpenAIProvider } from "./providers/openai/OpenAIProvider.js";
|
|
7
8
|
export { registerOpenAIProvider } from "./providers/openai/index.js";
|
|
9
|
+
export { registerAnthropicProvider } from "./providers/anthropic/index.js";
|
|
8
10
|
export * from "./errors/index.js";
|
package/dist/llm.d.ts.map
CHANGED
|
@@ -1 +1 @@
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CAAA;KAAE,GAAG,OAAO,CAAC,UAAU,CAAC;IAiBrF,KAAK,CACT,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,EACxB,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,GAChD,OAAO,CAAC,SAAS,CAAC;CAkBtB;AAED,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;AAEhD,eAAO,MAAM,GAAG,SAAgB,CAAC"}
|
package/dist/llm.js
CHANGED
|
@@ -2,6 +2,7 @@ import { Chat } from "./chat/Chat.js";
|
|
|
2
2
|
import { providerRegistry } from "./providers/registry.js";
|
|
3
3
|
import { ensureOpenAIRegistered } from "./providers/openai/index.js";
|
|
4
4
|
import { registerGeminiProvider } from "./providers/gemini/index.js";
|
|
5
|
+
import { registerAnthropicProvider } from "./providers/anthropic/index.js";
|
|
5
6
|
import { GeneratedImage } from "./image/GeneratedImage.js";
|
|
6
7
|
import { models } from "./models/ModelRegistry.js";
|
|
7
8
|
import { Transcription } from "./transcription/Transcription.js";
|
|
@@ -40,6 +41,9 @@ class LLMCore {
|
|
|
40
41
|
if (config.provider === "gemini") {
|
|
41
42
|
registerGeminiProvider();
|
|
42
43
|
}
|
|
44
|
+
if (config.provider === "anthropic") {
|
|
45
|
+
registerAnthropicProvider();
|
|
46
|
+
}
|
|
43
47
|
this.provider = providerRegistry.resolve(config.provider);
|
|
44
48
|
}
|
|
45
49
|
else {
|
|
@@ -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;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M,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC;AAED,MAAM,WAAW,kBAAkB;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,gBAAgB,EAAE,CAAC;CAC7B;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAClD,MAAM,CAAC,CAAC,OAAO,EAAE,WAAW,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;IACxD,UAAU,CAAC,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;IACpC,KAAK,CAAC,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IACtD,UAAU,CAAC,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,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"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Provider, ChatRequest, ChatResponse, ModelInfo, ChatChunk, ImageRequest, ImageResponse, ModerationRequest, ModerationResponse, TranscriptionRequest, TranscriptionResponse } from "../Provider.js";
|
|
2
|
+
import { EmbeddingRequest, EmbeddingResponse } from "../Embedding.js";
|
|
3
|
+
export interface AnthropicProviderOptions {
|
|
4
|
+
apiKey: string;
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class AnthropicProvider implements Provider {
|
|
8
|
+
private readonly options;
|
|
9
|
+
private readonly baseUrl;
|
|
10
|
+
private readonly chatHandler;
|
|
11
|
+
private readonly streamHandler;
|
|
12
|
+
private readonly modelsHandler;
|
|
13
|
+
capabilities: {
|
|
14
|
+
supportsVision: (model: string) => boolean;
|
|
15
|
+
supportsTools: (model: string) => boolean;
|
|
16
|
+
supportsStructuredOutput: (model: string) => boolean;
|
|
17
|
+
supportsEmbeddings: (_model: string) => boolean;
|
|
18
|
+
supportsImageGeneration: (_model: string) => boolean;
|
|
19
|
+
supportsTranscription: (_model: string) => boolean;
|
|
20
|
+
supportsModeration: (_model: string) => boolean;
|
|
21
|
+
getContextWindow: (model: string) => number | null;
|
|
22
|
+
};
|
|
23
|
+
constructor(options: AnthropicProviderOptions);
|
|
24
|
+
chat(request: ChatRequest): Promise<ChatResponse>;
|
|
25
|
+
stream(request: ChatRequest): AsyncGenerator<ChatChunk>;
|
|
26
|
+
listModels(): Promise<ModelInfo[]>;
|
|
27
|
+
paint(_request: ImageRequest): Promise<ImageResponse>;
|
|
28
|
+
transcribe(_request: TranscriptionRequest): Promise<TranscriptionResponse>;
|
|
29
|
+
moderate(_request: ModerationRequest): Promise<ModerationResponse>;
|
|
30
|
+
embed(_request: EmbeddingRequest): Promise<EmbeddingResponse>;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=AnthropicProvider.d.ts.map
|
|
@@ -0,0 +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,CAAkB;IAGzC,YAAY;gCACO,MAAM;+BACP,MAAM;0CACK,MAAM;qCACX,MAAM;0CACD,MAAM;wCACR,MAAM;qCACT,MAAM;kCACT,MAAM;MAChC;gBAE2B,OAAO,EAAE,wBAAwB;IAOxD,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;IAKlC,KAAK,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC;IAIrD,UAAU,CAAC,QAAQ,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAI1E,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAIlE,KAAK,CAAC,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAGpE"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Capabilities } from "./Capabilities.js";
|
|
2
|
+
import { AnthropicChat } from "./Chat.js";
|
|
3
|
+
import { AnthropicStreaming } from "./Streaming.js";
|
|
4
|
+
import { AnthropicModels } from "./Models.js";
|
|
5
|
+
export class AnthropicProvider {
|
|
6
|
+
options;
|
|
7
|
+
baseUrl;
|
|
8
|
+
chatHandler;
|
|
9
|
+
streamHandler;
|
|
10
|
+
modelsHandler;
|
|
11
|
+
// Capabilities Interface Implementation
|
|
12
|
+
capabilities = {
|
|
13
|
+
supportsVision: (model) => Capabilities.supportsVision(model),
|
|
14
|
+
supportsTools: (model) => Capabilities.supportsTools(model),
|
|
15
|
+
supportsStructuredOutput: (model) => Capabilities.supportsJsonMode(model), // Mapping JsonMode to StructuredOutput approximation
|
|
16
|
+
supportsEmbeddings: (_model) => false,
|
|
17
|
+
supportsImageGeneration: (_model) => false,
|
|
18
|
+
supportsTranscription: (_model) => false,
|
|
19
|
+
supportsModeration: (_model) => false,
|
|
20
|
+
getContextWindow: (model) => Capabilities.getContextWindow(model),
|
|
21
|
+
};
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.options = options;
|
|
24
|
+
this.baseUrl = options.baseUrl ?? "https://api.anthropic.com/v1";
|
|
25
|
+
this.chatHandler = new AnthropicChat(this.baseUrl, options.apiKey);
|
|
26
|
+
this.streamHandler = new AnthropicStreaming(this.baseUrl, options.apiKey);
|
|
27
|
+
this.modelsHandler = new AnthropicModels(this.baseUrl, options.apiKey);
|
|
28
|
+
}
|
|
29
|
+
async chat(request) {
|
|
30
|
+
return this.chatHandler.execute(request);
|
|
31
|
+
}
|
|
32
|
+
async *stream(request) {
|
|
33
|
+
yield* this.streamHandler.execute(request);
|
|
34
|
+
}
|
|
35
|
+
async listModels() {
|
|
36
|
+
return this.modelsHandler.execute();
|
|
37
|
+
}
|
|
38
|
+
// Unsupported methods
|
|
39
|
+
async paint(_request) {
|
|
40
|
+
throw new Error("Anthropic doesn't support image generation");
|
|
41
|
+
}
|
|
42
|
+
async transcribe(_request) {
|
|
43
|
+
throw new Error("Anthropic doesn't support transcription");
|
|
44
|
+
}
|
|
45
|
+
async moderate(_request) {
|
|
46
|
+
throw new Error("Anthropic doesn't support moderation");
|
|
47
|
+
}
|
|
48
|
+
async embed(_request) {
|
|
49
|
+
throw new Error("Anthropic doesn't support embeddings");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
export declare class Capabilities {
|
|
25
|
+
static getFamily(modelId: string): string;
|
|
26
|
+
static getDefinition(modelId: string): ModelFamilyDefinition;
|
|
27
|
+
static getContextWindow(modelId: string): number | null;
|
|
28
|
+
static getMaxOutputTokens(modelId: string): number | null;
|
|
29
|
+
static supportsVision(modelId: string): boolean;
|
|
30
|
+
static supportsTools(modelId: string): boolean;
|
|
31
|
+
static supportsJsonMode(modelId: string): boolean;
|
|
32
|
+
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
|
+
static getCapabilities(modelId: string): string[];
|
|
40
|
+
static getPricing(modelId: string): {
|
|
41
|
+
text_tokens: {
|
|
42
|
+
standard: any;
|
|
43
|
+
batch: any;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=Capabilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Capabilities.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/Capabilities.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAE/B,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,YAAY,CAAC;IACtB,QAAQ,EAAE,aAAa,CAAC;IACxB,IAAI,EAAE,SAAS,CAAC;CACjB;AAED,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAiElE,CAAC;AAEF,qBAAa,YAAY;IACvB,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAUzC,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,qBAAqB;IAK5D,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIvD,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIzD,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAI/C,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAI9C,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIjD,MAAM,CAAC,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIzD,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAI7C,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAI9C,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE;IAa5E,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAcjD,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM;;;;;;CA2BlC"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
export const ANTHROPIC_MODELS = {
|
|
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
|
+
};
|
|
67
|
+
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
|
+
static getContextWindow(modelId) {
|
|
83
|
+
return this.getDefinition(modelId).contextWindow;
|
|
84
|
+
}
|
|
85
|
+
static getMaxOutputTokens(modelId) {
|
|
86
|
+
return this.getDefinition(modelId).maxOutputTokens;
|
|
87
|
+
}
|
|
88
|
+
static supportsVision(modelId) {
|
|
89
|
+
return !!this.getDefinition(modelId).features.vision;
|
|
90
|
+
}
|
|
91
|
+
static supportsTools(modelId) {
|
|
92
|
+
return !!this.getDefinition(modelId).features.tools;
|
|
93
|
+
}
|
|
94
|
+
static supportsJsonMode(modelId) {
|
|
95
|
+
return !!this.getDefinition(modelId).features.jsonMode;
|
|
96
|
+
}
|
|
97
|
+
static supportsExtendedThinking(modelId) {
|
|
98
|
+
return !!this.getDefinition(modelId).features.reasoning;
|
|
99
|
+
}
|
|
100
|
+
static getInputPrice(modelId) {
|
|
101
|
+
return this.getDefinition(modelId).pricing.input || 3.0;
|
|
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;
|
|
115
|
+
}
|
|
116
|
+
static getCapabilities(modelId) {
|
|
117
|
+
const capabilities = ["streaming"];
|
|
118
|
+
const def = this.getDefinition(modelId);
|
|
119
|
+
if (def.features.tools)
|
|
120
|
+
capabilities.push("function_calling");
|
|
121
|
+
// Assuming all recent anthropic models support batch if they are claude-3+
|
|
122
|
+
if (/claude-3/.test(modelId))
|
|
123
|
+
capabilities.push("batch");
|
|
124
|
+
if (def.features.reasoning)
|
|
125
|
+
capabilities.push("reasoning");
|
|
126
|
+
if (def.features.citations)
|
|
127
|
+
capabilities.push("citations");
|
|
128
|
+
return capabilities;
|
|
129
|
+
}
|
|
130
|
+
static getPricing(modelId) {
|
|
131
|
+
const def = this.getDefinition(modelId);
|
|
132
|
+
const inputCpm = def.pricing.input || 3.0;
|
|
133
|
+
const outputCpm = def.pricing.output || 15.0;
|
|
134
|
+
const standardPricing = {
|
|
135
|
+
input_per_million: inputCpm,
|
|
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
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
text_tokens: {
|
|
148
|
+
standard: standardPricing,
|
|
149
|
+
batch: batchPricing
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ChatRequest, ChatResponse } from "../Provider.js";
|
|
2
|
+
export declare class AnthropicChat {
|
|
3
|
+
private readonly baseUrl;
|
|
4
|
+
private readonly apiKey;
|
|
5
|
+
constructor(baseUrl: string, apiKey: string);
|
|
6
|
+
execute(request: ChatRequest): Promise<ChatResponse>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=Chat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/providers/anthropic/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAS3D,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;CAmG3D"}
|