hazo_llm_api 1.0.1

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.
Files changed (151) hide show
  1. package/README.md +536 -0
  2. package/dist/components/hazo_llm_prompt_config/hazo_llm_prompt_config.d.ts +16 -0
  3. package/dist/components/hazo_llm_prompt_config/hazo_llm_prompt_config.d.ts.map +1 -0
  4. package/dist/components/hazo_llm_prompt_config/hazo_llm_prompt_config.js +258 -0
  5. package/dist/components/hazo_llm_prompt_config/hazo_llm_prompt_config.js.map +1 -0
  6. package/dist/components/hazo_llm_prompt_config/index.d.ts +8 -0
  7. package/dist/components/hazo_llm_prompt_config/index.d.ts.map +1 -0
  8. package/dist/components/hazo_llm_prompt_config/index.js +7 -0
  9. package/dist/components/hazo_llm_prompt_config/index.js.map +1 -0
  10. package/dist/components/hazo_llm_prompt_config/types.d.ts +74 -0
  11. package/dist/components/hazo_llm_prompt_config/types.d.ts.map +1 -0
  12. package/dist/components/hazo_llm_prompt_config/types.js +8 -0
  13. package/dist/components/hazo_llm_prompt_config/types.js.map +1 -0
  14. package/dist/components/index.d.ts +7 -0
  15. package/dist/components/index.d.ts.map +1 -0
  16. package/dist/components/index.js +7 -0
  17. package/dist/components/index.js.map +1 -0
  18. package/dist/components/layout/index.d.ts +7 -0
  19. package/dist/components/layout/index.d.ts.map +1 -0
  20. package/dist/components/layout/index.js +7 -0
  21. package/dist/components/layout/index.js.map +1 -0
  22. package/dist/components/layout/layout.d.ts +21 -0
  23. package/dist/components/layout/layout.d.ts.map +1 -0
  24. package/dist/components/layout/layout.js +18 -0
  25. package/dist/components/layout/layout.js.map +1 -0
  26. package/dist/index.d.ts +11 -0
  27. package/dist/index.d.ts.map +1 -0
  28. package/dist/index.js +13 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/lib/config/config_parser.d.ts +131 -0
  31. package/dist/lib/config/config_parser.d.ts.map +1 -0
  32. package/dist/lib/config/config_parser.js +297 -0
  33. package/dist/lib/config/config_parser.js.map +1 -0
  34. package/dist/lib/config/index.d.ts +8 -0
  35. package/dist/lib/config/index.d.ts.map +1 -0
  36. package/dist/lib/config/index.js +22 -0
  37. package/dist/lib/config/index.js.map +1 -0
  38. package/dist/lib/config/provider_loader.d.ts +113 -0
  39. package/dist/lib/config/provider_loader.d.ts.map +1 -0
  40. package/dist/lib/config/provider_loader.js +169 -0
  41. package/dist/lib/config/provider_loader.js.map +1 -0
  42. package/dist/lib/database/index.d.ts +8 -0
  43. package/dist/lib/database/index.d.ts.map +1 -0
  44. package/dist/lib/database/index.js +8 -0
  45. package/dist/lib/database/index.js.map +1 -0
  46. package/dist/lib/database/init_database.d.ts +62 -0
  47. package/dist/lib/database/init_database.d.ts.map +1 -0
  48. package/dist/lib/database/init_database.js +436 -0
  49. package/dist/lib/database/init_database.js.map +1 -0
  50. package/dist/lib/database/utils.d.ts +50 -0
  51. package/dist/lib/database/utils.d.ts.map +1 -0
  52. package/dist/lib/database/utils.js +78 -0
  53. package/dist/lib/database/utils.js.map +1 -0
  54. package/dist/lib/index.d.ts +14 -0
  55. package/dist/lib/index.d.ts.map +1 -0
  56. package/dist/lib/index.js +17 -0
  57. package/dist/lib/index.js.map +1 -0
  58. package/dist/lib/llm_api/hazo_llm_image_image.d.ts +26 -0
  59. package/dist/lib/llm_api/hazo_llm_image_image.d.ts.map +1 -0
  60. package/dist/lib/llm_api/hazo_llm_image_image.js +92 -0
  61. package/dist/lib/llm_api/hazo_llm_image_image.js.map +1 -0
  62. package/dist/lib/llm_api/hazo_llm_image_image_text.d.ts +26 -0
  63. package/dist/lib/llm_api/hazo_llm_image_image_text.d.ts.map +1 -0
  64. package/dist/lib/llm_api/hazo_llm_image_image_text.js +220 -0
  65. package/dist/lib/llm_api/hazo_llm_image_image_text.js.map +1 -0
  66. package/dist/lib/llm_api/hazo_llm_image_text.d.ts +20 -0
  67. package/dist/lib/llm_api/hazo_llm_image_text.d.ts.map +1 -0
  68. package/dist/lib/llm_api/hazo_llm_image_text.js +76 -0
  69. package/dist/lib/llm_api/hazo_llm_image_text.js.map +1 -0
  70. package/dist/lib/llm_api/hazo_llm_text_image.d.ts +20 -0
  71. package/dist/lib/llm_api/hazo_llm_text_image.d.ts.map +1 -0
  72. package/dist/lib/llm_api/hazo_llm_text_image.js +67 -0
  73. package/dist/lib/llm_api/hazo_llm_text_image.js.map +1 -0
  74. package/dist/lib/llm_api/hazo_llm_text_image_text.d.ts +26 -0
  75. package/dist/lib/llm_api/hazo_llm_text_image_text.d.ts.map +1 -0
  76. package/dist/lib/llm_api/hazo_llm_text_image_text.js +152 -0
  77. package/dist/lib/llm_api/hazo_llm_text_image_text.js.map +1 -0
  78. package/dist/lib/llm_api/hazo_llm_text_text.d.ts +20 -0
  79. package/dist/lib/llm_api/hazo_llm_text_text.d.ts.map +1 -0
  80. package/dist/lib/llm_api/hazo_llm_text_text.js +89 -0
  81. package/dist/lib/llm_api/hazo_llm_text_text.js.map +1 -0
  82. package/dist/lib/llm_api/index.d.ts +99 -0
  83. package/dist/lib/llm_api/index.d.ts.map +1 -0
  84. package/dist/lib/llm_api/index.js +952 -0
  85. package/dist/lib/llm_api/index.js.map +1 -0
  86. package/dist/lib/llm_api/provider_helper.d.ts +107 -0
  87. package/dist/lib/llm_api/provider_helper.d.ts.map +1 -0
  88. package/dist/lib/llm_api/provider_helper.js +159 -0
  89. package/dist/lib/llm_api/provider_helper.js.map +1 -0
  90. package/dist/lib/llm_api/types.d.ts +352 -0
  91. package/dist/lib/llm_api/types.d.ts.map +1 -0
  92. package/dist/lib/llm_api/types.js +8 -0
  93. package/dist/lib/llm_api/types.js.map +1 -0
  94. package/dist/lib/prompts/get_prompt.d.ts +50 -0
  95. package/dist/lib/prompts/get_prompt.d.ts.map +1 -0
  96. package/dist/lib/prompts/get_prompt.js +232 -0
  97. package/dist/lib/prompts/get_prompt.js.map +1 -0
  98. package/dist/lib/prompts/index.d.ts +9 -0
  99. package/dist/lib/prompts/index.d.ts.map +1 -0
  100. package/dist/lib/prompts/index.js +9 -0
  101. package/dist/lib/prompts/index.js.map +1 -0
  102. package/dist/lib/prompts/prompt_cache.d.ts +151 -0
  103. package/dist/lib/prompts/prompt_cache.d.ts.map +1 -0
  104. package/dist/lib/prompts/prompt_cache.js +276 -0
  105. package/dist/lib/prompts/prompt_cache.js.map +1 -0
  106. package/dist/lib/prompts/substitute_variables.d.ts +38 -0
  107. package/dist/lib/prompts/substitute_variables.d.ts.map +1 -0
  108. package/dist/lib/prompts/substitute_variables.js +175 -0
  109. package/dist/lib/prompts/substitute_variables.js.map +1 -0
  110. package/dist/lib/providers/gemini/gemini_client.d.ts +25 -0
  111. package/dist/lib/providers/gemini/gemini_client.d.ts.map +1 -0
  112. package/dist/lib/providers/gemini/gemini_client.js +235 -0
  113. package/dist/lib/providers/gemini/gemini_client.js.map +1 -0
  114. package/dist/lib/providers/gemini/gemini_provider.d.ts +111 -0
  115. package/dist/lib/providers/gemini/gemini_provider.d.ts.map +1 -0
  116. package/dist/lib/providers/gemini/gemini_provider.js +431 -0
  117. package/dist/lib/providers/gemini/gemini_provider.js.map +1 -0
  118. package/dist/lib/providers/gemini/index.d.ts +8 -0
  119. package/dist/lib/providers/gemini/index.d.ts.map +1 -0
  120. package/dist/lib/providers/gemini/index.js +8 -0
  121. package/dist/lib/providers/gemini/index.js.map +1 -0
  122. package/dist/lib/providers/index.d.ts +8 -0
  123. package/dist/lib/providers/index.d.ts.map +1 -0
  124. package/dist/lib/providers/index.js +8 -0
  125. package/dist/lib/providers/index.js.map +1 -0
  126. package/dist/lib/providers/qwen/index.d.ts +8 -0
  127. package/dist/lib/providers/qwen/index.d.ts.map +1 -0
  128. package/dist/lib/providers/qwen/index.js +8 -0
  129. package/dist/lib/providers/qwen/index.js.map +1 -0
  130. package/dist/lib/providers/qwen/qwen_client.d.ts +154 -0
  131. package/dist/lib/providers/qwen/qwen_client.d.ts.map +1 -0
  132. package/dist/lib/providers/qwen/qwen_client.js +1002 -0
  133. package/dist/lib/providers/qwen/qwen_client.js.map +1 -0
  134. package/dist/lib/providers/qwen/qwen_provider.d.ts +139 -0
  135. package/dist/lib/providers/qwen/qwen_provider.d.ts.map +1 -0
  136. package/dist/lib/providers/qwen/qwen_provider.js +304 -0
  137. package/dist/lib/providers/qwen/qwen_provider.js.map +1 -0
  138. package/dist/lib/providers/registry.d.ts +66 -0
  139. package/dist/lib/providers/registry.d.ts.map +1 -0
  140. package/dist/lib/providers/registry.js +158 -0
  141. package/dist/lib/providers/registry.js.map +1 -0
  142. package/dist/lib/providers/types.d.ts +95 -0
  143. package/dist/lib/providers/types.d.ts.map +1 -0
  144. package/dist/lib/providers/types.js +19 -0
  145. package/dist/lib/providers/types.js.map +1 -0
  146. package/dist/server.d.ts +21 -0
  147. package/dist/server.d.ts.map +1 -0
  148. package/dist/server.js +32 -0
  149. package/dist/server.js.map +1 -0
  150. package/package.json +68 -0
  151. package/techdoc.md +857 -0
