@output.ai/llm 0.2.4 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@output.ai/llm",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "Framework abstraction to interact with LLM models",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -13,7 +13,7 @@
13
13
  "@ai-sdk/azure": "2.0.53",
14
14
  "@ai-sdk/openai": "2.0.52",
15
15
  "@output.ai/core": ">=0.0.1",
16
- "ai": "5.0.48",
16
+ "ai": "5.0.52",
17
17
  "gray-matter": "4.0.3",
18
18
  "liquidjs": "10.22.0"
19
19
  },
package/src/index.d.ts CHANGED
@@ -59,12 +59,12 @@ export type Prompt = {
59
59
  * Load a prompt file and render it with variables.
60
60
  *
61
61
  * @param {string} name - Name of the prompt file (without .prompt extension)
62
- * @param {Record<string, string | number>} [variables] - Variables to interpolate
62
+ * @param {Record<string, string | number | boolean>} [variables] - Variables to interpolate
63
63
  * @returns {Prompt} Loaded and rendered prompt object
64
64
  */
65
65
  export function loadPrompt(
66
66
  name: string,
67
- variables?: Record<string, string | number>
67
+ variables?: Record<string, string | number | boolean>
68
68
  ): Prompt;
69
69
 
70
70
  /**
@@ -75,13 +75,13 @@ export function loadPrompt(
75
75
  *
76
76
  * @param {object} args - Generation arguments
77
77
  * @param {string} args.prompt - Prompt file name
78
- * @param {Record<string, string | number>} args.variables - Variables to interpolate
78
+ * @param {Record<string, string | number | boolean>} args.variables - Variables to interpolate
79
79
  * @returns {Promise<string>} Generated text
80
80
  */
81
81
  export function generateText(
82
82
  args: {
83
83
  prompt: string,
84
- variables?: Record<string, string | number>
84
+ variables?: Record<string, string | number | boolean>
85
85
  }
86
86
  ): Promise<string>;
87
87
 
@@ -93,7 +93,7 @@ export function generateText(
93
93
  *
94
94
  * @param {object} args - Generation arguments
95
95
  * @param {string} args.prompt - Prompt file name
96
- * @param {Record<string, string | number>} args.variables - Variables to interpolate
96
+ * @param {Record<string, string | number | boolean>} args.variables - Variables to interpolate
97
97
  * @param {z.ZodObject} args.schema - Output schema
98
98
  * @param {string} [args.schemaName] - Output schema name
99
99
  * @param {string} [args.schemaDescription] - Output schema description
@@ -102,7 +102,7 @@ export function generateText(
102
102
  export function generateObject<TSchema extends z.ZodObject>(
103
103
  args: {
104
104
  prompt: string,
105
- variables?: Record<string, string | number>,
105
+ variables?: Record<string, string | number | boolean>,
106
106
  schema: TSchema,
107
107
  schemaName?: string,
108
108
  schemaDescription?: string
@@ -117,7 +117,7 @@ export function generateObject<TSchema extends z.ZodObject>(
117
117
  *
118
118
  * @param {object} args - Generation arguments
119
119
  * @param {string} args.prompt - Prompt file name
120
- * @param {Record<string, string | number>} args.variables - Variables to interpolate
120
+ * @param {Record<string, string | number | boolean>} args.variables - Variables to interpolate
121
121
  * @param {z.ZodType} args.schema - Output schema (array item)
122
122
  * @param {string} [args.schemaName] - Output schema name
123
123
  * @param {string} [args.schemaDescription] - Output schema description
@@ -126,7 +126,7 @@ export function generateObject<TSchema extends z.ZodObject>(
126
126
  export function generateArray<TSchema extends z.ZodType>(
127
127
  args: {
128
128
  prompt: string,
129
- variables?: Record<string, string | number>,
129
+ variables?: Record<string, string | number | boolean>,
130
130
  schema: TSchema,
131
131
  schemaName?: string,
132
132
  schemaDescription?: string
@@ -141,14 +141,14 @@ export function generateArray<TSchema extends z.ZodType>(
141
141
  *
142
142
  * @param {object} args - Generation arguments
143
143
  * @param {string} args.prompt - Prompt file name
144
- * @param {Record<string, string | number>} args.variables - Variables to interpolate
144
+ * @param {Record<string, string | number | boolean>} args.variables - Variables to interpolate
145
145
  * @param {string[]} args.enum - Allowed values for the generation
146
146
  * @returns {Promise<string>} One of the provided enum values
147
147
  */
148
148
  export function generateEnum<const TEnum extends readonly [string, ...string[]]>(
149
149
  args: {
150
150
  prompt: string,
151
- variables?: Record<string, string | number>,
151
+ variables?: Record<string, string | number | boolean>,
152
152
  enum: TEnum
153
153
  }
154
154
  ): Promise<TEnum[number]>;
@@ -18,7 +18,7 @@ const renderPrompt = ( name, content, values ) => {
18
18
  * Load a prompt file and render it with variables.
19
19
  *
20
20
  * @param {string} name - Name of the prompt file (without .prompt extension)
21
- * @param {Record<string, string | number>} [values] - Variables to interpolate
21
+ * @param {Record<string, string | number | boolean>} [values] - Variables to interpolate
22
22
  * @returns {Prompt} Loaded and rendered prompt object
23
23
  */
24
24
  export const loadPrompt = ( name, values = {} ) => {
@@ -146,4 +146,34 @@ temperature: 0.7
146
146
  expect( result.config.maxTokens ).toBe( 1024 );
147
147
  } );
148
148
 
149
+ it( 'should render boolean variables correctly', () => {
150
+ const promptContent = `---
151
+ provider: anthropic
152
+ model: claude-3-5-sonnet-20241022
153
+ ---
154
+
155
+ <user>{% if debug %}Debug mode enabled{% else %}Debug mode disabled{% endif %}</user>`;
156
+
157
+ loadContent.mockReturnValue( promptContent );
158
+
159
+ const result = loadPrompt( 'test', { debug: true } );
160
+
161
+ expect( result.messages[0].content ).toBe( 'Debug mode enabled' );
162
+ } );
163
+
164
+ it( 'should render false boolean variables', () => {
165
+ const promptContent = `---
166
+ provider: anthropic
167
+ model: claude-3-5-sonnet-20241022
168
+ ---
169
+
170
+ <user>{% if enabled %}Feature enabled{% else %}Feature disabled{% endif %}</user>`;
171
+
172
+ loadContent.mockReturnValue( promptContent );
173
+
174
+ const result = loadPrompt( 'test', { enabled: false } );
175
+
176
+ expect( result.messages[0].content ).toBe( 'Feature disabled' );
177
+ } );
178
+
149
179
  } );