llm-exe 2.1.3 → 2.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +50 -3
- package/dist/index.d.ts +50 -3
- package/dist/index.js +211 -49
- package/dist/index.mjs +211 -49
- package/package.json +5 -2
- package/readme.md +3 -3
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
|
};
|
|
@@ -983,9 +993,36 @@ type AllUseLlmOptions = AllLlm & {
|
|
|
983
993
|
"anthropic.claude-3-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,12 +1219,22 @@ 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>;
|
|
1192
1239
|
"anthropic.claude-3-opus": Config<keyof AllLlm>;
|
|
1193
1240
|
"anthropic.claude-3-sonnet": Config<keyof AllLlm>;
|
|
@@ -1237,4 +1284,4 @@ declare function createEmbedding<T extends EmbeddingProviderKey>(provider: T, op
|
|
|
1237
1284
|
};
|
|
1238
1285
|
};
|
|
1239
1286
|
|
|
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 };
|
|
1287
|
+
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
|
};
|
|
@@ -983,9 +993,36 @@ type AllUseLlmOptions = AllLlm & {
|
|
|
983
993
|
"anthropic.claude-3-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,12 +1219,22 @@ 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>;
|
|
1192
1239
|
"anthropic.claude-3-opus": Config<keyof AllLlm>;
|
|
1193
1240
|
"anthropic.claude-3-sonnet": Config<keyof AllLlm>;
|
|
@@ -1237,4 +1284,4 @@ declare function createEmbedding<T extends EmbeddingProviderKey>(provider: T, op
|
|
|
1237
1284
|
};
|
|
1238
1285
|
};
|
|
1239
1286
|
|
|
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 };
|
|
1287
|
+
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
|
@@ -2185,8 +2185,7 @@ var openai = {
|
|
|
2185
2185
|
"openai.gpt-4o-mini": withDefaultModel(openAiChatV1, "gpt-4o-mini")
|
|
2186
2186
|
};
|
|
2187
2187
|
|
|
2188
|
-
// src/llm/config/anthropic/
|
|
2189
|
-
var ANTORPIC_VERSION = "2023-06-01";
|
|
2188
|
+
// src/llm/config/anthropic/promptSanitize.ts
|
|
2190
2189
|
function anthropicPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
2191
2190
|
if (typeof _messages === "string") {
|
|
2192
2191
|
return [
|
|
@@ -2220,49 +2219,6 @@ function anthropicPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
|
2220
2219
|
];
|
|
2221
2220
|
}
|
|
2222
2221
|
__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
2222
|
|
|
2267
2223
|
// src/llm/config/bedrock/index.ts
|
|
2268
2224
|
var ANTORPIC_BEDROCK_VERSION = "bedrock-2023-05-31";
|
|
@@ -2351,6 +2307,53 @@ var bedrock = {
|
|
|
2351
2307
|
"amazon:meta.chat.v1": amazonMetaChatV1
|
|
2352
2308
|
};
|
|
2353
2309
|
|
|
2310
|
+
// src/llm/config/anthropic/index.ts
|
|
2311
|
+
var ANTHROPIC_VERSION = "2023-06-01";
|
|
2312
|
+
var anthropicChatV1 = {
|
|
2313
|
+
key: "anthropic.chat.v1",
|
|
2314
|
+
provider: "anthropic.chat",
|
|
2315
|
+
endpoint: `https://api.anthropic.com/v1/messages`,
|
|
2316
|
+
headers: `{"x-api-key":"{{anthropicApiKey}}", "Content-Type": "application/json", "anthropic-version": "${ANTHROPIC_VERSION}" }`,
|
|
2317
|
+
method: "POST",
|
|
2318
|
+
options: {
|
|
2319
|
+
prompt: {},
|
|
2320
|
+
system: {},
|
|
2321
|
+
maxTokens: {
|
|
2322
|
+
required: [
|
|
2323
|
+
true,
|
|
2324
|
+
"maxTokens required"
|
|
2325
|
+
],
|
|
2326
|
+
default: 4096
|
|
2327
|
+
},
|
|
2328
|
+
anthropicApiKey: {
|
|
2329
|
+
default: getEnvironmentVariable("ANTHROPIC_API_KEY")
|
|
2330
|
+
}
|
|
2331
|
+
},
|
|
2332
|
+
mapBody: {
|
|
2333
|
+
model: {
|
|
2334
|
+
key: "model"
|
|
2335
|
+
},
|
|
2336
|
+
maxTokens: {
|
|
2337
|
+
key: "max_tokens"
|
|
2338
|
+
},
|
|
2339
|
+
system: {
|
|
2340
|
+
key: "system"
|
|
2341
|
+
},
|
|
2342
|
+
prompt: {
|
|
2343
|
+
key: "messages",
|
|
2344
|
+
sanitize: anthropicPromptSanitize
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
};
|
|
2348
|
+
var anthropic = {
|
|
2349
|
+
"anthropic.chat.v1": anthropicChatV1,
|
|
2350
|
+
"anthropic.claude-3-7-sonnet": withDefaultModel(anthropicChatV1, "claude-3-7-sonnet-latest"),
|
|
2351
|
+
"anthropic.claude-3-5-sonnet": withDefaultModel(anthropicChatV1, "claude-3-5-sonnet-latest"),
|
|
2352
|
+
"anthropic.claude-3-opus": withDefaultModel(anthropicChatV1, "claude-3-opus-latest"),
|
|
2353
|
+
"anthropic.claude-3-sonnet": withDefaultModel(anthropicChatV1, "claude-3-sonnet-latest"),
|
|
2354
|
+
"anthropic.claude-3-haiku": withDefaultModel(anthropicChatV1, "claude-3-haiku-latest")
|
|
2355
|
+
};
|
|
2356
|
+
|
|
2354
2357
|
// src/llm/config/x/index.ts
|
|
2355
2358
|
var xaiChatV1 = {
|
|
2356
2359
|
key: "xai.chat.v1",
|
|
@@ -2429,7 +2432,106 @@ var ollamaChatV1 = {
|
|
|
2429
2432
|
}
|
|
2430
2433
|
};
|
|
2431
2434
|
var ollama = {
|
|
2432
|
-
"ollama.chat.v1": ollamaChatV1
|
|
2435
|
+
"ollama.chat.v1": ollamaChatV1,
|
|
2436
|
+
"ollama.deepseek-r1": withDefaultModel(ollamaChatV1, "deepseek-r1"),
|
|
2437
|
+
"ollama.llama3.3": withDefaultModel(ollamaChatV1, "llama3.3"),
|
|
2438
|
+
"ollama.llama3.2": withDefaultModel(ollamaChatV1, "llama3.2"),
|
|
2439
|
+
"ollama.llama3.1": withDefaultModel(ollamaChatV1, "llama3.1"),
|
|
2440
|
+
"ollama.qwq": withDefaultModel(ollamaChatV1, "qwq")
|
|
2441
|
+
};
|
|
2442
|
+
|
|
2443
|
+
// src/utils/modules/modifyPromptRoleChange.ts
|
|
2444
|
+
function modifyPromptRoleChange(messages, roleChanges) {
|
|
2445
|
+
const roleChangeMap = new Map(roleChanges.map(({ from, to }) => [
|
|
2446
|
+
from,
|
|
2447
|
+
to
|
|
2448
|
+
]));
|
|
2449
|
+
if (Array.isArray(messages)) {
|
|
2450
|
+
return messages.map((message) => {
|
|
2451
|
+
const newRole2 = roleChangeMap.get(message.role);
|
|
2452
|
+
return newRole2 ? {
|
|
2453
|
+
...message,
|
|
2454
|
+
role: newRole2
|
|
2455
|
+
} : message;
|
|
2456
|
+
});
|
|
2457
|
+
}
|
|
2458
|
+
const newRole = roleChangeMap.get(messages.role);
|
|
2459
|
+
return newRole ? {
|
|
2460
|
+
...messages,
|
|
2461
|
+
role: newRole
|
|
2462
|
+
} : messages;
|
|
2463
|
+
}
|
|
2464
|
+
__name(modifyPromptRoleChange, "modifyPromptRoleChange");
|
|
2465
|
+
|
|
2466
|
+
// src/llm/config/google/promptSanitizeMessageCallback.ts
|
|
2467
|
+
function googleGeminiPromptMessageCallback(_message) {
|
|
2468
|
+
let message = {
|
|
2469
|
+
..._message
|
|
2470
|
+
};
|
|
2471
|
+
message = modifyPromptRoleChange(_message, [
|
|
2472
|
+
{
|
|
2473
|
+
from: "assistant",
|
|
2474
|
+
to: "model"
|
|
2475
|
+
},
|
|
2476
|
+
{
|
|
2477
|
+
from: "system",
|
|
2478
|
+
to: "model"
|
|
2479
|
+
}
|
|
2480
|
+
]);
|
|
2481
|
+
const { role, ...payload } = message;
|
|
2482
|
+
const parts = [];
|
|
2483
|
+
if (typeof payload.content === "string") {
|
|
2484
|
+
parts.push({
|
|
2485
|
+
text: message.content
|
|
2486
|
+
});
|
|
2487
|
+
}
|
|
2488
|
+
return {
|
|
2489
|
+
role,
|
|
2490
|
+
parts
|
|
2491
|
+
};
|
|
2492
|
+
}
|
|
2493
|
+
__name(googleGeminiPromptMessageCallback, "googleGeminiPromptMessageCallback");
|
|
2494
|
+
|
|
2495
|
+
// src/llm/config/google/promptSanitize.ts
|
|
2496
|
+
function googleGeminiPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
2497
|
+
if (typeof _messages === "string") {
|
|
2498
|
+
return _messages;
|
|
2499
|
+
}
|
|
2500
|
+
if (Array.isArray(_messages)) {
|
|
2501
|
+
if (_messages.length === 0) {
|
|
2502
|
+
throw new Error("Empty messages array");
|
|
2503
|
+
}
|
|
2504
|
+
}
|
|
2505
|
+
return _messages.map(googleGeminiPromptMessageCallback);
|
|
2506
|
+
}
|
|
2507
|
+
__name(googleGeminiPromptSanitize, "googleGeminiPromptSanitize");
|
|
2508
|
+
|
|
2509
|
+
// src/llm/config/google/index.ts
|
|
2510
|
+
var googleGeminiChatV1 = {
|
|
2511
|
+
key: "google.chat.v1",
|
|
2512
|
+
provider: "google.chat",
|
|
2513
|
+
endpoint: `https://generativelanguage.googleapis.com/v1beta/models/{{model}}:generateContent?key={{geminiApiKey}}`,
|
|
2514
|
+
options: {
|
|
2515
|
+
prompt: {},
|
|
2516
|
+
// topP: {},
|
|
2517
|
+
geminiApiKey: {
|
|
2518
|
+
default: getEnvironmentVariable("GEMINI_API_KEY")
|
|
2519
|
+
}
|
|
2520
|
+
},
|
|
2521
|
+
method: "POST",
|
|
2522
|
+
headers: `{"Content-Type": "application/json" }`,
|
|
2523
|
+
mapBody: {
|
|
2524
|
+
prompt: {
|
|
2525
|
+
key: "contents",
|
|
2526
|
+
sanitize: googleGeminiPromptSanitize
|
|
2527
|
+
}
|
|
2528
|
+
}
|
|
2529
|
+
};
|
|
2530
|
+
var google = {
|
|
2531
|
+
"google.chat.v1": googleGeminiChatV1,
|
|
2532
|
+
"google.gemini-2.0-flash": withDefaultModel(googleGeminiChatV1, "gemini-2.0-flash"),
|
|
2533
|
+
"google.gemini-2.0-flash-lite": withDefaultModel(googleGeminiChatV1, "gemini-2.0-flash-lite"),
|
|
2534
|
+
"google.gemini-1.5-pro": withDefaultModel(googleGeminiChatV1, "gemini-1.5-pro")
|
|
2433
2535
|
};
|
|
2434
2536
|
|
|
2435
2537
|
// src/llm/config.ts
|
|
@@ -2438,14 +2540,18 @@ var configs = {
|
|
|
2438
2540
|
...anthropic,
|
|
2439
2541
|
...bedrock,
|
|
2440
2542
|
...xai,
|
|
2441
|
-
...ollama
|
|
2543
|
+
...ollama,
|
|
2544
|
+
...google
|
|
2442
2545
|
};
|
|
2443
2546
|
function getLlmConfig(provider) {
|
|
2547
|
+
if (!provider) {
|
|
2548
|
+
throw new Error(`Missing provider`);
|
|
2549
|
+
}
|
|
2444
2550
|
const pick2 = configs[provider];
|
|
2445
2551
|
if (pick2) {
|
|
2446
2552
|
return pick2;
|
|
2447
2553
|
}
|
|
2448
|
-
throw new Error(
|
|
2554
|
+
throw new Error(`Invalid provider: ${provider}`);
|
|
2449
2555
|
}
|
|
2450
2556
|
__name(getLlmConfig, "getLlmConfig");
|
|
2451
2557
|
|
|
@@ -2791,6 +2897,57 @@ function OutputOllamaChat(result, _config) {
|
|
|
2791
2897
|
}
|
|
2792
2898
|
__name(OutputOllamaChat, "OutputOllamaChat");
|
|
2793
2899
|
|
|
2900
|
+
// src/llm/output/google.gemini/formatResult.ts
|
|
2901
|
+
function formatResult4(result) {
|
|
2902
|
+
const { parts = [] } = result?.content || {};
|
|
2903
|
+
if (parts.length === 1) {
|
|
2904
|
+
const answer = parts[0];
|
|
2905
|
+
if (!!answer?.functionCall && typeof answer?.functionCall === "object") {
|
|
2906
|
+
return {
|
|
2907
|
+
type: "function_use",
|
|
2908
|
+
name: answer.functionCall.name,
|
|
2909
|
+
input: JSON.parse(answer.functionCall.args)
|
|
2910
|
+
};
|
|
2911
|
+
} else {
|
|
2912
|
+
return {
|
|
2913
|
+
type: "text",
|
|
2914
|
+
text: answer.text || ""
|
|
2915
|
+
};
|
|
2916
|
+
}
|
|
2917
|
+
}
|
|
2918
|
+
return {
|
|
2919
|
+
type: "text",
|
|
2920
|
+
text: ""
|
|
2921
|
+
};
|
|
2922
|
+
}
|
|
2923
|
+
__name(formatResult4, "formatResult");
|
|
2924
|
+
|
|
2925
|
+
// src/llm/output/google.gemini/index.ts
|
|
2926
|
+
function OutputGoogleGeminiChat(result, _config) {
|
|
2927
|
+
const id = "result.id";
|
|
2928
|
+
const name = result.modelVersion;
|
|
2929
|
+
const created = (/* @__PURE__ */ new Date()).getTime();
|
|
2930
|
+
const [_content, ..._options] = result?.candidates || [];
|
|
2931
|
+
const stopReason = _content?.finishReason?.toLowerCase();
|
|
2932
|
+
const content = formatContent(_content, formatResult4);
|
|
2933
|
+
const options = formatOptions(_options, formatResult4);
|
|
2934
|
+
const usage = {
|
|
2935
|
+
output_tokens: result?.usageMetadata?.candidatesTokenCount,
|
|
2936
|
+
input_tokens: result?.usageMetadata?.promptTokenCount,
|
|
2937
|
+
total_tokens: result?.usageMetadata?.totalTokenCount
|
|
2938
|
+
};
|
|
2939
|
+
return BaseLlmOutput2({
|
|
2940
|
+
id,
|
|
2941
|
+
name,
|
|
2942
|
+
created,
|
|
2943
|
+
usage,
|
|
2944
|
+
stopReason,
|
|
2945
|
+
content,
|
|
2946
|
+
options
|
|
2947
|
+
});
|
|
2948
|
+
}
|
|
2949
|
+
__name(OutputGoogleGeminiChat, "OutputGoogleGeminiChat");
|
|
2950
|
+
|
|
2794
2951
|
// src/llm/output/index.ts
|
|
2795
2952
|
function getOutputParser(config, response) {
|
|
2796
2953
|
switch (config?.key) {
|
|
@@ -2808,6 +2965,8 @@ function getOutputParser(config, response) {
|
|
|
2808
2965
|
return OutputXAIChat(response, config);
|
|
2809
2966
|
case "ollama.chat.v1":
|
|
2810
2967
|
return OutputOllamaChat(response, config);
|
|
2968
|
+
case "google.chat.v1":
|
|
2969
|
+
return OutputGoogleGeminiChat(response, config);
|
|
2811
2970
|
default: {
|
|
2812
2971
|
if (config?.key?.startsWith("custom:")) {
|
|
2813
2972
|
return OutputDefault(response, config);
|
|
@@ -3421,11 +3580,14 @@ var embeddingConfigs = {
|
|
|
3421
3580
|
}
|
|
3422
3581
|
};
|
|
3423
3582
|
function getEmbeddingConfig(provider) {
|
|
3583
|
+
if (!provider) {
|
|
3584
|
+
throw new Error(`Missing provider`);
|
|
3585
|
+
}
|
|
3424
3586
|
const pick2 = embeddingConfigs[provider];
|
|
3425
3587
|
if (pick2) {
|
|
3426
3588
|
return pick2;
|
|
3427
3589
|
}
|
|
3428
|
-
throw new Error(
|
|
3590
|
+
throw new Error(`Invalid provider: ${provider}`);
|
|
3429
3591
|
}
|
|
3430
3592
|
__name(getEmbeddingConfig, "getEmbeddingConfig");
|
|
3431
3593
|
|
package/dist/index.mjs
CHANGED
|
@@ -2137,8 +2137,7 @@ var openai = {
|
|
|
2137
2137
|
"openai.gpt-4o-mini": withDefaultModel(openAiChatV1, "gpt-4o-mini")
|
|
2138
2138
|
};
|
|
2139
2139
|
|
|
2140
|
-
// src/llm/config/anthropic/
|
|
2141
|
-
var ANTORPIC_VERSION = "2023-06-01";
|
|
2140
|
+
// src/llm/config/anthropic/promptSanitize.ts
|
|
2142
2141
|
function anthropicPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
2143
2142
|
if (typeof _messages === "string") {
|
|
2144
2143
|
return [
|
|
@@ -2172,49 +2171,6 @@ function anthropicPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
|
2172
2171
|
];
|
|
2173
2172
|
}
|
|
2174
2173
|
__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
2174
|
|
|
2219
2175
|
// src/llm/config/bedrock/index.ts
|
|
2220
2176
|
var ANTORPIC_BEDROCK_VERSION = "bedrock-2023-05-31";
|
|
@@ -2303,6 +2259,53 @@ var bedrock = {
|
|
|
2303
2259
|
"amazon:meta.chat.v1": amazonMetaChatV1
|
|
2304
2260
|
};
|
|
2305
2261
|
|
|
2262
|
+
// src/llm/config/anthropic/index.ts
|
|
2263
|
+
var ANTHROPIC_VERSION = "2023-06-01";
|
|
2264
|
+
var anthropicChatV1 = {
|
|
2265
|
+
key: "anthropic.chat.v1",
|
|
2266
|
+
provider: "anthropic.chat",
|
|
2267
|
+
endpoint: `https://api.anthropic.com/v1/messages`,
|
|
2268
|
+
headers: `{"x-api-key":"{{anthropicApiKey}}", "Content-Type": "application/json", "anthropic-version": "${ANTHROPIC_VERSION}" }`,
|
|
2269
|
+
method: "POST",
|
|
2270
|
+
options: {
|
|
2271
|
+
prompt: {},
|
|
2272
|
+
system: {},
|
|
2273
|
+
maxTokens: {
|
|
2274
|
+
required: [
|
|
2275
|
+
true,
|
|
2276
|
+
"maxTokens required"
|
|
2277
|
+
],
|
|
2278
|
+
default: 4096
|
|
2279
|
+
},
|
|
2280
|
+
anthropicApiKey: {
|
|
2281
|
+
default: getEnvironmentVariable("ANTHROPIC_API_KEY")
|
|
2282
|
+
}
|
|
2283
|
+
},
|
|
2284
|
+
mapBody: {
|
|
2285
|
+
model: {
|
|
2286
|
+
key: "model"
|
|
2287
|
+
},
|
|
2288
|
+
maxTokens: {
|
|
2289
|
+
key: "max_tokens"
|
|
2290
|
+
},
|
|
2291
|
+
system: {
|
|
2292
|
+
key: "system"
|
|
2293
|
+
},
|
|
2294
|
+
prompt: {
|
|
2295
|
+
key: "messages",
|
|
2296
|
+
sanitize: anthropicPromptSanitize
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
};
|
|
2300
|
+
var anthropic = {
|
|
2301
|
+
"anthropic.chat.v1": anthropicChatV1,
|
|
2302
|
+
"anthropic.claude-3-7-sonnet": withDefaultModel(anthropicChatV1, "claude-3-7-sonnet-latest"),
|
|
2303
|
+
"anthropic.claude-3-5-sonnet": withDefaultModel(anthropicChatV1, "claude-3-5-sonnet-latest"),
|
|
2304
|
+
"anthropic.claude-3-opus": withDefaultModel(anthropicChatV1, "claude-3-opus-latest"),
|
|
2305
|
+
"anthropic.claude-3-sonnet": withDefaultModel(anthropicChatV1, "claude-3-sonnet-latest"),
|
|
2306
|
+
"anthropic.claude-3-haiku": withDefaultModel(anthropicChatV1, "claude-3-haiku-latest")
|
|
2307
|
+
};
|
|
2308
|
+
|
|
2306
2309
|
// src/llm/config/x/index.ts
|
|
2307
2310
|
var xaiChatV1 = {
|
|
2308
2311
|
key: "xai.chat.v1",
|
|
@@ -2381,7 +2384,106 @@ var ollamaChatV1 = {
|
|
|
2381
2384
|
}
|
|
2382
2385
|
};
|
|
2383
2386
|
var ollama = {
|
|
2384
|
-
"ollama.chat.v1": ollamaChatV1
|
|
2387
|
+
"ollama.chat.v1": ollamaChatV1,
|
|
2388
|
+
"ollama.deepseek-r1": withDefaultModel(ollamaChatV1, "deepseek-r1"),
|
|
2389
|
+
"ollama.llama3.3": withDefaultModel(ollamaChatV1, "llama3.3"),
|
|
2390
|
+
"ollama.llama3.2": withDefaultModel(ollamaChatV1, "llama3.2"),
|
|
2391
|
+
"ollama.llama3.1": withDefaultModel(ollamaChatV1, "llama3.1"),
|
|
2392
|
+
"ollama.qwq": withDefaultModel(ollamaChatV1, "qwq")
|
|
2393
|
+
};
|
|
2394
|
+
|
|
2395
|
+
// src/utils/modules/modifyPromptRoleChange.ts
|
|
2396
|
+
function modifyPromptRoleChange(messages, roleChanges) {
|
|
2397
|
+
const roleChangeMap = new Map(roleChanges.map(({ from, to }) => [
|
|
2398
|
+
from,
|
|
2399
|
+
to
|
|
2400
|
+
]));
|
|
2401
|
+
if (Array.isArray(messages)) {
|
|
2402
|
+
return messages.map((message) => {
|
|
2403
|
+
const newRole2 = roleChangeMap.get(message.role);
|
|
2404
|
+
return newRole2 ? {
|
|
2405
|
+
...message,
|
|
2406
|
+
role: newRole2
|
|
2407
|
+
} : message;
|
|
2408
|
+
});
|
|
2409
|
+
}
|
|
2410
|
+
const newRole = roleChangeMap.get(messages.role);
|
|
2411
|
+
return newRole ? {
|
|
2412
|
+
...messages,
|
|
2413
|
+
role: newRole
|
|
2414
|
+
} : messages;
|
|
2415
|
+
}
|
|
2416
|
+
__name(modifyPromptRoleChange, "modifyPromptRoleChange");
|
|
2417
|
+
|
|
2418
|
+
// src/llm/config/google/promptSanitizeMessageCallback.ts
|
|
2419
|
+
function googleGeminiPromptMessageCallback(_message) {
|
|
2420
|
+
let message = {
|
|
2421
|
+
..._message
|
|
2422
|
+
};
|
|
2423
|
+
message = modifyPromptRoleChange(_message, [
|
|
2424
|
+
{
|
|
2425
|
+
from: "assistant",
|
|
2426
|
+
to: "model"
|
|
2427
|
+
},
|
|
2428
|
+
{
|
|
2429
|
+
from: "system",
|
|
2430
|
+
to: "model"
|
|
2431
|
+
}
|
|
2432
|
+
]);
|
|
2433
|
+
const { role, ...payload } = message;
|
|
2434
|
+
const parts = [];
|
|
2435
|
+
if (typeof payload.content === "string") {
|
|
2436
|
+
parts.push({
|
|
2437
|
+
text: message.content
|
|
2438
|
+
});
|
|
2439
|
+
}
|
|
2440
|
+
return {
|
|
2441
|
+
role,
|
|
2442
|
+
parts
|
|
2443
|
+
};
|
|
2444
|
+
}
|
|
2445
|
+
__name(googleGeminiPromptMessageCallback, "googleGeminiPromptMessageCallback");
|
|
2446
|
+
|
|
2447
|
+
// src/llm/config/google/promptSanitize.ts
|
|
2448
|
+
function googleGeminiPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
2449
|
+
if (typeof _messages === "string") {
|
|
2450
|
+
return _messages;
|
|
2451
|
+
}
|
|
2452
|
+
if (Array.isArray(_messages)) {
|
|
2453
|
+
if (_messages.length === 0) {
|
|
2454
|
+
throw new Error("Empty messages array");
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
return _messages.map(googleGeminiPromptMessageCallback);
|
|
2458
|
+
}
|
|
2459
|
+
__name(googleGeminiPromptSanitize, "googleGeminiPromptSanitize");
|
|
2460
|
+
|
|
2461
|
+
// src/llm/config/google/index.ts
|
|
2462
|
+
var googleGeminiChatV1 = {
|
|
2463
|
+
key: "google.chat.v1",
|
|
2464
|
+
provider: "google.chat",
|
|
2465
|
+
endpoint: `https://generativelanguage.googleapis.com/v1beta/models/{{model}}:generateContent?key={{geminiApiKey}}`,
|
|
2466
|
+
options: {
|
|
2467
|
+
prompt: {},
|
|
2468
|
+
// topP: {},
|
|
2469
|
+
geminiApiKey: {
|
|
2470
|
+
default: getEnvironmentVariable("GEMINI_API_KEY")
|
|
2471
|
+
}
|
|
2472
|
+
},
|
|
2473
|
+
method: "POST",
|
|
2474
|
+
headers: `{"Content-Type": "application/json" }`,
|
|
2475
|
+
mapBody: {
|
|
2476
|
+
prompt: {
|
|
2477
|
+
key: "contents",
|
|
2478
|
+
sanitize: googleGeminiPromptSanitize
|
|
2479
|
+
}
|
|
2480
|
+
}
|
|
2481
|
+
};
|
|
2482
|
+
var google = {
|
|
2483
|
+
"google.chat.v1": googleGeminiChatV1,
|
|
2484
|
+
"google.gemini-2.0-flash": withDefaultModel(googleGeminiChatV1, "gemini-2.0-flash"),
|
|
2485
|
+
"google.gemini-2.0-flash-lite": withDefaultModel(googleGeminiChatV1, "gemini-2.0-flash-lite"),
|
|
2486
|
+
"google.gemini-1.5-pro": withDefaultModel(googleGeminiChatV1, "gemini-1.5-pro")
|
|
2385
2487
|
};
|
|
2386
2488
|
|
|
2387
2489
|
// src/llm/config.ts
|
|
@@ -2390,14 +2492,18 @@ var configs = {
|
|
|
2390
2492
|
...anthropic,
|
|
2391
2493
|
...bedrock,
|
|
2392
2494
|
...xai,
|
|
2393
|
-
...ollama
|
|
2495
|
+
...ollama,
|
|
2496
|
+
...google
|
|
2394
2497
|
};
|
|
2395
2498
|
function getLlmConfig(provider) {
|
|
2499
|
+
if (!provider) {
|
|
2500
|
+
throw new Error(`Missing provider`);
|
|
2501
|
+
}
|
|
2396
2502
|
const pick2 = configs[provider];
|
|
2397
2503
|
if (pick2) {
|
|
2398
2504
|
return pick2;
|
|
2399
2505
|
}
|
|
2400
|
-
throw new Error(
|
|
2506
|
+
throw new Error(`Invalid provider: ${provider}`);
|
|
2401
2507
|
}
|
|
2402
2508
|
__name(getLlmConfig, "getLlmConfig");
|
|
2403
2509
|
|
|
@@ -2743,6 +2849,57 @@ function OutputOllamaChat(result, _config) {
|
|
|
2743
2849
|
}
|
|
2744
2850
|
__name(OutputOllamaChat, "OutputOllamaChat");
|
|
2745
2851
|
|
|
2852
|
+
// src/llm/output/google.gemini/formatResult.ts
|
|
2853
|
+
function formatResult4(result) {
|
|
2854
|
+
const { parts = [] } = result?.content || {};
|
|
2855
|
+
if (parts.length === 1) {
|
|
2856
|
+
const answer = parts[0];
|
|
2857
|
+
if (!!answer?.functionCall && typeof answer?.functionCall === "object") {
|
|
2858
|
+
return {
|
|
2859
|
+
type: "function_use",
|
|
2860
|
+
name: answer.functionCall.name,
|
|
2861
|
+
input: JSON.parse(answer.functionCall.args)
|
|
2862
|
+
};
|
|
2863
|
+
} else {
|
|
2864
|
+
return {
|
|
2865
|
+
type: "text",
|
|
2866
|
+
text: answer.text || ""
|
|
2867
|
+
};
|
|
2868
|
+
}
|
|
2869
|
+
}
|
|
2870
|
+
return {
|
|
2871
|
+
type: "text",
|
|
2872
|
+
text: ""
|
|
2873
|
+
};
|
|
2874
|
+
}
|
|
2875
|
+
__name(formatResult4, "formatResult");
|
|
2876
|
+
|
|
2877
|
+
// src/llm/output/google.gemini/index.ts
|
|
2878
|
+
function OutputGoogleGeminiChat(result, _config) {
|
|
2879
|
+
const id = "result.id";
|
|
2880
|
+
const name = result.modelVersion;
|
|
2881
|
+
const created = (/* @__PURE__ */ new Date()).getTime();
|
|
2882
|
+
const [_content, ..._options] = result?.candidates || [];
|
|
2883
|
+
const stopReason = _content?.finishReason?.toLowerCase();
|
|
2884
|
+
const content = formatContent(_content, formatResult4);
|
|
2885
|
+
const options = formatOptions(_options, formatResult4);
|
|
2886
|
+
const usage = {
|
|
2887
|
+
output_tokens: result?.usageMetadata?.candidatesTokenCount,
|
|
2888
|
+
input_tokens: result?.usageMetadata?.promptTokenCount,
|
|
2889
|
+
total_tokens: result?.usageMetadata?.totalTokenCount
|
|
2890
|
+
};
|
|
2891
|
+
return BaseLlmOutput2({
|
|
2892
|
+
id,
|
|
2893
|
+
name,
|
|
2894
|
+
created,
|
|
2895
|
+
usage,
|
|
2896
|
+
stopReason,
|
|
2897
|
+
content,
|
|
2898
|
+
options
|
|
2899
|
+
});
|
|
2900
|
+
}
|
|
2901
|
+
__name(OutputGoogleGeminiChat, "OutputGoogleGeminiChat");
|
|
2902
|
+
|
|
2746
2903
|
// src/llm/output/index.ts
|
|
2747
2904
|
function getOutputParser(config, response) {
|
|
2748
2905
|
switch (config?.key) {
|
|
@@ -2760,6 +2917,8 @@ function getOutputParser(config, response) {
|
|
|
2760
2917
|
return OutputXAIChat(response, config);
|
|
2761
2918
|
case "ollama.chat.v1":
|
|
2762
2919
|
return OutputOllamaChat(response, config);
|
|
2920
|
+
case "google.chat.v1":
|
|
2921
|
+
return OutputGoogleGeminiChat(response, config);
|
|
2763
2922
|
default: {
|
|
2764
2923
|
if (config?.key?.startsWith("custom:")) {
|
|
2765
2924
|
return OutputDefault(response, config);
|
|
@@ -3373,11 +3532,14 @@ var embeddingConfigs = {
|
|
|
3373
3532
|
}
|
|
3374
3533
|
};
|
|
3375
3534
|
function getEmbeddingConfig(provider) {
|
|
3535
|
+
if (!provider) {
|
|
3536
|
+
throw new Error(`Missing provider`);
|
|
3537
|
+
}
|
|
3376
3538
|
const pick2 = embeddingConfigs[provider];
|
|
3377
3539
|
if (pick2) {
|
|
3378
3540
|
return pick2;
|
|
3379
3541
|
}
|
|
3380
|
-
throw new Error(
|
|
3542
|
+
throw new Error(`Invalid provider: ${provider}`);
|
|
3381
3543
|
}
|
|
3382
3544
|
__name(getEmbeddingConfig, "getEmbeddingConfig");
|
|
3383
3545
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "llm-exe",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.5",
|
|
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
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# llm-exe
|
|
2
2
|
|
|
3
|
-
[](https://github.com/gregreindel/llm-exe/actions/workflows/tests.yml) [](https://coveralls.io/github/gregreindel/llm-exe?branch=main) [](https://badge.fury.io/js/llm-exe)
|
|
4
4
|
|
|
5
5
|
A package that provides simplified base components to make building and maintaining LLM-powered applications easier.
|
|
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)
|
|
10
|
-
- Call LLM's from different providers without changing your code. (OpenAi/Anthropic/xAI/AWS Bedrock)
|
|
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.
|