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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "llm-exe",
3
- "version": "2.0.0-beta.8",
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
- "agent"
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
- ```javascript
39
- import {
40
- useLlm,
41
- createChatPrompt,
42
- createParser
43
- } from "llm-exe";
44
-
45
- const instruction = `<some prompt>
46
-
47
- Your response must be formatted like:
48
- <subtask>
49
- <subtask>
50
- <subtask>`;
51
-
52
- const llm = useLlm("openai.chat.v1",{ /* options */ });
53
- const prompt = createChatPrompt(instruction).addUserMessage()
54
- const parser = createParser("listToArray");
55
-
56
- const executor = createLlmExecutor({
57
- llm,
58
- prompt,
59
- parser
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: '<some prompt>\n
72
- * Your response must be formatted like:\n<subtask>\n<subtask>\n
73
- * <subtask>'
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: 'Hello! When was my last appointment?'
75
+ * content: 'Is AI cool?'
78
76
  * }]
79
77
  *
80
78
  */
81
79
 
82
80
  /**
83
81
  *
84
- * console.log(response)
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
  ```