llm-exe 2.1.1 → 2.1.2
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 +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +99 -1
- package/dist/index.mjs +99 -1
- package/package.json +3 -3
- package/readme.md +3 -2
package/dist/index.d.mts
CHANGED
|
@@ -954,6 +954,9 @@ type AllLlm = {
|
|
|
954
954
|
"amazon:meta.chat.v1": {
|
|
955
955
|
input: AmazonBedrockRequest;
|
|
956
956
|
};
|
|
957
|
+
"xai.chat.v1": {
|
|
958
|
+
input: OpenAiRequest;
|
|
959
|
+
};
|
|
957
960
|
};
|
|
958
961
|
type AllUseLlmOptions = AllLlm & {
|
|
959
962
|
"openai.gpt-4": {
|
|
@@ -977,6 +980,9 @@ type AllUseLlmOptions = AllLlm & {
|
|
|
977
980
|
"anthropic.claude-3-haiku": {
|
|
978
981
|
input: Omit<AnthropicRequest, "model">;
|
|
979
982
|
};
|
|
983
|
+
"xai.grok-2": {
|
|
984
|
+
input: OpenAiRequest;
|
|
985
|
+
};
|
|
980
986
|
};
|
|
981
987
|
type LlmProviderKey = keyof AllLlm;
|
|
982
988
|
type EmbeddingProviderKey = keyof AllEmbedding;
|
|
@@ -994,7 +1000,7 @@ interface BaseRequest<_T extends Record<string, any>> {
|
|
|
994
1000
|
interface BaseLlm<_T extends BaseLlCall = BaseLlCall> extends BaseRequest<_T> {
|
|
995
1001
|
}
|
|
996
1002
|
|
|
997
|
-
type LlmProvider = "openai.chat" | "openai.embedding" | "openai.chat-mock" | "anthropic.chat" | "amazon:anthropic.chat" | "amazon:meta.chat" | "amazon:nova.chat" | "amazon.embedding";
|
|
1003
|
+
type LlmProvider = "openai.chat" | "openai.embedding" | "openai.chat-mock" | "anthropic.chat" | "amazon:anthropic.chat" | "amazon:meta.chat" | "amazon:nova.chat" | "amazon.embedding" | "xai.chat";
|
|
998
1004
|
interface Config<Pk = LlmProviderKey> {
|
|
999
1005
|
key: Pk;
|
|
1000
1006
|
provider: LlmProvider;
|
|
@@ -1168,6 +1174,8 @@ declare namespace index {
|
|
|
1168
1174
|
}
|
|
1169
1175
|
|
|
1170
1176
|
declare const configs: {
|
|
1177
|
+
"xai.chat.v1": Config<keyof AllLlm>;
|
|
1178
|
+
"xai.grok-2": Config<keyof AllLlm>;
|
|
1171
1179
|
"amazon:anthropic.chat.v1": Config<keyof AllLlm>;
|
|
1172
1180
|
"amazon:meta.chat.v1": Config<keyof AllLlm>;
|
|
1173
1181
|
"anthropic.chat.v1": Config<keyof AllLlm>;
|
package/dist/index.d.ts
CHANGED
|
@@ -954,6 +954,9 @@ type AllLlm = {
|
|
|
954
954
|
"amazon:meta.chat.v1": {
|
|
955
955
|
input: AmazonBedrockRequest;
|
|
956
956
|
};
|
|
957
|
+
"xai.chat.v1": {
|
|
958
|
+
input: OpenAiRequest;
|
|
959
|
+
};
|
|
957
960
|
};
|
|
958
961
|
type AllUseLlmOptions = AllLlm & {
|
|
959
962
|
"openai.gpt-4": {
|
|
@@ -977,6 +980,9 @@ type AllUseLlmOptions = AllLlm & {
|
|
|
977
980
|
"anthropic.claude-3-haiku": {
|
|
978
981
|
input: Omit<AnthropicRequest, "model">;
|
|
979
982
|
};
|
|
983
|
+
"xai.grok-2": {
|
|
984
|
+
input: OpenAiRequest;
|
|
985
|
+
};
|
|
980
986
|
};
|
|
981
987
|
type LlmProviderKey = keyof AllLlm;
|
|
982
988
|
type EmbeddingProviderKey = keyof AllEmbedding;
|
|
@@ -994,7 +1000,7 @@ interface BaseRequest<_T extends Record<string, any>> {
|
|
|
994
1000
|
interface BaseLlm<_T extends BaseLlCall = BaseLlCall> extends BaseRequest<_T> {
|
|
995
1001
|
}
|
|
996
1002
|
|
|
997
|
-
type LlmProvider = "openai.chat" | "openai.embedding" | "openai.chat-mock" | "anthropic.chat" | "amazon:anthropic.chat" | "amazon:meta.chat" | "amazon:nova.chat" | "amazon.embedding";
|
|
1003
|
+
type LlmProvider = "openai.chat" | "openai.embedding" | "openai.chat-mock" | "anthropic.chat" | "amazon:anthropic.chat" | "amazon:meta.chat" | "amazon:nova.chat" | "amazon.embedding" | "xai.chat";
|
|
998
1004
|
interface Config<Pk = LlmProviderKey> {
|
|
999
1005
|
key: Pk;
|
|
1000
1006
|
provider: LlmProvider;
|
|
@@ -1168,6 +1174,8 @@ declare namespace index {
|
|
|
1168
1174
|
}
|
|
1169
1175
|
|
|
1170
1176
|
declare const configs: {
|
|
1177
|
+
"xai.chat.v1": Config<keyof AllLlm>;
|
|
1178
|
+
"xai.grok-2": Config<keyof AllLlm>;
|
|
1171
1179
|
"amazon:anthropic.chat.v1": Config<keyof AllLlm>;
|
|
1172
1180
|
"amazon:meta.chat.v1": Config<keyof AllLlm>;
|
|
1173
1181
|
"anthropic.chat.v1": Config<keyof AllLlm>;
|
package/dist/index.js
CHANGED
|
@@ -2295,11 +2295,59 @@ var bedrock = {
|
|
|
2295
2295
|
"amazon:meta.chat.v1": amazonMetaChatV1
|
|
2296
2296
|
};
|
|
2297
2297
|
|
|
2298
|
+
// src/llm/config/x/index.ts
|
|
2299
|
+
var xaiChatV1 = {
|
|
2300
|
+
key: "xai.chat.v1",
|
|
2301
|
+
provider: "xai.chat",
|
|
2302
|
+
endpoint: `https://api.x.ai/v1/chat/completions`,
|
|
2303
|
+
options: {
|
|
2304
|
+
prompt: {},
|
|
2305
|
+
topP: {},
|
|
2306
|
+
useJson: {},
|
|
2307
|
+
xAiApiKey: {
|
|
2308
|
+
default: getEnvironmentVariable("XAI_API_KEY")
|
|
2309
|
+
}
|
|
2310
|
+
},
|
|
2311
|
+
method: "POST",
|
|
2312
|
+
headers: `{"Authorization":"Bearer {{xAiApiKey}}", "Content-Type": "application/json" }`,
|
|
2313
|
+
mapBody: {
|
|
2314
|
+
prompt: {
|
|
2315
|
+
key: "messages",
|
|
2316
|
+
sanitize: /* @__PURE__ */ __name((v) => {
|
|
2317
|
+
if (typeof v === "string") {
|
|
2318
|
+
return [
|
|
2319
|
+
{
|
|
2320
|
+
role: "user",
|
|
2321
|
+
content: v
|
|
2322
|
+
}
|
|
2323
|
+
];
|
|
2324
|
+
}
|
|
2325
|
+
return v;
|
|
2326
|
+
}, "sanitize")
|
|
2327
|
+
},
|
|
2328
|
+
model: {
|
|
2329
|
+
key: "model"
|
|
2330
|
+
},
|
|
2331
|
+
topP: {
|
|
2332
|
+
key: "top_p"
|
|
2333
|
+
},
|
|
2334
|
+
useJson: {
|
|
2335
|
+
key: "response_format.type",
|
|
2336
|
+
sanitize: /* @__PURE__ */ __name((v) => v ? "json_object" : "text", "sanitize")
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
};
|
|
2340
|
+
var xai = {
|
|
2341
|
+
"xai.chat.v1": xaiChatV1,
|
|
2342
|
+
"xai.grok-2": withDefaultModel(xaiChatV1, "grok-2-latest")
|
|
2343
|
+
};
|
|
2344
|
+
|
|
2298
2345
|
// src/llm/config.ts
|
|
2299
2346
|
var configs = {
|
|
2300
2347
|
...openai,
|
|
2301
2348
|
...anthropic,
|
|
2302
|
-
...bedrock
|
|
2349
|
+
...bedrock,
|
|
2350
|
+
...xai
|
|
2303
2351
|
};
|
|
2304
2352
|
function getLlmConfig(provider) {
|
|
2305
2353
|
const pick2 = configs[provider];
|
|
@@ -2530,6 +2578,54 @@ function OutputDefault(result, _config) {
|
|
|
2530
2578
|
}
|
|
2531
2579
|
__name(OutputDefault, "OutputDefault");
|
|
2532
2580
|
|
|
2581
|
+
// src/llm/output/xai.ts
|
|
2582
|
+
function formatResult3(result) {
|
|
2583
|
+
if (typeof result?.message?.content === "string") {
|
|
2584
|
+
return {
|
|
2585
|
+
type: "text",
|
|
2586
|
+
text: result.message.content
|
|
2587
|
+
};
|
|
2588
|
+
} else if (result?.message && "tool_calls" in result.message) {
|
|
2589
|
+
const tool_calls = result.message.tool_calls;
|
|
2590
|
+
for (const call of tool_calls) {
|
|
2591
|
+
return {
|
|
2592
|
+
type: "function_use",
|
|
2593
|
+
name: call.function.name,
|
|
2594
|
+
input: JSON.parse(call.function.arguments)
|
|
2595
|
+
};
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
return {
|
|
2599
|
+
type: "text",
|
|
2600
|
+
text: ""
|
|
2601
|
+
};
|
|
2602
|
+
}
|
|
2603
|
+
__name(formatResult3, "formatResult");
|
|
2604
|
+
function OutputXAIChat(result, _config) {
|
|
2605
|
+
const id = result.id;
|
|
2606
|
+
const name = result?.model;
|
|
2607
|
+
const created = result.created;
|
|
2608
|
+
const [_content, ..._options] = result?.choices || [];
|
|
2609
|
+
const stopReason = _content?.finish_reason;
|
|
2610
|
+
const content = formatContent(_content, formatResult3);
|
|
2611
|
+
const options = formatOptions(_options, formatResult3);
|
|
2612
|
+
const usage = {
|
|
2613
|
+
output_tokens: result?.usage?.completion_tokens,
|
|
2614
|
+
input_tokens: result?.usage?.prompt_tokens,
|
|
2615
|
+
total_tokens: result?.usage?.total_tokens
|
|
2616
|
+
};
|
|
2617
|
+
return BaseLlmOutput2({
|
|
2618
|
+
id,
|
|
2619
|
+
name,
|
|
2620
|
+
created,
|
|
2621
|
+
usage,
|
|
2622
|
+
stopReason,
|
|
2623
|
+
content,
|
|
2624
|
+
options
|
|
2625
|
+
});
|
|
2626
|
+
}
|
|
2627
|
+
__name(OutputXAIChat, "OutputXAIChat");
|
|
2628
|
+
|
|
2533
2629
|
// src/llm/output/index.ts
|
|
2534
2630
|
function getOutputParser(config, response) {
|
|
2535
2631
|
switch (config?.key) {
|
|
@@ -2543,6 +2639,8 @@ function getOutputParser(config, response) {
|
|
|
2543
2639
|
return OutputMetaLlama3Chat(response, config);
|
|
2544
2640
|
// case "amazon:nova.chat.v1":
|
|
2545
2641
|
// return OutputDefault(response, config);
|
|
2642
|
+
case "xai.chat.v1":
|
|
2643
|
+
return OutputXAIChat(response, config);
|
|
2546
2644
|
default: {
|
|
2547
2645
|
if (config?.key?.startsWith("custom:")) {
|
|
2548
2646
|
return OutputDefault(response, config);
|
package/dist/index.mjs
CHANGED
|
@@ -2247,11 +2247,59 @@ var bedrock = {
|
|
|
2247
2247
|
"amazon:meta.chat.v1": amazonMetaChatV1
|
|
2248
2248
|
};
|
|
2249
2249
|
|
|
2250
|
+
// src/llm/config/x/index.ts
|
|
2251
|
+
var xaiChatV1 = {
|
|
2252
|
+
key: "xai.chat.v1",
|
|
2253
|
+
provider: "xai.chat",
|
|
2254
|
+
endpoint: `https://api.x.ai/v1/chat/completions`,
|
|
2255
|
+
options: {
|
|
2256
|
+
prompt: {},
|
|
2257
|
+
topP: {},
|
|
2258
|
+
useJson: {},
|
|
2259
|
+
xAiApiKey: {
|
|
2260
|
+
default: getEnvironmentVariable("XAI_API_KEY")
|
|
2261
|
+
}
|
|
2262
|
+
},
|
|
2263
|
+
method: "POST",
|
|
2264
|
+
headers: `{"Authorization":"Bearer {{xAiApiKey}}", "Content-Type": "application/json" }`,
|
|
2265
|
+
mapBody: {
|
|
2266
|
+
prompt: {
|
|
2267
|
+
key: "messages",
|
|
2268
|
+
sanitize: /* @__PURE__ */ __name((v) => {
|
|
2269
|
+
if (typeof v === "string") {
|
|
2270
|
+
return [
|
|
2271
|
+
{
|
|
2272
|
+
role: "user",
|
|
2273
|
+
content: v
|
|
2274
|
+
}
|
|
2275
|
+
];
|
|
2276
|
+
}
|
|
2277
|
+
return v;
|
|
2278
|
+
}, "sanitize")
|
|
2279
|
+
},
|
|
2280
|
+
model: {
|
|
2281
|
+
key: "model"
|
|
2282
|
+
},
|
|
2283
|
+
topP: {
|
|
2284
|
+
key: "top_p"
|
|
2285
|
+
},
|
|
2286
|
+
useJson: {
|
|
2287
|
+
key: "response_format.type",
|
|
2288
|
+
sanitize: /* @__PURE__ */ __name((v) => v ? "json_object" : "text", "sanitize")
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
};
|
|
2292
|
+
var xai = {
|
|
2293
|
+
"xai.chat.v1": xaiChatV1,
|
|
2294
|
+
"xai.grok-2": withDefaultModel(xaiChatV1, "grok-2-latest")
|
|
2295
|
+
};
|
|
2296
|
+
|
|
2250
2297
|
// src/llm/config.ts
|
|
2251
2298
|
var configs = {
|
|
2252
2299
|
...openai,
|
|
2253
2300
|
...anthropic,
|
|
2254
|
-
...bedrock
|
|
2301
|
+
...bedrock,
|
|
2302
|
+
...xai
|
|
2255
2303
|
};
|
|
2256
2304
|
function getLlmConfig(provider) {
|
|
2257
2305
|
const pick2 = configs[provider];
|
|
@@ -2482,6 +2530,54 @@ function OutputDefault(result, _config) {
|
|
|
2482
2530
|
}
|
|
2483
2531
|
__name(OutputDefault, "OutputDefault");
|
|
2484
2532
|
|
|
2533
|
+
// src/llm/output/xai.ts
|
|
2534
|
+
function formatResult3(result) {
|
|
2535
|
+
if (typeof result?.message?.content === "string") {
|
|
2536
|
+
return {
|
|
2537
|
+
type: "text",
|
|
2538
|
+
text: result.message.content
|
|
2539
|
+
};
|
|
2540
|
+
} else if (result?.message && "tool_calls" in result.message) {
|
|
2541
|
+
const tool_calls = result.message.tool_calls;
|
|
2542
|
+
for (const call of tool_calls) {
|
|
2543
|
+
return {
|
|
2544
|
+
type: "function_use",
|
|
2545
|
+
name: call.function.name,
|
|
2546
|
+
input: JSON.parse(call.function.arguments)
|
|
2547
|
+
};
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
return {
|
|
2551
|
+
type: "text",
|
|
2552
|
+
text: ""
|
|
2553
|
+
};
|
|
2554
|
+
}
|
|
2555
|
+
__name(formatResult3, "formatResult");
|
|
2556
|
+
function OutputXAIChat(result, _config) {
|
|
2557
|
+
const id = result.id;
|
|
2558
|
+
const name = result?.model;
|
|
2559
|
+
const created = result.created;
|
|
2560
|
+
const [_content, ..._options] = result?.choices || [];
|
|
2561
|
+
const stopReason = _content?.finish_reason;
|
|
2562
|
+
const content = formatContent(_content, formatResult3);
|
|
2563
|
+
const options = formatOptions(_options, formatResult3);
|
|
2564
|
+
const usage = {
|
|
2565
|
+
output_tokens: result?.usage?.completion_tokens,
|
|
2566
|
+
input_tokens: result?.usage?.prompt_tokens,
|
|
2567
|
+
total_tokens: result?.usage?.total_tokens
|
|
2568
|
+
};
|
|
2569
|
+
return BaseLlmOutput2({
|
|
2570
|
+
id,
|
|
2571
|
+
name,
|
|
2572
|
+
created,
|
|
2573
|
+
usage,
|
|
2574
|
+
stopReason,
|
|
2575
|
+
content,
|
|
2576
|
+
options
|
|
2577
|
+
});
|
|
2578
|
+
}
|
|
2579
|
+
__name(OutputXAIChat, "OutputXAIChat");
|
|
2580
|
+
|
|
2485
2581
|
// src/llm/output/index.ts
|
|
2486
2582
|
function getOutputParser(config, response) {
|
|
2487
2583
|
switch (config?.key) {
|
|
@@ -2495,6 +2591,8 @@ function getOutputParser(config, response) {
|
|
|
2495
2591
|
return OutputMetaLlama3Chat(response, config);
|
|
2496
2592
|
// case "amazon:nova.chat.v1":
|
|
2497
2593
|
// return OutputDefault(response, config);
|
|
2594
|
+
case "xai.chat.v1":
|
|
2595
|
+
return OutputXAIChat(response, config);
|
|
2498
2596
|
default: {
|
|
2499
2597
|
if (config?.key?.startsWith("custom:")) {
|
|
2500
2598
|
return OutputDefault(response, config);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "llm-exe",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
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",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"gpt-3.5-turbo",
|
|
13
13
|
"gpt-4",
|
|
14
14
|
"claude",
|
|
15
|
+
"grok",
|
|
15
16
|
"chain",
|
|
16
17
|
"prompt",
|
|
17
18
|
"agent"
|
|
@@ -23,8 +24,7 @@
|
|
|
23
24
|
"exports": {
|
|
24
25
|
".": {
|
|
25
26
|
"require": "./dist/index.js",
|
|
26
|
-
"import": "./dist/index.mjs"
|
|
27
|
-
"types": "./dist/index.d.ts"
|
|
27
|
+
"import": "./dist/index.mjs"
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
package/readme.md
CHANGED
|
@@ -6,7 +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).
|
|
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)
|
|
10
11
|
- Supercharge your prompts by using handlebars within prompt template.
|
|
11
12
|
- Allow LLM's to call functions (or call other LLM executors).
|
|
12
13
|
- Not very opinionated. You have control on how you use it.
|
|
@@ -14,7 +15,7 @@ A package that provides simplified base components to make building and maintain
|
|
|
14
15
|

|
|
15
16
|
|
|
16
17
|
|
|
17
|
-
See full docs [
|
|
18
|
+
See full docs here: [https://llm-exe.com](https://llm-exe.com)
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
---
|