hazo_llm_api 1.0.4 → 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/dist/components/index.d.ts +7 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +7 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/layout/index.d.ts +7 -0
- package/dist/components/layout/index.d.ts.map +1 -0
- package/dist/components/layout/index.js +7 -0
- package/dist/components/layout/index.js.map +1 -0
- package/dist/components/layout/layout.d.ts +21 -0
- package/dist/components/layout/layout.d.ts.map +1 -0
- package/dist/components/layout/layout.js +18 -0
- package/dist/components/layout/layout.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/config/config_parser.d.ts +131 -0
- package/dist/lib/config/config_parser.d.ts.map +1 -0
- package/dist/lib/config/config_parser.js +297 -0
- package/dist/lib/config/config_parser.js.map +1 -0
- package/dist/lib/config/index.d.ts +8 -0
- package/dist/lib/config/index.d.ts.map +1 -0
- package/dist/lib/config/index.js +22 -0
- package/dist/lib/config/index.js.map +1 -0
- package/dist/lib/config/provider_loader.d.ts +113 -0
- package/dist/lib/config/provider_loader.d.ts.map +1 -0
- package/dist/lib/config/provider_loader.js +169 -0
- package/dist/lib/config/provider_loader.js.map +1 -0
- package/dist/lib/database/index.d.ts +8 -0
- package/dist/lib/database/index.d.ts.map +1 -0
- package/dist/lib/database/index.js +10 -0
- package/dist/lib/database/index.js.map +1 -0
- package/dist/lib/database/init_database.d.ts +118 -0
- package/dist/lib/database/init_database.d.ts.map +1 -0
- package/dist/lib/database/init_database.js +591 -0
- package/dist/lib/database/init_database.js.map +1 -0
- package/dist/lib/database/utils.d.ts +53 -0
- package/dist/lib/database/utils.d.ts.map +1 -0
- package/dist/lib/database/utils.js +87 -0
- package/dist/lib/database/utils.js.map +1 -0
- package/dist/lib/index.d.ts +14 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +17 -0
- package/dist/lib/index.js.map +1 -0
- 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_image_image.d.ts +26 -0
- package/dist/lib/llm_api/hazo_llm_image_image.d.ts.map +1 -0
- package/dist/lib/llm_api/hazo_llm_image_image.js +94 -0
- package/dist/lib/llm_api/hazo_llm_image_image.js.map +1 -0
- package/dist/lib/llm_api/hazo_llm_image_image_text.d.ts +26 -0
- package/dist/lib/llm_api/hazo_llm_image_image_text.d.ts.map +1 -0
- package/dist/lib/llm_api/hazo_llm_image_image_text.js +222 -0
- package/dist/lib/llm_api/hazo_llm_image_image_text.js.map +1 -0
- package/dist/lib/llm_api/hazo_llm_image_text.d.ts +20 -0
- package/dist/lib/llm_api/hazo_llm_image_text.d.ts.map +1 -0
- package/dist/lib/llm_api/hazo_llm_image_text.js +78 -0
- package/dist/lib/llm_api/hazo_llm_image_text.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/hazo_llm_text_image.d.ts +20 -0
- package/dist/lib/llm_api/hazo_llm_text_image.d.ts.map +1 -0
- package/dist/lib/llm_api/hazo_llm_text_image.js +69 -0
- package/dist/lib/llm_api/hazo_llm_text_image.js.map +1 -0
- package/dist/lib/llm_api/hazo_llm_text_image_text.d.ts +26 -0
- package/dist/lib/llm_api/hazo_llm_text_image_text.d.ts.map +1 -0
- package/dist/lib/llm_api/hazo_llm_text_image_text.js +154 -0
- package/dist/lib/llm_api/hazo_llm_text_image_text.js.map +1 -0
- package/dist/lib/llm_api/hazo_llm_text_text.d.ts +20 -0
- package/dist/lib/llm_api/hazo_llm_text_text.d.ts.map +1 -0
- package/dist/lib/llm_api/hazo_llm_text_text.js +91 -0
- package/dist/lib/llm_api/hazo_llm_text_text.js.map +1 -0
- package/dist/lib/llm_api/index.d.ts +223 -0
- package/dist/lib/llm_api/index.d.ts.map +1 -0
- package/dist/lib/llm_api/index.js +1220 -0
- package/dist/lib/llm_api/index.js.map +1 -0
- package/dist/lib/llm_api/provider_helper.d.ts +163 -0
- package/dist/lib/llm_api/provider_helper.d.ts.map +1 -0
- package/dist/lib/llm_api/provider_helper.js +346 -0
- package/dist/lib/llm_api/provider_helper.js.map +1 -0
- package/dist/lib/llm_api/types.d.ts +667 -0
- package/dist/lib/llm_api/types.d.ts.map +1 -0
- package/dist/lib/llm_api/types.js +49 -0
- package/dist/lib/llm_api/types.js.map +1 -0
- package/dist/lib/prompts/get_prompt.d.ts +76 -0
- package/dist/lib/prompts/get_prompt.d.ts.map +1 -0
- package/dist/lib/prompts/get_prompt.js +342 -0
- package/dist/lib/prompts/get_prompt.js.map +1 -0
- package/dist/lib/prompts/index.d.ts +9 -0
- package/dist/lib/prompts/index.d.ts.map +1 -0
- package/dist/lib/prompts/index.js +9 -0
- package/dist/lib/prompts/index.js.map +1 -0
- package/dist/lib/prompts/prompt_cache.d.ts +151 -0
- package/dist/lib/prompts/prompt_cache.d.ts.map +1 -0
- package/dist/lib/prompts/prompt_cache.js +276 -0
- package/dist/lib/prompts/prompt_cache.js.map +1 -0
- package/dist/lib/prompts/substitute_variables.d.ts +38 -0
- package/dist/lib/prompts/substitute_variables.d.ts.map +1 -0
- package/dist/lib/prompts/substitute_variables.js +171 -0
- package/dist/lib/prompts/substitute_variables.js.map +1 -0
- package/dist/lib/providers/gemini/gemini_client.d.ts +25 -0
- package/dist/lib/providers/gemini/gemini_client.d.ts.map +1 -0
- package/dist/lib/providers/gemini/gemini_client.js +235 -0
- package/dist/lib/providers/gemini/gemini_client.js.map +1 -0
- package/dist/lib/providers/gemini/gemini_provider.d.ts +111 -0
- package/dist/lib/providers/gemini/gemini_provider.d.ts.map +1 -0
- package/dist/lib/providers/gemini/gemini_provider.js +431 -0
- package/dist/lib/providers/gemini/gemini_provider.js.map +1 -0
- package/dist/lib/providers/gemini/index.d.ts +8 -0
- package/dist/lib/providers/gemini/index.d.ts.map +1 -0
- package/dist/lib/providers/gemini/index.js +8 -0
- package/dist/lib/providers/gemini/index.js.map +1 -0
- package/dist/lib/providers/index.d.ts +8 -0
- package/dist/lib/providers/index.d.ts.map +1 -0
- package/dist/lib/providers/index.js +8 -0
- package/dist/lib/providers/index.js.map +1 -0
- package/dist/lib/providers/qwen/index.d.ts +8 -0
- package/dist/lib/providers/qwen/index.d.ts.map +1 -0
- package/dist/lib/providers/qwen/index.js +8 -0
- package/dist/lib/providers/qwen/index.js.map +1 -0
- package/dist/lib/providers/qwen/qwen_client.d.ts +154 -0
- package/dist/lib/providers/qwen/qwen_client.d.ts.map +1 -0
- package/dist/lib/providers/qwen/qwen_client.js +1002 -0
- package/dist/lib/providers/qwen/qwen_client.js.map +1 -0
- package/dist/lib/providers/qwen/qwen_provider.d.ts +139 -0
- package/dist/lib/providers/qwen/qwen_provider.d.ts.map +1 -0
- package/dist/lib/providers/qwen/qwen_provider.js +304 -0
- package/dist/lib/providers/qwen/qwen_provider.js.map +1 -0
- package/dist/lib/providers/registry.d.ts +66 -0
- package/dist/lib/providers/registry.d.ts.map +1 -0
- package/dist/lib/providers/registry.js +158 -0
- package/dist/lib/providers/registry.js.map +1 -0
- package/dist/lib/providers/types.d.ts +145 -0
- package/dist/lib/providers/types.d.ts.map +1 -0
- package/dist/lib/providers/types.js +37 -0
- package/dist/lib/providers/types.js.map +1 -0
- package/dist/server.d.ts +27 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +50 -0
- package/dist/server.js.map +1 -0
- package/package.json +12 -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,E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AiB,EAAE,CAAC;gBACvB,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;IAED,+BAA+B;IAC/B,MAAM,aAAa,GAAG,mBAAmB,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IAChE,MAAM,gBAAgB,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,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"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hazo_llm_text_image Function
|
|
3
|
+
*
|
|
4
|
+
* Text input → Image output
|
|
5
|
+
* Generate an image from a text description/prompt.
|
|
6
|
+
* Uses image generation capable models.
|
|
7
|
+
*/
|
|
8
|
+
import type { Database as SqlJsDatabase } from 'sql.js';
|
|
9
|
+
import type { TextImageParams, LLMResponse, LLMApiConfig } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Call the LLM with text input and get image output
|
|
12
|
+
*
|
|
13
|
+
* @param params - Text input parameters for image generation
|
|
14
|
+
* @param _db - Database instance (unused, kept for API consistency)
|
|
15
|
+
* @param config - LLM API configuration
|
|
16
|
+
* @param llm - Optional LLM provider name (uses primary LLM if not specified)
|
|
17
|
+
* @returns LLM response with generated image data
|
|
18
|
+
*/
|
|
19
|
+
export declare function hazo_llm_text_image(params: TextImageParams, _db: SqlJsDatabase | null, config: LLMApiConfig, llm?: string): Promise<LLMResponse>;
|
|
20
|
+
//# sourceMappingURL=hazo_llm_text_image.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hazo_llm_text_image.d.ts","sourceRoot":"","sources":["../../../src/lib/llm_api/hazo_llm_text_image.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,QAAQ,IAAI,aAAa,EAAE,MAAM,QAAQ,CAAC;AACxD,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,YAAY,EACb,MAAM,YAAY,CAAC;AAuBpB;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,eAAe,EACvB,GAAG,EAAE,aAAa,GAAG,IAAI,EACzB,MAAM,EAAE,YAAY,EACpB,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,WAAW,CAAC,CAmDtB"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hazo_llm_text_image Function
|
|
3
|
+
*
|
|
4
|
+
* Text input → Image output
|
|
5
|
+
* Generate an image from a text description/prompt.
|
|
6
|
+
* Uses image generation capable models.
|
|
7
|
+
*/
|
|
8
|
+
import { substitute_variables } from '../prompts/substitute_variables.js';
|
|
9
|
+
import { SERVICE_TYPES } from '../providers/types.js';
|
|
10
|
+
import { get_validated_provider, log_api_start, log_api_complete, log_api_details, log_api_response, handle_caught_error, } from './provider_helper.js';
|
|
11
|
+
// =============================================================================
|
|
12
|
+
// Constants
|
|
13
|
+
// =============================================================================
|
|
14
|
+
const FILE_NAME = 'hazo_llm_text_image.ts';
|
|
15
|
+
const API_NAME = 'text_image';
|
|
16
|
+
// =============================================================================
|
|
17
|
+
// hazo_llm_text_image Function
|
|
18
|
+
// =============================================================================
|
|
19
|
+
/**
|
|
20
|
+
* Call the LLM with text input and get image output
|
|
21
|
+
*
|
|
22
|
+
* @param params - Text input parameters for image generation
|
|
23
|
+
* @param _db - Database instance (unused, kept for API consistency)
|
|
24
|
+
* @param config - LLM API configuration
|
|
25
|
+
* @param llm - Optional LLM provider name (uses primary LLM if not specified)
|
|
26
|
+
* @returns LLM response with generated image data
|
|
27
|
+
*/
|
|
28
|
+
export async function hazo_llm_text_image(params, _db, config, llm) {
|
|
29
|
+
// Use default logger if not provided
|
|
30
|
+
const { default_logger } = await import('./index.js');
|
|
31
|
+
const logger = config.logger || default_logger;
|
|
32
|
+
try {
|
|
33
|
+
log_api_start(API_NAME, FILE_NAME, logger);
|
|
34
|
+
// ==========================================================================
|
|
35
|
+
// Step 1: Prepare prompt with variable substitution
|
|
36
|
+
// ==========================================================================
|
|
37
|
+
const final_prompt = substitute_variables(params.prompt, params.prompt_variables, logger);
|
|
38
|
+
// ==========================================================================
|
|
39
|
+
// Step 2: Get and validate provider
|
|
40
|
+
// ==========================================================================
|
|
41
|
+
const provider_result = get_validated_provider({
|
|
42
|
+
llm,
|
|
43
|
+
service_type: SERVICE_TYPES.TEXT_IMAGE,
|
|
44
|
+
logger,
|
|
45
|
+
});
|
|
46
|
+
if (!provider_result.success) {
|
|
47
|
+
return provider_result.error_response;
|
|
48
|
+
}
|
|
49
|
+
const provider = provider_result.provider;
|
|
50
|
+
log_api_details(provider, SERVICE_TYPES.TEXT_IMAGE, FILE_NAME, logger, {
|
|
51
|
+
prompt_text: final_prompt,
|
|
52
|
+
llm_requested: llm || 'primary',
|
|
53
|
+
});
|
|
54
|
+
// ==========================================================================
|
|
55
|
+
// Step 3: Call the provider
|
|
56
|
+
// ==========================================================================
|
|
57
|
+
const response = await provider.text_image({
|
|
58
|
+
...params,
|
|
59
|
+
prompt: final_prompt,
|
|
60
|
+
}, logger);
|
|
61
|
+
log_api_response(response, FILE_NAME, logger);
|
|
62
|
+
log_api_complete(API_NAME, FILE_NAME, response.success, logger);
|
|
63
|
+
return response;
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
return handle_caught_error(error, 'hazo_llm_text_image', FILE_NAME, logger);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=hazo_llm_text_image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hazo_llm_text_image.js","sourceRoot":"","sources":["../../../src/lib/llm_api/hazo_llm_text_image.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAQH,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAE9B,gFAAgF;AAChF,YAAY;AACZ,gFAAgF;AAEhF,MAAM,SAAS,GAAG,wBAAwB,CAAC;AAC3C,MAAM,QAAQ,GAAG,YAAY,CAAC;AAE9B,gFAAgF;AAChF,+BAA+B;AAC/B,gFAAgF;AAEhF;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,MAAuB,EACvB,GAAyB,EACzB,MAAoB,EACpB,GAAY;IAEZ,qCAAqC;IACrC,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC;IACtD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,cAAc,CAAC;IAE/C,IAAI,CAAC;QACH,aAAa,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;QAE3C,6EAA6E;QAC7E,oDAAoD;QACpD,6EAA6E;QAC7E,MAAM,YAAY,GAAG,oBAAoB,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;QAE1F,6EAA6E;QAC7E,oCAAoC;QACpC,6EAA6E;QAC7E,MAAM,eAAe,GAAG,sBAAsB,CAAC;YAC7C,GAAG;YACH,YAAY,EAAE,aAAa,CAAC,UAAU;YACtC,MAAM;SACP,CAAC,CAAC;QAEH,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC;YAC7B,OAAO,eAAe,CAAC,cAAc,CAAC;QACxC,CAAC;QAED,MAAM,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC;QAE1C,eAAe,CAAC,QAAQ,EAAE,aAAa,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE;YACrE,WAAW,EAAE,YAAY;YACzB,aAAa,EAAE,GAAG,IAAI,SAAS;SAChC,CAAC,CAAC;QAEH,6EAA6E;QAC7E,4BAA4B;QAC5B,6EAA6E;QAC7E,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,UAAU,CACxC;YACE,GAAG,MAAM;YACT,MAAM,EAAE,YAAY;SACrB,EACD,MAAM,CACP,CAAC;QAEF,gBAAgB,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;QAC9C,gBAAgB,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAEhE,OAAO,QAAQ,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,mBAAmB,CAAC,KAAK,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IAC9E,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hazo_llm_text_image_text Function
|
|
3
|
+
*
|
|
4
|
+
* Text → Image → Text (Chained)
|
|
5
|
+
* 1. Generate an image from prompt_image using hazo_llm_text_image
|
|
6
|
+
* 2. Analyze the generated image with prompt_text using hazo_llm_image_text
|
|
7
|
+
* 3. Return both the generated image and the analysis text
|
|
8
|
+
*/
|
|
9
|
+
import type { Database as SqlJsDatabase } from 'sql.js';
|
|
10
|
+
import type { TextImageTextParams, LLMResponse, LLMApiConfig } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Generate an image from text, then analyze it with a second prompt
|
|
13
|
+
*
|
|
14
|
+
* Flow:
|
|
15
|
+
* 1. Call hazo_llm_text_image with prompt_image to generate an image
|
|
16
|
+
* 2. Call hazo_llm_image_text with the generated image and prompt_text
|
|
17
|
+
* 3. Return the generated image and the text analysis from step 2
|
|
18
|
+
*
|
|
19
|
+
* @param params - Parameters with two prompts: one for image gen, one for analysis
|
|
20
|
+
* @param db - Database instance
|
|
21
|
+
* @param config - LLM API configuration
|
|
22
|
+
* @param llm - Optional LLM provider name (uses primary LLM if not specified)
|
|
23
|
+
* @returns LLM response with generated image and analysis text
|
|
24
|
+
*/
|
|
25
|
+
export declare function hazo_llm_text_image_text(params: TextImageTextParams, db: SqlJsDatabase | null, config: LLMApiConfig, llm?: string): Promise<LLMResponse>;
|
|
26
|
+
//# sourceMappingURL=hazo_llm_text_image_text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hazo_llm_text_image_text.d.ts","sourceRoot":"","sources":["../../../src/lib/llm_api/hazo_llm_text_image_text.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,QAAQ,IAAI,aAAa,EAAE,MAAM,QAAQ,CAAC;AACxD,OAAO,KAAK,EACV,mBAAmB,EACnB,WAAW,EACX,YAAY,EACb,MAAM,YAAY,CAAC;AAQpB;;;;;;;;;;;;;GAaG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,mBAAmB,EAC3B,EAAE,EAAE,aAAa,GAAG,IAAI,EACxB,MAAM,EAAE,YAAY,EACpB,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,WAAW,CAAC,CAoJtB"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hazo_llm_text_image_text Function
|
|
3
|
+
*
|
|
4
|
+
* Text → Image → Text (Chained)
|
|
5
|
+
* 1. Generate an image from prompt_image using hazo_llm_text_image
|
|
6
|
+
* 2. Analyze the generated image with prompt_text using hazo_llm_image_text
|
|
7
|
+
* 3. Return both the generated image and the analysis text
|
|
8
|
+
*/
|
|
9
|
+
import { hazo_llm_text_image } from './hazo_llm_text_image.js';
|
|
10
|
+
import { hazo_llm_image_text } from './hazo_llm_image_text.js';
|
|
11
|
+
// =============================================================================
|
|
12
|
+
// hazo_llm_text_image_text Function
|
|
13
|
+
// =============================================================================
|
|
14
|
+
/**
|
|
15
|
+
* Generate an image from text, then analyze it with a second prompt
|
|
16
|
+
*
|
|
17
|
+
* Flow:
|
|
18
|
+
* 1. Call hazo_llm_text_image with prompt_image to generate an image
|
|
19
|
+
* 2. Call hazo_llm_image_text with the generated image and prompt_text
|
|
20
|
+
* 3. Return the generated image and the text analysis from step 2
|
|
21
|
+
*
|
|
22
|
+
* @param params - Parameters with two prompts: one for image gen, one for analysis
|
|
23
|
+
* @param db - Database instance
|
|
24
|
+
* @param config - LLM API configuration
|
|
25
|
+
* @param llm - Optional LLM provider name (uses primary LLM if not specified)
|
|
26
|
+
* @returns LLM response with generated image and analysis text
|
|
27
|
+
*/
|
|
28
|
+
export async function hazo_llm_text_image_text(params, db, config, llm) {
|
|
29
|
+
const file_name = 'hazo_llm_text_image_text.ts';
|
|
30
|
+
// Use default logger if not provided
|
|
31
|
+
const { default_logger } = await import('./index.js');
|
|
32
|
+
const logger = config.logger || default_logger;
|
|
33
|
+
const api_name = 'text_image_text';
|
|
34
|
+
try {
|
|
35
|
+
// ==========================================================================
|
|
36
|
+
// Log API call start
|
|
37
|
+
// ==========================================================================
|
|
38
|
+
logger.debug(`########################################################################### ${api_name}`, {
|
|
39
|
+
file: file_name,
|
|
40
|
+
line: 48,
|
|
41
|
+
});
|
|
42
|
+
// Log API call details with generation configs
|
|
43
|
+
logger.debug('API call details', {
|
|
44
|
+
file: file_name,
|
|
45
|
+
line: 53,
|
|
46
|
+
data: {
|
|
47
|
+
chain_steps: ['text_image', 'image_text'],
|
|
48
|
+
prompt_image: params.prompt_image,
|
|
49
|
+
prompt_text: params.prompt_text,
|
|
50
|
+
prompt_image_variables: params.prompt_image_variables,
|
|
51
|
+
prompt_text_variables: params.prompt_text_variables,
|
|
52
|
+
llm_requested: llm || 'primary',
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
// ==========================================================================
|
|
56
|
+
// Step 1: Generate image from prompt_image
|
|
57
|
+
// ==========================================================================
|
|
58
|
+
logger.debug('Chain Step 1: Image generation', {
|
|
59
|
+
file: file_name,
|
|
60
|
+
line: 66,
|
|
61
|
+
});
|
|
62
|
+
const image_response = await hazo_llm_text_image({
|
|
63
|
+
prompt: params.prompt_image,
|
|
64
|
+
prompt_variables: params.prompt_image_variables,
|
|
65
|
+
}, db, config, llm);
|
|
66
|
+
// Check if image generation succeeded
|
|
67
|
+
if (!image_response.success) {
|
|
68
|
+
logger.error('Image generation failed in text_image_text chain', {
|
|
69
|
+
file: file_name,
|
|
70
|
+
line: 79,
|
|
71
|
+
data: { error: image_response.error },
|
|
72
|
+
});
|
|
73
|
+
return {
|
|
74
|
+
success: false,
|
|
75
|
+
error: `Image generation failed: ${image_response.error}`,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
// Check if we got an image
|
|
79
|
+
if (!image_response.image_b64 || !image_response.image_mime_type) {
|
|
80
|
+
logger.error('No image returned from image generation', {
|
|
81
|
+
file: file_name,
|
|
82
|
+
line: 90,
|
|
83
|
+
});
|
|
84
|
+
return {
|
|
85
|
+
success: false,
|
|
86
|
+
error: 'Image generation did not return an image',
|
|
87
|
+
text: image_response.text, // Include any text that was returned
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// ==========================================================================
|
|
91
|
+
// Step 2: Analyze the generated image with prompt_text
|
|
92
|
+
// ==========================================================================
|
|
93
|
+
logger.debug('Chain Step 2: Image analysis', {
|
|
94
|
+
file: file_name,
|
|
95
|
+
line: 103,
|
|
96
|
+
});
|
|
97
|
+
const text_response = await hazo_llm_image_text({
|
|
98
|
+
prompt: params.prompt_text,
|
|
99
|
+
image_b64: image_response.image_b64,
|
|
100
|
+
image_mime_type: image_response.image_mime_type,
|
|
101
|
+
prompt_variables: params.prompt_text_variables,
|
|
102
|
+
}, db, config, llm);
|
|
103
|
+
// Check if text analysis succeeded
|
|
104
|
+
if (!text_response.success) {
|
|
105
|
+
logger.error('Text analysis failed in text_image_text chain', {
|
|
106
|
+
file: file_name,
|
|
107
|
+
line: 120,
|
|
108
|
+
data: { error: text_response.error },
|
|
109
|
+
});
|
|
110
|
+
return {
|
|
111
|
+
success: false,
|
|
112
|
+
error: `Image analysis failed: ${text_response.error}`,
|
|
113
|
+
// Still return the generated image even if analysis failed
|
|
114
|
+
image_b64: image_response.image_b64,
|
|
115
|
+
image_mime_type: image_response.image_mime_type,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
// ==========================================================================
|
|
119
|
+
// Log API response
|
|
120
|
+
// ==========================================================================
|
|
121
|
+
logger.debug('API response', {
|
|
122
|
+
file: file_name,
|
|
123
|
+
line: 136,
|
|
124
|
+
data: {
|
|
125
|
+
success: true,
|
|
126
|
+
text: text_response.text,
|
|
127
|
+
image_b64: '[IMAGE_DATA_PLACEHOLDER]',
|
|
128
|
+
image_mime_type: image_response.image_mime_type,
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
// Log API call complete
|
|
132
|
+
logger.debug(`<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ${api_name} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`, {
|
|
133
|
+
file: file_name,
|
|
134
|
+
line: 147,
|
|
135
|
+
data: { success: true, has_image: true },
|
|
136
|
+
});
|
|
137
|
+
return {
|
|
138
|
+
success: true,
|
|
139
|
+
text: text_response.text,
|
|
140
|
+
image_b64: image_response.image_b64,
|
|
141
|
+
image_mime_type: image_response.image_mime_type,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
const error_message = error instanceof Error ? error.message : String(error);
|
|
146
|
+
logger.error('Error in hazo_llm_text_image_text', {
|
|
147
|
+
file: file_name,
|
|
148
|
+
line: 138,
|
|
149
|
+
data: { error: error_message },
|
|
150
|
+
});
|
|
151
|
+
return { success: false, error: error_message };
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=hazo_llm_text_image_text.js.map
|