llm-exe 2.1.4 → 2.1.6
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 +52 -6
- package/dist/index.d.ts +52 -6
- package/dist/index.js +273 -51
- package/dist/index.mjs +273 -51
- package/package.json +5 -2
- package/readme.md +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -13,7 +13,7 @@ interface Serializable {
|
|
|
13
13
|
deserialize?(): void;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
type IChatMessageRole = "system" | "assistant" | "user" | "function" | "function_call";
|
|
16
|
+
type IChatMessageRole = "system" | "model" | "assistant" | "user" | "function" | "function_call";
|
|
17
17
|
interface IChatMessageContentDetailed {
|
|
18
18
|
type: string;
|
|
19
19
|
text?: string;
|
|
@@ -930,6 +930,10 @@ interface AnthropicRequest extends GenericLLm {
|
|
|
930
930
|
model: string;
|
|
931
931
|
anthropicApiKey?: string;
|
|
932
932
|
}
|
|
933
|
+
interface GeminiRequest extends GenericLLm {
|
|
934
|
+
model: string;
|
|
935
|
+
geminiApiKey?: string;
|
|
936
|
+
}
|
|
933
937
|
type AllEmbedding = {
|
|
934
938
|
"openai.embedding.v1": {
|
|
935
939
|
input: OpenAiEmbeddingOptions;
|
|
@@ -960,6 +964,9 @@ type AllLlm = {
|
|
|
960
964
|
"ollama.chat.v1": {
|
|
961
965
|
input: GenericLLm;
|
|
962
966
|
};
|
|
967
|
+
"google.chat.v1": {
|
|
968
|
+
input: GeminiRequest;
|
|
969
|
+
};
|
|
963
970
|
};
|
|
964
971
|
type AllUseLlmOptions = AllLlm & {
|
|
965
972
|
"openai.gpt-4": {
|
|
@@ -971,6 +978,9 @@ type AllUseLlmOptions = AllLlm & {
|
|
|
971
978
|
"openai.gpt-4o-mini": {
|
|
972
979
|
input: Omit<OpenAiRequest, "model">;
|
|
973
980
|
};
|
|
981
|
+
"anthropic.claude-3-7-sonnet": {
|
|
982
|
+
input: Omit<AnthropicRequest, "model">;
|
|
983
|
+
};
|
|
974
984
|
"anthropic.claude-3-5-sonnet": {
|
|
975
985
|
input: Omit<AnthropicRequest, "model">;
|
|
976
986
|
};
|
|
@@ -980,12 +990,39 @@ type AllUseLlmOptions = AllLlm & {
|
|
|
980
990
|
"anthropic.claude-3-sonnet": {
|
|
981
991
|
input: Omit<AnthropicRequest, "model">;
|
|
982
992
|
};
|
|
983
|
-
"anthropic.claude-3-haiku": {
|
|
993
|
+
"anthropic.claude-3-5-haiku": {
|
|
984
994
|
input: Omit<AnthropicRequest, "model">;
|
|
985
995
|
};
|
|
996
|
+
"google.gemini-2.5-pro-exp-03-25": {
|
|
997
|
+
input: Omit<GeminiRequest, "model">;
|
|
998
|
+
};
|
|
999
|
+
"google.gemini-2.0-flash": {
|
|
1000
|
+
input: Omit<GeminiRequest, "model">;
|
|
1001
|
+
};
|
|
1002
|
+
"google.gemini-2.0-flash-lite": {
|
|
1003
|
+
input: Omit<GeminiRequest, "model">;
|
|
1004
|
+
};
|
|
1005
|
+
"google.gemini-1.5-pro": {
|
|
1006
|
+
input: Omit<GeminiRequest, "model">;
|
|
1007
|
+
};
|
|
986
1008
|
"xai.grok-2": {
|
|
987
1009
|
input: OpenAiRequest;
|
|
988
1010
|
};
|
|
1011
|
+
"ollama.deepseek-r1": {
|
|
1012
|
+
input: GenericLLm;
|
|
1013
|
+
};
|
|
1014
|
+
"ollama.llama3.3": {
|
|
1015
|
+
input: GenericLLm;
|
|
1016
|
+
};
|
|
1017
|
+
"ollama.llama3.2": {
|
|
1018
|
+
input: GenericLLm;
|
|
1019
|
+
};
|
|
1020
|
+
"ollama.llama3.1": {
|
|
1021
|
+
input: GenericLLm;
|
|
1022
|
+
};
|
|
1023
|
+
"ollama.qwq": {
|
|
1024
|
+
input: GenericLLm;
|
|
1025
|
+
};
|
|
989
1026
|
};
|
|
990
1027
|
type LlmProviderKey = keyof AllLlm;
|
|
991
1028
|
type EmbeddingProviderKey = keyof AllEmbedding;
|
|
@@ -1003,7 +1040,7 @@ interface BaseRequest<_T extends Record<string, any>> {
|
|
|
1003
1040
|
interface BaseLlm<_T extends BaseLlCall = BaseLlCall> extends BaseRequest<_T> {
|
|
1004
1041
|
}
|
|
1005
1042
|
|
|
1006
|
-
type LlmProvider = "openai.chat" | "openai.embedding" | "openai.chat-mock" | "anthropic.chat" | "amazon:anthropic.chat" | "amazon:meta.chat" | "amazon:nova.chat" | "amazon.embedding" | "xai.chat" | "ollama.chat";
|
|
1043
|
+
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";
|
|
1007
1044
|
interface Config<Pk = LlmProviderKey> {
|
|
1008
1045
|
key: Pk;
|
|
1009
1046
|
provider: LlmProvider;
|
|
@@ -1182,16 +1219,25 @@ declare namespace index {
|
|
|
1182
1219
|
}
|
|
1183
1220
|
|
|
1184
1221
|
declare const configs: {
|
|
1222
|
+
"google.chat.v1": Config<keyof AllLlm>;
|
|
1223
|
+
"google.gemini-2.0-flash": Config<keyof AllLlm>;
|
|
1224
|
+
"google.gemini-2.0-flash-lite": Config<keyof AllLlm>;
|
|
1225
|
+
"google.gemini-1.5-pro": Config<keyof AllLlm>;
|
|
1185
1226
|
"ollama.chat.v1": Config<keyof AllLlm>;
|
|
1227
|
+
"ollama.deepseek-r1": Config<keyof AllLlm>;
|
|
1228
|
+
"ollama.llama3.3": Config<keyof AllLlm>;
|
|
1229
|
+
"ollama.llama3.2": Config<keyof AllLlm>;
|
|
1230
|
+
"ollama.llama3.1": Config<keyof AllLlm>;
|
|
1231
|
+
"ollama.qwq": Config<keyof AllLlm>;
|
|
1186
1232
|
"xai.chat.v1": Config<keyof AllLlm>;
|
|
1187
1233
|
"xai.grok-2": Config<keyof AllLlm>;
|
|
1188
1234
|
"amazon:anthropic.chat.v1": Config<keyof AllLlm>;
|
|
1189
1235
|
"amazon:meta.chat.v1": Config<keyof AllLlm>;
|
|
1190
1236
|
"anthropic.chat.v1": Config<keyof AllLlm>;
|
|
1237
|
+
"anthropic.claude-3-7-sonnet": Config<keyof AllLlm>;
|
|
1191
1238
|
"anthropic.claude-3-5-sonnet": Config<keyof AllLlm>;
|
|
1239
|
+
"anthropic.claude-3-5-haiku": Config<keyof AllLlm>;
|
|
1192
1240
|
"anthropic.claude-3-opus": Config<keyof AllLlm>;
|
|
1193
|
-
"anthropic.claude-3-sonnet": Config<keyof AllLlm>;
|
|
1194
|
-
"anthropic.claude-3-haiku": Config<keyof AllLlm>;
|
|
1195
1241
|
"openai.chat.v1": Config<keyof AllLlm>;
|
|
1196
1242
|
"openai.chat-mock.v1": Config<keyof AllLlm>;
|
|
1197
1243
|
"openai.gpt-4o": Config<keyof AllLlm>;
|
|
@@ -1237,4 +1283,4 @@ declare function createEmbedding<T extends EmbeddingProviderKey>(provider: T, op
|
|
|
1237
1283
|
};
|
|
1238
1284
|
};
|
|
1239
1285
|
|
|
1240
|
-
export { BaseExecutor, type BaseLlm, BaseParser, BasePrompt, BaseStateItem, ChatPrompt, CustomParser, DefaultState, DefaultStateItem, type IChatMessages, LlmExecutorOpenAiFunctions, type LlmProvider, type OpenAIModelName, OpenAiFunctionParser, TextPrompt, createCallableExecutor, createChatPrompt, createCoreExecutor, createCustomParser, createDialogue, createEmbedding, createLlmExecutor, createParser, createPrompt, createState, createStateItem, useExecutors, useLlm, index as utils };
|
|
1286
|
+
export { BaseExecutor, type BaseLlm, BaseParser, BasePrompt, BaseStateItem, ChatPrompt, CustomParser, DefaultState, DefaultStateItem, type ExecutorContext, type IChatMessages, LlmExecutorOpenAiFunctions, type LlmProvider, type OpenAIModelName, OpenAiFunctionParser, TextPrompt, createCallableExecutor, createChatPrompt, createCoreExecutor, createCustomParser, createDialogue, createEmbedding, createLlmExecutor, createParser, createPrompt, createState, createStateItem, useExecutors, useLlm, index as utils };
|
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ interface Serializable {
|
|
|
13
13
|
deserialize?(): void;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
type IChatMessageRole = "system" | "assistant" | "user" | "function" | "function_call";
|
|
16
|
+
type IChatMessageRole = "system" | "model" | "assistant" | "user" | "function" | "function_call";
|
|
17
17
|
interface IChatMessageContentDetailed {
|
|
18
18
|
type: string;
|
|
19
19
|
text?: string;
|
|
@@ -930,6 +930,10 @@ interface AnthropicRequest extends GenericLLm {
|
|
|
930
930
|
model: string;
|
|
931
931
|
anthropicApiKey?: string;
|
|
932
932
|
}
|
|
933
|
+
interface GeminiRequest extends GenericLLm {
|
|
934
|
+
model: string;
|
|
935
|
+
geminiApiKey?: string;
|
|
936
|
+
}
|
|
933
937
|
type AllEmbedding = {
|
|
934
938
|
"openai.embedding.v1": {
|
|
935
939
|
input: OpenAiEmbeddingOptions;
|
|
@@ -960,6 +964,9 @@ type AllLlm = {
|
|
|
960
964
|
"ollama.chat.v1": {
|
|
961
965
|
input: GenericLLm;
|
|
962
966
|
};
|
|
967
|
+
"google.chat.v1": {
|
|
968
|
+
input: GeminiRequest;
|
|
969
|
+
};
|
|
963
970
|
};
|
|
964
971
|
type AllUseLlmOptions = AllLlm & {
|
|
965
972
|
"openai.gpt-4": {
|
|
@@ -971,6 +978,9 @@ type AllUseLlmOptions = AllLlm & {
|
|
|
971
978
|
"openai.gpt-4o-mini": {
|
|
972
979
|
input: Omit<OpenAiRequest, "model">;
|
|
973
980
|
};
|
|
981
|
+
"anthropic.claude-3-7-sonnet": {
|
|
982
|
+
input: Omit<AnthropicRequest, "model">;
|
|
983
|
+
};
|
|
974
984
|
"anthropic.claude-3-5-sonnet": {
|
|
975
985
|
input: Omit<AnthropicRequest, "model">;
|
|
976
986
|
};
|
|
@@ -980,12 +990,39 @@ type AllUseLlmOptions = AllLlm & {
|
|
|
980
990
|
"anthropic.claude-3-sonnet": {
|
|
981
991
|
input: Omit<AnthropicRequest, "model">;
|
|
982
992
|
};
|
|
983
|
-
"anthropic.claude-3-haiku": {
|
|
993
|
+
"anthropic.claude-3-5-haiku": {
|
|
984
994
|
input: Omit<AnthropicRequest, "model">;
|
|
985
995
|
};
|
|
996
|
+
"google.gemini-2.5-pro-exp-03-25": {
|
|
997
|
+
input: Omit<GeminiRequest, "model">;
|
|
998
|
+
};
|
|
999
|
+
"google.gemini-2.0-flash": {
|
|
1000
|
+
input: Omit<GeminiRequest, "model">;
|
|
1001
|
+
};
|
|
1002
|
+
"google.gemini-2.0-flash-lite": {
|
|
1003
|
+
input: Omit<GeminiRequest, "model">;
|
|
1004
|
+
};
|
|
1005
|
+
"google.gemini-1.5-pro": {
|
|
1006
|
+
input: Omit<GeminiRequest, "model">;
|
|
1007
|
+
};
|
|
986
1008
|
"xai.grok-2": {
|
|
987
1009
|
input: OpenAiRequest;
|
|
988
1010
|
};
|
|
1011
|
+
"ollama.deepseek-r1": {
|
|
1012
|
+
input: GenericLLm;
|
|
1013
|
+
};
|
|
1014
|
+
"ollama.llama3.3": {
|
|
1015
|
+
input: GenericLLm;
|
|
1016
|
+
};
|
|
1017
|
+
"ollama.llama3.2": {
|
|
1018
|
+
input: GenericLLm;
|
|
1019
|
+
};
|
|
1020
|
+
"ollama.llama3.1": {
|
|
1021
|
+
input: GenericLLm;
|
|
1022
|
+
};
|
|
1023
|
+
"ollama.qwq": {
|
|
1024
|
+
input: GenericLLm;
|
|
1025
|
+
};
|
|
989
1026
|
};
|
|
990
1027
|
type LlmProviderKey = keyof AllLlm;
|
|
991
1028
|
type EmbeddingProviderKey = keyof AllEmbedding;
|
|
@@ -1003,7 +1040,7 @@ interface BaseRequest<_T extends Record<string, any>> {
|
|
|
1003
1040
|
interface BaseLlm<_T extends BaseLlCall = BaseLlCall> extends BaseRequest<_T> {
|
|
1004
1041
|
}
|
|
1005
1042
|
|
|
1006
|
-
type LlmProvider = "openai.chat" | "openai.embedding" | "openai.chat-mock" | "anthropic.chat" | "amazon:anthropic.chat" | "amazon:meta.chat" | "amazon:nova.chat" | "amazon.embedding" | "xai.chat" | "ollama.chat";
|
|
1043
|
+
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";
|
|
1007
1044
|
interface Config<Pk = LlmProviderKey> {
|
|
1008
1045
|
key: Pk;
|
|
1009
1046
|
provider: LlmProvider;
|
|
@@ -1182,16 +1219,25 @@ declare namespace index {
|
|
|
1182
1219
|
}
|
|
1183
1220
|
|
|
1184
1221
|
declare const configs: {
|
|
1222
|
+
"google.chat.v1": Config<keyof AllLlm>;
|
|
1223
|
+
"google.gemini-2.0-flash": Config<keyof AllLlm>;
|
|
1224
|
+
"google.gemini-2.0-flash-lite": Config<keyof AllLlm>;
|
|
1225
|
+
"google.gemini-1.5-pro": Config<keyof AllLlm>;
|
|
1185
1226
|
"ollama.chat.v1": Config<keyof AllLlm>;
|
|
1227
|
+
"ollama.deepseek-r1": Config<keyof AllLlm>;
|
|
1228
|
+
"ollama.llama3.3": Config<keyof AllLlm>;
|
|
1229
|
+
"ollama.llama3.2": Config<keyof AllLlm>;
|
|
1230
|
+
"ollama.llama3.1": Config<keyof AllLlm>;
|
|
1231
|
+
"ollama.qwq": Config<keyof AllLlm>;
|
|
1186
1232
|
"xai.chat.v1": Config<keyof AllLlm>;
|
|
1187
1233
|
"xai.grok-2": Config<keyof AllLlm>;
|
|
1188
1234
|
"amazon:anthropic.chat.v1": Config<keyof AllLlm>;
|
|
1189
1235
|
"amazon:meta.chat.v1": Config<keyof AllLlm>;
|
|
1190
1236
|
"anthropic.chat.v1": Config<keyof AllLlm>;
|
|
1237
|
+
"anthropic.claude-3-7-sonnet": Config<keyof AllLlm>;
|
|
1191
1238
|
"anthropic.claude-3-5-sonnet": Config<keyof AllLlm>;
|
|
1239
|
+
"anthropic.claude-3-5-haiku": Config<keyof AllLlm>;
|
|
1192
1240
|
"anthropic.claude-3-opus": Config<keyof AllLlm>;
|
|
1193
|
-
"anthropic.claude-3-sonnet": Config<keyof AllLlm>;
|
|
1194
|
-
"anthropic.claude-3-haiku": Config<keyof AllLlm>;
|
|
1195
1241
|
"openai.chat.v1": Config<keyof AllLlm>;
|
|
1196
1242
|
"openai.chat-mock.v1": Config<keyof AllLlm>;
|
|
1197
1243
|
"openai.gpt-4o": Config<keyof AllLlm>;
|
|
@@ -1237,4 +1283,4 @@ declare function createEmbedding<T extends EmbeddingProviderKey>(provider: T, op
|
|
|
1237
1283
|
};
|
|
1238
1284
|
};
|
|
1239
1285
|
|
|
1240
|
-
export { BaseExecutor, type BaseLlm, BaseParser, BasePrompt, BaseStateItem, ChatPrompt, CustomParser, DefaultState, DefaultStateItem, type IChatMessages, LlmExecutorOpenAiFunctions, type LlmProvider, type OpenAIModelName, OpenAiFunctionParser, TextPrompt, createCallableExecutor, createChatPrompt, createCoreExecutor, createCustomParser, createDialogue, createEmbedding, createLlmExecutor, createParser, createPrompt, createState, createStateItem, useExecutors, useLlm, index as utils };
|
|
1286
|
+
export { BaseExecutor, type BaseLlm, BaseParser, BasePrompt, BaseStateItem, ChatPrompt, CustomParser, DefaultState, DefaultStateItem, type ExecutorContext, type IChatMessages, LlmExecutorOpenAiFunctions, type LlmProvider, type OpenAIModelName, OpenAiFunctionParser, TextPrompt, createCallableExecutor, createChatPrompt, createCoreExecutor, createCustomParser, createDialogue, createEmbedding, createLlmExecutor, createParser, createPrompt, createState, createStateItem, useExecutors, useLlm, index as utils };
|
package/dist/index.js
CHANGED
|
@@ -1572,6 +1572,23 @@ function validateParserSchema(schema, parsed) {
|
|
|
1572
1572
|
}
|
|
1573
1573
|
__name(validateParserSchema, "validateParserSchema");
|
|
1574
1574
|
|
|
1575
|
+
// src/utils/modules/errors.ts
|
|
1576
|
+
var _LlmExeError = class _LlmExeError extends Error {
|
|
1577
|
+
constructor(message, code, context) {
|
|
1578
|
+
super(message ?? "");
|
|
1579
|
+
__publicField(this, "code");
|
|
1580
|
+
__publicField(this, "context");
|
|
1581
|
+
this.name = this.constructor.name;
|
|
1582
|
+
this.code = code ?? "unknown";
|
|
1583
|
+
this.context = context;
|
|
1584
|
+
if (Error.captureStackTrace) {
|
|
1585
|
+
Error.captureStackTrace(this, this.constructor);
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
};
|
|
1589
|
+
__name(_LlmExeError, "LlmExeError");
|
|
1590
|
+
var LlmExeError = _LlmExeError;
|
|
1591
|
+
|
|
1575
1592
|
// src/parser/parsers/JsonParser.ts
|
|
1576
1593
|
var _JsonParser = class _JsonParser extends BaseParserWithJson {
|
|
1577
1594
|
constructor(options = {}) {
|
|
@@ -1584,7 +1601,11 @@ var _JsonParser = class _JsonParser extends BaseParserWithJson {
|
|
|
1584
1601
|
if (this.validateSchema) {
|
|
1585
1602
|
const valid = validateParserSchema(this.schema, enforce);
|
|
1586
1603
|
if (valid && valid.length) {
|
|
1587
|
-
throw new
|
|
1604
|
+
throw new LlmExeError(valid[0].message, "parser", {
|
|
1605
|
+
parser: "json",
|
|
1606
|
+
output: parsed,
|
|
1607
|
+
error: valid[0].message
|
|
1608
|
+
});
|
|
1588
1609
|
}
|
|
1589
1610
|
}
|
|
1590
1611
|
return enforce;
|
|
@@ -1629,7 +1650,11 @@ var _ListToJsonParser = class _ListToJsonParser extends BaseParserWithJson {
|
|
|
1629
1650
|
if (this?.validateSchema) {
|
|
1630
1651
|
const valid = validateParserSchema(this.schema, parsed);
|
|
1631
1652
|
if (valid && valid.length) {
|
|
1632
|
-
throw new
|
|
1653
|
+
throw new LlmExeError(valid[0].message, "parser", {
|
|
1654
|
+
parser: "json",
|
|
1655
|
+
output: parsed,
|
|
1656
|
+
error: valid[0].message
|
|
1657
|
+
});
|
|
1633
1658
|
}
|
|
1634
1659
|
}
|
|
1635
1660
|
return parsed;
|
|
@@ -2185,8 +2210,7 @@ var openai = {
|
|
|
2185
2210
|
"openai.gpt-4o-mini": withDefaultModel(openAiChatV1, "gpt-4o-mini")
|
|
2186
2211
|
};
|
|
2187
2212
|
|
|
2188
|
-
// src/llm/config/anthropic/
|
|
2189
|
-
var ANTORPIC_VERSION = "2023-06-01";
|
|
2213
|
+
// src/llm/config/anthropic/promptSanitize.ts
|
|
2190
2214
|
function anthropicPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
2191
2215
|
if (typeof _messages === "string") {
|
|
2192
2216
|
return [
|
|
@@ -2220,49 +2244,6 @@ function anthropicPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
|
2220
2244
|
];
|
|
2221
2245
|
}
|
|
2222
2246
|
__name(anthropicPromptSanitize, "anthropicPromptSanitize");
|
|
2223
|
-
var anthropicChatV1 = {
|
|
2224
|
-
key: "anthropic.chat.v1",
|
|
2225
|
-
provider: "anthropic.chat",
|
|
2226
|
-
endpoint: `https://api.anthropic.com/v1/messages`,
|
|
2227
|
-
headers: `{"x-api-key":"{{anthropicApiKey}}", "Content-Type": "application/json", "anthropic-version": "${ANTORPIC_VERSION}" }`,
|
|
2228
|
-
method: "POST",
|
|
2229
|
-
options: {
|
|
2230
|
-
prompt: {},
|
|
2231
|
-
system: {},
|
|
2232
|
-
maxTokens: {
|
|
2233
|
-
required: [
|
|
2234
|
-
true,
|
|
2235
|
-
"maxTokens required"
|
|
2236
|
-
],
|
|
2237
|
-
default: 4096
|
|
2238
|
-
},
|
|
2239
|
-
anthropicApiKey: {
|
|
2240
|
-
default: getEnvironmentVariable("ANTHROPIC_API_KEY")
|
|
2241
|
-
}
|
|
2242
|
-
},
|
|
2243
|
-
mapBody: {
|
|
2244
|
-
model: {
|
|
2245
|
-
key: "model"
|
|
2246
|
-
},
|
|
2247
|
-
maxTokens: {
|
|
2248
|
-
key: "max_tokens"
|
|
2249
|
-
},
|
|
2250
|
-
system: {
|
|
2251
|
-
key: "system"
|
|
2252
|
-
},
|
|
2253
|
-
prompt: {
|
|
2254
|
-
key: "messages",
|
|
2255
|
-
sanitize: anthropicPromptSanitize
|
|
2256
|
-
}
|
|
2257
|
-
}
|
|
2258
|
-
};
|
|
2259
|
-
var anthropic = {
|
|
2260
|
-
"anthropic.chat.v1": anthropicChatV1,
|
|
2261
|
-
"anthropic.claude-3-5-sonnet": withDefaultModel(anthropicChatV1, "claude-3-5-sonnet-20240620"),
|
|
2262
|
-
"anthropic.claude-3-opus": withDefaultModel(anthropicChatV1, "claude-3-opus-20240229"),
|
|
2263
|
-
"anthropic.claude-3-sonnet": withDefaultModel(anthropicChatV1, "claude-3-sonnet-20240229"),
|
|
2264
|
-
"anthropic.claude-3-haiku": withDefaultModel(anthropicChatV1, "claude-3-haiku-20240307")
|
|
2265
|
-
};
|
|
2266
2247
|
|
|
2267
2248
|
// src/llm/config/bedrock/index.ts
|
|
2268
2249
|
var ANTORPIC_BEDROCK_VERSION = "bedrock-2023-05-31";
|
|
@@ -2351,6 +2332,52 @@ var bedrock = {
|
|
|
2351
2332
|
"amazon:meta.chat.v1": amazonMetaChatV1
|
|
2352
2333
|
};
|
|
2353
2334
|
|
|
2335
|
+
// src/llm/config/anthropic/index.ts
|
|
2336
|
+
var ANTHROPIC_VERSION = "2023-06-01";
|
|
2337
|
+
var anthropicChatV1 = {
|
|
2338
|
+
key: "anthropic.chat.v1",
|
|
2339
|
+
provider: "anthropic.chat",
|
|
2340
|
+
endpoint: `https://api.anthropic.com/v1/messages`,
|
|
2341
|
+
headers: `{"x-api-key":"{{anthropicApiKey}}", "Content-Type": "application/json", "anthropic-version": "${ANTHROPIC_VERSION}" }`,
|
|
2342
|
+
method: "POST",
|
|
2343
|
+
options: {
|
|
2344
|
+
prompt: {},
|
|
2345
|
+
system: {},
|
|
2346
|
+
maxTokens: {
|
|
2347
|
+
required: [
|
|
2348
|
+
true,
|
|
2349
|
+
"maxTokens required"
|
|
2350
|
+
],
|
|
2351
|
+
default: 4096
|
|
2352
|
+
},
|
|
2353
|
+
anthropicApiKey: {
|
|
2354
|
+
default: getEnvironmentVariable("ANTHROPIC_API_KEY")
|
|
2355
|
+
}
|
|
2356
|
+
},
|
|
2357
|
+
mapBody: {
|
|
2358
|
+
model: {
|
|
2359
|
+
key: "model"
|
|
2360
|
+
},
|
|
2361
|
+
maxTokens: {
|
|
2362
|
+
key: "max_tokens"
|
|
2363
|
+
},
|
|
2364
|
+
system: {
|
|
2365
|
+
key: "system"
|
|
2366
|
+
},
|
|
2367
|
+
prompt: {
|
|
2368
|
+
key: "messages",
|
|
2369
|
+
sanitize: anthropicPromptSanitize
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
};
|
|
2373
|
+
var anthropic = {
|
|
2374
|
+
"anthropic.chat.v1": anthropicChatV1,
|
|
2375
|
+
"anthropic.claude-3-7-sonnet": withDefaultModel(anthropicChatV1, "claude-3-7-sonnet-latest"),
|
|
2376
|
+
"anthropic.claude-3-5-sonnet": withDefaultModel(anthropicChatV1, "claude-3-5-sonnet-latest"),
|
|
2377
|
+
"anthropic.claude-3-5-haiku": withDefaultModel(anthropicChatV1, "claude-3-5-haiku-latest"),
|
|
2378
|
+
"anthropic.claude-3-opus": withDefaultModel(anthropicChatV1, "claude-3-opus-latest")
|
|
2379
|
+
};
|
|
2380
|
+
|
|
2354
2381
|
// src/llm/config/x/index.ts
|
|
2355
2382
|
var xaiChatV1 = {
|
|
2356
2383
|
key: "xai.chat.v1",
|
|
@@ -2429,7 +2456,135 @@ var ollamaChatV1 = {
|
|
|
2429
2456
|
}
|
|
2430
2457
|
};
|
|
2431
2458
|
var ollama = {
|
|
2432
|
-
"ollama.chat.v1": ollamaChatV1
|
|
2459
|
+
"ollama.chat.v1": ollamaChatV1,
|
|
2460
|
+
"ollama.deepseek-r1": withDefaultModel(ollamaChatV1, "deepseek-r1"),
|
|
2461
|
+
"ollama.llama3.3": withDefaultModel(ollamaChatV1, "llama3.3"),
|
|
2462
|
+
"ollama.llama3.2": withDefaultModel(ollamaChatV1, "llama3.2"),
|
|
2463
|
+
"ollama.llama3.1": withDefaultModel(ollamaChatV1, "llama3.1"),
|
|
2464
|
+
"ollama.qwq": withDefaultModel(ollamaChatV1, "qwq")
|
|
2465
|
+
};
|
|
2466
|
+
|
|
2467
|
+
// src/utils/modules/modifyPromptRoleChange.ts
|
|
2468
|
+
function modifyPromptRoleChange(messages, roleChanges) {
|
|
2469
|
+
const roleChangeMap = new Map(roleChanges.map(({ from, to }) => [
|
|
2470
|
+
from,
|
|
2471
|
+
to
|
|
2472
|
+
]));
|
|
2473
|
+
if (Array.isArray(messages)) {
|
|
2474
|
+
return messages.map((message) => {
|
|
2475
|
+
const newRole2 = roleChangeMap.get(message.role);
|
|
2476
|
+
return newRole2 ? {
|
|
2477
|
+
...message,
|
|
2478
|
+
role: newRole2
|
|
2479
|
+
} : message;
|
|
2480
|
+
});
|
|
2481
|
+
}
|
|
2482
|
+
const newRole = roleChangeMap.get(messages.role);
|
|
2483
|
+
return newRole ? {
|
|
2484
|
+
...messages,
|
|
2485
|
+
role: newRole
|
|
2486
|
+
} : messages;
|
|
2487
|
+
}
|
|
2488
|
+
__name(modifyPromptRoleChange, "modifyPromptRoleChange");
|
|
2489
|
+
|
|
2490
|
+
// src/llm/config/google/promptSanitizeMessageCallback.ts
|
|
2491
|
+
function googleGeminiPromptMessageCallback(_message) {
|
|
2492
|
+
let message = {
|
|
2493
|
+
..._message
|
|
2494
|
+
};
|
|
2495
|
+
message = modifyPromptRoleChange(_message, [
|
|
2496
|
+
{
|
|
2497
|
+
from: "assistant",
|
|
2498
|
+
to: "model"
|
|
2499
|
+
}
|
|
2500
|
+
]);
|
|
2501
|
+
const { role, ...payload } = message;
|
|
2502
|
+
const parts = [];
|
|
2503
|
+
if (typeof payload.content === "string") {
|
|
2504
|
+
parts.push({
|
|
2505
|
+
text: message.content
|
|
2506
|
+
});
|
|
2507
|
+
}
|
|
2508
|
+
return {
|
|
2509
|
+
role,
|
|
2510
|
+
parts
|
|
2511
|
+
};
|
|
2512
|
+
}
|
|
2513
|
+
__name(googleGeminiPromptMessageCallback, "googleGeminiPromptMessageCallback");
|
|
2514
|
+
|
|
2515
|
+
// src/llm/config/google/promptSanitize.ts
|
|
2516
|
+
function googleGeminiPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
2517
|
+
if (typeof _messages === "string") {
|
|
2518
|
+
return [
|
|
2519
|
+
{
|
|
2520
|
+
role: "user",
|
|
2521
|
+
parts: [
|
|
2522
|
+
{
|
|
2523
|
+
text: _messages
|
|
2524
|
+
}
|
|
2525
|
+
]
|
|
2526
|
+
}
|
|
2527
|
+
];
|
|
2528
|
+
}
|
|
2529
|
+
if (Array.isArray(_messages)) {
|
|
2530
|
+
if (_messages.length === 0) {
|
|
2531
|
+
throw new Error("Empty messages array");
|
|
2532
|
+
}
|
|
2533
|
+
if (_messages.length === 1 && _messages[0].role === "system") {
|
|
2534
|
+
return [
|
|
2535
|
+
{
|
|
2536
|
+
role: "user",
|
|
2537
|
+
parts: [
|
|
2538
|
+
{
|
|
2539
|
+
text: _messages[0].content
|
|
2540
|
+
}
|
|
2541
|
+
]
|
|
2542
|
+
}
|
|
2543
|
+
];
|
|
2544
|
+
}
|
|
2545
|
+
const hasSystemInstruction = _messages.some((message) => message.role === "system");
|
|
2546
|
+
if (hasSystemInstruction) {
|
|
2547
|
+
const theSystemInstructions = _messages.filter((message) => message.role === "system");
|
|
2548
|
+
const withoutSystemInstructions = _messages.filter((message) => message.role !== "system");
|
|
2549
|
+
_outputObj.system_instruction = {
|
|
2550
|
+
parts: theSystemInstructions.map((message) => ({
|
|
2551
|
+
text: message.content
|
|
2552
|
+
}))
|
|
2553
|
+
};
|
|
2554
|
+
return withoutSystemInstructions.map(googleGeminiPromptMessageCallback);
|
|
2555
|
+
}
|
|
2556
|
+
return _messages.map(googleGeminiPromptMessageCallback);
|
|
2557
|
+
}
|
|
2558
|
+
throw new Error("Invalid messages format");
|
|
2559
|
+
}
|
|
2560
|
+
__name(googleGeminiPromptSanitize, "googleGeminiPromptSanitize");
|
|
2561
|
+
|
|
2562
|
+
// src/llm/config/google/index.ts
|
|
2563
|
+
var googleGeminiChatV1 = {
|
|
2564
|
+
key: "google.chat.v1",
|
|
2565
|
+
provider: "google.chat",
|
|
2566
|
+
endpoint: `https://generativelanguage.googleapis.com/v1beta/models/{{model}}:generateContent?key={{geminiApiKey}}`,
|
|
2567
|
+
options: {
|
|
2568
|
+
prompt: {},
|
|
2569
|
+
// topP: {},
|
|
2570
|
+
geminiApiKey: {
|
|
2571
|
+
default: getEnvironmentVariable("GEMINI_API_KEY")
|
|
2572
|
+
}
|
|
2573
|
+
},
|
|
2574
|
+
method: "POST",
|
|
2575
|
+
headers: `{"Content-Type": "application/json" }`,
|
|
2576
|
+
mapBody: {
|
|
2577
|
+
prompt: {
|
|
2578
|
+
key: "contents",
|
|
2579
|
+
sanitize: googleGeminiPromptSanitize
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
};
|
|
2583
|
+
var google = {
|
|
2584
|
+
"google.chat.v1": googleGeminiChatV1,
|
|
2585
|
+
"google.gemini-2.0-flash": withDefaultModel(googleGeminiChatV1, "gemini-2.0-flash"),
|
|
2586
|
+
"google.gemini-2.0-flash-lite": withDefaultModel(googleGeminiChatV1, "gemini-2.0-flash-lite"),
|
|
2587
|
+
"google.gemini-1.5-pro": withDefaultModel(googleGeminiChatV1, "gemini-1.5-pro")
|
|
2433
2588
|
};
|
|
2434
2589
|
|
|
2435
2590
|
// src/llm/config.ts
|
|
@@ -2438,14 +2593,25 @@ var configs = {
|
|
|
2438
2593
|
...anthropic,
|
|
2439
2594
|
...bedrock,
|
|
2440
2595
|
...xai,
|
|
2441
|
-
...ollama
|
|
2596
|
+
...ollama,
|
|
2597
|
+
...google
|
|
2442
2598
|
};
|
|
2443
2599
|
function getLlmConfig(provider) {
|
|
2600
|
+
if (!provider) {
|
|
2601
|
+
throw new LlmExeError(`Missing provider`, "unknown", {
|
|
2602
|
+
error: "Missing provider",
|
|
2603
|
+
resolution: "Provide a valid provider"
|
|
2604
|
+
});
|
|
2605
|
+
}
|
|
2444
2606
|
const pick2 = configs[provider];
|
|
2445
2607
|
if (pick2) {
|
|
2446
2608
|
return pick2;
|
|
2447
2609
|
}
|
|
2448
|
-
throw new
|
|
2610
|
+
throw new LlmExeError(`Invalid provider: ${provider}`, "unknown", {
|
|
2611
|
+
provider,
|
|
2612
|
+
error: `Invalid provider: ${provider}`,
|
|
2613
|
+
resolution: "Provide a valid provider"
|
|
2614
|
+
});
|
|
2449
2615
|
}
|
|
2450
2616
|
__name(getLlmConfig, "getLlmConfig");
|
|
2451
2617
|
|
|
@@ -2791,6 +2957,57 @@ function OutputOllamaChat(result, _config) {
|
|
|
2791
2957
|
}
|
|
2792
2958
|
__name(OutputOllamaChat, "OutputOllamaChat");
|
|
2793
2959
|
|
|
2960
|
+
// src/llm/output/google.gemini/formatResult.ts
|
|
2961
|
+
function formatResult4(result) {
|
|
2962
|
+
const { parts = [] } = result?.content || {};
|
|
2963
|
+
if (parts.length === 1) {
|
|
2964
|
+
const answer = parts[0];
|
|
2965
|
+
if (!!answer?.functionCall && typeof answer?.functionCall === "object") {
|
|
2966
|
+
return {
|
|
2967
|
+
type: "function_use",
|
|
2968
|
+
name: answer.functionCall.name,
|
|
2969
|
+
input: JSON.parse(answer.functionCall.args)
|
|
2970
|
+
};
|
|
2971
|
+
} else {
|
|
2972
|
+
return {
|
|
2973
|
+
type: "text",
|
|
2974
|
+
text: answer.text || ""
|
|
2975
|
+
};
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
2978
|
+
return {
|
|
2979
|
+
type: "text",
|
|
2980
|
+
text: ""
|
|
2981
|
+
};
|
|
2982
|
+
}
|
|
2983
|
+
__name(formatResult4, "formatResult");
|
|
2984
|
+
|
|
2985
|
+
// src/llm/output/google.gemini/index.ts
|
|
2986
|
+
function OutputGoogleGeminiChat(result, _config) {
|
|
2987
|
+
const id = "result.id";
|
|
2988
|
+
const name = result.modelVersion;
|
|
2989
|
+
const created = (/* @__PURE__ */ new Date()).getTime();
|
|
2990
|
+
const [_content, ..._options] = result?.candidates || [];
|
|
2991
|
+
const stopReason = _content?.finishReason?.toLowerCase();
|
|
2992
|
+
const content = formatContent(_content, formatResult4);
|
|
2993
|
+
const options = formatOptions(_options, formatResult4);
|
|
2994
|
+
const usage = {
|
|
2995
|
+
output_tokens: result?.usageMetadata?.candidatesTokenCount,
|
|
2996
|
+
input_tokens: result?.usageMetadata?.promptTokenCount,
|
|
2997
|
+
total_tokens: result?.usageMetadata?.totalTokenCount
|
|
2998
|
+
};
|
|
2999
|
+
return BaseLlmOutput2({
|
|
3000
|
+
id,
|
|
3001
|
+
name,
|
|
3002
|
+
created,
|
|
3003
|
+
usage,
|
|
3004
|
+
stopReason,
|
|
3005
|
+
content,
|
|
3006
|
+
options
|
|
3007
|
+
});
|
|
3008
|
+
}
|
|
3009
|
+
__name(OutputGoogleGeminiChat, "OutputGoogleGeminiChat");
|
|
3010
|
+
|
|
2794
3011
|
// src/llm/output/index.ts
|
|
2795
3012
|
function getOutputParser(config, response) {
|
|
2796
3013
|
switch (config?.key) {
|
|
@@ -2808,6 +3025,8 @@ function getOutputParser(config, response) {
|
|
|
2808
3025
|
return OutputXAIChat(response, config);
|
|
2809
3026
|
case "ollama.chat.v1":
|
|
2810
3027
|
return OutputOllamaChat(response, config);
|
|
3028
|
+
case "google.chat.v1":
|
|
3029
|
+
return OutputGoogleGeminiChat(response, config);
|
|
2811
3030
|
default: {
|
|
2812
3031
|
if (config?.key?.startsWith("custom:")) {
|
|
2813
3032
|
return OutputDefault(response, config);
|
|
@@ -3421,11 +3640,14 @@ var embeddingConfigs = {
|
|
|
3421
3640
|
}
|
|
3422
3641
|
};
|
|
3423
3642
|
function getEmbeddingConfig(provider) {
|
|
3643
|
+
if (!provider) {
|
|
3644
|
+
throw new Error(`Missing provider`);
|
|
3645
|
+
}
|
|
3424
3646
|
const pick2 = embeddingConfigs[provider];
|
|
3425
3647
|
if (pick2) {
|
|
3426
3648
|
return pick2;
|
|
3427
3649
|
}
|
|
3428
|
-
throw new Error(
|
|
3650
|
+
throw new Error(`Invalid provider: ${provider}`);
|
|
3429
3651
|
}
|
|
3430
3652
|
__name(getEmbeddingConfig, "getEmbeddingConfig");
|
|
3431
3653
|
|
package/dist/index.mjs
CHANGED
|
@@ -1524,6 +1524,23 @@ function validateParserSchema(schema, parsed) {
|
|
|
1524
1524
|
}
|
|
1525
1525
|
__name(validateParserSchema, "validateParserSchema");
|
|
1526
1526
|
|
|
1527
|
+
// src/utils/modules/errors.ts
|
|
1528
|
+
var _LlmExeError = class _LlmExeError extends Error {
|
|
1529
|
+
constructor(message, code, context) {
|
|
1530
|
+
super(message ?? "");
|
|
1531
|
+
__publicField(this, "code");
|
|
1532
|
+
__publicField(this, "context");
|
|
1533
|
+
this.name = this.constructor.name;
|
|
1534
|
+
this.code = code ?? "unknown";
|
|
1535
|
+
this.context = context;
|
|
1536
|
+
if (Error.captureStackTrace) {
|
|
1537
|
+
Error.captureStackTrace(this, this.constructor);
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
};
|
|
1541
|
+
__name(_LlmExeError, "LlmExeError");
|
|
1542
|
+
var LlmExeError = _LlmExeError;
|
|
1543
|
+
|
|
1527
1544
|
// src/parser/parsers/JsonParser.ts
|
|
1528
1545
|
var _JsonParser = class _JsonParser extends BaseParserWithJson {
|
|
1529
1546
|
constructor(options = {}) {
|
|
@@ -1536,7 +1553,11 @@ var _JsonParser = class _JsonParser extends BaseParserWithJson {
|
|
|
1536
1553
|
if (this.validateSchema) {
|
|
1537
1554
|
const valid = validateParserSchema(this.schema, enforce);
|
|
1538
1555
|
if (valid && valid.length) {
|
|
1539
|
-
throw new
|
|
1556
|
+
throw new LlmExeError(valid[0].message, "parser", {
|
|
1557
|
+
parser: "json",
|
|
1558
|
+
output: parsed,
|
|
1559
|
+
error: valid[0].message
|
|
1560
|
+
});
|
|
1540
1561
|
}
|
|
1541
1562
|
}
|
|
1542
1563
|
return enforce;
|
|
@@ -1581,7 +1602,11 @@ var _ListToJsonParser = class _ListToJsonParser extends BaseParserWithJson {
|
|
|
1581
1602
|
if (this?.validateSchema) {
|
|
1582
1603
|
const valid = validateParserSchema(this.schema, parsed);
|
|
1583
1604
|
if (valid && valid.length) {
|
|
1584
|
-
throw new
|
|
1605
|
+
throw new LlmExeError(valid[0].message, "parser", {
|
|
1606
|
+
parser: "json",
|
|
1607
|
+
output: parsed,
|
|
1608
|
+
error: valid[0].message
|
|
1609
|
+
});
|
|
1585
1610
|
}
|
|
1586
1611
|
}
|
|
1587
1612
|
return parsed;
|
|
@@ -2137,8 +2162,7 @@ var openai = {
|
|
|
2137
2162
|
"openai.gpt-4o-mini": withDefaultModel(openAiChatV1, "gpt-4o-mini")
|
|
2138
2163
|
};
|
|
2139
2164
|
|
|
2140
|
-
// src/llm/config/anthropic/
|
|
2141
|
-
var ANTORPIC_VERSION = "2023-06-01";
|
|
2165
|
+
// src/llm/config/anthropic/promptSanitize.ts
|
|
2142
2166
|
function anthropicPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
2143
2167
|
if (typeof _messages === "string") {
|
|
2144
2168
|
return [
|
|
@@ -2172,49 +2196,6 @@ function anthropicPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
|
2172
2196
|
];
|
|
2173
2197
|
}
|
|
2174
2198
|
__name(anthropicPromptSanitize, "anthropicPromptSanitize");
|
|
2175
|
-
var anthropicChatV1 = {
|
|
2176
|
-
key: "anthropic.chat.v1",
|
|
2177
|
-
provider: "anthropic.chat",
|
|
2178
|
-
endpoint: `https://api.anthropic.com/v1/messages`,
|
|
2179
|
-
headers: `{"x-api-key":"{{anthropicApiKey}}", "Content-Type": "application/json", "anthropic-version": "${ANTORPIC_VERSION}" }`,
|
|
2180
|
-
method: "POST",
|
|
2181
|
-
options: {
|
|
2182
|
-
prompt: {},
|
|
2183
|
-
system: {},
|
|
2184
|
-
maxTokens: {
|
|
2185
|
-
required: [
|
|
2186
|
-
true,
|
|
2187
|
-
"maxTokens required"
|
|
2188
|
-
],
|
|
2189
|
-
default: 4096
|
|
2190
|
-
},
|
|
2191
|
-
anthropicApiKey: {
|
|
2192
|
-
default: getEnvironmentVariable("ANTHROPIC_API_KEY")
|
|
2193
|
-
}
|
|
2194
|
-
},
|
|
2195
|
-
mapBody: {
|
|
2196
|
-
model: {
|
|
2197
|
-
key: "model"
|
|
2198
|
-
},
|
|
2199
|
-
maxTokens: {
|
|
2200
|
-
key: "max_tokens"
|
|
2201
|
-
},
|
|
2202
|
-
system: {
|
|
2203
|
-
key: "system"
|
|
2204
|
-
},
|
|
2205
|
-
prompt: {
|
|
2206
|
-
key: "messages",
|
|
2207
|
-
sanitize: anthropicPromptSanitize
|
|
2208
|
-
}
|
|
2209
|
-
}
|
|
2210
|
-
};
|
|
2211
|
-
var anthropic = {
|
|
2212
|
-
"anthropic.chat.v1": anthropicChatV1,
|
|
2213
|
-
"anthropic.claude-3-5-sonnet": withDefaultModel(anthropicChatV1, "claude-3-5-sonnet-20240620"),
|
|
2214
|
-
"anthropic.claude-3-opus": withDefaultModel(anthropicChatV1, "claude-3-opus-20240229"),
|
|
2215
|
-
"anthropic.claude-3-sonnet": withDefaultModel(anthropicChatV1, "claude-3-sonnet-20240229"),
|
|
2216
|
-
"anthropic.claude-3-haiku": withDefaultModel(anthropicChatV1, "claude-3-haiku-20240307")
|
|
2217
|
-
};
|
|
2218
2199
|
|
|
2219
2200
|
// src/llm/config/bedrock/index.ts
|
|
2220
2201
|
var ANTORPIC_BEDROCK_VERSION = "bedrock-2023-05-31";
|
|
@@ -2303,6 +2284,52 @@ var bedrock = {
|
|
|
2303
2284
|
"amazon:meta.chat.v1": amazonMetaChatV1
|
|
2304
2285
|
};
|
|
2305
2286
|
|
|
2287
|
+
// src/llm/config/anthropic/index.ts
|
|
2288
|
+
var ANTHROPIC_VERSION = "2023-06-01";
|
|
2289
|
+
var anthropicChatV1 = {
|
|
2290
|
+
key: "anthropic.chat.v1",
|
|
2291
|
+
provider: "anthropic.chat",
|
|
2292
|
+
endpoint: `https://api.anthropic.com/v1/messages`,
|
|
2293
|
+
headers: `{"x-api-key":"{{anthropicApiKey}}", "Content-Type": "application/json", "anthropic-version": "${ANTHROPIC_VERSION}" }`,
|
|
2294
|
+
method: "POST",
|
|
2295
|
+
options: {
|
|
2296
|
+
prompt: {},
|
|
2297
|
+
system: {},
|
|
2298
|
+
maxTokens: {
|
|
2299
|
+
required: [
|
|
2300
|
+
true,
|
|
2301
|
+
"maxTokens required"
|
|
2302
|
+
],
|
|
2303
|
+
default: 4096
|
|
2304
|
+
},
|
|
2305
|
+
anthropicApiKey: {
|
|
2306
|
+
default: getEnvironmentVariable("ANTHROPIC_API_KEY")
|
|
2307
|
+
}
|
|
2308
|
+
},
|
|
2309
|
+
mapBody: {
|
|
2310
|
+
model: {
|
|
2311
|
+
key: "model"
|
|
2312
|
+
},
|
|
2313
|
+
maxTokens: {
|
|
2314
|
+
key: "max_tokens"
|
|
2315
|
+
},
|
|
2316
|
+
system: {
|
|
2317
|
+
key: "system"
|
|
2318
|
+
},
|
|
2319
|
+
prompt: {
|
|
2320
|
+
key: "messages",
|
|
2321
|
+
sanitize: anthropicPromptSanitize
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
};
|
|
2325
|
+
var anthropic = {
|
|
2326
|
+
"anthropic.chat.v1": anthropicChatV1,
|
|
2327
|
+
"anthropic.claude-3-7-sonnet": withDefaultModel(anthropicChatV1, "claude-3-7-sonnet-latest"),
|
|
2328
|
+
"anthropic.claude-3-5-sonnet": withDefaultModel(anthropicChatV1, "claude-3-5-sonnet-latest"),
|
|
2329
|
+
"anthropic.claude-3-5-haiku": withDefaultModel(anthropicChatV1, "claude-3-5-haiku-latest"),
|
|
2330
|
+
"anthropic.claude-3-opus": withDefaultModel(anthropicChatV1, "claude-3-opus-latest")
|
|
2331
|
+
};
|
|
2332
|
+
|
|
2306
2333
|
// src/llm/config/x/index.ts
|
|
2307
2334
|
var xaiChatV1 = {
|
|
2308
2335
|
key: "xai.chat.v1",
|
|
@@ -2381,7 +2408,135 @@ var ollamaChatV1 = {
|
|
|
2381
2408
|
}
|
|
2382
2409
|
};
|
|
2383
2410
|
var ollama = {
|
|
2384
|
-
"ollama.chat.v1": ollamaChatV1
|
|
2411
|
+
"ollama.chat.v1": ollamaChatV1,
|
|
2412
|
+
"ollama.deepseek-r1": withDefaultModel(ollamaChatV1, "deepseek-r1"),
|
|
2413
|
+
"ollama.llama3.3": withDefaultModel(ollamaChatV1, "llama3.3"),
|
|
2414
|
+
"ollama.llama3.2": withDefaultModel(ollamaChatV1, "llama3.2"),
|
|
2415
|
+
"ollama.llama3.1": withDefaultModel(ollamaChatV1, "llama3.1"),
|
|
2416
|
+
"ollama.qwq": withDefaultModel(ollamaChatV1, "qwq")
|
|
2417
|
+
};
|
|
2418
|
+
|
|
2419
|
+
// src/utils/modules/modifyPromptRoleChange.ts
|
|
2420
|
+
function modifyPromptRoleChange(messages, roleChanges) {
|
|
2421
|
+
const roleChangeMap = new Map(roleChanges.map(({ from, to }) => [
|
|
2422
|
+
from,
|
|
2423
|
+
to
|
|
2424
|
+
]));
|
|
2425
|
+
if (Array.isArray(messages)) {
|
|
2426
|
+
return messages.map((message) => {
|
|
2427
|
+
const newRole2 = roleChangeMap.get(message.role);
|
|
2428
|
+
return newRole2 ? {
|
|
2429
|
+
...message,
|
|
2430
|
+
role: newRole2
|
|
2431
|
+
} : message;
|
|
2432
|
+
});
|
|
2433
|
+
}
|
|
2434
|
+
const newRole = roleChangeMap.get(messages.role);
|
|
2435
|
+
return newRole ? {
|
|
2436
|
+
...messages,
|
|
2437
|
+
role: newRole
|
|
2438
|
+
} : messages;
|
|
2439
|
+
}
|
|
2440
|
+
__name(modifyPromptRoleChange, "modifyPromptRoleChange");
|
|
2441
|
+
|
|
2442
|
+
// src/llm/config/google/promptSanitizeMessageCallback.ts
|
|
2443
|
+
function googleGeminiPromptMessageCallback(_message) {
|
|
2444
|
+
let message = {
|
|
2445
|
+
..._message
|
|
2446
|
+
};
|
|
2447
|
+
message = modifyPromptRoleChange(_message, [
|
|
2448
|
+
{
|
|
2449
|
+
from: "assistant",
|
|
2450
|
+
to: "model"
|
|
2451
|
+
}
|
|
2452
|
+
]);
|
|
2453
|
+
const { role, ...payload } = message;
|
|
2454
|
+
const parts = [];
|
|
2455
|
+
if (typeof payload.content === "string") {
|
|
2456
|
+
parts.push({
|
|
2457
|
+
text: message.content
|
|
2458
|
+
});
|
|
2459
|
+
}
|
|
2460
|
+
return {
|
|
2461
|
+
role,
|
|
2462
|
+
parts
|
|
2463
|
+
};
|
|
2464
|
+
}
|
|
2465
|
+
__name(googleGeminiPromptMessageCallback, "googleGeminiPromptMessageCallback");
|
|
2466
|
+
|
|
2467
|
+
// src/llm/config/google/promptSanitize.ts
|
|
2468
|
+
function googleGeminiPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
2469
|
+
if (typeof _messages === "string") {
|
|
2470
|
+
return [
|
|
2471
|
+
{
|
|
2472
|
+
role: "user",
|
|
2473
|
+
parts: [
|
|
2474
|
+
{
|
|
2475
|
+
text: _messages
|
|
2476
|
+
}
|
|
2477
|
+
]
|
|
2478
|
+
}
|
|
2479
|
+
];
|
|
2480
|
+
}
|
|
2481
|
+
if (Array.isArray(_messages)) {
|
|
2482
|
+
if (_messages.length === 0) {
|
|
2483
|
+
throw new Error("Empty messages array");
|
|
2484
|
+
}
|
|
2485
|
+
if (_messages.length === 1 && _messages[0].role === "system") {
|
|
2486
|
+
return [
|
|
2487
|
+
{
|
|
2488
|
+
role: "user",
|
|
2489
|
+
parts: [
|
|
2490
|
+
{
|
|
2491
|
+
text: _messages[0].content
|
|
2492
|
+
}
|
|
2493
|
+
]
|
|
2494
|
+
}
|
|
2495
|
+
];
|
|
2496
|
+
}
|
|
2497
|
+
const hasSystemInstruction = _messages.some((message) => message.role === "system");
|
|
2498
|
+
if (hasSystemInstruction) {
|
|
2499
|
+
const theSystemInstructions = _messages.filter((message) => message.role === "system");
|
|
2500
|
+
const withoutSystemInstructions = _messages.filter((message) => message.role !== "system");
|
|
2501
|
+
_outputObj.system_instruction = {
|
|
2502
|
+
parts: theSystemInstructions.map((message) => ({
|
|
2503
|
+
text: message.content
|
|
2504
|
+
}))
|
|
2505
|
+
};
|
|
2506
|
+
return withoutSystemInstructions.map(googleGeminiPromptMessageCallback);
|
|
2507
|
+
}
|
|
2508
|
+
return _messages.map(googleGeminiPromptMessageCallback);
|
|
2509
|
+
}
|
|
2510
|
+
throw new Error("Invalid messages format");
|
|
2511
|
+
}
|
|
2512
|
+
__name(googleGeminiPromptSanitize, "googleGeminiPromptSanitize");
|
|
2513
|
+
|
|
2514
|
+
// src/llm/config/google/index.ts
|
|
2515
|
+
var googleGeminiChatV1 = {
|
|
2516
|
+
key: "google.chat.v1",
|
|
2517
|
+
provider: "google.chat",
|
|
2518
|
+
endpoint: `https://generativelanguage.googleapis.com/v1beta/models/{{model}}:generateContent?key={{geminiApiKey}}`,
|
|
2519
|
+
options: {
|
|
2520
|
+
prompt: {},
|
|
2521
|
+
// topP: {},
|
|
2522
|
+
geminiApiKey: {
|
|
2523
|
+
default: getEnvironmentVariable("GEMINI_API_KEY")
|
|
2524
|
+
}
|
|
2525
|
+
},
|
|
2526
|
+
method: "POST",
|
|
2527
|
+
headers: `{"Content-Type": "application/json" }`,
|
|
2528
|
+
mapBody: {
|
|
2529
|
+
prompt: {
|
|
2530
|
+
key: "contents",
|
|
2531
|
+
sanitize: googleGeminiPromptSanitize
|
|
2532
|
+
}
|
|
2533
|
+
}
|
|
2534
|
+
};
|
|
2535
|
+
var google = {
|
|
2536
|
+
"google.chat.v1": googleGeminiChatV1,
|
|
2537
|
+
"google.gemini-2.0-flash": withDefaultModel(googleGeminiChatV1, "gemini-2.0-flash"),
|
|
2538
|
+
"google.gemini-2.0-flash-lite": withDefaultModel(googleGeminiChatV1, "gemini-2.0-flash-lite"),
|
|
2539
|
+
"google.gemini-1.5-pro": withDefaultModel(googleGeminiChatV1, "gemini-1.5-pro")
|
|
2385
2540
|
};
|
|
2386
2541
|
|
|
2387
2542
|
// src/llm/config.ts
|
|
@@ -2390,14 +2545,25 @@ var configs = {
|
|
|
2390
2545
|
...anthropic,
|
|
2391
2546
|
...bedrock,
|
|
2392
2547
|
...xai,
|
|
2393
|
-
...ollama
|
|
2548
|
+
...ollama,
|
|
2549
|
+
...google
|
|
2394
2550
|
};
|
|
2395
2551
|
function getLlmConfig(provider) {
|
|
2552
|
+
if (!provider) {
|
|
2553
|
+
throw new LlmExeError(`Missing provider`, "unknown", {
|
|
2554
|
+
error: "Missing provider",
|
|
2555
|
+
resolution: "Provide a valid provider"
|
|
2556
|
+
});
|
|
2557
|
+
}
|
|
2396
2558
|
const pick2 = configs[provider];
|
|
2397
2559
|
if (pick2) {
|
|
2398
2560
|
return pick2;
|
|
2399
2561
|
}
|
|
2400
|
-
throw new
|
|
2562
|
+
throw new LlmExeError(`Invalid provider: ${provider}`, "unknown", {
|
|
2563
|
+
provider,
|
|
2564
|
+
error: `Invalid provider: ${provider}`,
|
|
2565
|
+
resolution: "Provide a valid provider"
|
|
2566
|
+
});
|
|
2401
2567
|
}
|
|
2402
2568
|
__name(getLlmConfig, "getLlmConfig");
|
|
2403
2569
|
|
|
@@ -2743,6 +2909,57 @@ function OutputOllamaChat(result, _config) {
|
|
|
2743
2909
|
}
|
|
2744
2910
|
__name(OutputOllamaChat, "OutputOllamaChat");
|
|
2745
2911
|
|
|
2912
|
+
// src/llm/output/google.gemini/formatResult.ts
|
|
2913
|
+
function formatResult4(result) {
|
|
2914
|
+
const { parts = [] } = result?.content || {};
|
|
2915
|
+
if (parts.length === 1) {
|
|
2916
|
+
const answer = parts[0];
|
|
2917
|
+
if (!!answer?.functionCall && typeof answer?.functionCall === "object") {
|
|
2918
|
+
return {
|
|
2919
|
+
type: "function_use",
|
|
2920
|
+
name: answer.functionCall.name,
|
|
2921
|
+
input: JSON.parse(answer.functionCall.args)
|
|
2922
|
+
};
|
|
2923
|
+
} else {
|
|
2924
|
+
return {
|
|
2925
|
+
type: "text",
|
|
2926
|
+
text: answer.text || ""
|
|
2927
|
+
};
|
|
2928
|
+
}
|
|
2929
|
+
}
|
|
2930
|
+
return {
|
|
2931
|
+
type: "text",
|
|
2932
|
+
text: ""
|
|
2933
|
+
};
|
|
2934
|
+
}
|
|
2935
|
+
__name(formatResult4, "formatResult");
|
|
2936
|
+
|
|
2937
|
+
// src/llm/output/google.gemini/index.ts
|
|
2938
|
+
function OutputGoogleGeminiChat(result, _config) {
|
|
2939
|
+
const id = "result.id";
|
|
2940
|
+
const name = result.modelVersion;
|
|
2941
|
+
const created = (/* @__PURE__ */ new Date()).getTime();
|
|
2942
|
+
const [_content, ..._options] = result?.candidates || [];
|
|
2943
|
+
const stopReason = _content?.finishReason?.toLowerCase();
|
|
2944
|
+
const content = formatContent(_content, formatResult4);
|
|
2945
|
+
const options = formatOptions(_options, formatResult4);
|
|
2946
|
+
const usage = {
|
|
2947
|
+
output_tokens: result?.usageMetadata?.candidatesTokenCount,
|
|
2948
|
+
input_tokens: result?.usageMetadata?.promptTokenCount,
|
|
2949
|
+
total_tokens: result?.usageMetadata?.totalTokenCount
|
|
2950
|
+
};
|
|
2951
|
+
return BaseLlmOutput2({
|
|
2952
|
+
id,
|
|
2953
|
+
name,
|
|
2954
|
+
created,
|
|
2955
|
+
usage,
|
|
2956
|
+
stopReason,
|
|
2957
|
+
content,
|
|
2958
|
+
options
|
|
2959
|
+
});
|
|
2960
|
+
}
|
|
2961
|
+
__name(OutputGoogleGeminiChat, "OutputGoogleGeminiChat");
|
|
2962
|
+
|
|
2746
2963
|
// src/llm/output/index.ts
|
|
2747
2964
|
function getOutputParser(config, response) {
|
|
2748
2965
|
switch (config?.key) {
|
|
@@ -2760,6 +2977,8 @@ function getOutputParser(config, response) {
|
|
|
2760
2977
|
return OutputXAIChat(response, config);
|
|
2761
2978
|
case "ollama.chat.v1":
|
|
2762
2979
|
return OutputOllamaChat(response, config);
|
|
2980
|
+
case "google.chat.v1":
|
|
2981
|
+
return OutputGoogleGeminiChat(response, config);
|
|
2763
2982
|
default: {
|
|
2764
2983
|
if (config?.key?.startsWith("custom:")) {
|
|
2765
2984
|
return OutputDefault(response, config);
|
|
@@ -3373,11 +3592,14 @@ var embeddingConfigs = {
|
|
|
3373
3592
|
}
|
|
3374
3593
|
};
|
|
3375
3594
|
function getEmbeddingConfig(provider) {
|
|
3595
|
+
if (!provider) {
|
|
3596
|
+
throw new Error(`Missing provider`);
|
|
3597
|
+
}
|
|
3376
3598
|
const pick2 = embeddingConfigs[provider];
|
|
3377
3599
|
if (pick2) {
|
|
3378
3600
|
return pick2;
|
|
3379
3601
|
}
|
|
3380
|
-
throw new Error(
|
|
3602
|
+
throw new Error(`Invalid provider: ${provider}`);
|
|
3381
3603
|
}
|
|
3382
3604
|
__name(getEmbeddingConfig, "getEmbeddingConfig");
|
|
3383
3605
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "llm-exe",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.6",
|
|
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",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"gpt-4",
|
|
14
14
|
"claude",
|
|
15
15
|
"grok",
|
|
16
|
+
"gemini",
|
|
16
17
|
"chain",
|
|
17
18
|
"prompt",
|
|
18
19
|
"agent"
|
|
@@ -34,7 +35,9 @@
|
|
|
34
35
|
"node": ">=18"
|
|
35
36
|
},
|
|
36
37
|
"scripts": {
|
|
37
|
-
"test": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --coverage --forceExit",
|
|
38
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --config jest.config.ts --detectOpenHandles --coverage --forceExit",
|
|
39
|
+
"test-examples": "eval $(cat .env) NODE_OPTIONS=--experimental-vm-modules jest --config jest.config.examples.ts --detectOpenHandles --coverage --forceExit",
|
|
40
|
+
"test-one": "eval $(cat .env) NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --coverage --forceExit --config jest.config.examples.ts examples/helloWorldReasoning.test.ts",
|
|
38
41
|
"build": "(concurrently \"tsc --p ./tsconfig.json -w\" \"tsc-alias -p tsconfig.json -w\")",
|
|
39
42
|
"build:ci": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
40
43
|
"build:package": "tsup src/index.ts --format cjs,esm --dts --clean",
|
package/readme.md
CHANGED
|
@@ -6,8 +6,8 @@ A package that provides simplified base components to make building and maintain
|
|
|
6
6
|
|
|
7
7
|
- Write functions powered by LLM's with easy to use building blocks.
|
|
8
8
|
- Pure Javascript and Typescript. Allows you to pass and infer types.
|
|
9
|
-
- Support for text-based (llama-3) and chat-based prompts. (gpt-4o, claude-3.5, grok-3, Bedrock, Ollama, etc)
|
|
10
|
-
- Call LLM's from different providers without changing your code. (OpenAi/Anthropic/xAI/AWS Bedrock/Ollama)
|
|
9
|
+
- Support for text-based (llama-3) and chat-based prompts. (gpt-4o, claude-3.5, grok-3, Gemini, Bedrock, Ollama, etc)
|
|
10
|
+
- Call LLM's from different providers without changing your code. (OpenAi/Anthropic/xAI/Google/AWS Bedrock/Ollama)
|
|
11
11
|
- Supercharge your prompts by using handlebars within prompt template.
|
|
12
12
|
- Allow LLM's to call functions (or call other LLM executors).
|
|
13
13
|
- Not very opinionated. You have control on how you use it.
|