hazo_llm_api 1.0.3 → 1.0.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/README.md +4 -4
- package/dist/lib/config/config_parser.d.ts +1 -1
- package/dist/lib/config/config_parser.js +5 -5
- package/dist/lib/config/config_parser.js.map +1 -1
- package/dist/lib/config/provider_loader.js +1 -1
- package/dist/lib/config/provider_loader.js.map +1 -1
- package/dist/lib/database/init_database.d.ts.map +1 -1
- package/dist/lib/database/init_database.js +72 -5
- package/dist/lib/database/init_database.js.map +1 -1
- package/dist/lib/database/utils.d.ts +9 -6
- package/dist/lib/database/utils.d.ts.map +1 -1
- package/dist/lib/database/utils.js +14 -5
- package/dist/lib/database/utils.js.map +1 -1
- package/dist/lib/llm_api/chain_helpers.d.ts +117 -0
- package/dist/lib/llm_api/chain_helpers.d.ts.map +1 -0
- package/dist/lib/llm_api/chain_helpers.js +445 -0
- package/dist/lib/llm_api/chain_helpers.js.map +1 -0
- package/dist/lib/llm_api/hazo_llm_prompt_chain.d.ts +20 -0
- package/dist/lib/llm_api/hazo_llm_prompt_chain.d.ts.map +1 -0
- package/dist/lib/llm_api/hazo_llm_prompt_chain.js +368 -0
- package/dist/lib/llm_api/hazo_llm_prompt_chain.js.map +1 -0
- package/dist/lib/llm_api/index.d.ts +34 -2
- package/dist/lib/llm_api/index.d.ts.map +1 -1
- package/dist/lib/llm_api/index.js +57 -5
- package/dist/lib/llm_api/index.js.map +1 -1
- package/dist/lib/llm_api/provider_helper.js +1 -1
- package/dist/lib/llm_api/provider_helper.js.map +1 -1
- package/dist/lib/llm_api/types.d.ts +143 -1
- package/dist/lib/llm_api/types.d.ts.map +1 -1
- package/dist/lib/llm_api/types.js.map +1 -1
- package/dist/lib/prompts/get_prompt.d.ts +27 -1
- package/dist/lib/prompts/get_prompt.d.ts.map +1 -1
- package/dist/lib/prompts/get_prompt.js +112 -2
- package/dist/lib/prompts/get_prompt.js.map +1 -1
- package/dist/lib/prompts/index.d.ts +1 -1
- package/dist/lib/prompts/index.d.ts.map +1 -1
- package/dist/lib/prompts/index.js +1 -1
- package/dist/lib/prompts/index.js.map +1 -1
- package/dist/lib/prompts/substitute_variables.d.ts +2 -2
- package/dist/lib/prompts/substitute_variables.d.ts.map +1 -1
- package/dist/lib/prompts/substitute_variables.js +10 -14
- package/dist/lib/prompts/substitute_variables.js.map +1 -1
- package/dist/lib/providers/qwen/qwen_provider.js +1 -1
- package/dist/lib/providers/qwen/qwen_provider.js.map +1 -1
- package/dist/server.d.ts +4 -3
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +3 -2
- package/dist/server.js.map +1 -1
- package/package.json +12 -1
- package/techdoc.md +2 -2
- package/dist/components/hazo_llm_prompt_config/hazo_llm_prompt_config.d.ts +0 -16
- package/dist/components/hazo_llm_prompt_config/hazo_llm_prompt_config.d.ts.map +0 -1
- package/dist/components/hazo_llm_prompt_config/hazo_llm_prompt_config.js +0 -258
- package/dist/components/hazo_llm_prompt_config/hazo_llm_prompt_config.js.map +0 -1
- package/dist/components/hazo_llm_prompt_config/index.d.ts +0 -8
- package/dist/components/hazo_llm_prompt_config/index.d.ts.map +0 -1
- package/dist/components/hazo_llm_prompt_config/index.js +0 -7
- package/dist/components/hazo_llm_prompt_config/index.js.map +0 -1
- package/dist/components/hazo_llm_prompt_config/types.d.ts +0 -74
- package/dist/components/hazo_llm_prompt_config/types.d.ts.map +0 -1
- package/dist/components/hazo_llm_prompt_config/types.js +0 -8
- package/dist/components/hazo_llm_prompt_config/types.js.map +0 -1
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hazo_llm_prompt_chain Function
|
|
3
|
+
*
|
|
4
|
+
* Executes a sequence of LLM calls where each call can reference
|
|
5
|
+
* values from previous call results. Supports all 4 service types:
|
|
6
|
+
* text_text, image_text, text_image, image_image.
|
|
7
|
+
*/
|
|
8
|
+
import { hazo_llm_text_text } from './hazo_llm_text_text.js';
|
|
9
|
+
import { hazo_llm_image_text } from './hazo_llm_image_text.js';
|
|
10
|
+
import { hazo_llm_text_image } from './hazo_llm_text_image.js';
|
|
11
|
+
import { hazo_llm_image_image } from './hazo_llm_image_image.js';
|
|
12
|
+
import { resolve_chain_field, build_prompt_variables, merge_chain_results, parse_llm_json_response, resolve_chain_image_definition, } from './chain_helpers.js';
|
|
13
|
+
// =============================================================================
|
|
14
|
+
// Constants
|
|
15
|
+
// =============================================================================
|
|
16
|
+
const FILE_NAME = 'hazo_llm_prompt_chain.ts';
|
|
17
|
+
const API_NAME = 'prompt_chain';
|
|
18
|
+
// Default call type for backward compatibility
|
|
19
|
+
const DEFAULT_CALL_TYPE = 'text_text';
|
|
20
|
+
// =============================================================================
|
|
21
|
+
// Helper Functions
|
|
22
|
+
// =============================================================================
|
|
23
|
+
/**
|
|
24
|
+
* Build service-specific parameters based on call type
|
|
25
|
+
*
|
|
26
|
+
* @param call_def - The chain call definition
|
|
27
|
+
* @param call_type - The service type to build params for
|
|
28
|
+
* @param prompt_variables - Resolved prompt variables
|
|
29
|
+
* @param previous_results - Array of previous call results
|
|
30
|
+
* @param logger - Logger instance
|
|
31
|
+
* @returns Build result with params or error
|
|
32
|
+
*/
|
|
33
|
+
function build_service_params(call_def, call_type, prompt_variables, previous_results, logger) {
|
|
34
|
+
// Base params common to all types
|
|
35
|
+
const base_params = {
|
|
36
|
+
prompt: '', // Will be overridden by dynamic prompt
|
|
37
|
+
prompt_variables,
|
|
38
|
+
};
|
|
39
|
+
switch (call_type) {
|
|
40
|
+
case 'text_text':
|
|
41
|
+
return { success: true, params: base_params };
|
|
42
|
+
case 'text_image':
|
|
43
|
+
return { success: true, params: base_params };
|
|
44
|
+
case 'image_text': {
|
|
45
|
+
// Resolve image_b64 and image_mime_type
|
|
46
|
+
if (!call_def.image_b64 || !call_def.image_mime_type) {
|
|
47
|
+
return {
|
|
48
|
+
success: false,
|
|
49
|
+
error: 'image_text requires image_b64 and image_mime_type fields',
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const image_b64 = resolve_chain_field(call_def.image_b64, previous_results, logger);
|
|
53
|
+
const image_mime_type = resolve_chain_field(call_def.image_mime_type, previous_results, logger);
|
|
54
|
+
if (!image_b64) {
|
|
55
|
+
return {
|
|
56
|
+
success: false,
|
|
57
|
+
error: 'Could not resolve image_b64 for image_text call',
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (!image_mime_type) {
|
|
61
|
+
return {
|
|
62
|
+
success: false,
|
|
63
|
+
error: 'Could not resolve image_mime_type for image_text call',
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
logger.debug('Resolved image for image_text', {
|
|
67
|
+
file: FILE_NAME,
|
|
68
|
+
data: {
|
|
69
|
+
image_b64_length: image_b64.length,
|
|
70
|
+
image_mime_type,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
return {
|
|
74
|
+
success: true,
|
|
75
|
+
params: {
|
|
76
|
+
...base_params,
|
|
77
|
+
image_b64,
|
|
78
|
+
image_mime_type,
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
case 'image_image': {
|
|
83
|
+
const images = [];
|
|
84
|
+
// Multi-image mode - prefer images array if provided
|
|
85
|
+
if (call_def.images && call_def.images.length > 0) {
|
|
86
|
+
for (const img_def of call_def.images) {
|
|
87
|
+
const resolved = resolve_chain_image_definition(img_def, previous_results, logger);
|
|
88
|
+
if (resolved) {
|
|
89
|
+
images.push({
|
|
90
|
+
data: resolved.image_b64,
|
|
91
|
+
mime_type: resolved.image_mime_type,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
logger.warn('Failed to resolve image in images array', {
|
|
96
|
+
file: FILE_NAME,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// Single image mode
|
|
102
|
+
else if (call_def.image_b64 && call_def.image_mime_type) {
|
|
103
|
+
const image_b64 = resolve_chain_field(call_def.image_b64, previous_results, logger);
|
|
104
|
+
const image_mime_type = resolve_chain_field(call_def.image_mime_type, previous_results, logger);
|
|
105
|
+
if (image_b64 && image_mime_type) {
|
|
106
|
+
images.push({
|
|
107
|
+
data: image_b64,
|
|
108
|
+
mime_type: image_mime_type,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (images.length === 0) {
|
|
113
|
+
return {
|
|
114
|
+
success: false,
|
|
115
|
+
error: 'image_image requires at least one image (via image_b64/image_mime_type or images array)',
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
logger.debug('Resolved images for image_image', {
|
|
119
|
+
file: FILE_NAME,
|
|
120
|
+
data: { image_count: images.length },
|
|
121
|
+
});
|
|
122
|
+
return {
|
|
123
|
+
success: true,
|
|
124
|
+
params: {
|
|
125
|
+
...base_params,
|
|
126
|
+
images,
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
default:
|
|
131
|
+
return {
|
|
132
|
+
success: false,
|
|
133
|
+
error: `Unknown call_type: ${call_type}`,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Dispatch to the appropriate service function based on call type
|
|
139
|
+
*
|
|
140
|
+
* @param call_type - The service type to invoke
|
|
141
|
+
* @param params - Service-specific parameters
|
|
142
|
+
* @param prompt_area - Prompt area for dynamic prompt lookup
|
|
143
|
+
* @param prompt_key - Prompt key for dynamic prompt lookup
|
|
144
|
+
* @param db - Database instance
|
|
145
|
+
* @param config - LLM API configuration
|
|
146
|
+
* @param llm - Optional LLM provider name
|
|
147
|
+
* @returns LLM response
|
|
148
|
+
*/
|
|
149
|
+
async function dispatch_service_call(call_type, params, prompt_area, prompt_key, db, config, llm) {
|
|
150
|
+
// Add prompt_area and prompt_key for dynamic prompt lookup
|
|
151
|
+
const params_with_prompt = {
|
|
152
|
+
...params,
|
|
153
|
+
prompt_area,
|
|
154
|
+
prompt_key,
|
|
155
|
+
};
|
|
156
|
+
switch (call_type) {
|
|
157
|
+
case 'text_text':
|
|
158
|
+
return await hazo_llm_text_text(params_with_prompt, db, config, llm);
|
|
159
|
+
case 'image_text':
|
|
160
|
+
return await hazo_llm_image_text(params_with_prompt, db, config, llm);
|
|
161
|
+
case 'text_image':
|
|
162
|
+
return await hazo_llm_text_image(params_with_prompt, db, config, llm);
|
|
163
|
+
case 'image_image':
|
|
164
|
+
return await hazo_llm_image_image(params_with_prompt, db, config, llm);
|
|
165
|
+
default:
|
|
166
|
+
throw new Error(`Unsupported call_type: ${call_type}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Check if a call type produces text output
|
|
171
|
+
*/
|
|
172
|
+
function is_text_output_type(call_type) {
|
|
173
|
+
return call_type === 'text_text' || call_type === 'image_text';
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Check if a call type produces image output
|
|
177
|
+
*/
|
|
178
|
+
function is_image_output_type(call_type) {
|
|
179
|
+
return call_type === 'text_image' || call_type === 'image_image';
|
|
180
|
+
}
|
|
181
|
+
// =============================================================================
|
|
182
|
+
// hazo_llm_prompt_chain Function
|
|
183
|
+
// =============================================================================
|
|
184
|
+
/**
|
|
185
|
+
* Execute a chain of prompt calls with dynamic value resolution
|
|
186
|
+
*
|
|
187
|
+
* @param params - Chain parameters including call definitions
|
|
188
|
+
* @param db - Database instance for prompt retrieval
|
|
189
|
+
* @param config - LLM API configuration
|
|
190
|
+
* @param llm - Optional LLM provider name
|
|
191
|
+
* @returns Chain response with merged results and individual call outcomes
|
|
192
|
+
*/
|
|
193
|
+
export async function hazo_llm_prompt_chain(params, db, config, llm) {
|
|
194
|
+
// Use default logger if not provided
|
|
195
|
+
const { default_logger } = await import('./index.js');
|
|
196
|
+
const logger = config.logger || default_logger;
|
|
197
|
+
const continue_on_error = params.continue_on_error ?? true;
|
|
198
|
+
const call_results = [];
|
|
199
|
+
const errors = [];
|
|
200
|
+
logger.debug(`########################################################################### ${API_NAME}`, {
|
|
201
|
+
file: FILE_NAME,
|
|
202
|
+
});
|
|
203
|
+
logger.info('Starting prompt chain execution', {
|
|
204
|
+
file: FILE_NAME,
|
|
205
|
+
data: {
|
|
206
|
+
total_calls: params.chain_calls.length,
|
|
207
|
+
continue_on_error,
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
// Execute each call in sequence
|
|
211
|
+
for (let i = 0; i < params.chain_calls.length; i++) {
|
|
212
|
+
const call_def = params.chain_calls[i];
|
|
213
|
+
logger.debug(`Chain Step ${i + 1}/${params.chain_calls.length}`, {
|
|
214
|
+
file: FILE_NAME,
|
|
215
|
+
});
|
|
216
|
+
// Resolve prompt_area and prompt_key
|
|
217
|
+
const prompt_area = resolve_chain_field(call_def.prompt_area, call_results, logger);
|
|
218
|
+
const prompt_key = resolve_chain_field(call_def.prompt_key, call_results, logger);
|
|
219
|
+
if (!prompt_area || !prompt_key) {
|
|
220
|
+
const error_msg = `Could not resolve prompt_area or prompt_key for call ${i}`;
|
|
221
|
+
logger.error(error_msg, {
|
|
222
|
+
file: FILE_NAME,
|
|
223
|
+
data: { call_index: i, prompt_area, prompt_key },
|
|
224
|
+
});
|
|
225
|
+
errors.push({ call_index: i, error: error_msg });
|
|
226
|
+
call_results.push({
|
|
227
|
+
call_index: i,
|
|
228
|
+
success: false,
|
|
229
|
+
error: error_msg,
|
|
230
|
+
prompt_area: prompt_area || 'unresolved',
|
|
231
|
+
prompt_key: prompt_key || 'unresolved',
|
|
232
|
+
});
|
|
233
|
+
if (!continue_on_error) {
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
// Get call type (default to text_text for backward compatibility)
|
|
239
|
+
const call_type = call_def.call_type || DEFAULT_CALL_TYPE;
|
|
240
|
+
// Build prompt variables from variables array
|
|
241
|
+
const prompt_variables = build_prompt_variables(call_def.variables, call_results, logger);
|
|
242
|
+
// Build service-specific parameters
|
|
243
|
+
const param_result = build_service_params(call_def, call_type, prompt_variables, call_results, logger);
|
|
244
|
+
if (!param_result.success) {
|
|
245
|
+
const error_msg = param_result.error || 'Failed to build parameters';
|
|
246
|
+
logger.error(error_msg, {
|
|
247
|
+
file: FILE_NAME,
|
|
248
|
+
data: { call_index: i, call_type },
|
|
249
|
+
});
|
|
250
|
+
errors.push({ call_index: i, error: error_msg });
|
|
251
|
+
call_results.push({
|
|
252
|
+
call_index: i,
|
|
253
|
+
success: false,
|
|
254
|
+
error: error_msg,
|
|
255
|
+
prompt_area,
|
|
256
|
+
prompt_key,
|
|
257
|
+
});
|
|
258
|
+
if (!continue_on_error) {
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
logger.info(`Executing ${call_type} call`, {
|
|
264
|
+
file: FILE_NAME,
|
|
265
|
+
data: {
|
|
266
|
+
call_index: i,
|
|
267
|
+
call_type,
|
|
268
|
+
prompt_area,
|
|
269
|
+
prompt_key,
|
|
270
|
+
variables_defined: call_def.variables?.length || 0,
|
|
271
|
+
variables_resolved: prompt_variables.length > 0 ? prompt_variables[0] : {},
|
|
272
|
+
},
|
|
273
|
+
});
|
|
274
|
+
// Execute the LLM call
|
|
275
|
+
try {
|
|
276
|
+
const response = await dispatch_service_call(call_type, param_result.params, prompt_area, prompt_key, db, config, llm);
|
|
277
|
+
if (!response.success) {
|
|
278
|
+
const error_msg = response.error || 'Unknown error';
|
|
279
|
+
logger.error(`Call ${i} failed`, {
|
|
280
|
+
file: FILE_NAME,
|
|
281
|
+
data: { call_index: i, call_type, error: error_msg },
|
|
282
|
+
});
|
|
283
|
+
errors.push({ call_index: i, error: error_msg });
|
|
284
|
+
call_results.push({
|
|
285
|
+
call_index: i,
|
|
286
|
+
success: false,
|
|
287
|
+
error: error_msg,
|
|
288
|
+
prompt_area,
|
|
289
|
+
prompt_key,
|
|
290
|
+
});
|
|
291
|
+
if (!continue_on_error) {
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
// Build result based on call type
|
|
297
|
+
const result = {
|
|
298
|
+
call_index: i,
|
|
299
|
+
success: true,
|
|
300
|
+
prompt_area,
|
|
301
|
+
prompt_key,
|
|
302
|
+
};
|
|
303
|
+
// Text output types (text_text, image_text)
|
|
304
|
+
if (is_text_output_type(call_type)) {
|
|
305
|
+
result.raw_text = response.text || '';
|
|
306
|
+
result.parsed_result = parse_llm_json_response(result.raw_text, logger) || undefined;
|
|
307
|
+
}
|
|
308
|
+
// Image output types (text_image, image_image)
|
|
309
|
+
if (is_image_output_type(call_type)) {
|
|
310
|
+
result.image_b64 = response.image_b64;
|
|
311
|
+
result.image_mime_type = response.image_mime_type;
|
|
312
|
+
}
|
|
313
|
+
call_results.push(result);
|
|
314
|
+
logger.info(`Call ${i} completed successfully`, {
|
|
315
|
+
file: FILE_NAME,
|
|
316
|
+
data: {
|
|
317
|
+
call_index: i,
|
|
318
|
+
call_type,
|
|
319
|
+
has_text: !!result.raw_text,
|
|
320
|
+
has_parsed_result: !!result.parsed_result,
|
|
321
|
+
has_image: !!result.image_b64,
|
|
322
|
+
},
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
catch (error) {
|
|
326
|
+
const error_msg = error instanceof Error ? error.message : String(error);
|
|
327
|
+
logger.error(`Call ${i} threw exception`, {
|
|
328
|
+
file: FILE_NAME,
|
|
329
|
+
data: { call_index: i, call_type, error: error_msg },
|
|
330
|
+
});
|
|
331
|
+
errors.push({ call_index: i, error: error_msg });
|
|
332
|
+
call_results.push({
|
|
333
|
+
call_index: i,
|
|
334
|
+
success: false,
|
|
335
|
+
error: error_msg,
|
|
336
|
+
prompt_area,
|
|
337
|
+
prompt_key,
|
|
338
|
+
});
|
|
339
|
+
if (!continue_on_error) {
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
// Merge all successful results
|
|
345
|
+
const merged_result = merge_chain_results(call_results, logger);
|
|
346
|
+
const successful_calls = call_results.filter((r) => r.success).length;
|
|
347
|
+
logger.info('Prompt chain execution complete', {
|
|
348
|
+
file: FILE_NAME,
|
|
349
|
+
data: {
|
|
350
|
+
total_calls: params.chain_calls.length,
|
|
351
|
+
successful_calls,
|
|
352
|
+
error_count: errors.length,
|
|
353
|
+
},
|
|
354
|
+
});
|
|
355
|
+
logger.debug(`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ${API_NAME} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`, {
|
|
356
|
+
file: FILE_NAME,
|
|
357
|
+
data: { success: successful_calls > 0 },
|
|
358
|
+
});
|
|
359
|
+
return {
|
|
360
|
+
success: successful_calls > 0,
|
|
361
|
+
merged_result,
|
|
362
|
+
call_results,
|
|
363
|
+
errors,
|
|
364
|
+
total_calls: params.chain_calls.length,
|
|
365
|
+
successful_calls,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
//# sourceMappingURL=hazo_llm_prompt_chain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hazo_llm_prompt_chain.js","sourceRoot":"","sources":["../../../src/lib/llm_api/hazo_llm_prompt_chain.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAmBH,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,mBAAmB,EACnB,uBAAuB,EACvB,8BAA8B,GAC/B,MAAM,oBAAoB,CAAC;AAE5B,gFAAgF;AAChF,YAAY;AACZ,gFAAgF;AAEhF,MAAM,SAAS,GAAG,0BAA0B,CAAC;AAC7C,MAAM,QAAQ,G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AAO,CAAC,CAAC,MAAM,CAAC;IAEtE,MAAM,CAAC,IAAI,CAAC,iCAAiC,EAAE;QAC7C,IAAI,EAAE,SAAS;QACf,IAAI,EAAE;YACJ,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM;YACtC,gBAAgB;YAChB,WAAW,EAAE,MAAM,CAAC,MAAM;SAC3B;KACF,CAAC,CAAC;IAEH,MAAM,CAAC,KAAK,CACV,oCAAoC,QAAQ,mCAAmC,EAC/E;QACE,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,EAAE,OAAO,EAAE,gBAAgB,GAAG,CAAC,EAAE;KACxC,CACF,CAAC;IAEF,OAAO;QACL,OAAO,EAAE,gBAAgB,GAAG,CAAC;QAC7B,aAAa;QACb,YAAY;QACZ,MAAM;QACN,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM;QACtC,gBAAgB;KACjB,CAAC;AACJ,CAAC"}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*
|
|
13
13
|
* Database is auto-initialized on module import using config defaults.
|
|
14
14
|
*/
|
|
15
|
-
import type { LLMApiConfig, LLMApiClient, LLMResponse, LLMStreamResponse, TextTextParams, ImageTextParams, TextImageParams, ImageImageParams, TextImageTextParams, ImageImageTextParams, Logger } from './types.js';
|
|
15
|
+
import type { LLMApiConfig, LLMApiClient, LLMResponse, LLMStreamResponse, TextTextParams, ImageTextParams, TextImageParams, ImageImageParams, TextImageTextParams, ImageImageTextParams, PromptChainParams, PromptChainResponse, Logger } from './types.js';
|
|
16
16
|
import type { ProviderName } from '../providers/types.js';
|
|
17
17
|
/**
|
|
18
18
|
* Default console logger used when no custom logger is provided
|
|
@@ -145,6 +145,38 @@ export declare function hazo_llm_text_image_text(params: TextImageTextParams, ll
|
|
|
145
145
|
* @returns LLM response with final image and description text
|
|
146
146
|
*/
|
|
147
147
|
export declare function hazo_llm_image_image_text(params: ImageImageTextParams, llm?: ProviderName): Promise<LLMResponse>;
|
|
148
|
+
/**
|
|
149
|
+
* Execute a chain of prompts with dynamic value resolution
|
|
150
|
+
* Each call can reference values from previous call results
|
|
151
|
+
*
|
|
152
|
+
* @param params - Chain parameters including call definitions
|
|
153
|
+
* @param llm - Optional LLM provider name (uses primary LLM if not specified). Use LLM_PROVIDERS constants for type safety.
|
|
154
|
+
* @returns Chain response with merged results and individual call outcomes
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* import { hazo_llm_prompt_chain } from 'hazo_llm_api/server';
|
|
159
|
+
*
|
|
160
|
+
* const response = await hazo_llm_prompt_chain({
|
|
161
|
+
* chain_calls: [
|
|
162
|
+
* {
|
|
163
|
+
* prompt_area: { match_type: 'direct', value: 'document' },
|
|
164
|
+
* prompt_key: { match_type: 'direct', value: 'initial_read' }
|
|
165
|
+
* },
|
|
166
|
+
* {
|
|
167
|
+
* prompt_area: { match_type: 'direct', value: 'document' },
|
|
168
|
+
* prompt_key: { match_type: 'direct', value: 'process_results' },
|
|
169
|
+
* local_1: {
|
|
170
|
+
* match_type: 'call_chain',
|
|
171
|
+
* value: 'call[0].tax_category',
|
|
172
|
+
* variable_name: 'previous_category'
|
|
173
|
+
* }
|
|
174
|
+
* }
|
|
175
|
+
* ]
|
|
176
|
+
* });
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
export declare function hazo_llm_prompt_chain(params: PromptChainParams, llm?: ProviderName): Promise<PromptChainResponse>;
|
|
148
180
|
/**
|
|
149
181
|
* Text input → Text output (Streaming)
|
|
150
182
|
* Generate text from a prompt with streaming response
|
|
@@ -187,5 +219,5 @@ export declare function is_initialized(): boolean;
|
|
|
187
219
|
* @returns Current configuration or null if not initialized
|
|
188
220
|
*/
|
|
189
221
|
export declare function get_current_config(): Omit<LLMApiConfig, 'logger'> | null;
|
|
190
|
-
export type { LLMApiConfig, LLMApiClient, LLMResponse, TextTextParams, ImageTextParams, TextImageParams, ImageImageParams, TextImageTextParams, ImageImageTextParams, ChainImage, Logger, PromptVariable, PromptVariables, Base64Data, PromptTextMode, PromptRecord, CallLLMParams, GeminiGenerationConfig, GeminiApiGenerationConfig, } from './types.js';
|
|
222
|
+
export type { LLMApiConfig, LLMApiClient, LLMResponse, TextTextParams, ImageTextParams, TextImageParams, ImageImageParams, TextImageTextParams, ImageImageTextParams, ChainImage, Logger, PromptVariable, PromptVariables, Base64Data, PromptTextMode, PromptRecord, CallLLMParams, GeminiGenerationConfig, GeminiApiGenerationConfig, ChainMatchType, ChainFieldDefinition, ChainCallDefinition, ChainCallResult, PromptChainParams, PromptChainResponse, } from './types.js';
|
|
191
223
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/llm_api/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,iBAAiB,EAEjB,cAAc,EACd,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,MAAM,EAEP,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/llm_api/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,iBAAiB,EAEjB,cAAc,EACd,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,MAAM,EAEP,MAAM,YAAY,CAAC;AAqBpB,OAAO,KAAK,EAAe,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAkBvE;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,MAa5B,CAAC;AAYF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED;;;;;GAKG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AG,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,CAQtH;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,iBAAiB,EAAE,GAAG,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAevH;AAMD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAuB,yBAAyB,CAC9C,MAAM,EAAE,cAAc,EACtB,GAAG,CAAC,EAAE,YAAY,GACjB,iBAAiB,CAoDnB;AAED;;;;;;;GAOG;AACH,wBAAuB,0BAA0B,CAC/C,MAAM,EAAE,eAAe,EACvB,GAAG,CAAC,EAAE,YAAY,GACjB,iBAAiB,CAoDnB;AAMD;;;GAGG;AACH,wBAAgB,cAAc,IAAI,OAAO,CAExC;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,GAAG,IAAI,CASxE;AAMD,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,cAAc,EACd,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,oBAAoB,EACpB,UAAU,EACV,MAAM,EACN,cAAc,EACd,eAAe,EACf,UAAU,EACV,cAAc,EACd,YAAY,EACZ,aAAa,EACb,sBAAsB,EACtB,yBAAyB,EAEzB,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,eAAe,EACf,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,YAAY,CAAC"}
|
|
@@ -20,6 +20,7 @@ import { hazo_llm_text_image as hazo_llm_text_image_internal } from './hazo_llm_
|
|
|
20
20
|
import { hazo_llm_image_image as hazo_llm_image_image_internal } from './hazo_llm_image_image.js';
|
|
21
21
|
import { hazo_llm_text_image_text as hazo_llm_text_image_text_internal } from './hazo_llm_text_image_text.js';
|
|
22
22
|
import { hazo_llm_image_image_text as hazo_llm_image_image_text_internal } from './hazo_llm_image_image_text.js';
|
|
23
|
+
import { hazo_llm_prompt_chain as hazo_llm_prompt_chain_internal } from './hazo_llm_prompt_chain.js';
|
|
23
24
|
import { register_provider, set_enabled_llms, set_primary_llm, get_primary_llm, get_registered_providers, get_provider, } from '../providers/registry.js';
|
|
24
25
|
import { GeminiProvider } from '../providers/gemini/index.js';
|
|
25
26
|
import { QwenProvider } from '../providers/qwen/index.js';
|
|
@@ -110,16 +111,16 @@ export function set_hooks(hooks) {
|
|
|
110
111
|
// =============================================================================
|
|
111
112
|
/**
|
|
112
113
|
* Find the config file path
|
|
113
|
-
* Searches in
|
|
114
|
+
* Searches in config/ subdirectory and parent directories
|
|
114
115
|
* @returns The path to the config file or null if not found
|
|
115
116
|
*/
|
|
116
117
|
function find_config_file() {
|
|
117
118
|
const config_filename = 'hazo_llm_api_config.ini';
|
|
118
|
-
// Search paths: current dir, parent dir, grandparent dir
|
|
119
|
+
// Search paths: config/ in current dir, parent dir, grandparent dir
|
|
119
120
|
const search_paths = [
|
|
120
|
-
path.join(process.cwd(), config_filename),
|
|
121
|
-
path.join(process.cwd(), '..', config_filename),
|
|
122
|
-
path.join(process.cwd(), '..', '..', config_filename),
|
|
121
|
+
path.join(process.cwd(), 'config', config_filename),
|
|
122
|
+
path.join(process.cwd(), '..', 'config', config_filename),
|
|
123
|
+
path.join(process.cwd(), '..', '..', 'config', config_filename),
|
|
123
124
|
];
|
|
124
125
|
for (const config_path of search_paths) {
|
|
125
126
|
try {
|
|
@@ -853,6 +854,9 @@ export async function initialize_llm_api(config = {}) {
|
|
|
853
854
|
hazo_llm_image_image_text: async (params, llm) => {
|
|
854
855
|
return hazo_llm_image_image_text(params, llm);
|
|
855
856
|
},
|
|
857
|
+
hazo_llm_prompt_chain: async (params, llm) => {
|
|
858
|
+
return hazo_llm_prompt_chain(params, llm);
|
|
859
|
+
},
|
|
856
860
|
};
|
|
857
861
|
return client;
|
|
858
862
|
}
|
|
@@ -1007,6 +1011,54 @@ export async function hazo_llm_image_image_text(params, llm) {
|
|
|
1007
1011
|
return { success: false, error: error instanceof Error ? error.message : String(error) };
|
|
1008
1012
|
}
|
|
1009
1013
|
}
|
|
1014
|
+
/**
|
|
1015
|
+
* Execute a chain of prompts with dynamic value resolution
|
|
1016
|
+
* Each call can reference values from previous call results
|
|
1017
|
+
*
|
|
1018
|
+
* @param params - Chain parameters including call definitions
|
|
1019
|
+
* @param llm - Optional LLM provider name (uses primary LLM if not specified). Use LLM_PROVIDERS constants for type safety.
|
|
1020
|
+
* @returns Chain response with merged results and individual call outcomes
|
|
1021
|
+
*
|
|
1022
|
+
* @example
|
|
1023
|
+
* ```typescript
|
|
1024
|
+
* import { hazo_llm_prompt_chain } from 'hazo_llm_api/server';
|
|
1025
|
+
*
|
|
1026
|
+
* const response = await hazo_llm_prompt_chain({
|
|
1027
|
+
* chain_calls: [
|
|
1028
|
+
* {
|
|
1029
|
+
* prompt_area: { match_type: 'direct', value: 'document' },
|
|
1030
|
+
* prompt_key: { match_type: 'direct', value: 'initial_read' }
|
|
1031
|
+
* },
|
|
1032
|
+
* {
|
|
1033
|
+
* prompt_area: { match_type: 'direct', value: 'document' },
|
|
1034
|
+
* prompt_key: { match_type: 'direct', value: 'process_results' },
|
|
1035
|
+
* local_1: {
|
|
1036
|
+
* match_type: 'call_chain',
|
|
1037
|
+
* value: 'call[0].tax_category',
|
|
1038
|
+
* variable_name: 'previous_category'
|
|
1039
|
+
* }
|
|
1040
|
+
* }
|
|
1041
|
+
* ]
|
|
1042
|
+
* });
|
|
1043
|
+
* ```
|
|
1044
|
+
*/
|
|
1045
|
+
export async function hazo_llm_prompt_chain(params, llm) {
|
|
1046
|
+
try {
|
|
1047
|
+
const config = check_initialized();
|
|
1048
|
+
const db = get_database();
|
|
1049
|
+
return hazo_llm_prompt_chain_internal(params, db, config, llm);
|
|
1050
|
+
}
|
|
1051
|
+
catch (error) {
|
|
1052
|
+
return {
|
|
1053
|
+
success: false,
|
|
1054
|
+
merged_result: {},
|
|
1055
|
+
call_results: [],
|
|
1056
|
+
errors: [{ call_index: -1, error: error instanceof Error ? error.message : String(error) }],
|
|
1057
|
+
total_calls: params.chain_calls.length,
|
|
1058
|
+
successful_calls: 0,
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1010
1062
|
// =============================================================================
|
|
1011
1063
|
// Streaming Functions
|
|
1012
1064
|
// =============================================================================
|