package/README.md ADDED
@@ -0,0 +1,536 @@
1
+ # hazo_llm_api
2
+
3
+ A wrapper package for calling different LLMs with built-in prompt management and variable substitution.
4
+
5
+ ## Overview
6
+
7
+ `hazo_llm_api` provides specialized functions for different LLM input/output combinations:
8
+
9
+ | Function | Input | Output | Use Case |
10
+ |----------|-------|--------|----------|
11
+ | `hazo_llm_text_text` | Text | Text | Standard text generation, Q&A, summarization |
12
+ | `hazo_llm_image_text` | Image | Text | Image analysis, OCR, object detection |
13
+ | `hazo_llm_text_image` | Text | Image | Image generation from descriptions |
14
+ | `hazo_llm_image_image` | Image(s) | Image | Image editing, combining, transformation |
15
+ | `hazo_llm_text_image_text` | Text × 2 | Image + Text | Generate image then analyze it (chained) |
16
+ | `hazo_llm_image_image_text` | Images + Prompts | Image + Text | Chain image transformations then describe (chained) |
17
+
18
+ **Features:**
19
+ - **Multi-Provider Support**: Use Gemini, Qwen, or add your own LLM providers
20
+ - **Prompt Management**: Store and retrieve prompts from a SQLite database with LRU caching
21
+ - **Variable Substitution**: Replace `$variables` in prompts with dynamic values
22
+ - **Multi-modal Support**: Handle text and images seamlessly
23
+ - **Extensible Architecture**: Provider-based design with simple registration system
24
+ - **Type-Safe**: Full TypeScript support with comprehensive type definitions
25
+ - **Auto-Initialization**: Database initializes automatically on import
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ npm install hazo_llm_api
31
+ ```
32
+
33
+ ## Quick Start
34
+
35
+ ### 1. Set Up Configuration
36
+
37
+ Create `hazo_llm_api_config.ini` in your project root:
38
+
39
+ ```ini
40
+ [llm]
41
+ enabled_llms=["gemini", "qwen"]
42
+ primary_llm=gemini
43
+ sqlite_path=prompt_library.sqlite
44
+
45
+ [llm_gemini]
46
+ api_url=https://generativelanguage.googleapis.com/v1/models/gemini-2.5-flash:generateContent
47
+ api_url_image=https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-image:generateContent
48
+ capabilities=["text_text", "image_text", "text_image", "image_image"]
49
+ image_temperature=0.1
50
+ ```
51
+
52
+ Create `.env.local` with your API keys:
53
+
54
+ ```bash
55
+ GEMINI_API_KEY=your_api_key_here
56
+ QWEN_API_KEY=your_qwen_api_key_here
57
+ ```
58
+
59
+ ### 2. Initialize the LLM API
60
+
61
+ ```typescript
62
+ import {
63
+ initialize_llm_api,
64
+ hazo_llm_text_text,
65
+ hazo_llm_image_text,
66
+ hazo_llm_text_image,
67
+ hazo_llm_image_image,
68
+ } from 'hazo_llm_api/server';
69
+
70
+ // Create a logger (Winston-compatible)
71
+ const logger = {
72
+ error: console.error,
73
+ info: console.log,
74
+ warn: console.warn,
75
+ debug: console.debug,
76
+ };
77
+
78
+ // Initialize - reads config from hazo_llm_api_config.ini
79
+ await initialize_llm_api({ logger });
80
+ ```
81
+
82
+ ### 3. Text → Text (Standard Generation)
83
+
84
+ ```typescript
85
+ const response = await hazo_llm_text_text({
86
+ prompt: 'Explain quantum computing in simple terms.',
87
+ });
88
+
89
+ if (response.success) {
90
+ console.log(response.text);
91
+ }
92
+ ```
93
+
94
+ ### 4. Image → Text (Image Analysis)
95
+
96
+ ```typescript
97
+ const response = await hazo_llm_image_text({
98
+ prompt: 'Describe what you see in this image.',
99
+ image_b64: 'base64_encoded_image_string...',
100
+ image_mime_type: 'image/jpeg',
101
+ });
102
+
103
+ if (response.success) {
104
+ console.log(response.text);
105
+ }
106
+ ```
107
+
108
+ ### 5. Text → Image (Image Generation)
109
+
110
+ ```typescript
111
+ const response = await hazo_llm_text_image({
112
+ prompt: 'A serene mountain landscape at sunset',
113
+ });
114
+
115
+ if (response.success && response.image_b64) {
116
+ // Use the generated image
117
+ const image_src = `data:${response.image_mime_type};base64,${response.image_b64}`;
118
+ }
119
+ ```
120
+
121
+ ### 6. Image → Image (Single Image Transformation)
122
+
123
+ ```typescript
124
+ const response = await hazo_llm_image_image({
125
+ prompt: 'Convert this image to a watercolor painting style',
126
+ image_b64: 'base64_encoded_image_string...',
127
+ image_mime_type: 'image/jpeg',
128
+ });
129
+
130
+ if (response.success && response.image_b64) {
131
+ // Use the transformed image
132
+ }
133
+ ```
134
+
135
+ ### 7. Multiple Images → Image (Combine Images)
136
+
137
+ ```typescript
138
+ const response = await hazo_llm_image_image({
139
+ prompt: 'Combine these two images into one cohesive creative image',
140
+ images: [
141
+ { data: 'base64_image_1...', mime_type: 'image/jpeg' },
142
+ { data: 'base64_image_2...', mime_type: 'image/png' },
143
+ ],
144
+ });
145
+
146
+ if (response.success && response.image_b64) {
147
+ // Use the combined image
148
+ }
149
+ ```
150
+
151
+ ### 8. Text → Image → Text (Chained)
152
+
153
+ ```typescript
154
+ const response = await hazo_llm_text_image_text({
155
+ prompt_image: 'A serene Japanese garden with a koi pond',
156
+ prompt_text: 'Describe the mood and elements of this image in detail.',
157
+ });
158
+
159
+ if (response.success) {
160
+ // response.image_b64 - the generated image
161
+ // response.text - the analysis of the generated image
162
+ }
163
+ ```
164
+
165
+ ### 9. Images → Image → Text (Multi-Step Chain)
166
+
167
+ ```typescript
168
+ const response = await hazo_llm_image_image_text({
169
+ // Minimum 2 images required
170
+ images: [
171
+ { image_b64: 'base64_image_1...', image_mime_type: 'image/jpeg' },
172
+ { image_b64: 'base64_image_2...', image_mime_type: 'image/png' },
173
+ { image_b64: 'base64_image_3...', image_mime_type: 'image/jpeg' },
174
+ ],
175
+ // Number of prompts = number of images - 1
176
+ prompts: [
177
+ 'Combine these two images into a surreal landscape', // Combines image 1 + 2
178
+ 'Add elements from this third image to the result', // Combines result + image 3
179
+ ],
180
+ description_prompt: 'Describe this final artistic composition in detail.',
181
+ });
182
+
183
+ if (response.success) {
184
+ // response.image_b64 - the final chained image
185
+ // response.text - the description of the result
186
+ }
187
+ ```
188
+
189
+ **Flow:**
190
+ 1. Step 1: `images[0]` + `images[1]` + `prompts[0]` → result_1
191
+ 2. Step 2: result_1 + `images[2]` + `prompts[1]` → result_2
192
+ 3. ... continue for more images
193
+ 4. Final: last result + `description_prompt` → text output
194
+
195
+ ## API Reference
196
+
197
+ ### `initialize_llm_api(config: LLMApiConfig): Promise<LLMApiClient>`
198
+
199
+ Initialize the LLM API. Must be called before using any other functions.
200
+
201
+ Configuration is read from `hazo_llm_api_config.ini` file, which should be in your project root.
202
+
203
+ #### LLMApiConfig
204
+
205
+ | Property | Type | Required | Default | Description |
206
+ |----------|------|----------|---------|-------------|
207
+ | `logger` | Logger | Yes | - | Winston-compatible logger instance |
208
+ | `sqlite_path` | string | No | From config file | Path to SQLite database |
209
+ | `api_url` | string | No | - | Legacy: API endpoint URL (deprecated, use config file) |
210
+ | `api_url_image` | string | No | - | Legacy: Image API endpoint (deprecated, use config file) |
211
+ | `api_key` | string | No | - | Legacy: API key (deprecated, use .env.local) |
212
+ | `llm_model` | string | No | From config file | Legacy: Provider name (deprecated, use config file) |
213
+
214
+ **Note:** The config file approach is recommended over passing configuration directly. This keeps sensitive API keys out of your codebase.
215
+
216
+ ---
217
+
218
+ ### `hazo_llm_text_text(params: TextTextParams): Promise<LLMResponse>`
219
+
220
+ Text input → Text output. Standard text generation.
221
+
222
+ #### TextTextParams
223
+
224
+ | Parameter | Type | Required | Description |
225
+ |-----------|------|----------|-------------|
226
+ | `prompt` | string | Yes | The prompt text |
227
+ | `prompt_variables` | PromptVariables | No | Variables to substitute |
228
+ | `prompt_area` | string | No | Area for dynamic prompt lookup |
229
+ | `prompt_key` | string | No | Key for dynamic prompt lookup |
230
+
231
+ ---
232
+
233
+ ### `hazo_llm_image_text(params: ImageTextParams): Promise<LLMResponse>`
234
+
235
+ Image input → Text output. Analyze an image and get text description.
236
+
237
+ #### ImageTextParams
238
+
239
+ | Parameter | Type | Required | Description |
240
+ |-----------|------|----------|-------------|
241
+ | `prompt` | string | Yes | Instructions for analyzing the image |
242
+ | `image_b64` | string | Yes | Base64 encoded image data |
243
+ | `image_mime_type` | string | Yes | MIME type (e.g., "image/jpeg") |
244
+ | `prompt_variables` | PromptVariables | No | Variables to substitute |
245
+
246
+ ---
247
+
248
+ ### `hazo_llm_text_image(params: TextImageParams): Promise<LLMResponse>`
249
+
250
+ Text input → Image output. Generate an image from a text description.
251
+
252
+ #### TextImageParams
253
+
254
+ | Parameter | Type | Required | Description |
255
+ |-----------|------|----------|-------------|
256
+ | `prompt` | string | Yes | Description of image to generate |
257
+ | `prompt_variables` | PromptVariables | No | Variables to substitute |
258
+
259
+ ---
260
+
261
+ ### `hazo_llm_image_image(params: ImageImageParams): Promise<LLMResponse>`
262
+
263
+ Image(s) input → Image output. Transform, edit, or combine images based on instructions.
264
+
265
+ Supports both single image and multiple images input.
266
+
267
+ #### ImageImageParams
268
+
269
+ | Parameter | Type | Required | Description |
270
+ |-----------|------|----------|-------------|
271
+ | `prompt` | string | Yes | Transformation/combination instructions |
272
+ | `image_b64` | string | For single image | Base64 encoded input image |
273
+ | `image_mime_type` | string | For single image | MIME type of input image |
274
+ | `images` | Base64Data[] | For multiple images | Array of images to combine |
275
+ | `prompt_variables` | PromptVariables | No | Variables to substitute |
276
+
277
+ **Note:** Use either `image_b64`/`image_mime_type` for single image OR `images` array for multiple images.
278
+
279
+ ---
280
+
281
+ ### `hazo_llm_text_image_text(params: TextImageTextParams): Promise<LLMResponse>`
282
+
283
+ Text → Image → Text (Chained). Generate an image from one prompt, then analyze it with a second prompt.
284
+
285
+ This function chains two operations:
286
+ 1. Generate an image using `prompt_image`
287
+ 2. Analyze the generated image using `prompt_text`
288
+
289
+ Returns both the generated image and the analysis text.
290
+
291
+ #### TextImageTextParams
292
+
293
+ | Parameter | Type | Required | Description |
294
+ |-----------|------|----------|-------------|
295
+ | `prompt_image` | string | Yes | Description of image to generate |
296
+ | `prompt_text` | string | Yes | Prompt for analyzing the generated image |
297
+ | `prompt_image_variables` | PromptVariables | No | Variables for image generation prompt |
298
+ | `prompt_text_variables` | PromptVariables | No | Variables for analysis prompt |
299
+
300
+ ---
301
+
302
+ ### `hazo_llm_image_image_text(params: ImageImageTextParams): Promise<LLMResponse>`
303
+
304
+ Images → Image → Text (Multi-Step Chained). Chain multiple image transformations, then describe the result.
305
+
306
+ **Flow:**
307
+ 1. Combine `images[0]` + `images[1]` using `prompts[0]` → result_1
308
+ 2. Combine result_1 + `images[2]` using `prompts[1]` → result_2
309
+ 3. Continue for all images
310
+ 4. Describe final result using `description_prompt` → text output
311
+
312
+ Returns both the final image and the description text.
313
+
314
+ #### ImageImageTextParams
315
+
316
+ | Parameter | Type | Required | Description |
317
+ |-----------|------|----------|-------------|
318
+ | `images` | ChainImage[] | Yes | Array of images to chain (minimum 2) |
319
+ | `prompts` | string[] | Yes | Transformation prompts (length = images.length - 1) |
320
+ | `description_prompt` | string | Yes | Prompt for describing the final image |
321
+ | `description_prompt_variables` | PromptVariables | No | Variables for description prompt |
322
+
323
+ #### ChainImage
324
+
325
+ | Parameter | Type | Required | Description |
326
+ |-----------|------|----------|-------------|
327
+ | `image_b64` | string | Yes | Base64 encoded image data |
328
+ | `image_mime_type` | string | Yes | MIME type (e.g., "image/jpeg") |
329
+
330
+ ---
331
+
332
+ ### LLMResponse
333
+
334
+ All functions return an `LLMResponse`:
335
+
336
+ ```typescript
337
+ interface LLMResponse {
338
+ success: boolean; // Whether the call succeeded
339
+ text?: string; // Generated text response
340
+ image_b64?: string; // Generated image (base64)
341
+ image_mime_type?: string; // MIME type of generated image
342
+ error?: string; // Error message if failed
343
+ raw_response?: unknown; // Raw API response
344
+ }
345
+ ```
346
+
347
+ ## Using Specific LLM Providers
348
+
349
+ By default, all functions use the `primary_llm` configured in your config file. You can override this per-call:
350
+
351
+ ```typescript
352
+ // Use Gemini explicitly
353
+ const response1 = await hazo_llm_text_text(
354
+ { prompt: 'Hello world' },
355
+ 'gemini'
356
+ );
357
+
358
+ // Use Qwen explicitly
359
+ const response2 = await hazo_llm_text_text(
360
+ { prompt: 'Hello world' },
361
+ 'qwen'
362
+ );
363
+
364
+ // Use primary LLM (from config)
365
+ const response3 = await hazo_llm_text_text(
366
+ { prompt: 'Hello world' }
367
+ );
368
+ ```
369
+
370
+ ### Provider Configuration
371
+
372
+ Each provider has its own section in `hazo_llm_api_config.ini`:
373
+
374
+ ```ini
375
+ [llm_gemini]
376
+ api_url=https://generativelanguage.googleapis.com/v1/models/gemini-2.5-flash:generateContent
377
+ api_url_image=https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-image:generateContent
378
+ capabilities=["text_text", "image_text", "text_image", "image_image"]
379
+ text_temperature=0.7
380
+ image_temperature=0.1
381
+
382
+ [llm_qwen]
383
+ api_url=https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions
384
+ model_text_text=qwen-max
385
+ model_image_text=qwen-vl-max
386
+ capabilities=["text_text", "image_text"]
387
+ text_temperature=0.8
388
+ ```
389
+
390
+ ### Supported Providers
391
+
392
+ | Provider | Capabilities | Configuration Required |
393
+ |----------|-------------|------------------------|
394
+ | Gemini | text_text, image_text, text_image, image_image | GEMINI_API_KEY in .env.local |
395
+ | Qwen | text_text, image_text, text_image, image_image | QWEN_API_KEY in .env.local |
396
+ | Custom | Define your own | Implement LLMProvider interface |
397
+
398
+ See `TECHDOC.md` for instructions on adding custom providers.
399
+
400
+ ## Prompt Management
401
+
402
+ ### Database Schema
403
+
404
+ Prompts are stored in a SQLite database with the following table:
405
+
406
+ **Table: `prompts_library`**
407
+
408
+ | Column | Type | Description |
409
+ |--------|------|-------------|
410
+ | `uuid` | TEXT | Unique identifier |
411
+ | `prompt_area` | TEXT | Category/area for the prompt |
412
+ | `prompt_key` | TEXT | Unique key within the area |
413
+ | `prompt_text` | TEXT | The prompt template |
414
+ | `prompt_variables` | TEXT | JSON array of expected variables |
415
+ | `prompt_notes` | TEXT | Documentation/notes |
416
+ | `created_at` | TEXT | Creation timestamp |
417
+ | `changed_by` | TEXT | Last update timestamp |
418
+
419
+ ### Variable Substitution
420
+
421
+ Variables in prompt text starting with `$` are automatically replaced:
422
+
423
+ ```
424
+ Prompt: "Write about $topic in $style style."
425
+ Variables: [{ topic: "AI", style: "academic" }]
426
+ Result: "Write about AI in academic style."
427
+ ```
428
+
429
+ ### Dynamic Prompts
430
+
431
+ Use `prompt_area` and `prompt_key` to fetch prompts from the database:
432
+
433
+ ```typescript
434
+ const response = await hazo_llm_text_text({
435
+ prompt: '', // Will be overridden by dynamic prompt
436
+ prompt_area: 'marketing',
437
+ prompt_key: 'product_description',
438
+ prompt_variables: [{ product_name: 'Widget Pro' }],
439
+ });
440
+ ```
441
+
442
+ ## Server-Side Only
443
+
444
+ **Important**: All LLM API functions must be used server-side only.
445
+
446
+ ```typescript
447
+ // ✅ Correct - Server-side import
448
+ import { hazo_llm_text_text } from 'hazo_llm_api/server';
449
+
450
+ // ❌ Wrong - Will fail on client-side
451
+ import { hazo_llm_text_text } from 'hazo_llm_api';
452
+ ```
453
+
454
+ Use in:
455
+ - Next.js API routes
456
+ - Next.js Server Components
457
+ - Next.js Server Actions
458
+ - Node.js backend services
459
+
460
+ ## Examples
461
+
462
+ ### Chat/Q&A
463
+
464
+ ```typescript
465
+ const response = await hazo_llm_text_text({
466
+ prompt: `Answer this question: ${user_question}`,
467
+ });
468
+ ```
469
+
470
+ ### Document Summarization
471
+
472
+ ```typescript
473
+ const response = await hazo_llm_text_text({
474
+ prompt: `Summarize this document in 3 bullet points:\n\n${document_text}`,
475
+ });
476
+ ```
477
+
478
+ ### Image OCR
479
+
480
+ ```typescript
481
+ const response = await hazo_llm_image_text({
482
+ prompt: 'Extract all text from this image.',
483
+ image_b64: document_image_base64,
484
+ image_mime_type: 'image/png',
485
+ });
486
+ ```
487
+
488
+ ### Product Image Analysis
489
+
490
+ ```typescript
491
+ const response = await hazo_llm_image_text({
492
+ prompt: 'Describe this product and list its key features.',
493
+ image_b64: product_image_base64,
494
+ image_mime_type: 'image/jpeg',
495
+ });
496
+ ```
497
+
498
+ ## Error Handling
499
+
500
+ ```typescript
501
+ const response = await hazo_llm_text_text({
502
+ prompt: 'Hello world',
503
+ });
504
+
505
+ if (!response.success) {
506
+ logger.error('LLM call failed', { error: response.error });
507
+ // Handle error appropriately
508
+ }
509
+ ```
510
+
511
+ ## Configuration
512
+
513
+ ### Logger Interface
514
+
515
+ The logger must implement these methods (Winston-compatible):
516
+
517
+ ```typescript
518
+ interface Logger {
519
+ error: (message: string, meta?: Record<string, unknown>) => void;
520
+ info: (message: string, meta?: Record<string, unknown>) => void;
521
+ warn: (message: string, meta?: Record<string, unknown>) => void;
522
+ debug: (message: string, meta?: Record<string, unknown>) => void;
523
+ }
524
+ ```
525
+
526
+ ## License
527
+
528
+ MIT
529
+
530
+ ## Author
531
+
532
+ Pubs Abayasiri
533
+
534
+ ## Support
535
+
536
+ For issues and questions, please visit the [GitHub Issues](https://github.com/pub12/hazo_llm_api/issues) page.
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Hazo LLM Prompt Config Component
3
+ *
4
+ * A comprehensive UI component for managing LLM prompts in the prompts_library table.
5
+ * Features include:
6
+ * - Data table displaying all prompts
7
+ * - Add, Edit, and Delete functionality
8
+ * - Dialog-based form for prompt creation/editing
9
+ * - Multi-entry variable definitions with add/delete support
10
+ */
11
+ import type { HazoLlmPromptConfigProps } from './types.js';
12
+ /**
13
+ * HazoLlmPromptConfig - Main prompt configuration management component
14
+ */
15
+ export declare function HazoLlmPromptConfig({ api_endpoint_list, api_endpoint_create, api_endpoint_update, api_endpoint_delete, on_change, class_name }: HazoLlmPromptConfigProps): import("react/jsx-runtime").JSX.Element;
16
+ //# sourceMappingURL=hazo_llm_prompt_config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hazo_llm_prompt_config.d.ts","sourceRoot":"","sources":["../../../src/components/hazo_llm_prompt_config/hazo_llm_prompt_config.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAcH,OAAO,KAAK,EACV,wBAAwB,EAKzB,MAAM,YAAY,CAAC;AA+KpB;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,SAAS,EACT,UAAe,EAChB,EAAE,wBAAwB,2CA+a1B"}