llm-exe 2.3.6 → 2.3.8
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/dist/index.d.mts +15 -2
- package/dist/index.d.ts +15 -2
- package/dist/index.js +146 -74
- package/dist/index.mjs +146 -74
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -996,6 +996,10 @@ interface AmazonEmbeddingOptions extends GenericEmbeddingOptions {
|
|
|
996
996
|
awsSecretKey?: string;
|
|
997
997
|
awsAccessKey?: string;
|
|
998
998
|
}
|
|
999
|
+
interface CohereBedrockEmbeddingOptions extends AmazonEmbeddingOptions {
|
|
1000
|
+
inputType?: "search_document" | "search_query" | "classification" | "clustering";
|
|
1001
|
+
truncate?: "NONE" | "START" | "END" | "LEFT" | "RIGHT";
|
|
1002
|
+
}
|
|
999
1003
|
interface GenericLLm extends BaseLlmOptions {
|
|
1000
1004
|
model?: string;
|
|
1001
1005
|
system?: string;
|
|
@@ -1059,6 +1063,9 @@ type AllEmbedding = {
|
|
|
1059
1063
|
"amazon.embedding.v1": {
|
|
1060
1064
|
input: AmazonEmbeddingOptions;
|
|
1061
1065
|
};
|
|
1066
|
+
"amazon:cohere.embedding.v1": {
|
|
1067
|
+
input: CohereBedrockEmbeddingOptions;
|
|
1068
|
+
};
|
|
1062
1069
|
};
|
|
1063
1070
|
type AllLlm = {
|
|
1064
1071
|
"openai.chat.v1": {
|
|
@@ -1255,7 +1262,7 @@ interface BaseRequest<_T extends Record<string, any>> {
|
|
|
1255
1262
|
interface BaseLlm<_T extends BaseLlCall = BaseLlCall> extends BaseRequest<_T> {
|
|
1256
1263
|
}
|
|
1257
1264
|
|
|
1258
|
-
type LlmProvider = "openai.chat" | "openai.embedding" | "google.embedding" | "openai.chat-mock" | "anthropic.chat" | "amazon:anthropic.chat" | "amazon:meta.chat" | "amazon:nova.chat" | "amazon.embedding" | "xai.chat" | "google.chat" | "ollama.chat" | "deepseek.chat";
|
|
1265
|
+
type LlmProvider = "openai.chat" | "openai.embedding" | "google.embedding" | "openai.chat-mock" | "anthropic.chat" | "amazon:anthropic.chat" | "amazon:meta.chat" | "amazon:nova.chat" | "amazon.embedding" | "amazon:cohere.embedding" | "xai.chat" | "google.chat" | "ollama.chat" | "deepseek.chat";
|
|
1259
1266
|
interface Config<Pk = LlmProviderKey> {
|
|
1260
1267
|
/**
|
|
1261
1268
|
* Unique identifier for this configuration (e.g., "openai.chat.v1", "anthropic.claude-3-opus")
|
|
@@ -1356,7 +1363,13 @@ interface Config<Pk = LlmProviderKey> {
|
|
|
1356
1363
|
*/
|
|
1357
1364
|
functions?: (functions: any[], options?: any, currentInput?: Record<string, any>, config?: Config) => Record<string, any>;
|
|
1358
1365
|
};
|
|
1359
|
-
|
|
1366
|
+
/**
|
|
1367
|
+
* Optional response transformer for chat/LLM configs. The LLM call path
|
|
1368
|
+
* (`llm.call.ts`) defaults to `OutputDefault` when this is omitted.
|
|
1369
|
+
* Embedding configs do not use this — their flow dispatches via
|
|
1370
|
+
* `getEmbeddingOutputParser` instead.
|
|
1371
|
+
*/
|
|
1372
|
+
transformResponse?: (result: any, _config?: Config<any>) => OutputResult;
|
|
1360
1373
|
}
|
|
1361
1374
|
|
|
1362
1375
|
declare function enforceResultAttributes<O>(input: any): {
|
package/dist/index.d.ts
CHANGED
|
@@ -996,6 +996,10 @@ interface AmazonEmbeddingOptions extends GenericEmbeddingOptions {
|
|
|
996
996
|
awsSecretKey?: string;
|
|
997
997
|
awsAccessKey?: string;
|
|
998
998
|
}
|
|
999
|
+
interface CohereBedrockEmbeddingOptions extends AmazonEmbeddingOptions {
|
|
1000
|
+
inputType?: "search_document" | "search_query" | "classification" | "clustering";
|
|
1001
|
+
truncate?: "NONE" | "START" | "END" | "LEFT" | "RIGHT";
|
|
1002
|
+
}
|
|
999
1003
|
interface GenericLLm extends BaseLlmOptions {
|
|
1000
1004
|
model?: string;
|
|
1001
1005
|
system?: string;
|
|
@@ -1059,6 +1063,9 @@ type AllEmbedding = {
|
|
|
1059
1063
|
"amazon.embedding.v1": {
|
|
1060
1064
|
input: AmazonEmbeddingOptions;
|
|
1061
1065
|
};
|
|
1066
|
+
"amazon:cohere.embedding.v1": {
|
|
1067
|
+
input: CohereBedrockEmbeddingOptions;
|
|
1068
|
+
};
|
|
1062
1069
|
};
|
|
1063
1070
|
type AllLlm = {
|
|
1064
1071
|
"openai.chat.v1": {
|
|
@@ -1255,7 +1262,7 @@ interface BaseRequest<_T extends Record<string, any>> {
|
|
|
1255
1262
|
interface BaseLlm<_T extends BaseLlCall = BaseLlCall> extends BaseRequest<_T> {
|
|
1256
1263
|
}
|
|
1257
1264
|
|
|
1258
|
-
type LlmProvider = "openai.chat" | "openai.embedding" | "google.embedding" | "openai.chat-mock" | "anthropic.chat" | "amazon:anthropic.chat" | "amazon:meta.chat" | "amazon:nova.chat" | "amazon.embedding" | "xai.chat" | "google.chat" | "ollama.chat" | "deepseek.chat";
|
|
1265
|
+
type LlmProvider = "openai.chat" | "openai.embedding" | "google.embedding" | "openai.chat-mock" | "anthropic.chat" | "amazon:anthropic.chat" | "amazon:meta.chat" | "amazon:nova.chat" | "amazon.embedding" | "amazon:cohere.embedding" | "xai.chat" | "google.chat" | "ollama.chat" | "deepseek.chat";
|
|
1259
1266
|
interface Config<Pk = LlmProviderKey> {
|
|
1260
1267
|
/**
|
|
1261
1268
|
* Unique identifier for this configuration (e.g., "openai.chat.v1", "anthropic.claude-3-opus")
|
|
@@ -1356,7 +1363,13 @@ interface Config<Pk = LlmProviderKey> {
|
|
|
1356
1363
|
*/
|
|
1357
1364
|
functions?: (functions: any[], options?: any, currentInput?: Record<string, any>, config?: Config) => Record<string, any>;
|
|
1358
1365
|
};
|
|
1359
|
-
|
|
1366
|
+
/**
|
|
1367
|
+
* Optional response transformer for chat/LLM configs. The LLM call path
|
|
1368
|
+
* (`llm.call.ts`) defaults to `OutputDefault` when this is omitted.
|
|
1369
|
+
* Embedding configs do not use this — their flow dispatches via
|
|
1370
|
+
* `getEmbeddingOutputParser` instead.
|
|
1371
|
+
*/
|
|
1372
|
+
transformResponse?: (result: any, _config?: Config<any>) => OutputResult;
|
|
1360
1373
|
}
|
|
1361
1374
|
|
|
1362
1375
|
declare function enforceResultAttributes<O>(input: any): {
|
package/dist/index.js
CHANGED
|
@@ -3903,77 +3903,6 @@ function useLlmConfiguration(config) {
|
|
|
3903
3903
|
return (options = {}) => apiRequestWrapper(config, options, useLlm_call);
|
|
3904
3904
|
}
|
|
3905
3905
|
|
|
3906
|
-
// src/embedding/output/BaseEmbeddingOutput.ts
|
|
3907
|
-
function BaseEmbeddingOutput(result) {
|
|
3908
|
-
const __result = Object.freeze({
|
|
3909
|
-
id: result.id || (0, import_uuid.v4)(),
|
|
3910
|
-
model: result.model,
|
|
3911
|
-
usage: result.usage,
|
|
3912
|
-
embedding: [...result?.embedding || []],
|
|
3913
|
-
created: result?.created || (/* @__PURE__ */ new Date()).getTime()
|
|
3914
|
-
});
|
|
3915
|
-
function getResult() {
|
|
3916
|
-
return {
|
|
3917
|
-
id: __result.id,
|
|
3918
|
-
model: __result.model,
|
|
3919
|
-
created: __result.created,
|
|
3920
|
-
usage: __result.usage,
|
|
3921
|
-
embedding: __result.embedding
|
|
3922
|
-
};
|
|
3923
|
-
}
|
|
3924
|
-
function getEmbedding(index) {
|
|
3925
|
-
if (index && index > 0) {
|
|
3926
|
-
const arr = __result?.embedding;
|
|
3927
|
-
const val = arr[index];
|
|
3928
|
-
return val ? val : [];
|
|
3929
|
-
}
|
|
3930
|
-
return __result.embedding[0];
|
|
3931
|
-
}
|
|
3932
|
-
return {
|
|
3933
|
-
getEmbedding,
|
|
3934
|
-
getResult
|
|
3935
|
-
};
|
|
3936
|
-
}
|
|
3937
|
-
|
|
3938
|
-
// src/embedding/output/OpenAiEmbedding.ts
|
|
3939
|
-
function OpenAiEmbedding(result, config) {
|
|
3940
|
-
const __result = deepClone(result);
|
|
3941
|
-
const model = __result.model || config.model || "openai.unknown";
|
|
3942
|
-
const created = (/* @__PURE__ */ new Date()).getTime();
|
|
3943
|
-
const results = result?.data || [];
|
|
3944
|
-
const embedding = results.map((a) => a.embedding);
|
|
3945
|
-
const usage = {
|
|
3946
|
-
output_tokens: 0,
|
|
3947
|
-
input_tokens: result?.usage?.prompt_tokens,
|
|
3948
|
-
total_tokens: result?.usage?.total_tokens
|
|
3949
|
-
};
|
|
3950
|
-
return BaseEmbeddingOutput({
|
|
3951
|
-
model,
|
|
3952
|
-
created,
|
|
3953
|
-
usage,
|
|
3954
|
-
embedding
|
|
3955
|
-
});
|
|
3956
|
-
}
|
|
3957
|
-
|
|
3958
|
-
// src/embedding/output/AmazonTitan.ts
|
|
3959
|
-
function AmazonTitanEmbedding(result, config) {
|
|
3960
|
-
const __result = deepClone(result);
|
|
3961
|
-
const model = config.model || "amazon.unknown";
|
|
3962
|
-
const created = (/* @__PURE__ */ new Date()).getTime();
|
|
3963
|
-
const embedding = [__result.embedding];
|
|
3964
|
-
const usage = {
|
|
3965
|
-
output_tokens: 0,
|
|
3966
|
-
input_tokens: __result.inputTextTokenCount,
|
|
3967
|
-
total_tokens: __result.inputTextTokenCount
|
|
3968
|
-
};
|
|
3969
|
-
return BaseEmbeddingOutput({
|
|
3970
|
-
model,
|
|
3971
|
-
created,
|
|
3972
|
-
usage,
|
|
3973
|
-
embedding
|
|
3974
|
-
});
|
|
3975
|
-
}
|
|
3976
|
-
|
|
3977
3906
|
// src/embedding/config.ts
|
|
3978
3907
|
var embeddingConfigs = {
|
|
3979
3908
|
"openai.embedding.v1": {
|
|
@@ -4005,8 +3934,7 @@ var embeddingConfigs = {
|
|
|
4005
3934
|
encodingFormat: {
|
|
4006
3935
|
key: "encoding_format"
|
|
4007
3936
|
}
|
|
4008
|
-
}
|
|
4009
|
-
transformResponse: OpenAiEmbedding
|
|
3937
|
+
}
|
|
4010
3938
|
},
|
|
4011
3939
|
"amazon.embedding.v1": {
|
|
4012
3940
|
key: "amazon.embedding.v1",
|
|
@@ -4033,8 +3961,59 @@ var embeddingConfigs = {
|
|
|
4033
3961
|
dimensions: {
|
|
4034
3962
|
key: "dimensions"
|
|
4035
3963
|
}
|
|
3964
|
+
}
|
|
3965
|
+
},
|
|
3966
|
+
"amazon:cohere.embedding.v1": {
|
|
3967
|
+
key: "amazon:cohere.embedding.v1",
|
|
3968
|
+
provider: "amazon:cohere.embedding",
|
|
3969
|
+
endpoint: `https://bedrock-runtime.{{awsRegion}}.amazonaws.com/model/{{model}}/invoke`,
|
|
3970
|
+
method: "POST",
|
|
3971
|
+
headers: `{"Content-Type": "application/json" }`,
|
|
3972
|
+
options: {
|
|
3973
|
+
input: {},
|
|
3974
|
+
inputType: {
|
|
3975
|
+
default: "search_document"
|
|
3976
|
+
},
|
|
3977
|
+
truncate: {},
|
|
3978
|
+
dimensions: {},
|
|
3979
|
+
awsRegion: {
|
|
3980
|
+
default: getEnvironmentVariable("AWS_REGION"),
|
|
3981
|
+
required: [true, "aws region is required"]
|
|
3982
|
+
},
|
|
3983
|
+
awsSecretKey: {},
|
|
3984
|
+
awsAccessKey: {}
|
|
4036
3985
|
},
|
|
4037
|
-
|
|
3986
|
+
mapBody: {
|
|
3987
|
+
input: {
|
|
3988
|
+
key: "texts",
|
|
3989
|
+
transform: (value) => Array.isArray(value) ? value : [value]
|
|
3990
|
+
},
|
|
3991
|
+
inputType: {
|
|
3992
|
+
key: "input_type"
|
|
3993
|
+
},
|
|
3994
|
+
truncate: {
|
|
3995
|
+
key: "truncate"
|
|
3996
|
+
},
|
|
3997
|
+
dimensions: {
|
|
3998
|
+
key: "output_dimension",
|
|
3999
|
+
// Embed v3 has a fixed 1024-dim output and rejects the output_dimension
|
|
4000
|
+
// field entirely — even when the value matches. Drop the field for v3
|
|
4001
|
+
// when the user asked for the natural 1024; throw for any other value
|
|
4002
|
+
// so we don't silently mutate user intent.
|
|
4003
|
+
transform: (value, state) => {
|
|
4004
|
+
if (typeof value === "undefined") return void 0;
|
|
4005
|
+
const model = state?.model || "";
|
|
4006
|
+
const isV3 = /embed-(english|multilingual)-v3/.test(model);
|
|
4007
|
+
if (isV3) {
|
|
4008
|
+
if (value === 1024) return void 0;
|
|
4009
|
+
throw new Error(
|
|
4010
|
+
`Cohere Embed v3 only supports 1024-dimensional output (model: "${model}", requested: ${value}). Use cohere.embed-v4:0 for configurable dimensions.`
|
|
4011
|
+
);
|
|
4012
|
+
}
|
|
4013
|
+
return value;
|
|
4014
|
+
}
|
|
4015
|
+
}
|
|
4016
|
+
}
|
|
4038
4017
|
}
|
|
4039
4018
|
};
|
|
4040
4019
|
function getEmbeddingConfig(provider) {
|
|
@@ -4048,6 +4027,97 @@ function getEmbeddingConfig(provider) {
|
|
|
4048
4027
|
throw new Error(`Invalid provider: ${provider}`);
|
|
4049
4028
|
}
|
|
4050
4029
|
|
|
4030
|
+
// src/embedding/output/BaseEmbeddingOutput.ts
|
|
4031
|
+
function BaseEmbeddingOutput(result) {
|
|
4032
|
+
const __result = Object.freeze({
|
|
4033
|
+
id: result.id || (0, import_uuid.v4)(),
|
|
4034
|
+
model: result.model,
|
|
4035
|
+
usage: result.usage,
|
|
4036
|
+
embedding: [...result?.embedding || []],
|
|
4037
|
+
created: result?.created || (/* @__PURE__ */ new Date()).getTime()
|
|
4038
|
+
});
|
|
4039
|
+
function getResult() {
|
|
4040
|
+
return {
|
|
4041
|
+
id: __result.id,
|
|
4042
|
+
model: __result.model,
|
|
4043
|
+
created: __result.created,
|
|
4044
|
+
usage: __result.usage,
|
|
4045
|
+
embedding: __result.embedding
|
|
4046
|
+
};
|
|
4047
|
+
}
|
|
4048
|
+
function getEmbedding(index) {
|
|
4049
|
+
if (index && index > 0) {
|
|
4050
|
+
const arr = __result?.embedding;
|
|
4051
|
+
const val = arr[index];
|
|
4052
|
+
return val ? val : [];
|
|
4053
|
+
}
|
|
4054
|
+
return __result.embedding[0];
|
|
4055
|
+
}
|
|
4056
|
+
return {
|
|
4057
|
+
getEmbedding,
|
|
4058
|
+
getResult
|
|
4059
|
+
};
|
|
4060
|
+
}
|
|
4061
|
+
|
|
4062
|
+
// src/embedding/output/AmazonTitan.ts
|
|
4063
|
+
function AmazonTitanEmbedding(result, config) {
|
|
4064
|
+
const __result = deepClone(result);
|
|
4065
|
+
const model = config.model || "amazon.unknown";
|
|
4066
|
+
const created = (/* @__PURE__ */ new Date()).getTime();
|
|
4067
|
+
const embedding = [__result.embedding];
|
|
4068
|
+
const usage = {
|
|
4069
|
+
output_tokens: 0,
|
|
4070
|
+
input_tokens: __result.inputTextTokenCount,
|
|
4071
|
+
total_tokens: __result.inputTextTokenCount
|
|
4072
|
+
};
|
|
4073
|
+
return BaseEmbeddingOutput({
|
|
4074
|
+
model,
|
|
4075
|
+
created,
|
|
4076
|
+
usage,
|
|
4077
|
+
embedding
|
|
4078
|
+
});
|
|
4079
|
+
}
|
|
4080
|
+
|
|
4081
|
+
// src/embedding/output/CohereBedrockEmbedding.ts
|
|
4082
|
+
function CohereBedrockEmbedding(result, config) {
|
|
4083
|
+
const __result = deepClone(result);
|
|
4084
|
+
const model = config.model || "cohere.unknown";
|
|
4085
|
+
const created = (/* @__PURE__ */ new Date()).getTime();
|
|
4086
|
+
const embedding = Array.isArray(__result.embeddings) ? __result.embeddings : [];
|
|
4087
|
+
const usage = {
|
|
4088
|
+
output_tokens: 0,
|
|
4089
|
+
input_tokens: 0,
|
|
4090
|
+
total_tokens: 0
|
|
4091
|
+
};
|
|
4092
|
+
return BaseEmbeddingOutput({
|
|
4093
|
+
id: __result.id,
|
|
4094
|
+
model,
|
|
4095
|
+
created,
|
|
4096
|
+
usage,
|
|
4097
|
+
embedding
|
|
4098
|
+
});
|
|
4099
|
+
}
|
|
4100
|
+
|
|
4101
|
+
// src/embedding/output/OpenAiEmbedding.ts
|
|
4102
|
+
function OpenAiEmbedding(result, config) {
|
|
4103
|
+
const __result = deepClone(result);
|
|
4104
|
+
const model = __result.model || config.model || "openai.unknown";
|
|
4105
|
+
const created = (/* @__PURE__ */ new Date()).getTime();
|
|
4106
|
+
const results = result?.data || [];
|
|
4107
|
+
const embedding = results.map((a) => a.embedding);
|
|
4108
|
+
const usage = {
|
|
4109
|
+
output_tokens: 0,
|
|
4110
|
+
input_tokens: result?.usage?.prompt_tokens,
|
|
4111
|
+
total_tokens: result?.usage?.total_tokens
|
|
4112
|
+
};
|
|
4113
|
+
return BaseEmbeddingOutput({
|
|
4114
|
+
model,
|
|
4115
|
+
created,
|
|
4116
|
+
usage,
|
|
4117
|
+
embedding
|
|
4118
|
+
});
|
|
4119
|
+
}
|
|
4120
|
+
|
|
4051
4121
|
// src/embedding/output/getEmbeddingOutputParser.ts
|
|
4052
4122
|
function getEmbeddingOutputParser(config, response) {
|
|
4053
4123
|
switch (config.key) {
|
|
@@ -4055,6 +4125,8 @@ function getEmbeddingOutputParser(config, response) {
|
|
|
4055
4125
|
return OpenAiEmbedding(response, config);
|
|
4056
4126
|
case "amazon.embedding.v1":
|
|
4057
4127
|
return AmazonTitanEmbedding(response, config);
|
|
4128
|
+
case "amazon:cohere.embedding.v1":
|
|
4129
|
+
return CohereBedrockEmbedding(response, config);
|
|
4058
4130
|
default:
|
|
4059
4131
|
throw new Error("Unsupported provider");
|
|
4060
4132
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -3840,77 +3840,6 @@ function useLlmConfiguration(config) {
|
|
|
3840
3840
|
return (options = {}) => apiRequestWrapper(config, options, useLlm_call);
|
|
3841
3841
|
}
|
|
3842
3842
|
|
|
3843
|
-
// src/embedding/output/BaseEmbeddingOutput.ts
|
|
3844
|
-
function BaseEmbeddingOutput(result) {
|
|
3845
|
-
const __result = Object.freeze({
|
|
3846
|
-
id: result.id || uuidv4(),
|
|
3847
|
-
model: result.model,
|
|
3848
|
-
usage: result.usage,
|
|
3849
|
-
embedding: [...result?.embedding || []],
|
|
3850
|
-
created: result?.created || (/* @__PURE__ */ new Date()).getTime()
|
|
3851
|
-
});
|
|
3852
|
-
function getResult() {
|
|
3853
|
-
return {
|
|
3854
|
-
id: __result.id,
|
|
3855
|
-
model: __result.model,
|
|
3856
|
-
created: __result.created,
|
|
3857
|
-
usage: __result.usage,
|
|
3858
|
-
embedding: __result.embedding
|
|
3859
|
-
};
|
|
3860
|
-
}
|
|
3861
|
-
function getEmbedding(index) {
|
|
3862
|
-
if (index && index > 0) {
|
|
3863
|
-
const arr = __result?.embedding;
|
|
3864
|
-
const val = arr[index];
|
|
3865
|
-
return val ? val : [];
|
|
3866
|
-
}
|
|
3867
|
-
return __result.embedding[0];
|
|
3868
|
-
}
|
|
3869
|
-
return {
|
|
3870
|
-
getEmbedding,
|
|
3871
|
-
getResult
|
|
3872
|
-
};
|
|
3873
|
-
}
|
|
3874
|
-
|
|
3875
|
-
// src/embedding/output/OpenAiEmbedding.ts
|
|
3876
|
-
function OpenAiEmbedding(result, config) {
|
|
3877
|
-
const __result = deepClone(result);
|
|
3878
|
-
const model = __result.model || config.model || "openai.unknown";
|
|
3879
|
-
const created = (/* @__PURE__ */ new Date()).getTime();
|
|
3880
|
-
const results = result?.data || [];
|
|
3881
|
-
const embedding = results.map((a) => a.embedding);
|
|
3882
|
-
const usage = {
|
|
3883
|
-
output_tokens: 0,
|
|
3884
|
-
input_tokens: result?.usage?.prompt_tokens,
|
|
3885
|
-
total_tokens: result?.usage?.total_tokens
|
|
3886
|
-
};
|
|
3887
|
-
return BaseEmbeddingOutput({
|
|
3888
|
-
model,
|
|
3889
|
-
created,
|
|
3890
|
-
usage,
|
|
3891
|
-
embedding
|
|
3892
|
-
});
|
|
3893
|
-
}
|
|
3894
|
-
|
|
3895
|
-
// src/embedding/output/AmazonTitan.ts
|
|
3896
|
-
function AmazonTitanEmbedding(result, config) {
|
|
3897
|
-
const __result = deepClone(result);
|
|
3898
|
-
const model = config.model || "amazon.unknown";
|
|
3899
|
-
const created = (/* @__PURE__ */ new Date()).getTime();
|
|
3900
|
-
const embedding = [__result.embedding];
|
|
3901
|
-
const usage = {
|
|
3902
|
-
output_tokens: 0,
|
|
3903
|
-
input_tokens: __result.inputTextTokenCount,
|
|
3904
|
-
total_tokens: __result.inputTextTokenCount
|
|
3905
|
-
};
|
|
3906
|
-
return BaseEmbeddingOutput({
|
|
3907
|
-
model,
|
|
3908
|
-
created,
|
|
3909
|
-
usage,
|
|
3910
|
-
embedding
|
|
3911
|
-
});
|
|
3912
|
-
}
|
|
3913
|
-
|
|
3914
3843
|
// src/embedding/config.ts
|
|
3915
3844
|
var embeddingConfigs = {
|
|
3916
3845
|
"openai.embedding.v1": {
|
|
@@ -3942,8 +3871,7 @@ var embeddingConfigs = {
|
|
|
3942
3871
|
encodingFormat: {
|
|
3943
3872
|
key: "encoding_format"
|
|
3944
3873
|
}
|
|
3945
|
-
}
|
|
3946
|
-
transformResponse: OpenAiEmbedding
|
|
3874
|
+
}
|
|
3947
3875
|
},
|
|
3948
3876
|
"amazon.embedding.v1": {
|
|
3949
3877
|
key: "amazon.embedding.v1",
|
|
@@ -3970,8 +3898,59 @@ var embeddingConfigs = {
|
|
|
3970
3898
|
dimensions: {
|
|
3971
3899
|
key: "dimensions"
|
|
3972
3900
|
}
|
|
3901
|
+
}
|
|
3902
|
+
},
|
|
3903
|
+
"amazon:cohere.embedding.v1": {
|
|
3904
|
+
key: "amazon:cohere.embedding.v1",
|
|
3905
|
+
provider: "amazon:cohere.embedding",
|
|
3906
|
+
endpoint: `https://bedrock-runtime.{{awsRegion}}.amazonaws.com/model/{{model}}/invoke`,
|
|
3907
|
+
method: "POST",
|
|
3908
|
+
headers: `{"Content-Type": "application/json" }`,
|
|
3909
|
+
options: {
|
|
3910
|
+
input: {},
|
|
3911
|
+
inputType: {
|
|
3912
|
+
default: "search_document"
|
|
3913
|
+
},
|
|
3914
|
+
truncate: {},
|
|
3915
|
+
dimensions: {},
|
|
3916
|
+
awsRegion: {
|
|
3917
|
+
default: getEnvironmentVariable("AWS_REGION"),
|
|
3918
|
+
required: [true, "aws region is required"]
|
|
3919
|
+
},
|
|
3920
|
+
awsSecretKey: {},
|
|
3921
|
+
awsAccessKey: {}
|
|
3973
3922
|
},
|
|
3974
|
-
|
|
3923
|
+
mapBody: {
|
|
3924
|
+
input: {
|
|
3925
|
+
key: "texts",
|
|
3926
|
+
transform: (value) => Array.isArray(value) ? value : [value]
|
|
3927
|
+
},
|
|
3928
|
+
inputType: {
|
|
3929
|
+
key: "input_type"
|
|
3930
|
+
},
|
|
3931
|
+
truncate: {
|
|
3932
|
+
key: "truncate"
|
|
3933
|
+
},
|
|
3934
|
+
dimensions: {
|
|
3935
|
+
key: "output_dimension",
|
|
3936
|
+
// Embed v3 has a fixed 1024-dim output and rejects the output_dimension
|
|
3937
|
+
// field entirely — even when the value matches. Drop the field for v3
|
|
3938
|
+
// when the user asked for the natural 1024; throw for any other value
|
|
3939
|
+
// so we don't silently mutate user intent.
|
|
3940
|
+
transform: (value, state) => {
|
|
3941
|
+
if (typeof value === "undefined") return void 0;
|
|
3942
|
+
const model = state?.model || "";
|
|
3943
|
+
const isV3 = /embed-(english|multilingual)-v3/.test(model);
|
|
3944
|
+
if (isV3) {
|
|
3945
|
+
if (value === 1024) return void 0;
|
|
3946
|
+
throw new Error(
|
|
3947
|
+
`Cohere Embed v3 only supports 1024-dimensional output (model: "${model}", requested: ${value}). Use cohere.embed-v4:0 for configurable dimensions.`
|
|
3948
|
+
);
|
|
3949
|
+
}
|
|
3950
|
+
return value;
|
|
3951
|
+
}
|
|
3952
|
+
}
|
|
3953
|
+
}
|
|
3975
3954
|
}
|
|
3976
3955
|
};
|
|
3977
3956
|
function getEmbeddingConfig(provider) {
|
|
@@ -3985,6 +3964,97 @@ function getEmbeddingConfig(provider) {
|
|
|
3985
3964
|
throw new Error(`Invalid provider: ${provider}`);
|
|
3986
3965
|
}
|
|
3987
3966
|
|
|
3967
|
+
// src/embedding/output/BaseEmbeddingOutput.ts
|
|
3968
|
+
function BaseEmbeddingOutput(result) {
|
|
3969
|
+
const __result = Object.freeze({
|
|
3970
|
+
id: result.id || uuidv4(),
|
|
3971
|
+
model: result.model,
|
|
3972
|
+
usage: result.usage,
|
|
3973
|
+
embedding: [...result?.embedding || []],
|
|
3974
|
+
created: result?.created || (/* @__PURE__ */ new Date()).getTime()
|
|
3975
|
+
});
|
|
3976
|
+
function getResult() {
|
|
3977
|
+
return {
|
|
3978
|
+
id: __result.id,
|
|
3979
|
+
model: __result.model,
|
|
3980
|
+
created: __result.created,
|
|
3981
|
+
usage: __result.usage,
|
|
3982
|
+
embedding: __result.embedding
|
|
3983
|
+
};
|
|
3984
|
+
}
|
|
3985
|
+
function getEmbedding(index) {
|
|
3986
|
+
if (index && index > 0) {
|
|
3987
|
+
const arr = __result?.embedding;
|
|
3988
|
+
const val = arr[index];
|
|
3989
|
+
return val ? val : [];
|
|
3990
|
+
}
|
|
3991
|
+
return __result.embedding[0];
|
|
3992
|
+
}
|
|
3993
|
+
return {
|
|
3994
|
+
getEmbedding,
|
|
3995
|
+
getResult
|
|
3996
|
+
};
|
|
3997
|
+
}
|
|
3998
|
+
|
|
3999
|
+
// src/embedding/output/AmazonTitan.ts
|
|
4000
|
+
function AmazonTitanEmbedding(result, config) {
|
|
4001
|
+
const __result = deepClone(result);
|
|
4002
|
+
const model = config.model || "amazon.unknown";
|
|
4003
|
+
const created = (/* @__PURE__ */ new Date()).getTime();
|
|
4004
|
+
const embedding = [__result.embedding];
|
|
4005
|
+
const usage = {
|
|
4006
|
+
output_tokens: 0,
|
|
4007
|
+
input_tokens: __result.inputTextTokenCount,
|
|
4008
|
+
total_tokens: __result.inputTextTokenCount
|
|
4009
|
+
};
|
|
4010
|
+
return BaseEmbeddingOutput({
|
|
4011
|
+
model,
|
|
4012
|
+
created,
|
|
4013
|
+
usage,
|
|
4014
|
+
embedding
|
|
4015
|
+
});
|
|
4016
|
+
}
|
|
4017
|
+
|
|
4018
|
+
// src/embedding/output/CohereBedrockEmbedding.ts
|
|
4019
|
+
function CohereBedrockEmbedding(result, config) {
|
|
4020
|
+
const __result = deepClone(result);
|
|
4021
|
+
const model = config.model || "cohere.unknown";
|
|
4022
|
+
const created = (/* @__PURE__ */ new Date()).getTime();
|
|
4023
|
+
const embedding = Array.isArray(__result.embeddings) ? __result.embeddings : [];
|
|
4024
|
+
const usage = {
|
|
4025
|
+
output_tokens: 0,
|
|
4026
|
+
input_tokens: 0,
|
|
4027
|
+
total_tokens: 0
|
|
4028
|
+
};
|
|
4029
|
+
return BaseEmbeddingOutput({
|
|
4030
|
+
id: __result.id,
|
|
4031
|
+
model,
|
|
4032
|
+
created,
|
|
4033
|
+
usage,
|
|
4034
|
+
embedding
|
|
4035
|
+
});
|
|
4036
|
+
}
|
|
4037
|
+
|
|
4038
|
+
// src/embedding/output/OpenAiEmbedding.ts
|
|
4039
|
+
function OpenAiEmbedding(result, config) {
|
|
4040
|
+
const __result = deepClone(result);
|
|
4041
|
+
const model = __result.model || config.model || "openai.unknown";
|
|
4042
|
+
const created = (/* @__PURE__ */ new Date()).getTime();
|
|
4043
|
+
const results = result?.data || [];
|
|
4044
|
+
const embedding = results.map((a) => a.embedding);
|
|
4045
|
+
const usage = {
|
|
4046
|
+
output_tokens: 0,
|
|
4047
|
+
input_tokens: result?.usage?.prompt_tokens,
|
|
4048
|
+
total_tokens: result?.usage?.total_tokens
|
|
4049
|
+
};
|
|
4050
|
+
return BaseEmbeddingOutput({
|
|
4051
|
+
model,
|
|
4052
|
+
created,
|
|
4053
|
+
usage,
|
|
4054
|
+
embedding
|
|
4055
|
+
});
|
|
4056
|
+
}
|
|
4057
|
+
|
|
3988
4058
|
// src/embedding/output/getEmbeddingOutputParser.ts
|
|
3989
4059
|
function getEmbeddingOutputParser(config, response) {
|
|
3990
4060
|
switch (config.key) {
|
|
@@ -3992,6 +4062,8 @@ function getEmbeddingOutputParser(config, response) {
|
|
|
3992
4062
|
return OpenAiEmbedding(response, config);
|
|
3993
4063
|
case "amazon.embedding.v1":
|
|
3994
4064
|
return AmazonTitanEmbedding(response, config);
|
|
4065
|
+
case "amazon:cohere.embedding.v1":
|
|
4066
|
+
return CohereBedrockEmbedding(response, config);
|
|
3995
4067
|
default:
|
|
3996
4068
|
throw new Error("Unsupported provider");
|
|
3997
4069
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "llm-exe",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.8",
|
|
4
4
|
"description": "Simplify building LLM-powered apps with easy-to-use base components, supporting text and chat-based prompts with handlebars template engine, output parsers, and flexible function calling capabilities.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|