@ax-llm/ax 9.0.2 → 9.0.5
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 +22 -8
- package/build/module/src/ai/anthropic/api.d.ts +10 -9
- package/build/module/src/ai/anthropic/api.js +168 -60
- package/build/module/src/ai/anthropic/api.js.map +1 -1
- package/build/module/src/ai/anthropic/info.js +12 -6
- package/build/module/src/ai/anthropic/info.js.map +1 -1
- package/build/module/src/ai/anthropic/types.d.ts +63 -43
- package/build/module/src/ai/anthropic/types.js +9 -8
- package/build/module/src/ai/anthropic/types.js.map +1 -1
- package/build/module/src/ai/azure-openai/api.d.ts +11 -10
- package/build/module/src/ai/azure-openai/api.js +11 -7
- package/build/module/src/ai/azure-openai/api.js.map +1 -1
- package/build/module/src/ai/base.js +3 -0
- package/build/module/src/ai/base.js.map +1 -1
- package/build/module/src/ai/cohere/api.d.ts +13 -12
- package/build/module/src/ai/cohere/api.js +17 -15
- package/build/module/src/ai/cohere/api.js.map +1 -1
- package/build/module/src/ai/cohere/info.js +9 -9
- package/build/module/src/ai/cohere/info.js.map +1 -1
- package/build/module/src/ai/cohere/types.d.ts +12 -12
- package/build/module/src/ai/cohere/types.js +14 -14
- package/build/module/src/ai/cohere/types.js.map +1 -1
- package/build/module/src/ai/deepseek/api.d.ts +9 -8
- package/build/module/src/ai/deepseek/api.js +13 -9
- package/build/module/src/ai/deepseek/api.js.map +1 -1
- package/build/module/src/ai/deepseek/info.js +3 -3
- package/build/module/src/ai/deepseek/info.js.map +1 -1
- package/build/module/src/ai/deepseek/types.d.ts +1 -1
- package/build/module/src/ai/deepseek/types.js +5 -5
- package/build/module/src/ai/deepseek/types.js.map +1 -1
- package/build/module/src/ai/google-gemini/api.d.ts +15 -14
- package/build/module/src/ai/google-gemini/api.js +28 -24
- package/build/module/src/ai/google-gemini/api.js.map +1 -1
- package/build/module/src/ai/google-gemini/info.d.ts +1 -1
- package/build/module/src/ai/google-gemini/info.js +5 -5
- package/build/module/src/ai/google-gemini/info.js.map +1 -1
- package/build/module/src/ai/google-gemini/types.d.ts +32 -32
- package/build/module/src/ai/google-gemini/types.js +25 -25
- package/build/module/src/ai/google-gemini/types.js.map +1 -1
- package/build/module/src/ai/groq/api.d.ts +8 -7
- package/build/module/src/ai/groq/api.js +12 -8
- package/build/module/src/ai/groq/api.js.map +1 -1
- package/build/module/src/ai/groq/types.d.ts +1 -1
- package/build/module/src/ai/groq/types.js +7 -7
- package/build/module/src/ai/groq/types.js.map +1 -1
- package/build/module/src/ai/huggingface/api.d.ts +10 -9
- package/build/module/src/ai/huggingface/api.js +14 -10
- package/build/module/src/ai/huggingface/api.js.map +1 -1
- package/build/module/src/ai/huggingface/types.d.ts +6 -6
- package/build/module/src/ai/huggingface/types.js +4 -4
- package/build/module/src/ai/huggingface/types.js.map +1 -1
- package/build/module/src/ai/index.d.ts +1 -13
- package/build/module/src/ai/index.js +1 -39
- package/build/module/src/ai/index.js.map +1 -1
- package/build/module/src/ai/mistral/api.d.ts +9 -8
- package/build/module/src/ai/mistral/api.js +14 -10
- package/build/module/src/ai/mistral/api.js.map +1 -1
- package/build/module/src/ai/mistral/info.js +6 -6
- package/build/module/src/ai/mistral/info.js.map +1 -1
- package/build/module/src/ai/mistral/types.d.ts +2 -2
- package/build/module/src/ai/mistral/types.js +12 -12
- package/build/module/src/ai/mistral/types.js.map +1 -1
- package/build/module/src/ai/ollama/api.d.ts +12 -10
- package/build/module/src/ai/ollama/api.js +16 -8
- package/build/module/src/ai/ollama/api.js.map +1 -1
- package/build/module/src/ai/openai/api.d.ts +15 -14
- package/build/module/src/ai/openai/api.js +29 -24
- package/build/module/src/ai/openai/api.js.map +1 -1
- package/build/module/src/ai/openai/info.js +8 -8
- package/build/module/src/ai/openai/info.js.map +1 -1
- package/build/module/src/ai/openai/types.d.ts +17 -17
- package/build/module/src/ai/openai/types.js +17 -17
- package/build/module/src/ai/openai/types.js.map +1 -1
- package/build/module/src/ai/together/api.d.ts +8 -7
- package/build/module/src/ai/together/api.js +9 -5
- package/build/module/src/ai/together/api.js.map +1 -1
- package/build/module/src/ai/types.d.ts +2 -2
- package/build/module/src/ai/util.js +4 -2
- package/build/module/src/ai/util.js.map +1 -1
- package/build/module/src/ai/wrap.d.ts +47 -0
- package/build/module/src/ai/wrap.js +95 -0
- package/build/module/src/ai/wrap.js.map +1 -0
- package/build/module/src/db/base.d.ts +7 -7
- package/build/module/src/db/base.js +1 -1
- package/build/module/src/db/cloudflare.d.ts +9 -9
- package/build/module/src/db/cloudflare.js +2 -2
- package/build/module/src/db/cloudflare.js.map +1 -1
- package/build/module/src/db/index.d.ts +1 -6
- package/build/module/src/db/index.js +1 -17
- package/build/module/src/db/index.js.map +1 -1
- package/build/module/src/db/memory.d.ts +9 -9
- package/build/module/src/db/memory.js +2 -2
- package/build/module/src/db/memory.js.map +1 -1
- package/build/module/src/db/pinecone.d.ts +9 -9
- package/build/module/src/db/pinecone.js +2 -2
- package/build/module/src/db/pinecone.js.map +1 -1
- package/build/module/src/db/weaviate.d.ts +9 -9
- package/build/module/src/db/weaviate.js +2 -2
- package/build/module/src/db/weaviate.js.map +1 -1
- package/build/module/src/db/wrap.d.ts +13 -0
- package/build/module/src/db/wrap.js +35 -0
- package/build/module/src/db/wrap.js.map +1 -0
- package/build/module/src/dsp/generate.js +10 -4
- package/build/module/src/dsp/generate.js.map +1 -1
- package/build/module/src/dsp/program.d.ts +1 -0
- package/build/module/src/dsp/program.js.map +1 -1
- package/build/module/src/dsp/router.js +2 -2
- package/build/module/src/examples/agent.js +3 -2
- package/build/module/src/examples/agent.js.map +1 -1
- package/build/module/src/examples/balancer.d.ts +1 -0
- package/build/module/src/examples/balancer.js +26 -0
- package/build/module/src/examples/balancer.js.map +1 -0
- package/build/module/src/examples/chain-of-thought.js +3 -2
- package/build/module/src/examples/chain-of-thought.js.map +1 -1
- package/build/module/src/examples/customer-support.js +3 -2
- package/build/module/src/examples/customer-support.js.map +1 -1
- package/build/module/src/examples/fibonacci.js +3 -2
- package/build/module/src/examples/fibonacci.js.map +1 -1
- package/build/module/src/examples/food-search.js +3 -2
- package/build/module/src/examples/food-search.js.map +1 -1
- package/build/module/src/examples/marketing.js +3 -2
- package/build/module/src/examples/marketing.js.map +1 -1
- package/build/module/src/examples/multi-modal.js +4 -3
- package/build/module/src/examples/multi-modal.js.map +1 -1
- package/build/module/src/examples/qna-tune.js +3 -2
- package/build/module/src/examples/qna-tune.js.map +1 -1
- package/build/module/src/examples/qna-use-tuned.js +3 -2
- package/build/module/src/examples/qna-use-tuned.js.map +1 -1
- package/build/module/src/examples/rag-docs.js +4 -3
- package/build/module/src/examples/rag-docs.js.map +1 -1
- package/build/module/src/examples/rag.js +3 -2
- package/build/module/src/examples/rag.js.map +1 -1
- package/build/module/src/examples/react.js +3 -2
- package/build/module/src/examples/react.js.map +1 -1
- package/build/module/src/examples/routing.js +3 -2
- package/build/module/src/examples/routing.js.map +1 -1
- package/build/module/src/examples/smart-home.js +3 -2
- package/build/module/src/examples/smart-home.js.map +1 -1
- package/build/module/src/examples/streaming1.js +7 -3
- package/build/module/src/examples/streaming1.js.map +1 -1
- package/build/module/src/examples/streaming2.js +10 -6
- package/build/module/src/examples/streaming2.js.map +1 -1
- package/build/module/src/examples/summarize.js +6 -4
- package/build/module/src/examples/summarize.js.map +1 -1
- package/build/module/src/examples/vectordb.js +4 -4
- package/build/module/src/examples/vectordb.js.map +1 -1
- package/build/module/src/mem/memory.js +11 -6
- package/build/module/src/mem/memory.js.map +1 -1
- package/build/module/src/prompts/prompts.test.js +7 -3
- package/build/module/src/prompts/prompts.test.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,16 +63,21 @@ yarn add @ax-llm/ax
|
|
|
63
63
|
## Example: Using chain-of-thought to summarize text
|
|
64
64
|
|
|
65
65
|
```typescript
|
|
66
|
-
import {
|
|
66
|
+
import { AxAI, AxChainOfThought } from '@ax-llm/ax';
|
|
67
67
|
|
|
68
68
|
const textToSummarize = `
|
|
69
69
|
The technological singularity—or simply the singularity[1]—is a hypothetical future point in time at which technological growth becomes uncontrollable and irreversible, resulting in unforeseeable changes to human civilization.[2][3] ...`;
|
|
70
70
|
|
|
71
|
-
const ai =
|
|
71
|
+
const ai = new AxAI({
|
|
72
|
+
name: 'openai',
|
|
73
|
+
apiKey: process.env.OPENAI_APIKEY as string
|
|
74
|
+
});
|
|
75
|
+
|
|
72
76
|
const gen = new AxChainOfThought(
|
|
73
77
|
ai,
|
|
74
78
|
`textToSummarize -> shortSummary "summarize in 5 to 10 words"`
|
|
75
79
|
);
|
|
80
|
+
|
|
76
81
|
const res = await gen.forward({ textToSummarize });
|
|
77
82
|
|
|
78
83
|
console.log('>', res);
|
|
@@ -266,7 +271,7 @@ const technicalSupport = new AxRoute('technicalSupport', [
|
|
|
266
271
|
'how do I update to the latest version?'
|
|
267
272
|
]);
|
|
268
273
|
|
|
269
|
-
const ai =
|
|
274
|
+
const ai = new AxAI({ name: 'openai', apiKey: process.env.OPENAI_APIKEY as string });
|
|
270
275
|
|
|
271
276
|
const router = new AxRouter(ai);
|
|
272
277
|
await router.setRoutes(
|
|
@@ -302,10 +307,11 @@ trace.setGlobalTracerProvider(provider);
|
|
|
302
307
|
|
|
303
308
|
const tracer = trace.getTracer('test');
|
|
304
309
|
|
|
305
|
-
const ai =
|
|
306
|
-
|
|
310
|
+
const ai = new AxAI({
|
|
311
|
+
name: 'ollama',
|
|
312
|
+
config: { model: 'nous-hermes2' },
|
|
307
313
|
options: { tracer }
|
|
308
|
-
}
|
|
314
|
+
});
|
|
309
315
|
|
|
310
316
|
const gen = new AxChainOfThought(
|
|
311
317
|
ai,
|
|
@@ -353,7 +359,10 @@ const examples = await hf.getData<{ question: string; answer: string }>({
|
|
|
353
359
|
fields: ['question', 'answer']
|
|
354
360
|
});
|
|
355
361
|
|
|
356
|
-
const ai =
|
|
362
|
+
const ai = new AxAI({
|
|
363
|
+
name: 'openai',
|
|
364
|
+
apiKey: process.env.OPENAI_APIKEY as string
|
|
365
|
+
});
|
|
357
366
|
|
|
358
367
|
// Setup the program to tune
|
|
359
368
|
const program = new AxChainOfThought<{ question: string }, { answer: string }>(
|
|
@@ -383,7 +392,10 @@ await optimize.compile(metricFn, { filename: 'demos.json' });
|
|
|
383
392
|
And to use the generated demos with the above `ChainOfThought` program
|
|
384
393
|
|
|
385
394
|
```typescript
|
|
386
|
-
const ai =
|
|
395
|
+
const ai = new AxAI({
|
|
396
|
+
name: 'openai',
|
|
397
|
+
apiKey: process.env.OPENAI_APIKEY as string
|
|
398
|
+
});
|
|
387
399
|
|
|
388
400
|
// Setup the program to use the tuned data
|
|
389
401
|
const program = new AxChainOfThought<{ question: string }, { answer: string }>(
|
|
@@ -427,6 +439,8 @@ OPENAI_APIKEY=openai_key npm run tsx ./src/examples/marketing.ts
|
|
|
427
439
|
| streaming1.ts | Output fields validation while streaming |
|
|
428
440
|
| streaming2.ts | Per output field validation while streaming |
|
|
429
441
|
| smart-hone.ts | Agent looks for dog in smart home |
|
|
442
|
+
| multi-modal.ts | Use an image input along with other text inputs |
|
|
443
|
+
| balancer.ts | Balance between various llm's based on cost, etc |
|
|
430
444
|
|
|
431
445
|
## Built-in Functions
|
|
432
446
|
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import type { API } from '../../util/apicall.js';
|
|
2
2
|
import { AxBaseAI } from '../base.js';
|
|
3
3
|
import type { AxAIServiceOptions, AxChatRequest, AxChatResponse, AxModelConfig } from '../types.js';
|
|
4
|
-
import { type
|
|
5
|
-
export declare const
|
|
6
|
-
export interface
|
|
4
|
+
import { type AxAIAnthropicChatError, type AxAIAnthropicChatRequest, type AxAIAnthropicChatResponse, type AxAIAnthropicChatResponseDelta, type AxAIAnthropicConfig } from './types.js';
|
|
5
|
+
export declare const axAIAnthropicDefaultConfig: () => AxAIAnthropicConfig;
|
|
6
|
+
export interface AxAIAnthropicArgs {
|
|
7
|
+
name: 'anthropic';
|
|
7
8
|
apiKey: string;
|
|
8
|
-
config?: Readonly<
|
|
9
|
+
config?: Readonly<AxAIAnthropicConfig>;
|
|
9
10
|
options?: Readonly<AxAIServiceOptions>;
|
|
10
11
|
}
|
|
11
|
-
export declare class
|
|
12
|
+
export declare class AxAIAnthropic extends AxBaseAI<AxAIAnthropicChatRequest, unknown, AxAIAnthropicChatResponse, AxAIAnthropicChatResponseDelta, unknown> {
|
|
12
13
|
private config;
|
|
13
|
-
constructor({ apiKey, config, options }: Readonly<
|
|
14
|
+
constructor({ apiKey, config, options }: Readonly<Omit<AxAIAnthropicArgs, 'name'>>);
|
|
14
15
|
getModelConfig(): AxModelConfig;
|
|
15
|
-
generateChatReq: (req: Readonly<AxChatRequest>) => [API,
|
|
16
|
-
generateChatResp: (
|
|
17
|
-
generateChatStreamResp: (resp: Readonly<
|
|
16
|
+
generateChatReq: (req: Readonly<AxChatRequest>) => [API, AxAIAnthropicChatRequest];
|
|
17
|
+
generateChatResp: (resp: Readonly<AxAIAnthropicChatResponse | AxAIAnthropicChatError>) => AxChatResponse;
|
|
18
|
+
generateChatStreamResp: (resp: Readonly<AxAIAnthropicChatResponseDelta>, state: object) => AxChatResponse;
|
|
18
19
|
}
|
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
import { AxBaseAI, axBaseAIDefaultConfig } from '../base.js';
|
|
2
2
|
import { axModelInfoAnthropic } from './info.js';
|
|
3
|
-
import {
|
|
4
|
-
export const
|
|
5
|
-
model:
|
|
3
|
+
import { AxAIAnthropicModel } from './types.js';
|
|
4
|
+
export const axAIAnthropicDefaultConfig = () => structuredClone({
|
|
5
|
+
model: AxAIAnthropicModel.Claude3Haiku,
|
|
6
6
|
...axBaseAIDefaultConfig()
|
|
7
7
|
});
|
|
8
|
-
export class
|
|
8
|
+
export class AxAIAnthropic extends AxBaseAI {
|
|
9
9
|
config;
|
|
10
|
-
constructor({ apiKey, config
|
|
10
|
+
constructor({ apiKey, config, options }) {
|
|
11
11
|
if (!apiKey || apiKey === '') {
|
|
12
12
|
throw new Error('Anthropic API key not set');
|
|
13
13
|
}
|
|
14
|
+
const _config = {
|
|
15
|
+
...axAIAnthropicDefaultConfig(),
|
|
16
|
+
...config
|
|
17
|
+
};
|
|
14
18
|
super({
|
|
15
19
|
name: 'Anthropic',
|
|
16
20
|
apiURL: 'https://api.anthropic.com/v1',
|
|
17
21
|
headers: {
|
|
18
22
|
'anthropic-version': '2023-06-01',
|
|
19
|
-
'anthropic-beta': 'tools-2024-04-04',
|
|
20
23
|
'x-api-key': apiKey
|
|
21
24
|
},
|
|
22
25
|
modelInfo: axModelInfoAnthropic,
|
|
23
|
-
models: { model:
|
|
26
|
+
models: { model: _config.model },
|
|
24
27
|
options,
|
|
25
28
|
supportFor: { functions: true, streaming: true }
|
|
26
29
|
});
|
|
27
|
-
this.config =
|
|
30
|
+
this.config = _config;
|
|
28
31
|
}
|
|
29
32
|
getModelConfig() {
|
|
30
33
|
const { config } = this;
|
|
@@ -40,42 +43,30 @@ export class AxAnthropic extends AxBaseAI {
|
|
|
40
43
|
const apiConfig = {
|
|
41
44
|
name: '/messages'
|
|
42
45
|
};
|
|
43
|
-
const messages = req
|
|
44
|
-
if (msg.role === 'function') {
|
|
45
|
-
return {
|
|
46
|
-
role: 'user',
|
|
47
|
-
content: msg.content,
|
|
48
|
-
tool_use_id: msg.functionId
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
return {
|
|
52
|
-
role: msg.role,
|
|
53
|
-
content: msg.content ?? ''
|
|
54
|
-
};
|
|
55
|
-
}) ?? [];
|
|
46
|
+
const messages = createMessages(req);
|
|
56
47
|
const tools = req.functions?.map((v) => ({
|
|
57
48
|
name: v.name,
|
|
58
49
|
description: v.description,
|
|
59
50
|
input_schema: v.parameters
|
|
60
51
|
}));
|
|
52
|
+
const stream = req.modelConfig?.stream ?? this.config.stream;
|
|
61
53
|
const reqValue = {
|
|
62
|
-
model: req.
|
|
54
|
+
model: req.model ?? this.config.model,
|
|
63
55
|
max_tokens: req.modelConfig?.maxTokens ?? this.config.maxTokens,
|
|
64
56
|
stop_sequences: req.modelConfig?.stopSequences ?? this.config.stopSequences,
|
|
65
57
|
temperature: req.modelConfig?.temperature ?? this.config.temperature,
|
|
66
58
|
top_p: req.modelConfig?.topP ?? this.config.topP,
|
|
67
59
|
top_k: req.modelConfig?.topK ?? this.config.topK,
|
|
68
60
|
...(tools && tools.length > 0 ? { tools } : {}),
|
|
61
|
+
...(stream ? { stream: true } : {}),
|
|
69
62
|
messages
|
|
70
63
|
};
|
|
71
64
|
return [apiConfig, reqValue];
|
|
72
65
|
};
|
|
73
|
-
generateChatResp = (
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
throw new Error(`Anthropic Chat API Error: ${err.error.message}`);
|
|
66
|
+
generateChatResp = (resp) => {
|
|
67
|
+
if (resp.type === 'error') {
|
|
68
|
+
throw new Error(`Anthropic Chat API Error: ${resp.error.message}`);
|
|
77
69
|
}
|
|
78
|
-
const resp = response;
|
|
79
70
|
const results = resp.content.map((msg) => {
|
|
80
71
|
let finishReason;
|
|
81
72
|
if (msg.type === 'tool_use') {
|
|
@@ -109,50 +100,167 @@ export class AxAnthropic extends AxBaseAI {
|
|
|
109
100
|
modelUsage
|
|
110
101
|
};
|
|
111
102
|
};
|
|
112
|
-
generateChatStreamResp = (resp) => {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
103
|
+
generateChatStreamResp = (resp, state) => {
|
|
104
|
+
if (!('type' in resp)) {
|
|
105
|
+
throw new Error('Invalid Anthropic streaming event');
|
|
106
|
+
}
|
|
107
|
+
const sstate = state;
|
|
108
|
+
if (!sstate.indexIdMap) {
|
|
109
|
+
sstate.indexIdMap = {};
|
|
110
|
+
}
|
|
111
|
+
if (resp.type === 'error') {
|
|
112
|
+
const { error } = resp;
|
|
113
|
+
throw new Error(error.message);
|
|
114
|
+
}
|
|
115
|
+
if (resp.type === 'message_start') {
|
|
116
116
|
const { message } = resp;
|
|
117
|
-
results = [
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
117
|
+
const results = [{ content: '', id: message.id }];
|
|
118
|
+
const modelUsage = {
|
|
119
|
+
promptTokens: message.usage?.input_tokens ?? 0,
|
|
120
|
+
completionTokens: message.usage?.output_tokens ?? 0,
|
|
121
|
+
totalTokens: (message.usage?.input_tokens ?? 0) +
|
|
122
|
+
(message.usage?.output_tokens ?? 0)
|
|
123
|
+
};
|
|
124
|
+
return {
|
|
125
|
+
results,
|
|
126
|
+
modelUsage
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
|
-
if ('
|
|
130
|
-
const { content_block:
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
129
|
+
if (resp.type === 'content_block_start') {
|
|
130
|
+
const { content_block: contentBlock } = resp;
|
|
131
|
+
if (contentBlock.type === 'text') {
|
|
132
|
+
return {
|
|
133
|
+
results: [{ content: contentBlock.text }]
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
if (contentBlock.type === 'tool_use') {
|
|
137
|
+
if (typeof contentBlock.id === 'string' &&
|
|
138
|
+
typeof resp.index === 'number' &&
|
|
139
|
+
!sstate.indexIdMap[resp.index]) {
|
|
140
|
+
sstate.indexIdMap[resp.index] = contentBlock.id;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
137
143
|
}
|
|
138
|
-
if ('
|
|
139
|
-
'stop_reason' in resp.delta) {
|
|
144
|
+
if (resp.type === 'content_block_delta') {
|
|
140
145
|
const { delta } = resp;
|
|
141
|
-
|
|
142
|
-
{
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
146
|
+
if (delta.type === 'text_delta') {
|
|
147
|
+
return {
|
|
148
|
+
results: [{ content: delta.text }]
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
if (delta.type === 'input_json_delta') {
|
|
152
|
+
const id = sstate.indexIdMap[resp.index];
|
|
153
|
+
if (!id) {
|
|
154
|
+
throw new Error('invalid streaming index no id found: ' + resp.index);
|
|
155
|
+
}
|
|
156
|
+
const functionCalls = [
|
|
157
|
+
{
|
|
158
|
+
id,
|
|
159
|
+
type: 'function',
|
|
160
|
+
function: {
|
|
161
|
+
name: '',
|
|
162
|
+
arguments: delta.partial_json
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
];
|
|
166
|
+
return {
|
|
167
|
+
results: [{ functionCalls }]
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (resp.type === 'message_delta') {
|
|
172
|
+
const { delta, usage } = resp;
|
|
173
|
+
return {
|
|
174
|
+
results: [
|
|
175
|
+
{
|
|
176
|
+
content: '',
|
|
177
|
+
finishReason: mapFinishReason(delta.stop_reason)
|
|
178
|
+
}
|
|
179
|
+
],
|
|
180
|
+
modelUsage: {
|
|
181
|
+
promptTokens: 0,
|
|
182
|
+
completionTokens: usage.output_tokens,
|
|
183
|
+
totalTokens: usage.output_tokens
|
|
184
|
+
}
|
|
148
185
|
};
|
|
149
186
|
}
|
|
150
187
|
return {
|
|
151
|
-
results
|
|
152
|
-
modelUsage
|
|
188
|
+
results: [{ content: '' }]
|
|
153
189
|
};
|
|
154
190
|
};
|
|
155
191
|
}
|
|
192
|
+
function createMessages(req) {
|
|
193
|
+
return req.chatPrompt.map((msg) => {
|
|
194
|
+
switch (msg.role) {
|
|
195
|
+
case 'function':
|
|
196
|
+
return {
|
|
197
|
+
role: 'user',
|
|
198
|
+
content: [
|
|
199
|
+
{
|
|
200
|
+
type: 'tool_result',
|
|
201
|
+
text: msg.content,
|
|
202
|
+
tool_use_id: msg.functionId
|
|
203
|
+
}
|
|
204
|
+
]
|
|
205
|
+
};
|
|
206
|
+
case 'user': {
|
|
207
|
+
if (typeof msg.content === 'string') {
|
|
208
|
+
return { role: 'user', content: msg.content };
|
|
209
|
+
}
|
|
210
|
+
const content = msg.content.map((v) => {
|
|
211
|
+
switch (v.type) {
|
|
212
|
+
case 'text':
|
|
213
|
+
return { type: 'text', text: v.text };
|
|
214
|
+
case 'image':
|
|
215
|
+
return {
|
|
216
|
+
type: 'image',
|
|
217
|
+
source: {
|
|
218
|
+
type: 'base64',
|
|
219
|
+
media_type: v.mimeType,
|
|
220
|
+
data: v.image
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
default:
|
|
224
|
+
throw new Error('Invalid content type');
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
return {
|
|
228
|
+
role: 'user',
|
|
229
|
+
content
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
case 'assistant': {
|
|
233
|
+
if (typeof msg.content === 'string') {
|
|
234
|
+
return { role: 'assistant', content: msg.content };
|
|
235
|
+
}
|
|
236
|
+
if (typeof msg.functionCalls !== 'undefined') {
|
|
237
|
+
const content = msg.functionCalls.map((v) => {
|
|
238
|
+
let input;
|
|
239
|
+
if (typeof v.function.arguments === 'string') {
|
|
240
|
+
input = JSON.parse(v.function.arguments);
|
|
241
|
+
}
|
|
242
|
+
else if (typeof v.function.arguments === 'object') {
|
|
243
|
+
input = v.function.arguments;
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
type: 'tool_use',
|
|
247
|
+
id: v.id,
|
|
248
|
+
name: v.function.name,
|
|
249
|
+
input
|
|
250
|
+
};
|
|
251
|
+
});
|
|
252
|
+
return {
|
|
253
|
+
role: 'assistant',
|
|
254
|
+
content
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
throw new Error('Invalid content type');
|
|
258
|
+
}
|
|
259
|
+
default:
|
|
260
|
+
throw new Error('Invalid role');
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
|
156
264
|
function mapFinishReason(stopReason) {
|
|
157
265
|
if (!stopReason) {
|
|
158
266
|
return undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../../../src/ai/anthropic/api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../../../src/ai/anthropic/api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAQ7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAWL,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAwB,EAAE,CAClE,eAAe,CAAC;IACd,KAAK,EAAE,kBAAkB,CAAC,YAAY;IACtC,GAAG,qBAAqB,EAAE;CAC3B,CAAC,CAAC;AASL,MAAM,OAAO,aAAc,SAAQ,QAMlC;IACS,MAAM,CAAsB;IAEpC,YAAY,EACV,MAAM,EACN,MAAM,EACN,OAAO,EACmC;QAC1C,IAAI,CAAC,MAAM,IAAI,MAAM,KAAK,EAAE,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAC/C,CAAC;QACD,MAAM,OAAO,GAAG;YACd,GAAG,0BAA0B,EAAE;YAC/B,GAAG,MAAM;SACV,CAAC;QACF,KAAK,CAAC;YACJ,IAAI,EAAE,WAAW;YACjB,MAAM,EAAE,8BAA8B;YACtC,OAAO,EAAE;gBACP,mBAAmB,EAAE,YAAY;gBACjC,WAAW,EAAE,MAAM;aACpB;YACD,SAAS,EAAE,oBAAoB;YAC/B,MAAM,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAe,EAAE;YAC1C,OAAO;YACP,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE;SACjD,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC;IACxB,CAAC;IAEQ,cAAc;QACrB,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GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;wBAC3C,CAAC;6BAAM,IAAI,OAAO,CAAC,CAAC,QAAQ,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;4BACpD,KAAK,GAAG,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC;wBAC/B,CAAC;wBACD,OAAO;4BACL,IAAI,EAAE,UAAmB;4BACzB,EAAE,EAAE,CAAC,CAAC,EAAE;4BACR,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI;4BACrB,KAAK;yBACN,CAAC;oBACJ,CAAC,CAAC,CAAC;oBACH,OAAO;wBACL,IAAI,EAAE,WAAoB;wBAC1B,OAAO;qBACR,CAAC;gBACJ,CAAC;gBACD,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;YAC1C,CAAC;YACD;gBACE,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;QACpC,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,eAAe,CACtB,UAA4D;IAE5D,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,QAAQ,UAAU,EAAE,CAAC;QACnB,KAAK,eAAe;YAClB,OAAO,MAAM,CAAC;YACd,MAAM;QACR,KAAK,YAAY;YACf,OAAO,QAAQ,CAAC;YAChB,MAAM;QACR,KAAK,UAAU;YACb,OAAO,eAAe,CAAC;YACvB,MAAM;QACR,KAAK,UAAU;YACb,OAAO,MAAM,CAAC;YACd,MAAM;QACR;YACE,OAAO,MAAM,CAAC;IAClB,CAAC;AACH,CAAC"}
|
|
@@ -1,31 +1,37 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AxAIAnthropicModel } from './types.js';
|
|
2
2
|
export const axModelInfoAnthropic = [
|
|
3
3
|
{
|
|
4
|
-
name:
|
|
4
|
+
name: AxAIAnthropicModel.Claude35Sonnet,
|
|
5
|
+
currency: 'usd',
|
|
6
|
+
promptTokenCostPer1M: 3.0,
|
|
7
|
+
completionTokenCostPer1M: 15.0
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
name: AxAIAnthropicModel.Claude3Opus,
|
|
5
11
|
currency: 'usd',
|
|
6
12
|
promptTokenCostPer1M: 15.0,
|
|
7
13
|
completionTokenCostPer1M: 75.0
|
|
8
14
|
},
|
|
9
15
|
{
|
|
10
|
-
name:
|
|
16
|
+
name: AxAIAnthropicModel.Claude3Sonnet,
|
|
11
17
|
currency: 'usd',
|
|
12
18
|
promptTokenCostPer1M: 3.0,
|
|
13
19
|
completionTokenCostPer1M: 15.0
|
|
14
20
|
},
|
|
15
21
|
{
|
|
16
|
-
name:
|
|
22
|
+
name: AxAIAnthropicModel.Claude3Haiku,
|
|
17
23
|
currency: 'usd',
|
|
18
24
|
promptTokenCostPer1M: 0.25,
|
|
19
25
|
completionTokenCostPer1M: 1.25
|
|
20
26
|
},
|
|
21
27
|
{
|
|
22
|
-
name:
|
|
28
|
+
name: AxAIAnthropicModel.Claude21,
|
|
23
29
|
currency: 'usd',
|
|
24
30
|
promptTokenCostPer1M: 8.0,
|
|
25
31
|
completionTokenCostPer1M: 25
|
|
26
32
|
},
|
|
27
33
|
{
|
|
28
|
-
name:
|
|
34
|
+
name: AxAIAnthropicModel.ClaudeInstant12,
|
|
29
35
|
currency: 'usd',
|
|
30
36
|
promptTokenCostPer1M: 0.8,
|
|
31
37
|
completionTokenCostPer1M: 2.24
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"info.js","sourceRoot":"","sources":["../../../../../src/ai/anthropic/info.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"info.js","sourceRoot":"","sources":["../../../../../src/ai/anthropic/info.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,MAAM,CAAC,MAAM,oBAAoB,GAAkB;IACjD;QACE,IAAI,EAAE,kBAAkB,CAAC,cAAc;QACvC,QAAQ,EAAE,KAAK;QACf,oBAAoB,EAAE,GAAG;QACzB,wBAAwB,EAAE,IAAI;KAC/B;IACD;QACE,IAAI,EAAE,kBAAkB,CAAC,WAAW;QACpC,QAAQ,EAAE,KAAK;QACf,oBAAoB,EAAE,IAAI;QAC1B,wBAAwB,EAAE,IAAI;KAC/B;IACD;QACE,IAAI,EAAE,kBAAkB,CAAC,aAAa;QACtC,QAAQ,EAAE,KAAK;QACf,oBAAoB,EAAE,GAAG;QACzB,wBAAwB,EAAE,IAAI;KAC/B;IACD;QACE,IAAI,EAAE,kBAAkB,CAAC,YAAY;QACrC,QAAQ,EAAE,KAAK;QACf,oBAAoB,EAAE,IAAI;QAC1B,wBAAwB,EAAE,IAAI;KAC/B;IACD;QACE,IAAI,EAAE,kBAAkB,CAAC,QAAQ;QACjC,QAAQ,EAAE,KAAK;QACf,oBAAoB,EAAE,GAAG;QACzB,wBAAwB,EAAE,EAAE;KAC7B;IACD;QACE,IAAI,EAAE,kBAAkB,CAAC,eAAe;QACxC,QAAQ,EAAE,KAAK;QACf,oBAAoB,EAAE,GAAG;QACzB,wBAAwB,EAAE,IAAI;KAC/B;CACF,CAAC"}
|
|
@@ -1,30 +1,46 @@
|
|
|
1
1
|
import type { AxModelConfig } from '../types.js';
|
|
2
|
-
export declare enum
|
|
2
|
+
export declare enum AxAIAnthropicModel {
|
|
3
|
+
Claude35Sonnet = "claude-3-5-sonnet-20240620",
|
|
3
4
|
Claude3Opus = "claude-3-opus-20240229",
|
|
4
5
|
Claude3Sonnet = "claude-3-sonnet-20240229",
|
|
5
6
|
Claude3Haiku = "claude-3-haiku-20240307",
|
|
6
7
|
Claude21 = "claude-2.1",
|
|
7
8
|
ClaudeInstant12 = "claude-instant-1.2"
|
|
8
9
|
}
|
|
9
|
-
export type
|
|
10
|
-
model:
|
|
10
|
+
export type AxAIAnthropicConfig = AxModelConfig & {
|
|
11
|
+
model: AxAIAnthropicModel;
|
|
11
12
|
};
|
|
12
|
-
export type
|
|
13
|
+
export type AxAIAnthropicChatRequest = {
|
|
13
14
|
model: string;
|
|
14
|
-
messages: {
|
|
15
|
-
role: 'user'
|
|
16
|
-
content: string | {
|
|
17
|
-
type: 'text'
|
|
18
|
-
text
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
source
|
|
15
|
+
messages: ({
|
|
16
|
+
role: 'user';
|
|
17
|
+
content: string | ({
|
|
18
|
+
type: 'text';
|
|
19
|
+
text: string;
|
|
20
|
+
} | {
|
|
21
|
+
type: 'image';
|
|
22
|
+
source: {
|
|
22
23
|
type: 'base64';
|
|
23
24
|
media_type: string;
|
|
24
25
|
data: string;
|
|
25
26
|
};
|
|
26
|
-
}
|
|
27
|
-
|
|
27
|
+
} | {
|
|
28
|
+
type: 'tool_result';
|
|
29
|
+
text: string;
|
|
30
|
+
tool_use_id: string;
|
|
31
|
+
})[];
|
|
32
|
+
} | {
|
|
33
|
+
role: 'assistant';
|
|
34
|
+
content: string | ({
|
|
35
|
+
type: 'text';
|
|
36
|
+
text: string;
|
|
37
|
+
} | {
|
|
38
|
+
type: 'tool_use';
|
|
39
|
+
id: string;
|
|
40
|
+
name: string;
|
|
41
|
+
input: object;
|
|
42
|
+
})[];
|
|
43
|
+
})[];
|
|
28
44
|
tools?: {
|
|
29
45
|
name: string;
|
|
30
46
|
description: string;
|
|
@@ -40,7 +56,7 @@ export type AxAnthropicChatRequest = {
|
|
|
40
56
|
user_id: string;
|
|
41
57
|
};
|
|
42
58
|
};
|
|
43
|
-
export type
|
|
59
|
+
export type AxAIAnthropicChatResponse = {
|
|
44
60
|
id: string;
|
|
45
61
|
type: 'message';
|
|
46
62
|
role: 'assistant';
|
|
@@ -59,17 +75,15 @@ export type AxAnthropicChatResponse = {
|
|
|
59
75
|
output_tokens: number;
|
|
60
76
|
};
|
|
61
77
|
};
|
|
62
|
-
export type
|
|
78
|
+
export type AxAIAnthropicChatError = {
|
|
63
79
|
type: 'error';
|
|
64
80
|
error: {
|
|
65
81
|
type: 'authentication_error';
|
|
66
82
|
message: string;
|
|
67
83
|
};
|
|
68
84
|
};
|
|
69
|
-
export interface
|
|
70
|
-
type:
|
|
71
|
-
}
|
|
72
|
-
export interface AxAnthropicMessageStartEvent extends AxAnthropicStreamEvent {
|
|
85
|
+
export interface AxAIAnthropicMessageStartEvent {
|
|
86
|
+
type: 'message_start';
|
|
73
87
|
message: {
|
|
74
88
|
id: string;
|
|
75
89
|
type: 'message';
|
|
@@ -84,49 +98,55 @@ export interface AxAnthropicMessageStartEvent extends AxAnthropicStreamEvent {
|
|
|
84
98
|
};
|
|
85
99
|
};
|
|
86
100
|
}
|
|
87
|
-
export interface
|
|
101
|
+
export interface AxAIAnthropicContentBlockStartEvent {
|
|
88
102
|
index: number;
|
|
103
|
+
type: 'content_block_start';
|
|
89
104
|
content_block: {
|
|
90
105
|
type: 'text';
|
|
91
106
|
text: string;
|
|
107
|
+
} | {
|
|
108
|
+
type: 'tool_use';
|
|
109
|
+
id: string;
|
|
110
|
+
name: string;
|
|
111
|
+
input: object;
|
|
92
112
|
};
|
|
93
113
|
}
|
|
94
|
-
export interface
|
|
114
|
+
export interface AxAIAnthropicContentBlockDeltaEvent {
|
|
95
115
|
index: number;
|
|
116
|
+
type: 'content_block_delta';
|
|
96
117
|
delta: {
|
|
97
118
|
type: 'text_delta';
|
|
98
119
|
text: string;
|
|
120
|
+
} | {
|
|
121
|
+
type: 'input_json_delta';
|
|
122
|
+
partial_json: string;
|
|
99
123
|
};
|
|
100
124
|
}
|
|
101
|
-
export interface
|
|
125
|
+
export interface AxAIAnthropicContentBlockStopEvent {
|
|
126
|
+
type: 'content_block_stop';
|
|
102
127
|
index: number;
|
|
103
128
|
}
|
|
104
|
-
export interface
|
|
129
|
+
export interface AxAIAnthropicMessageDeltaEvent {
|
|
130
|
+
type: 'message_delta';
|
|
105
131
|
delta: {
|
|
106
132
|
stop_reason: 'end_turn' | 'max_tokens' | 'stop_sequence' | null;
|
|
107
133
|
stop_sequence: string | null;
|
|
108
|
-
usage: {
|
|
109
|
-
output_tokens: number;
|
|
110
|
-
};
|
|
111
134
|
};
|
|
135
|
+
usage: {
|
|
136
|
+
output_tokens: number;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
export interface AxAIAnthropicMessageStopEvent {
|
|
140
|
+
type: 'message_stop';
|
|
141
|
+
}
|
|
142
|
+
export interface AxAIAnthropicPingEvent {
|
|
143
|
+
type: 'ping';
|
|
112
144
|
}
|
|
113
|
-
export
|
|
114
|
-
|
|
115
|
-
export interface AxAnthropicErrorEvent extends AxAnthropicStreamEvent {
|
|
145
|
+
export interface AxAIAnthropicErrorEvent {
|
|
146
|
+
type: 'error';
|
|
116
147
|
error: {
|
|
117
|
-
type: 'overloaded_error'
|
|
148
|
+
type: 'overloaded_error';
|
|
118
149
|
message: string;
|
|
119
150
|
};
|
|
120
151
|
}
|
|
121
|
-
export type
|
|
122
|
-
export interface AxAnthropicResponseDelta<T> {
|
|
123
|
-
id: string;
|
|
124
|
-
object: 'message';
|
|
125
|
-
model: string;
|
|
126
|
-
events: T[];
|
|
127
|
-
usage?: {
|
|
128
|
-
input_tokens: number;
|
|
129
|
-
output_tokens: number;
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
export type AxAnthropicChatResponseDelta = AxAnthropicResponseDelta<AxAxAnthropicStreamEventType>;
|
|
152
|
+
export type AxAIAnthropicChatResponseDelta = AxAIAnthropicMessageStartEvent | AxAIAnthropicContentBlockStartEvent | AxAIAnthropicContentBlockDeltaEvent | AxAIAnthropicContentBlockStopEvent | AxAIAnthropicMessageDeltaEvent | AxAIAnthropicMessageStopEvent | AxAIAnthropicPingEvent | AxAIAnthropicErrorEvent;
|