llm-exe 2.0.0-beta.8 → 2.1.0
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 +5 -8
- package/dist/index.d.ts +5 -8
- package/dist/index.js +509 -450
- package/dist/index.mjs +509 -450
- package/package.json +2 -3
- package/readme.md +31 -37
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "llm-exe",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
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",
|
|
@@ -9,12 +9,11 @@
|
|
|
9
9
|
"anthropic",
|
|
10
10
|
"bedrock",
|
|
11
11
|
"llama",
|
|
12
|
-
"gpt-3.5-turbo",
|
|
13
12
|
"gpt-4",
|
|
14
13
|
"claude",
|
|
15
14
|
"chain",
|
|
16
15
|
"prompt",
|
|
17
|
-
"
|
|
16
|
+
"agents"
|
|
18
17
|
],
|
|
19
18
|
"source": "./src/index.ts",
|
|
20
19
|
"main": "./dist/index.js",
|
package/readme.md
CHANGED
|
@@ -26,7 +26,7 @@ npm i llm-exe
|
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
```typescript
|
|
29
|
-
import * as llmExe from "llm-exe"
|
|
29
|
+
import * as llmExe from "llm-exe";
|
|
30
30
|
|
|
31
31
|
// or
|
|
32
32
|
|
|
@@ -35,32 +35,30 @@ import { /* specific modules */ } from from "llm-exe"
|
|
|
35
35
|
|
|
36
36
|
## Basic Example
|
|
37
37
|
Below is simple example:
|
|
38
|
-
```
|
|
39
|
-
import
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
llm,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const input = "Hello! When was my last appointment?";
|
|
63
|
-
const response = await executor.execute({ input })
|
|
38
|
+
```typescript
|
|
39
|
+
import * as llmExe from "llm-exe";
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Define a yes/no llm-powered function
|
|
43
|
+
*/
|
|
44
|
+
export async function YesOrNoBot<I extends string>(input: I) {
|
|
45
|
+
const llm = llmExe.useLlm("openai.gpt-4o-mini");
|
|
46
|
+
|
|
47
|
+
const instruction = `You are not an assistant, I need you to reply with only
|
|
48
|
+
'yes' or 'no' as an answer to the question below. Do not explain yourself
|
|
49
|
+
or ask questions. Answer with only yes or no.`;
|
|
50
|
+
|
|
51
|
+
const prompt = llmExe
|
|
52
|
+
.createChatPrompt(instruction)
|
|
53
|
+
.addUserMessage(input)
|
|
54
|
+
.addSystemMessage(`yes or no:`);
|
|
55
|
+
|
|
56
|
+
const parser = llmExe.createParser("stringExtract", { enum: ["yes", "no"] });
|
|
57
|
+
return llmExe.createLlmExecutor({ llm, prompt, parser }).execute({ input });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const isTheSkyBlue = await YesOrNoBot(`Is AI cool?`)
|
|
61
|
+
|
|
64
62
|
/**
|
|
65
63
|
*
|
|
66
64
|
* The prompt sent to the LLM would be:
|
|
@@ -68,24 +66,20 @@ const response = await executor.execute({ input })
|
|
|
68
66
|
*
|
|
69
67
|
* [{
|
|
70
68
|
* role: 'system',
|
|
71
|
-
* content: '
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
* content: 'You are not an assistant, I need you to reply with only
|
|
70
|
+
'yes' or 'no' as an answer to the question asked by the user. Do not explain yourself
|
|
71
|
+
or ask questions. Answer only with yes or no.'
|
|
74
72
|
* },
|
|
75
73
|
* {
|
|
76
74
|
* role: 'user',
|
|
77
|
-
* content: '
|
|
75
|
+
* content: 'Is AI cool?'
|
|
78
76
|
* }]
|
|
79
77
|
*
|
|
80
78
|
*/
|
|
81
79
|
|
|
82
80
|
/**
|
|
83
81
|
*
|
|
84
|
-
* console.log(
|
|
85
|
-
*
|
|
86
|
-
* "a subtask the llm generated",
|
|
87
|
-
* "a subtask the llm generated",
|
|
88
|
-
* "a subtask the llm generated",
|
|
89
|
-
* ]
|
|
82
|
+
* console.log(isTheSkyBlue)
|
|
83
|
+
* yes
|
|
90
84
|
* /
|
|
91
85
|
```
|