@ax-llm/ax 9.0.19 → 9.0.21
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/package.json +33 -85
- package/CHANGELOG.md +0 -184
- package/LICENSE +0 -201
- package/README.md +0 -569
- package/build/module/docs/assets/icons.d.ts +0 -1
- package/build/module/docs/assets/icons.js +0 -19
- package/build/module/docs/assets/icons.js.map +0 -1
- package/build/module/docs/assets/main.d.ts +0 -1
- package/build/module/docs/assets/main.js +0 -629
- package/build/module/docs/assets/main.js.map +0 -1
- package/build/module/docs/assets/navigation.d.ts +0 -1
- package/build/module/docs/assets/navigation.js +0 -3
- package/build/module/docs/assets/navigation.js.map +0 -1
- package/build/module/docs/assets/search.d.ts +0 -1
- package/build/module/docs/assets/search.js +0 -3
- package/build/module/docs/assets/search.js.map +0 -1
- package/build/module/src/ai/anthropic/api.d.ts +0 -19
- package/build/module/src/ai/anthropic/api.js +0 -326
- package/build/module/src/ai/anthropic/api.js.map +0 -1
- package/build/module/src/ai/anthropic/index.d.ts +0 -2
- package/build/module/src/ai/anthropic/index.js +0 -3
- package/build/module/src/ai/anthropic/index.js.map +0 -1
- package/build/module/src/ai/anthropic/info.d.ts +0 -2
- package/build/module/src/ai/anthropic/info.js +0 -40
- package/build/module/src/ai/anthropic/info.js.map +0 -1
- package/build/module/src/ai/anthropic/types.d.ts +0 -171
- package/build/module/src/ai/anthropic/types.js +0 -10
- package/build/module/src/ai/anthropic/types.js.map +0 -1
- package/build/module/src/ai/azure-openai/api.d.ts +0 -19
- package/build/module/src/ai/azure-openai/api.js +0 -30
- package/build/module/src/ai/azure-openai/api.js.map +0 -1
- package/build/module/src/ai/azure-openai/index.d.ts +0 -1
- package/build/module/src/ai/azure-openai/index.js +0 -2
- package/build/module/src/ai/azure-openai/index.js.map +0 -1
- package/build/module/src/ai/balance.d.ts +0 -23
- package/build/module/src/ai/balance.js +0 -87
- package/build/module/src/ai/balance.js.map +0 -1
- package/build/module/src/ai/base.d.ts +0 -55
- package/build/module/src/ai/base.js +0 -343
- package/build/module/src/ai/base.js.map +0 -1
- package/build/module/src/ai/cohere/api.d.ts +0 -22
- package/build/module/src/ai/cohere/api.js +0 -264
- package/build/module/src/ai/cohere/api.js.map +0 -1
- package/build/module/src/ai/cohere/index.d.ts +0 -2
- package/build/module/src/ai/cohere/index.js +0 -3
- package/build/module/src/ai/cohere/index.js.map +0 -1
- package/build/module/src/ai/cohere/info.d.ts +0 -2
- package/build/module/src/ai/cohere/info.js +0 -52
- package/build/module/src/ai/cohere/info.js.map +0 -1
- package/build/module/src/ai/cohere/types.d.ts +0 -102
- package/build/module/src/ai/cohere/types.js +0 -23
- package/build/module/src/ai/cohere/types.js.map +0 -1
- package/build/module/src/ai/deepseek/api.d.ts +0 -16
- package/build/module/src/ai/deepseek/api.js +0 -32
- package/build/module/src/ai/deepseek/api.js.map +0 -1
- package/build/module/src/ai/deepseek/index.d.ts +0 -2
- package/build/module/src/ai/deepseek/index.js +0 -3
- package/build/module/src/ai/deepseek/index.js.map +0 -1
- package/build/module/src/ai/deepseek/info.d.ts +0 -2
- package/build/module/src/ai/deepseek/info.js +0 -16
- package/build/module/src/ai/deepseek/info.js.map +0 -1
- package/build/module/src/ai/deepseek/types.d.ts +0 -8
- package/build/module/src/ai/deepseek/types.js +0 -10
- package/build/module/src/ai/deepseek/types.js.map +0 -1
- package/build/module/src/ai/google-gemini/api.d.ts +0 -36
- package/build/module/src/ai/google-gemini/api.js +0 -299
- package/build/module/src/ai/google-gemini/api.js.map +0 -1
- package/build/module/src/ai/google-gemini/index.d.ts +0 -2
- package/build/module/src/ai/google-gemini/index.js +0 -3
- package/build/module/src/ai/google-gemini/index.js.map +0 -1
- package/build/module/src/ai/google-gemini/info.d.ts +0 -6
- package/build/module/src/ai/google-gemini/info.js +0 -29
- package/build/module/src/ai/google-gemini/info.js.map +0 -1
- package/build/module/src/ai/google-gemini/types.d.ts +0 -146
- package/build/module/src/ai/google-gemini/types.js +0 -27
- package/build/module/src/ai/google-gemini/types.js.map +0 -1
- package/build/module/src/ai/groq/api.d.ts +0 -18
- package/build/module/src/ai/groq/api.js +0 -52
- package/build/module/src/ai/groq/api.js.map +0 -1
- package/build/module/src/ai/groq/index.d.ts +0 -1
- package/build/module/src/ai/groq/index.js +0 -2
- package/build/module/src/ai/groq/index.js.map +0 -1
- package/build/module/src/ai/groq/types.d.ts +0 -6
- package/build/module/src/ai/groq/types.js +0 -8
- package/build/module/src/ai/groq/types.js.map +0 -1
- package/build/module/src/ai/huggingface/api.d.ts +0 -19
- package/build/module/src/ai/huggingface/api.js +0 -115
- package/build/module/src/ai/huggingface/api.js.map +0 -1
- package/build/module/src/ai/huggingface/index.d.ts +0 -2
- package/build/module/src/ai/huggingface/index.js +0 -3
- package/build/module/src/ai/huggingface/index.js.map +0 -1
- package/build/module/src/ai/huggingface/info.d.ts +0 -6
- package/build/module/src/ai/huggingface/info.js +0 -6
- package/build/module/src/ai/huggingface/info.js.map +0 -1
- package/build/module/src/ai/huggingface/types.d.ts +0 -34
- package/build/module/src/ai/huggingface/types.js +0 -5
- package/build/module/src/ai/huggingface/types.js.map +0 -1
- package/build/module/src/ai/index.d.ts +0 -16
- package/build/module/src/ai/index.js +0 -16
- package/build/module/src/ai/index.js.map +0 -1
- package/build/module/src/ai/mistral/api.d.ts +0 -16
- package/build/module/src/ai/mistral/api.js +0 -32
- package/build/module/src/ai/mistral/api.js.map +0 -1
- package/build/module/src/ai/mistral/index.d.ts +0 -2
- package/build/module/src/ai/mistral/index.js +0 -3
- package/build/module/src/ai/mistral/index.js.map +0 -1
- package/build/module/src/ai/mistral/info.d.ts +0 -2
- package/build/module/src/ai/mistral/info.js +0 -34
- package/build/module/src/ai/mistral/info.js.map +0 -1
- package/build/module/src/ai/mistral/types.d.ts +0 -10
- package/build/module/src/ai/mistral/types.js +0 -13
- package/build/module/src/ai/mistral/types.js.map +0 -1
- package/build/module/src/ai/ollama/api.d.ts +0 -22
- package/build/module/src/ai/ollama/api.js +0 -32
- package/build/module/src/ai/ollama/api.js.map +0 -1
- package/build/module/src/ai/ollama/index.d.ts +0 -1
- package/build/module/src/ai/ollama/index.js +0 -2
- package/build/module/src/ai/ollama/index.js.map +0 -1
- package/build/module/src/ai/openai/api.d.ts +0 -29
- package/build/module/src/ai/openai/api.js +0 -283
- package/build/module/src/ai/openai/api.js.map +0 -1
- package/build/module/src/ai/openai/index.d.ts +0 -2
- package/build/module/src/ai/openai/index.js +0 -3
- package/build/module/src/ai/openai/index.js.map +0 -1
- package/build/module/src/ai/openai/info.d.ts +0 -6
- package/build/module/src/ai/openai/info.js +0 -50
- package/build/module/src/ai/openai/info.js.map +0 -1
- package/build/module/src/ai/openai/types.d.ts +0 -165
- package/build/module/src/ai/openai/types.js +0 -18
- package/build/module/src/ai/openai/types.js.map +0 -1
- package/build/module/src/ai/together/api.d.ts +0 -15
- package/build/module/src/ai/together/api.js +0 -28
- package/build/module/src/ai/together/api.js.map +0 -1
- package/build/module/src/ai/together/index.d.ts +0 -1
- package/build/module/src/ai/together/index.js +0 -2
- package/build/module/src/ai/together/index.js.map +0 -1
- package/build/module/src/ai/together/info.d.ts +0 -2
- package/build/module/src/ai/together/info.js +0 -2
- package/build/module/src/ai/together/info.js.map +0 -1
- package/build/module/src/ai/types.d.ts +0 -159
- package/build/module/src/ai/types.js +0 -2
- package/build/module/src/ai/types.js.map +0 -1
- package/build/module/src/ai/util.d.ts +0 -12
- package/build/module/src/ai/util.js +0 -63
- package/build/module/src/ai/util.js.map +0 -1
- package/build/module/src/ai/wrap.d.ts +0 -47
- package/build/module/src/ai/wrap.js +0 -95
- package/build/module/src/ai/wrap.js.map +0 -1
- package/build/module/src/db/base.d.ts +0 -23
- package/build/module/src/db/base.js +0 -87
- package/build/module/src/db/base.js.map +0 -1
- package/build/module/src/db/cloudflare.d.ts +0 -21
- package/build/module/src/db/cloudflare.js +0 -98
- package/build/module/src/db/cloudflare.js.map +0 -1
- package/build/module/src/db/index.d.ts +0 -6
- package/build/module/src/db/index.js +0 -7
- package/build/module/src/db/index.js.map +0 -1
- package/build/module/src/db/memory.d.ts +0 -21
- package/build/module/src/db/memory.js +0 -99
- package/build/module/src/db/memory.js.map +0 -1
- package/build/module/src/db/pinecone.d.ts +0 -21
- package/build/module/src/db/pinecone.js +0 -71
- package/build/module/src/db/pinecone.js.map +0 -1
- package/build/module/src/db/types.d.ts +0 -35
- package/build/module/src/db/types.js +0 -3
- package/build/module/src/db/types.js.map +0 -1
- package/build/module/src/db/weaviate.d.ts +0 -21
- package/build/module/src/db/weaviate.js +0 -127
- package/build/module/src/db/weaviate.js.map +0 -1
- package/build/module/src/db/wrap.d.ts +0 -13
- package/build/module/src/db/wrap.js +0 -35
- package/build/module/src/db/wrap.js.map +0 -1
- package/build/module/src/docs/index.d.ts +0 -4
- package/build/module/src/docs/index.js +0 -5
- package/build/module/src/docs/index.js.map +0 -1
- package/build/module/src/docs/manager.d.ts +0 -45
- package/build/module/src/docs/manager.js +0 -159
- package/build/module/src/docs/manager.js.map +0 -1
- package/build/module/src/docs/reranker.d.ts +0 -7
- package/build/module/src/docs/reranker.js +0 -26
- package/build/module/src/docs/reranker.js.map +0 -1
- package/build/module/src/docs/rewriter.d.ts +0 -4
- package/build/module/src/docs/rewriter.js +0 -9
- package/build/module/src/docs/rewriter.js.map +0 -1
- package/build/module/src/docs/tika.d.ts +0 -18
- package/build/module/src/docs/tika.js +0 -46
- package/build/module/src/docs/tika.js.map +0 -1
- package/build/module/src/dsp/asserts.d.ts +0 -32
- package/build/module/src/dsp/asserts.js +0 -91
- package/build/module/src/dsp/asserts.js.map +0 -1
- package/build/module/src/dsp/eval.d.ts +0 -43
- package/build/module/src/dsp/eval.js +0 -125
- package/build/module/src/dsp/eval.js.map +0 -1
- package/build/module/src/dsp/evaluate.d.ts +0 -12
- package/build/module/src/dsp/evaluate.js +0 -32
- package/build/module/src/dsp/evaluate.js.map +0 -1
- package/build/module/src/dsp/extract.d.ts +0 -25
- package/build/module/src/dsp/extract.js +0 -153
- package/build/module/src/dsp/extract.js.map +0 -1
- package/build/module/src/dsp/generate.d.ts +0 -55
- package/build/module/src/dsp/generate.js +0 -314
- package/build/module/src/dsp/generate.js.map +0 -1
- package/build/module/src/dsp/generate.test.d.ts +0 -1
- package/build/module/src/dsp/generate.test.js +0 -41
- package/build/module/src/dsp/generate.test.js.map +0 -1
- package/build/module/src/dsp/index.d.ts +0 -15
- package/build/module/src/dsp/index.js +0 -11
- package/build/module/src/dsp/index.js.map +0 -1
- package/build/module/src/dsp/loader.d.ts +0 -30
- package/build/module/src/dsp/loader.js +0 -81
- package/build/module/src/dsp/loader.js.map +0 -1
- package/build/module/src/dsp/optimize.d.ts +0 -27
- package/build/module/src/dsp/optimize.js +0 -95
- package/build/module/src/dsp/optimize.js.map +0 -1
- package/build/module/src/dsp/parser.d.ts +0 -87
- package/build/module/src/dsp/parser.js +0 -1542
- package/build/module/src/dsp/parser.js.map +0 -1
- package/build/module/src/dsp/program.d.ts +0 -73
- package/build/module/src/dsp/program.js +0 -116
- package/build/module/src/dsp/program.js.map +0 -1
- package/build/module/src/dsp/prompt.d.ts +0 -48
- package/build/module/src/dsp/prompt.js +0 -260
- package/build/module/src/dsp/prompt.js.map +0 -1
- package/build/module/src/dsp/registry.d.ts +0 -6
- package/build/module/src/dsp/registry.js +0 -15
- package/build/module/src/dsp/registry.js.map +0 -1
- package/build/module/src/dsp/router.d.ts +0 -26
- package/build/module/src/dsp/router.js +0 -71
- package/build/module/src/dsp/router.js.map +0 -1
- package/build/module/src/dsp/sig.d.ts +0 -37
- package/build/module/src/dsp/sig.js +0 -194
- package/build/module/src/dsp/sig.js.map +0 -1
- package/build/module/src/dsp/sig.test.d.ts +0 -1
- package/build/module/src/dsp/sig.test.js +0 -28
- package/build/module/src/dsp/sig.test.js.map +0 -1
- package/build/module/src/dsp/stopwords.d.ts +0 -1
- package/build/module/src/dsp/stopwords.js +0 -1164
- package/build/module/src/dsp/stopwords.js.map +0 -1
- package/build/module/src/dsp/strutil.d.ts +0 -11
- package/build/module/src/dsp/strutil.js +0 -60
- package/build/module/src/dsp/strutil.js.map +0 -1
- package/build/module/src/dsp/util.d.ts +0 -5
- package/build/module/src/dsp/util.js +0 -76
- package/build/module/src/dsp/util.js.map +0 -1
- package/build/module/src/funcs/code.d.ts +0 -9
- package/build/module/src/funcs/code.js +0 -63
- package/build/module/src/funcs/code.js.map +0 -1
- package/build/module/src/funcs/embed.d.ts +0 -6
- package/build/module/src/funcs/embed.js +0 -29
- package/build/module/src/funcs/embed.js.map +0 -1
- package/build/module/src/funcs/functions.d.ts +0 -16
- package/build/module/src/funcs/functions.js +0 -55
- package/build/module/src/funcs/functions.js.map +0 -1
- package/build/module/src/funcs/index.d.ts +0 -3
- package/build/module/src/funcs/index.js +0 -4
- package/build/module/src/funcs/index.js.map +0 -1
- package/build/module/src/funcs/jsonschema.d.ts +0 -2
- package/build/module/src/funcs/jsonschema.js +0 -97
- package/build/module/src/funcs/jsonschema.js.map +0 -1
- package/build/module/src/index.d.ts +0 -9
- package/build/module/src/index.js.map +0 -1
- package/build/module/src/mem/index.d.ts +0 -2
- package/build/module/src/mem/index.js +0 -3
- package/build/module/src/mem/index.js.map +0 -1
- package/build/module/src/mem/memory.d.ts +0 -16
- package/build/module/src/mem/memory.js +0 -77
- package/build/module/src/mem/memory.js.map +0 -1
- package/build/module/src/mem/types.d.ts +0 -10
- package/build/module/src/mem/types.js +0 -2
- package/build/module/src/mem/types.js.map +0 -1
- package/build/module/src/prompts/agent.d.ts +0 -34
- package/build/module/src/prompts/agent.js +0 -108
- package/build/module/src/prompts/agent.js.map +0 -1
- package/build/module/src/prompts/cot.d.ts +0 -9
- package/build/module/src/prompts/cot.js +0 -17
- package/build/module/src/prompts/cot.js.map +0 -1
- package/build/module/src/prompts/index.d.ts +0 -4
- package/build/module/src/prompts/index.js +0 -5
- package/build/module/src/prompts/index.js.map +0 -1
- package/build/module/src/prompts/prompts.test.d.ts +0 -1
- package/build/module/src/prompts/prompts.test.js +0 -54
- package/build/module/src/prompts/prompts.test.js.map +0 -1
- package/build/module/src/prompts/rag.d.ts +0 -23
- package/build/module/src/prompts/rag.js +0 -30
- package/build/module/src/prompts/rag.js.map +0 -1
- package/build/module/src/prompts/react.d.ts +0 -8
- package/build/module/src/prompts/react.js +0 -22
- package/build/module/src/prompts/react.js.map +0 -1
- package/build/module/src/trace/index.d.ts +0 -171
- package/build/module/src/trace/index.js +0 -67
- package/build/module/src/trace/index.js.map +0 -1
- package/build/module/src/util/apicall.d.ts +0 -18
- package/build/module/src/util/apicall.js +0 -50
- package/build/module/src/util/apicall.js.map +0 -1
- package/build/module/src/util/log.d.ts +0 -14
- package/build/module/src/util/log.js +0 -31
- package/build/module/src/util/log.js.map +0 -1
- package/build/module/src/util/other.d.ts +0 -1
- package/build/module/src/util/other.js +0 -5
- package/build/module/src/util/other.js.map +0 -1
- package/build/module/src/util/rate-limit.d.ts +0 -24
- package/build/module/src/util/rate-limit.js +0 -49
- package/build/module/src/util/rate-limit.js.map +0 -1
- package/build/module/src/util/stream.d.ts +0 -9
- package/build/module/src/util/stream.js +0 -29
- package/build/module/src/util/stream.js.map +0 -1
- package/build/module/src/util/transform.d.ts +0 -7
- package/build/module/src/util/transform.js +0 -59
- package/build/module/src/util/transform.js.map +0 -1
- /package/{build/module/src/index.js → index.js} +0 -0
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import type { ReadableStream } from 'stream/web';
|
|
2
|
-
import type { AxTracer } from '../trace/index.js';
|
|
3
|
-
export type AxModelInfo = {
|
|
4
|
-
name: string;
|
|
5
|
-
currency?: string;
|
|
6
|
-
characterIsToken?: boolean;
|
|
7
|
-
promptTokenCostPer1M?: number;
|
|
8
|
-
completionTokenCostPer1M?: number;
|
|
9
|
-
aliases?: string[];
|
|
10
|
-
};
|
|
11
|
-
export type AxTokenUsage = {
|
|
12
|
-
promptTokens: number;
|
|
13
|
-
completionTokens: number;
|
|
14
|
-
totalTokens: number;
|
|
15
|
-
};
|
|
16
|
-
export type AxModelConfig = {
|
|
17
|
-
maxTokens?: number;
|
|
18
|
-
temperature?: number;
|
|
19
|
-
topP?: number;
|
|
20
|
-
topK?: number;
|
|
21
|
-
presencePenalty?: number;
|
|
22
|
-
frequencyPenalty?: number;
|
|
23
|
-
stopSequences?: string[];
|
|
24
|
-
endSequences?: string[];
|
|
25
|
-
stream?: boolean;
|
|
26
|
-
n?: number;
|
|
27
|
-
};
|
|
28
|
-
export type AxFunctionHandler = (args?: any, extra?: Readonly<{
|
|
29
|
-
sessionId?: string;
|
|
30
|
-
traceId?: string;
|
|
31
|
-
}>) => unknown;
|
|
32
|
-
export type AxFunctionJSONSchema = {
|
|
33
|
-
type: string;
|
|
34
|
-
properties?: Record<string, AxFunctionJSONSchema & {
|
|
35
|
-
enum?: string[];
|
|
36
|
-
description: string;
|
|
37
|
-
}>;
|
|
38
|
-
required?: string[];
|
|
39
|
-
items?: AxFunctionJSONSchema;
|
|
40
|
-
};
|
|
41
|
-
export type AxFunction = {
|
|
42
|
-
name: string;
|
|
43
|
-
description: string;
|
|
44
|
-
parameters?: AxFunctionJSONSchema;
|
|
45
|
-
func?: AxFunctionHandler;
|
|
46
|
-
};
|
|
47
|
-
export type AxChatResponseResult = {
|
|
48
|
-
content?: string;
|
|
49
|
-
name?: string;
|
|
50
|
-
id?: string;
|
|
51
|
-
functionCalls?: {
|
|
52
|
-
id: string;
|
|
53
|
-
type: 'function';
|
|
54
|
-
function: {
|
|
55
|
-
name: string;
|
|
56
|
-
params?: string | object;
|
|
57
|
-
};
|
|
58
|
-
}[];
|
|
59
|
-
finishReason?: 'stop' | 'length' | 'function_call' | 'content_filter' | 'error';
|
|
60
|
-
};
|
|
61
|
-
export type AxChatResponse = {
|
|
62
|
-
sessionId?: string;
|
|
63
|
-
remoteId?: string;
|
|
64
|
-
results: readonly AxChatResponseResult[];
|
|
65
|
-
modelUsage?: AxTokenUsage;
|
|
66
|
-
embedModelUsage?: AxTokenUsage;
|
|
67
|
-
};
|
|
68
|
-
export type AxEmbedResponse = {
|
|
69
|
-
remoteId?: string;
|
|
70
|
-
sessionId?: string;
|
|
71
|
-
embeddings: readonly (readonly number[])[];
|
|
72
|
-
modelUsage?: AxTokenUsage;
|
|
73
|
-
};
|
|
74
|
-
export type AxModelInfoWithProvider = AxModelInfo & {
|
|
75
|
-
provider: string;
|
|
76
|
-
};
|
|
77
|
-
export type AxChatRequest = {
|
|
78
|
-
chatPrompt: Readonly<{
|
|
79
|
-
role: 'system';
|
|
80
|
-
content: string;
|
|
81
|
-
} | {
|
|
82
|
-
role: 'user';
|
|
83
|
-
name?: string;
|
|
84
|
-
content: string | ({
|
|
85
|
-
type: 'text';
|
|
86
|
-
text: string;
|
|
87
|
-
} | {
|
|
88
|
-
type: 'image';
|
|
89
|
-
mimeType: string;
|
|
90
|
-
image: string;
|
|
91
|
-
details?: 'high' | 'low' | 'auto';
|
|
92
|
-
})[];
|
|
93
|
-
} | {
|
|
94
|
-
role: 'assistant';
|
|
95
|
-
content?: string;
|
|
96
|
-
name?: string;
|
|
97
|
-
functionCalls?: {
|
|
98
|
-
id: string;
|
|
99
|
-
type: 'function';
|
|
100
|
-
function: {
|
|
101
|
-
name: string;
|
|
102
|
-
params?: string | object;
|
|
103
|
-
};
|
|
104
|
-
}[];
|
|
105
|
-
} | {
|
|
106
|
-
role: 'function';
|
|
107
|
-
result: string;
|
|
108
|
-
functionId: string;
|
|
109
|
-
}>[];
|
|
110
|
-
functions?: Readonly<{
|
|
111
|
-
name: string;
|
|
112
|
-
description: string;
|
|
113
|
-
parameters?: AxFunctionJSONSchema;
|
|
114
|
-
}>[];
|
|
115
|
-
functionCall?: 'none' | 'auto' | 'required' | {
|
|
116
|
-
type: 'function';
|
|
117
|
-
function: {
|
|
118
|
-
name: string;
|
|
119
|
-
};
|
|
120
|
-
};
|
|
121
|
-
modelConfig?: Readonly<AxModelConfig>;
|
|
122
|
-
model?: string;
|
|
123
|
-
};
|
|
124
|
-
export type AxEmbedRequest = {
|
|
125
|
-
texts?: readonly string[];
|
|
126
|
-
embedModel?: string;
|
|
127
|
-
};
|
|
128
|
-
export type AxRateLimiterFunction = <T = unknown>(reqFunc: () => Promise<T | ReadableStream<T>>, info: Readonly<{
|
|
129
|
-
modelUsage?: AxTokenUsage;
|
|
130
|
-
embedModelUsage?: AxTokenUsage;
|
|
131
|
-
}>) => Promise<T | ReadableStream<T>>;
|
|
132
|
-
export type AxAIPromptConfig = {
|
|
133
|
-
stream?: boolean;
|
|
134
|
-
};
|
|
135
|
-
export type AxAIServiceOptions = {
|
|
136
|
-
debug?: boolean;
|
|
137
|
-
rateLimiter?: AxRateLimiterFunction;
|
|
138
|
-
fetch?: typeof fetch;
|
|
139
|
-
tracer?: AxTracer;
|
|
140
|
-
};
|
|
141
|
-
export type AxAIServiceActionOptions = {
|
|
142
|
-
sessionId?: string;
|
|
143
|
-
traceId?: string;
|
|
144
|
-
};
|
|
145
|
-
export interface AxAIService {
|
|
146
|
-
getName(): string;
|
|
147
|
-
getModelInfo(): Readonly<AxModelInfo & {
|
|
148
|
-
provider: string;
|
|
149
|
-
}>;
|
|
150
|
-
getEmbedModelInfo(): Readonly<AxModelInfo> | undefined;
|
|
151
|
-
getModelConfig(): Readonly<AxModelConfig>;
|
|
152
|
-
getFeatures(): {
|
|
153
|
-
functions: boolean;
|
|
154
|
-
streaming: boolean;
|
|
155
|
-
};
|
|
156
|
-
chat(req: Readonly<AxChatRequest>, options?: Readonly<AxAIPromptConfig & AxAIServiceActionOptions>): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
|
|
157
|
-
embed(req: Readonly<AxEmbedRequest>, options?: Readonly<AxAIServiceActionOptions & AxAIServiceActionOptions>): Promise<AxEmbedResponse>;
|
|
158
|
-
setOptions(options: Readonly<AxAIServiceOptions>): void;
|
|
159
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/ai/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { AxChatResponseResult, AxModelInfo } from './types.js';
|
|
2
|
-
export declare const findItemByNameOrAlias: (list: readonly AxModelInfo[], name: string) => AxModelInfo | undefined;
|
|
3
|
-
export declare const uniqBy: <T>(array: readonly T[], uniqueField: (value: T) => unknown) => T[];
|
|
4
|
-
export declare const parseFunction: (value: string) => {
|
|
5
|
-
name: string;
|
|
6
|
-
args?: string;
|
|
7
|
-
} | undefined;
|
|
8
|
-
export interface mergeFunctionsState {
|
|
9
|
-
lastId?: string;
|
|
10
|
-
}
|
|
11
|
-
export declare function mergeFunctionCalls(functionCalls: NonNullable<AxChatResponseResult['functionCalls']>, functionCallDeltas: Readonly<NonNullable<AxChatResponseResult['functionCalls']>>): void;
|
|
12
|
-
export declare const hashObject: (obj: object) => string;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
-
import { createHash } from 'crypto';
|
|
3
|
-
export const findItemByNameOrAlias = (list, name) => {
|
|
4
|
-
for (const item of list) {
|
|
5
|
-
if (item.name === name || item.aliases?.includes(name)) {
|
|
6
|
-
return item;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return undefined;
|
|
10
|
-
};
|
|
11
|
-
export const uniqBy = (array, uniqueField) => {
|
|
12
|
-
const uniqueValues = new Map();
|
|
13
|
-
array.forEach((value) => {
|
|
14
|
-
const field = uniqueField(value);
|
|
15
|
-
if (!uniqueValues.has(field)) {
|
|
16
|
-
uniqueValues.set(field, value);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
return Array.from(uniqueValues.values());
|
|
20
|
-
};
|
|
21
|
-
const functionCallRe = /(\w+)\((.*)\)/s;
|
|
22
|
-
export const parseFunction = (value) => {
|
|
23
|
-
let v;
|
|
24
|
-
// extract function calls
|
|
25
|
-
if ((v = functionCallRe.exec(value)) !== null) {
|
|
26
|
-
const name = v.at(1)?.trim();
|
|
27
|
-
const args = v.at(2)?.trim();
|
|
28
|
-
if (!name || name) {
|
|
29
|
-
throw new Error(`Invalid function format: ${value}`);
|
|
30
|
-
}
|
|
31
|
-
return { name, args };
|
|
32
|
-
}
|
|
33
|
-
return;
|
|
34
|
-
};
|
|
35
|
-
export function mergeFunctionCalls(
|
|
36
|
-
// eslint-disable-next-line functional/prefer-immutable-types
|
|
37
|
-
functionCalls, functionCallDeltas) {
|
|
38
|
-
for (const _fc of functionCallDeltas) {
|
|
39
|
-
const fc = functionCalls.find((fc) => fc.id === _fc.id);
|
|
40
|
-
if (fc) {
|
|
41
|
-
if (typeof _fc.function.name == 'string' &&
|
|
42
|
-
_fc.function.name.length > 0) {
|
|
43
|
-
fc.function.name += _fc.function.name;
|
|
44
|
-
}
|
|
45
|
-
if (typeof _fc.function.params == 'string' &&
|
|
46
|
-
_fc.function.params.length > 0) {
|
|
47
|
-
fc.function.params += _fc.function.params;
|
|
48
|
-
}
|
|
49
|
-
if (typeof _fc.function.params == 'object') {
|
|
50
|
-
fc.function.params = _fc.function.params;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
functionCalls.push(_fc);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
export const hashObject = (obj) => {
|
|
59
|
-
const hash = createHash('sha256');
|
|
60
|
-
hash.update(JSON.stringify(obj));
|
|
61
|
-
return hash.digest('hex');
|
|
62
|
-
};
|
|
63
|
-
//# sourceMappingURL=util.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../../src/ai/util.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAIpC,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,IAA4B,EAC5B,IAAY,EACa,EAAE;IAC3B,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;QACxB,IAAI,IAAI,CA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,GAAG,CAAC,CAAC,CAAC;IACjC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC,CAAC"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { ReadableStream } from 'stream/web';
|
|
2
|
-
import { type AxAIAnthropicArgs } from './anthropic/api.js';
|
|
3
|
-
import type { AxAIAnthropicModel } from './anthropic/types.js';
|
|
4
|
-
import { type AxAIAzureOpenAIArgs } from './azure-openai/api.js';
|
|
5
|
-
import { type AxAICohereArgs } from './cohere/api.js';
|
|
6
|
-
import type { AxAICohereEmbedModel, AxAICohereModel } from './cohere/types.js';
|
|
7
|
-
import { type AxAIDeepSeekArgs } from './deepseek/api.js';
|
|
8
|
-
import type { AxAIDeepSeekModel } from './deepseek/types.js';
|
|
9
|
-
import { type AxAIGoogleGeminiArgs } from './google-gemini/api.js';
|
|
10
|
-
import type { AxAIGoogleGeminiEmbedModel, AxAIGoogleGeminiModel } from './google-gemini/types.js';
|
|
11
|
-
import { type AxAIGroqArgs } from './groq/api.js';
|
|
12
|
-
import type { AxAIGroqModel } from './groq/types.js';
|
|
13
|
-
import { type AxAIHuggingFaceArgs } from './huggingface/api.js';
|
|
14
|
-
import type { AxAIHuggingFaceModel } from './huggingface/types.js';
|
|
15
|
-
import { type AxAIMistralArgs } from './mistral/api.js';
|
|
16
|
-
import type { AxAIMistralModel } from './mistral/types.js';
|
|
17
|
-
import { type AxAIOllamaArgs } from './ollama/api.js';
|
|
18
|
-
import { type AxAIOpenAIArgs as AxAIOpenAIArgs } from './openai/api.js';
|
|
19
|
-
import type { AxAIOpenAIEmbedModel, AxAIOpenAIModel } from './openai/types.js';
|
|
20
|
-
import { type AxAITogetherArgs } from './together/api.js';
|
|
21
|
-
import type { AxAIPromptConfig, AxAIService, AxAIServiceActionOptions, AxAIServiceOptions, AxChatRequest, AxChatResponse, AxEmbedRequest, AxEmbedResponse, AxModelConfig, AxModelInfo } from './types.js';
|
|
22
|
-
export type AxAIModelMap<T> = Record<string, T>;
|
|
23
|
-
export interface AxAIOptions<TM = string, TEM = string> {
|
|
24
|
-
modelMap?: AxAIModelMap<TM>;
|
|
25
|
-
embedModelMap?: AxAIModelMap<TEM>;
|
|
26
|
-
}
|
|
27
|
-
export type AxAIArgs = (AxAIOpenAIArgs & AxAIOptions<AxAIOpenAIModel, AxAIOpenAIEmbedModel>) | (AxAIAzureOpenAIArgs & AxAIOptions<AxAIOpenAIModel, AxAIOpenAIEmbedModel>) | (AxAITogetherArgs & AxAIOptions<string, string>) | (AxAIAnthropicArgs & AxAIOptions<AxAIAnthropicModel, AxAIAnthropicModel>) | (AxAIGroqArgs & AxAIOptions<AxAIGroqModel, AxAIGroqModel>) | (AxAIGoogleGeminiArgs & AxAIOptions<AxAIGoogleGeminiModel, AxAIGoogleGeminiEmbedModel>) | (AxAICohereArgs & AxAIOptions<AxAICohereModel, AxAICohereEmbedModel>) | (AxAIHuggingFaceArgs & AxAIOptions<AxAIHuggingFaceModel, AxAIHuggingFaceModel>) | (AxAIMistralArgs & AxAIOptions<AxAIMistralModel, AxAIMistralModel>) | (AxAIDeepSeekArgs & AxAIOptions<AxAIDeepSeekModel, AxAIDeepSeekModel>) | (AxAIOllamaArgs & AxAIOptions<string, string>);
|
|
28
|
-
export type AxAIModels = AxAIOpenAIModel | AxAIAnthropicModel | AxAIGroqModel | AxAIGoogleGeminiModel | AxAICohereModel | AxAIHuggingFaceModel | AxAIMistralModel | AxAIDeepSeekModel | string;
|
|
29
|
-
export type AxAIEmbedModels = AxAIOpenAIEmbedModel | AxAIGoogleGeminiEmbedModel | AxAICohereEmbedModel | string;
|
|
30
|
-
export declare class AxAI implements AxAIService {
|
|
31
|
-
private ai;
|
|
32
|
-
private options;
|
|
33
|
-
constructor(options: Readonly<AxAIArgs>);
|
|
34
|
-
getName(): string;
|
|
35
|
-
getModelInfo(): Readonly<AxModelInfo & {
|
|
36
|
-
provider: string;
|
|
37
|
-
}>;
|
|
38
|
-
getEmbedModelInfo(): Readonly<AxModelInfo> | undefined;
|
|
39
|
-
getModelConfig(): Readonly<AxModelConfig>;
|
|
40
|
-
getFeatures(): {
|
|
41
|
-
functions: boolean;
|
|
42
|
-
streaming: boolean;
|
|
43
|
-
};
|
|
44
|
-
chat(req: Readonly<AxChatRequest>, options?: Readonly<AxAIPromptConfig & AxAIServiceActionOptions>): Promise<AxChatResponse | ReadableStream<AxChatResponse>>;
|
|
45
|
-
embed(req: Readonly<AxEmbedRequest>, options?: Readonly<AxAIServiceActionOptions & AxAIServiceActionOptions>): Promise<AxEmbedResponse>;
|
|
46
|
-
setOptions(options: Readonly<AxAIServiceOptions>): void;
|
|
47
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { AxAIAnthropic } from './anthropic/api.js';
|
|
2
|
-
import { AxAIAzureOpenAI } from './azure-openai/api.js';
|
|
3
|
-
import { AxAICohere } from './cohere/api.js';
|
|
4
|
-
import { AxAIDeepSeek } from './deepseek/api.js';
|
|
5
|
-
import { AxAIGoogleGemini } from './google-gemini/api.js';
|
|
6
|
-
import { AxAIGroq } from './groq/api.js';
|
|
7
|
-
import { AxAIHuggingFace } from './huggingface/api.js';
|
|
8
|
-
import { AxAIMistral } from './mistral/api.js';
|
|
9
|
-
import { AxAIOllama } from './ollama/api.js';
|
|
10
|
-
import { AxAIOpenAI } from './openai/api.js';
|
|
11
|
-
import { AxAITogether } from './together/api.js';
|
|
12
|
-
export class AxAI {
|
|
13
|
-
ai;
|
|
14
|
-
options;
|
|
15
|
-
constructor(options) {
|
|
16
|
-
const { modelMap, embedModelMap, ...args } = options;
|
|
17
|
-
this.options = { modelMap, embedModelMap };
|
|
18
|
-
switch (args.name) {
|
|
19
|
-
case 'openai':
|
|
20
|
-
this.ai = new AxAIOpenAI(args);
|
|
21
|
-
break;
|
|
22
|
-
case 'azure-openai':
|
|
23
|
-
this.ai = new AxAIAzureOpenAI(args);
|
|
24
|
-
break;
|
|
25
|
-
case 'huggingface':
|
|
26
|
-
this.ai = new AxAIHuggingFace(args);
|
|
27
|
-
break;
|
|
28
|
-
case 'groq':
|
|
29
|
-
this.ai = new AxAIGroq(args);
|
|
30
|
-
break;
|
|
31
|
-
case 'together':
|
|
32
|
-
this.ai = new AxAITogether(args);
|
|
33
|
-
break;
|
|
34
|
-
case 'cohere':
|
|
35
|
-
this.ai = new AxAICohere(args);
|
|
36
|
-
break;
|
|
37
|
-
case 'google-gemini':
|
|
38
|
-
this.ai = new AxAIGoogleGemini(args);
|
|
39
|
-
break;
|
|
40
|
-
case 'anthropic':
|
|
41
|
-
this.ai = new AxAIAnthropic(args);
|
|
42
|
-
break;
|
|
43
|
-
case 'mistral':
|
|
44
|
-
this.ai = new AxAIMistral(args);
|
|
45
|
-
break;
|
|
46
|
-
case 'deepseek':
|
|
47
|
-
this.ai = new AxAIDeepSeek(args);
|
|
48
|
-
break;
|
|
49
|
-
case 'ollama':
|
|
50
|
-
this.ai = new AxAIOllama(args);
|
|
51
|
-
break;
|
|
52
|
-
default:
|
|
53
|
-
throw new Error(`Unknown AI`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
getName() {
|
|
57
|
-
return this.ai.getName();
|
|
58
|
-
}
|
|
59
|
-
getModelInfo() {
|
|
60
|
-
return this.ai.getModelInfo();
|
|
61
|
-
}
|
|
62
|
-
getEmbedModelInfo() {
|
|
63
|
-
return this.ai.getEmbedModelInfo();
|
|
64
|
-
}
|
|
65
|
-
getModelConfig() {
|
|
66
|
-
return this.ai.getModelConfig();
|
|
67
|
-
}
|
|
68
|
-
getFeatures() {
|
|
69
|
-
return this.ai.getFeatures();
|
|
70
|
-
}
|
|
71
|
-
async chat(req, options) {
|
|
72
|
-
if (this.options?.modelMap && req.model) {
|
|
73
|
-
const model = this.options.modelMap[req.model];
|
|
74
|
-
if (!model || model.length === 0) {
|
|
75
|
-
throw new Error(`Model not found in model map: ${req.model}`);
|
|
76
|
-
}
|
|
77
|
-
return await this.ai.chat({ ...req, model }, options);
|
|
78
|
-
}
|
|
79
|
-
return await this.ai.chat(req, options);
|
|
80
|
-
}
|
|
81
|
-
async embed(req, options) {
|
|
82
|
-
if (this.options?.embedModelMap && req.embedModel) {
|
|
83
|
-
const embedModel = this.options.embedModelMap[req.embedModel];
|
|
84
|
-
if (!embedModel || embedModel.length === 0) {
|
|
85
|
-
throw new Error(`Model not found in embed model map: ${req.embedModel}`);
|
|
86
|
-
}
|
|
87
|
-
return await this.ai.embed({ ...req, embedModel }, options);
|
|
88
|
-
}
|
|
89
|
-
return await this.ai.embed(req, options);
|
|
90
|
-
}
|
|
91
|
-
setOptions(options) {
|
|
92
|
-
this.ai.setOptions(options);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
//# sourceMappingURL=wrap.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wrap.js","sourceRoot":"","sources":["../../../../src/ai/wrap.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAA0B,MAAM,oBAAoB,CAAC;AAE3E,OAAO,EACL,eAAe,EAEhB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAuB,MAAM,iBAAiB,CAAC;AAElE,OAAO,EAAE,YAAY,EAAyB,MAAM,mBAAmB,CAAC;AAExE,OAAO,EACL,gBAAgB,EAEjB,MAAM,wBAAwB,CAAC;AAKhC,OAAO,EAAE,QAAQ,EAAqB,MAAM,eAAe,CAAC;AAE5D,OAAO,EACL,eAAe,EAEhB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,WAAW,EAAwB,MAAM,kBAAkB,CAAC;AAErE,OAAO,EAAE,UAAU,EAAuB,MAAM,iBAAiB,CAAC;AAClE,OAAO,EACL,UAAU,EAEX,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,YAAY,EAAyB,MAAM,mBAAmB,CAAC;AAqDxE,MAAM,OAAO,IAAI;IACP,EAAE,CAAc;IAChB,OAAO,CAAc;IAE7B,YAAY,OAA2B;QACrC,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MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAC9D,IAAI,CAAC,UAAU,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC3C,MAAM,IAAI,KAAK,CACb,uCAAuC,GAAG,CAAC,UAAU,EAAE,CACxD,CAAC;YACJ,CAAC;YACD,OAAO,MAAM,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,GAAG,GAAG,EAAE,UAAU,EAAE,EAAE,OAAO,CAAC,CAAC;QAC9D,CAAC;QACD,OAAO,MAAM,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED,UAAU,CAAC,OAAqC;QAC9C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAC9B,CAAC;CACF"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { type AxSpan, type AxTracer } from '../trace/index.js';
|
|
2
|
-
import type { AxDBQueryRequest, AxDBQueryResponse, AxDBService, AxDBUpsertRequest, AxDBUpsertResponse } from './types.js';
|
|
3
|
-
export interface AxDBBaseArgs {
|
|
4
|
-
fetch?: typeof fetch;
|
|
5
|
-
tracer?: AxTracer;
|
|
6
|
-
}
|
|
7
|
-
export interface AxDBBaseOpOptions {
|
|
8
|
-
span?: AxSpan;
|
|
9
|
-
}
|
|
10
|
-
export declare class AxDBBase implements AxDBService {
|
|
11
|
-
protected name: string;
|
|
12
|
-
protected fetch?: typeof fetch;
|
|
13
|
-
private tracer?;
|
|
14
|
-
_upsert?: (req: Readonly<AxDBUpsertRequest>, update?: boolean, options?: Readonly<AxDBBaseOpOptions>) => Promise<AxDBUpsertResponse>;
|
|
15
|
-
_batchUpsert?: (batchReq: Readonly<AxDBUpsertRequest[]>, update?: boolean, options?: Readonly<AxDBBaseOpOptions>) => Promise<AxDBUpsertResponse>;
|
|
16
|
-
_query?: (req: Readonly<AxDBQueryRequest>, options?: Readonly<AxDBBaseOpOptions>) => Promise<AxDBQueryResponse>;
|
|
17
|
-
constructor({ name, fetch, tracer }: Readonly<AxDBBaseArgs & {
|
|
18
|
-
name: string;
|
|
19
|
-
}>);
|
|
20
|
-
upsert(req: Readonly<AxDBUpsertRequest>, update?: boolean): Promise<AxDBUpsertResponse>;
|
|
21
|
-
batchUpsert(req: Readonly<AxDBUpsertRequest[]>, update?: boolean): Promise<AxDBUpsertResponse>;
|
|
22
|
-
query(req: Readonly<AxDBQueryRequest>): Promise<AxDBQueryResponse>;
|
|
23
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { axSpanAttributes, AxSpanKind } from '../trace/index.js';
|
|
2
|
-
export class AxDBBase {
|
|
3
|
-
name;
|
|
4
|
-
fetch;
|
|
5
|
-
tracer;
|
|
6
|
-
_upsert;
|
|
7
|
-
_batchUpsert;
|
|
8
|
-
_query;
|
|
9
|
-
constructor({ name, fetch, tracer }) {
|
|
10
|
-
this.name = name;
|
|
11
|
-
this.fetch = fetch;
|
|
12
|
-
this.tracer = tracer;
|
|
13
|
-
}
|
|
14
|
-
async upsert(req, update) {
|
|
15
|
-
if (!this._upsert) {
|
|
16
|
-
throw new Error('upsert() not implemented');
|
|
17
|
-
}
|
|
18
|
-
if (!this.tracer) {
|
|
19
|
-
return await this._upsert(req, update);
|
|
20
|
-
}
|
|
21
|
-
return await this.tracer?.startActiveSpan('DB Upsert Request', {
|
|
22
|
-
kind: AxSpanKind.SERVER,
|
|
23
|
-
attributes: {
|
|
24
|
-
[axSpanAttributes.DB_SYSTEM]: this.name,
|
|
25
|
-
[axSpanAttributes.DB_OPERATION_NAME]: 'upsert',
|
|
26
|
-
[axSpanAttributes.DB_TABLE]: req.table,
|
|
27
|
-
[axSpanAttributes.DB_NAMESPACE]: req.namespace,
|
|
28
|
-
[axSpanAttributes.DB_OPERATION_NAME]: update ? 'update' : 'insert'
|
|
29
|
-
}
|
|
30
|
-
}, async (span) => {
|
|
31
|
-
const res = await this._upsert(req, update, { span });
|
|
32
|
-
span.end();
|
|
33
|
-
return res;
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
async batchUpsert(req, update) {
|
|
37
|
-
if (!this._batchUpsert) {
|
|
38
|
-
throw new Error('batchUpsert() not implemented');
|
|
39
|
-
}
|
|
40
|
-
if (req.length == 0) {
|
|
41
|
-
throw new Error('Batch request is empty');
|
|
42
|
-
}
|
|
43
|
-
if (!req[0]) {
|
|
44
|
-
throw new Error('Batch request is invalid first element is undefined');
|
|
45
|
-
}
|
|
46
|
-
if (!this.tracer) {
|
|
47
|
-
return await this._batchUpsert(req, update);
|
|
48
|
-
}
|
|
49
|
-
return await this.tracer?.startActiveSpan('DB Batch Upsert Request', {
|
|
50
|
-
kind: AxSpanKind.SERVER,
|
|
51
|
-
attributes: {
|
|
52
|
-
[axSpanAttributes.DB_SYSTEM]: this.name,
|
|
53
|
-
[axSpanAttributes.DB_OPERATION_NAME]: 'upsert',
|
|
54
|
-
[axSpanAttributes.DB_TABLE]: req[0].table,
|
|
55
|
-
[axSpanAttributes.DB_NAMESPACE]: req[0].namespace,
|
|
56
|
-
[axSpanAttributes.DB_OPERATION_NAME]: update ? 'update' : 'insert'
|
|
57
|
-
}
|
|
58
|
-
}, async (span) => {
|
|
59
|
-
const res = await this._batchUpsert(req, update, { span });
|
|
60
|
-
span.end();
|
|
61
|
-
return res;
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
async query(req) {
|
|
65
|
-
if (!this._query) {
|
|
66
|
-
throw new Error('query() not implemented');
|
|
67
|
-
}
|
|
68
|
-
if (!this.tracer) {
|
|
69
|
-
return await this._query(req);
|
|
70
|
-
}
|
|
71
|
-
return await this.tracer?.startActiveSpan('DB Query Request', {
|
|
72
|
-
kind: AxSpanKind.SERVER,
|
|
73
|
-
attributes: {
|
|
74
|
-
[axSpanAttributes.DB_SYSTEM]: this.name,
|
|
75
|
-
[axSpanAttributes.DB_OPERATION_NAME]: 'upsert',
|
|
76
|
-
[axSpanAttributes.DB_TABLE]: req.table,
|
|
77
|
-
[axSpanAttributes.DB_NAMESPACE]: req.namespace,
|
|
78
|
-
[axSpanAttributes.DB_OPERATION_NAME]: 'query'
|
|
79
|
-
}
|
|
80
|
-
}, async (span) => {
|
|
81
|
-
const res = await this._query(req, { span });
|
|
82
|
-
span.end();
|
|
83
|
-
return res;
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
//# sourceMappingURL=base.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/db/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,gBAAgB,EAChB,UAAU,EAEX,MAAM,mBAAmB,CAAC;AAmB3B,MAAM,OAAO,QAAQ;IACT,IAAI,CAAS;IACb,KAAK,CAAgB;IACvB,MAAM,CAAY;IAE1B,OAAO,CAI0B;IAEjC,YAAY,CAIqB;IAEjC,MAAM,CAG0B;IAEhC,YAAY,EACV,IAAI,EACJ,KAAK,EACL,MAAM,EACoC;QAC1C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,MAAM,CACV,GAAgC,EAChC,MAAgB;QAEhB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC9C,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QACzC,CAAC;QAED,OAAO,MAAM,IAAI,CAAC,MAAM,EAAE,eAAe,CACvC,mBAAmB,EACnB;YACE,IAAI,EAAE,UAAU,CAAC,MAAM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,KAAK;gBACtC,CAAC,gBAAgB,CAAC,YAAY,CAAC,EAAE,GAAG,CAAC,SAAS;gBAC9C,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,EAAE,OAAO;aAC9C;SACF,EACD,KAAK,EAAE,IAAI,EAAE,EAAE;YACb,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAO,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;YAC9C,IAAI,CAAC,GAAG,EAAE,CAAC;YACX,OAAO,GAAG,CAAC;QACb,CAAC,CACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { AxDBBase, type AxDBBaseArgs, type AxDBBaseOpOptions } from './base.js';
|
|
2
|
-
import type { AxDBQueryRequest, AxDBQueryResponse, AxDBUpsertRequest, AxDBUpsertResponse } from './types.js';
|
|
3
|
-
export type AxDBCloudflareOpOptions = AxDBBaseOpOptions;
|
|
4
|
-
export interface AxDBCloudflareArgs extends AxDBBaseArgs {
|
|
5
|
-
name: 'cloudflare';
|
|
6
|
-
apiKey: string;
|
|
7
|
-
accountId: string;
|
|
8
|
-
fetch?: typeof fetch;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Cloudflare: DB Service
|
|
12
|
-
* @export
|
|
13
|
-
*/
|
|
14
|
-
export declare class AxDBCloudflare extends AxDBBase {
|
|
15
|
-
private apiKey;
|
|
16
|
-
private accountId;
|
|
17
|
-
constructor({ apiKey, accountId, fetch, tracer }: Readonly<Omit<AxDBCloudflareArgs, 'name'>>);
|
|
18
|
-
_upsert: (req: Readonly<AxDBUpsertRequest>, update?: boolean, options?: Readonly<AxDBCloudflareOpOptions>) => Promise<AxDBUpsertResponse>;
|
|
19
|
-
batchUpsert: (batchReq: Readonly<AxDBUpsertRequest[]>, update?: boolean, options?: Readonly<AxDBCloudflareOpOptions>) => Promise<AxDBUpsertResponse>;
|
|
20
|
-
query: (req: Readonly<AxDBQueryRequest>, options?: Readonly<AxDBCloudflareOpOptions>) => Promise<AxDBQueryResponse>;
|
|
21
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { apiCall } from '../util/apicall.js';
|
|
2
|
-
import { AxDBBase } from './base.js';
|
|
3
|
-
const baseURL = 'https://api.cloudflare.com/client/v4/accounts/';
|
|
4
|
-
/**
|
|
5
|
-
* Cloudflare: DB Service
|
|
6
|
-
* @export
|
|
7
|
-
*/
|
|
8
|
-
export class AxDBCloudflare extends AxDBBase {
|
|
9
|
-
apiKey;
|
|
10
|
-
accountId;
|
|
11
|
-
constructor({ apiKey, accountId, fetch, tracer }) {
|
|
12
|
-
if (!apiKey || !accountId) {
|
|
13
|
-
throw new Error('Cloudflare credentials not set');
|
|
14
|
-
}
|
|
15
|
-
super({ name: 'Cloudflare', fetch, tracer });
|
|
16
|
-
this.apiKey = apiKey;
|
|
17
|
-
this.accountId = accountId;
|
|
18
|
-
}
|
|
19
|
-
_upsert = async (req, update, options) => {
|
|
20
|
-
const res = (await apiCall({
|
|
21
|
-
url: new URL(`${this.accountId}/vectorize/indexes/${req.table}/upsert`, baseURL),
|
|
22
|
-
headers: {
|
|
23
|
-
'X-Auth-Key': this.apiKey
|
|
24
|
-
},
|
|
25
|
-
fetch: this.fetch,
|
|
26
|
-
span: options?.span
|
|
27
|
-
}, {
|
|
28
|
-
id: req.id,
|
|
29
|
-
values: req.values,
|
|
30
|
-
namespace: req.namespace,
|
|
31
|
-
metadata: req.metadata
|
|
32
|
-
}));
|
|
33
|
-
if (res.errors) {
|
|
34
|
-
throw new Error(`Cloudflare upsert failed: ${res.errors.map(({ message }) => message).join(', ')}`);
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
ids: res.result.ids
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
batchUpsert = async (batchReq, update, options) => {
|
|
41
|
-
if (update) {
|
|
42
|
-
throw new Error('Weaviate does not support batch update');
|
|
43
|
-
}
|
|
44
|
-
if (batchReq.length < 1) {
|
|
45
|
-
throw new Error('Batch request is empty');
|
|
46
|
-
}
|
|
47
|
-
if (!batchReq[0] || !batchReq[0].table) {
|
|
48
|
-
throw new Error('Table name is empty');
|
|
49
|
-
}
|
|
50
|
-
const table = batchReq[0].table;
|
|
51
|
-
const res = (await apiCall({
|
|
52
|
-
url: new URL(`${this.accountId}/vectorize/indexes/${table}/upsert`, baseURL),
|
|
53
|
-
headers: {
|
|
54
|
-
'X-Auth-Key': this.apiKey
|
|
55
|
-
},
|
|
56
|
-
fetch: this.fetch,
|
|
57
|
-
span: options?.span
|
|
58
|
-
}, batchReq.map((req) => ({
|
|
59
|
-
id: req.id,
|
|
60
|
-
values: req.values,
|
|
61
|
-
namespace: req.namespace,
|
|
62
|
-
metadata: req.metadata
|
|
63
|
-
}))));
|
|
64
|
-
if (res.errors) {
|
|
65
|
-
throw new Error(`Cloudflare batch upsert failed: ${res.errors
|
|
66
|
-
.map(({ message }) => message)
|
|
67
|
-
.join(', ')}`);
|
|
68
|
-
}
|
|
69
|
-
return {
|
|
70
|
-
ids: res.result.ids
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
query = async (req, options) => {
|
|
74
|
-
const res = (await apiCall({
|
|
75
|
-
url: new URL(`${this.accountId}/vectorize/indexes/${req.table}/query`, baseURL),
|
|
76
|
-
headers: {
|
|
77
|
-
'X-Auth-Key': this.apiKey
|
|
78
|
-
},
|
|
79
|
-
fetch: this.fetch,
|
|
80
|
-
span: options?.span
|
|
81
|
-
}, {
|
|
82
|
-
vector: req.values,
|
|
83
|
-
topK: req.limit || 10,
|
|
84
|
-
returnValues: true
|
|
85
|
-
}));
|
|
86
|
-
if (res.errors) {
|
|
87
|
-
throw new Error(`Cloudflare query failed: ${res.errors.map(({ message }) => message).join(', ')}`);
|
|
88
|
-
}
|
|
89
|
-
const matches = res.result.matches.map(({ id, score, values, metadata }) => ({
|
|
90
|
-
id,
|
|
91
|
-
score,
|
|
92
|
-
values,
|
|
93
|
-
metadata
|
|
94
|
-
}));
|
|
95
|
-
return { matches };
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
//# sourceMappingURL=cloudflare.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cloudflare.js","sourceRoot":"","sources":["../../../../src/db/cloudflare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,OAAO,EAAE,QAAQ,EAA6C,MAAM,WAAW,CAAC;AAQhF,MAAM,OAAO,GAAG,gDAAgD,CAAC;AA8BjE;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,QAAQ;IAClC,MAAM,CAAS;IACf,SAAS,CAAS;IAE1B,YAAY,EACV,MAAM,EACN,SAAS,EACT,KAAK,EACL,MAAM,EACqC;QAC3C,IAAI,CAAC,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;YAC1B,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACpD,CAAC;QACD,KAAK,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QAC7C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAEQ,OAAO,GAAG,KAAK,EACtB,GAAgC,EAChC,MAAgB,EAChB,OAA2C,EACd,EAAE;QAC/B,MAAM,GAAG,GAAG,CAAC,MAAM,OAAO,CACxB;YACE,GAAG,EAAE,IAAI,GAAG,CACV,GAAG,IAAI,CAAC,SAAS,sBAAsB,GAAG,CAAC,KAAK,SAAS,EACzD,OAAO,CACR;YACD,OAAO,EAAE;gBACP,YAAY,EAAE,IAAI,CAAC,MAAM;aAC1B;YACD,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,IAAI,EAAE,OAAO,EAAE,IAAI;SACpB,EACD;YACE,EAAE,EAAE,GAAG,CAAC,EAAE;YACV,MAAM,EAAE,GA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