@stratix/ai-anthropic 0.6.0 → 0.6.2
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.
|
@@ -3,22 +3,61 @@ import type { TokenUsage } from '@stratix/core';
|
|
|
3
3
|
/**
|
|
4
4
|
* Anthropic provider implementation for Stratix AI Agents.
|
|
5
5
|
*
|
|
6
|
-
* Supports Claude 3 models (Opus, Sonnet, Haiku) with tool use.
|
|
6
|
+
* Supports Claude 3 models (Opus, Sonnet, Haiku) with tool use and streaming.
|
|
7
|
+
* Note: Anthropic does not support embeddings.
|
|
7
8
|
*
|
|
8
|
-
* @example
|
|
9
|
+
* @example Basic chat
|
|
9
10
|
* ```typescript
|
|
10
11
|
* const provider = new AnthropicProvider({
|
|
11
12
|
* apiKey: process.env.ANTHROPIC_API_KEY!
|
|
12
13
|
* });
|
|
13
14
|
*
|
|
14
15
|
* const response = await provider.chat({
|
|
15
|
-
* model: 'claude-3-sonnet-
|
|
16
|
+
* model: 'claude-3-5-sonnet-20241022',
|
|
16
17
|
* messages: [
|
|
17
18
|
* { role: 'user', content: 'Hello!', timestamp: new Date() }
|
|
18
19
|
* ],
|
|
19
20
|
* temperature: 0.7
|
|
20
21
|
* });
|
|
21
22
|
* ```
|
|
23
|
+
*
|
|
24
|
+
* @example Streaming
|
|
25
|
+
* ```typescript
|
|
26
|
+
* for await (const chunk of provider.streamChat({
|
|
27
|
+
* model: 'claude-3-5-sonnet-20241022',
|
|
28
|
+
* messages: [{ role: 'user', content: 'Write a story', timestamp: new Date() }]
|
|
29
|
+
* })) {
|
|
30
|
+
* process.stdout.write(chunk.content);
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @example Tool use
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const response = await provider.chat({
|
|
37
|
+
* model: 'claude-3-5-sonnet-20241022',
|
|
38
|
+
* messages: [{ role: 'user', content: 'What is the weather?', timestamp: new Date() }],
|
|
39
|
+
* tools: [{
|
|
40
|
+
* name: 'getWeather',
|
|
41
|
+
* description: 'Get weather for a location',
|
|
42
|
+
* parameters: {
|
|
43
|
+
* type: 'object',
|
|
44
|
+
* properties: { city: { type: 'string' } },
|
|
45
|
+
* required: ['city']
|
|
46
|
+
* }
|
|
47
|
+
* }]
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @example System messages
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const response = await provider.chat({
|
|
54
|
+
* model: 'claude-3-5-sonnet-20241022',
|
|
55
|
+
* messages: [
|
|
56
|
+
* { role: 'system', content: 'You are a helpful assistant', timestamp: new Date() },
|
|
57
|
+
* { role: 'user', content: 'Hello', timestamp: new Date() }
|
|
58
|
+
* ]
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
22
61
|
*/
|
|
23
62
|
export declare class AnthropicProvider implements LLMProvider {
|
|
24
63
|
readonly name = "anthropic";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnthropicProvider.d.ts","sourceRoot":"","sources":["../src/AnthropicProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,YAAY,EACZ,SAAS,EACT,eAAe,EACf,iBAAiB,EAClB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAgB,UAAU,EAAY,MAAM,eAAe,CAAC;AAYxE
|
|
1
|
+
{"version":3,"file":"AnthropicProvider.d.ts","sourceRoot":"","sources":["../src/AnthropicProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,YAAY,EACZ,SAAS,EACT,eAAe,EACf,iBAAiB,EAClB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAgB,UAAU,EAAY,MAAM,eAAe,CAAC;AAYxE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,qBAAa,iBAAkB,YAAW,WAAW;IACnD,QAAQ,CAAC,IAAI,eAAe;IAC5B,QAAQ,CAAC,MAAM,WAKb;IAEF,OAAO,CAAC,MAAM,CAAY;gBAEd,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;IAOlD,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;IAyC9C,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,aAAa,CAAC,SAAS,CAAC;IAqC/D,UAAU,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAQhE;;;;;;OAMG;IACH,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM;IAavD,OAAO,CAAC,eAAe;IAkBvB,OAAO,CAAC,YAAY;IAWpB,OAAO,CAAC,aAAa;CAgBtB"}
|
|
@@ -11,22 +11,61 @@ const MODEL_PRICING = {
|
|
|
11
11
|
/**
|
|
12
12
|
* Anthropic provider implementation for Stratix AI Agents.
|
|
13
13
|
*
|
|
14
|
-
* Supports Claude 3 models (Opus, Sonnet, Haiku) with tool use.
|
|
14
|
+
* Supports Claude 3 models (Opus, Sonnet, Haiku) with tool use and streaming.
|
|
15
|
+
* Note: Anthropic does not support embeddings.
|
|
15
16
|
*
|
|
16
|
-
* @example
|
|
17
|
+
* @example Basic chat
|
|
17
18
|
* ```typescript
|
|
18
19
|
* const provider = new AnthropicProvider({
|
|
19
20
|
* apiKey: process.env.ANTHROPIC_API_KEY!
|
|
20
21
|
* });
|
|
21
22
|
*
|
|
22
23
|
* const response = await provider.chat({
|
|
23
|
-
* model: 'claude-3-sonnet-
|
|
24
|
+
* model: 'claude-3-5-sonnet-20241022',
|
|
24
25
|
* messages: [
|
|
25
26
|
* { role: 'user', content: 'Hello!', timestamp: new Date() }
|
|
26
27
|
* ],
|
|
27
28
|
* temperature: 0.7
|
|
28
29
|
* });
|
|
29
30
|
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example Streaming
|
|
33
|
+
* ```typescript
|
|
34
|
+
* for await (const chunk of provider.streamChat({
|
|
35
|
+
* model: 'claude-3-5-sonnet-20241022',
|
|
36
|
+
* messages: [{ role: 'user', content: 'Write a story', timestamp: new Date() }]
|
|
37
|
+
* })) {
|
|
38
|
+
* process.stdout.write(chunk.content);
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @example Tool use
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const response = await provider.chat({
|
|
45
|
+
* model: 'claude-3-5-sonnet-20241022',
|
|
46
|
+
* messages: [{ role: 'user', content: 'What is the weather?', timestamp: new Date() }],
|
|
47
|
+
* tools: [{
|
|
48
|
+
* name: 'getWeather',
|
|
49
|
+
* description: 'Get weather for a location',
|
|
50
|
+
* parameters: {
|
|
51
|
+
* type: 'object',
|
|
52
|
+
* properties: { city: { type: 'string' } },
|
|
53
|
+
* required: ['city']
|
|
54
|
+
* }
|
|
55
|
+
* }]
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @example System messages
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const response = await provider.chat({
|
|
62
|
+
* model: 'claude-3-5-sonnet-20241022',
|
|
63
|
+
* messages: [
|
|
64
|
+
* { role: 'system', content: 'You are a helpful assistant', timestamp: new Date() },
|
|
65
|
+
* { role: 'user', content: 'Hello', timestamp: new Date() }
|
|
66
|
+
* ]
|
|
67
|
+
* });
|
|
68
|
+
* ```
|
|
30
69
|
*/
|
|
31
70
|
export class AnthropicProvider {
|
|
32
71
|
name = 'anthropic';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnthropicProvider.js","sourceRoot":"","sources":["../src/AnthropicProvider.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAW1C;;GAEG;AACH,MAAM,aAAa,GAA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