genai-lite 0.8.2 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +210 -207
- package/dist/adapters/image/GenaiElectronImageAdapter.d.ts +1 -0
- package/dist/adapters/image/GenaiElectronImageAdapter.js +5 -5
- package/dist/adapters/image/OpenAIImageAdapter.d.ts +1 -0
- package/dist/adapters/image/OpenAIImageAdapter.js +4 -4
- package/dist/config/llm-presets.json +24 -0
- package/dist/image/ImageService.js +2 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +6 -1
- package/dist/llm/LLMService.d.ts +30 -1
- package/dist/llm/LLMService.js +43 -5
- package/dist/llm/clients/AnthropicClientAdapter.d.ts +6 -2
- package/dist/llm/clients/AnthropicClientAdapter.js +26 -11
- package/dist/llm/clients/GeminiClientAdapter.d.ts +6 -2
- package/dist/llm/clients/GeminiClientAdapter.js +21 -9
- package/dist/llm/clients/LlamaCppClientAdapter.d.ts +8 -4
- package/dist/llm/clients/LlamaCppClientAdapter.js +131 -28
- package/dist/llm/clients/MistralClientAdapter.d.ts +6 -2
- package/dist/llm/clients/MistralClientAdapter.js +22 -11
- package/dist/llm/clients/MockClientAdapter.d.ts +2 -2
- package/dist/llm/clients/MockClientAdapter.js +36 -19
- package/dist/llm/clients/OpenAIClientAdapter.d.ts +6 -2
- package/dist/llm/clients/OpenAIClientAdapter.js +33 -9
- package/dist/llm/clients/OpenRouterClientAdapter.d.ts +6 -2
- package/dist/llm/clients/OpenRouterClientAdapter.js +87 -16
- package/dist/llm/clients/types.d.ts +18 -1
- package/dist/llm/clients/types.js +4 -0
- package/dist/llm/config.d.ts +9 -2
- package/dist/llm/config.js +697 -33
- package/dist/llm/services/ModelResolver.d.ts +6 -0
- package/dist/llm/services/ModelResolver.js +57 -17
- package/dist/llm/services/RequestValidator.d.ts +8 -0
- package/dist/llm/services/RequestValidator.js +9 -2
- package/dist/llm/services/SettingsManager.d.ts +1 -1
- package/dist/llm/services/SettingsManager.js +92 -4
- package/dist/llm/types.d.ts +127 -0
- package/dist/prompting/index.d.ts +1 -1
- package/dist/prompting/index.js +2 -1
- package/dist/prompting/parser.d.ts +23 -0
- package/dist/prompting/parser.js +33 -0
- package/dist/shared/adapters/errorUtils.d.ts +15 -0
- package/dist/shared/adapters/errorUtils.js +69 -1
- package/dist/shared/adapters/logprobsUtils.d.ts +13 -0
- package/dist/shared/adapters/logprobsUtils.js +33 -0
- package/dist/shared/services/AdapterRegistry.js +3 -1
- package/dist/shared/services/withRetry.d.ts +50 -0
- package/dist/shared/services/withRetry.js +78 -0
- package/dist/types/image.d.ts +2 -0
- package/package.json +59 -59
- package/src/config/image-presets.json +212 -212
- package/src/config/llm-presets.json +623 -599
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Luigi Acerbi
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Luigi Acerbi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,207 +1,210 @@
|
|
|
1
|
-
# genai-lite
|
|
2
|
-
|
|
3
|
-
A lightweight, portable Node.js/TypeScript library providing a unified interface for interacting with multiple Generative AI providers—both cloud-based (OpenAI, Anthropic, Google Gemini, Mistral) and local (llama.cpp, stable-diffusion.cpp). Supports both LLM chat and AI image generation.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- 🔌 **Unified API** - Single interface for multiple AI providers
|
|
8
|
-
- 🏠 **Local & Cloud Models** - Run models locally with llama.cpp or use cloud APIs
|
|
9
|
-
- 🖼️ **Image Generation** - First-class support for AI image generation (OpenAI, local diffusion)
|
|
10
|
-
- 🔐 **Flexible API Key Management** - Bring your own key storage solution
|
|
11
|
-
- 📦 **Zero Electron Dependencies** - Works in any Node.js environment
|
|
12
|
-
- 🎯 **TypeScript First** - Full type safety and IntelliSense support
|
|
13
|
-
- ⚡ **Lightweight** - Minimal dependencies, focused functionality
|
|
14
|
-
- 🛡️ **Provider Normalization** - Consistent responses across different AI APIs
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
- **[
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
- **[
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
- **[
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
- **
|
|
133
|
-
- **
|
|
134
|
-
- **
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
- **
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
1
|
+
# genai-lite
|
|
2
|
+
|
|
3
|
+
A lightweight, portable Node.js/TypeScript library providing a unified interface for interacting with multiple Generative AI providers—both cloud-based (OpenAI, Anthropic, Google Gemini, Mistral, OpenRouter) and local (llama.cpp, stable-diffusion.cpp). Supports both LLM chat and AI image generation.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🔌 **Unified API** - Single interface for multiple AI providers
|
|
8
|
+
- 🏠 **Local & Cloud Models** - Run models locally with llama.cpp or use cloud APIs
|
|
9
|
+
- 🖼️ **Image Generation** - First-class support for AI image generation (OpenAI, local diffusion)
|
|
10
|
+
- 🔐 **Flexible API Key Management** - Bring your own key storage solution
|
|
11
|
+
- 📦 **Zero Electron Dependencies** - Works in any Node.js environment
|
|
12
|
+
- 🎯 **TypeScript First** - Full type safety and IntelliSense support
|
|
13
|
+
- ⚡ **Lightweight** - Minimal dependencies, focused functionality
|
|
14
|
+
- 🛡️ **Provider Normalization** - Consistent responses across different AI APIs
|
|
15
|
+
- 🧠 **Local Reasoning Toggle** - Turn thinking on/off for detected GGUF models (Qwen 3.5-class, Gemma 4, and more) with vendor-tuned sampling defaults
|
|
16
|
+
- 🔁 **Built-in Reliability** - Automatic retries with backoff/`Retry-After`, per-request timeouts, and abort signals
|
|
17
|
+
- 🎨 **Configurable Model Presets** - Built-in presets with full customization options
|
|
18
|
+
- 🎭 **Template Engine** - Sophisticated templating with conditionals and variable substitution
|
|
19
|
+
- 📊 **Configurable Logging** - Debug mode, custom loggers (pino, winston), and silent mode for tests
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install genai-lite
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Set API keys as environment variables:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
export OPENAI_API_KEY=sk-...
|
|
31
|
+
export ANTHROPIC_API_KEY=sk-ant-...
|
|
32
|
+
export GEMINI_API_KEY=AIza...
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Quick Start
|
|
36
|
+
|
|
37
|
+
### Cloud Providers (OpenAI, Anthropic, Gemini, Mistral)
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import { LLMService, fromEnvironment } from 'genai-lite';
|
|
41
|
+
|
|
42
|
+
const llmService = new LLMService(fromEnvironment);
|
|
43
|
+
|
|
44
|
+
const response = await llmService.sendMessage({
|
|
45
|
+
providerId: 'openai',
|
|
46
|
+
modelId: 'gpt-4.1-mini',
|
|
47
|
+
messages: [
|
|
48
|
+
{ role: 'system', content: 'You are a helpful assistant.' },
|
|
49
|
+
{ role: 'user', content: 'Hello, how are you?' }
|
|
50
|
+
]
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
if (response.object === 'chat.completion') {
|
|
54
|
+
console.log(response.choices[0].message.content);
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Local Models (llama.cpp)
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { LLMService } from 'genai-lite';
|
|
62
|
+
|
|
63
|
+
// Start llama.cpp server first: llama-server -m /path/to/model.gguf --port 8080
|
|
64
|
+
const llmService = new LLMService(async () => 'not-needed');
|
|
65
|
+
|
|
66
|
+
const response = await llmService.sendMessage({
|
|
67
|
+
providerId: 'llamacpp',
|
|
68
|
+
modelId: 'llamacpp', // Generic ID for whatever model is loaded
|
|
69
|
+
messages: [
|
|
70
|
+
{ role: 'system', content: 'You are a helpful assistant.' },
|
|
71
|
+
{ role: 'user', content: 'Explain quantum computing briefly.' }
|
|
72
|
+
]
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
if (response.object === 'chat.completion') {
|
|
76
|
+
console.log(response.choices[0].message.content);
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Image Generation
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { ImageService, fromEnvironment } from 'genai-lite';
|
|
84
|
+
|
|
85
|
+
const imageService = new ImageService(fromEnvironment);
|
|
86
|
+
|
|
87
|
+
const result = await imageService.generateImage({
|
|
88
|
+
providerId: 'openai-images',
|
|
89
|
+
modelId: 'gpt-image-1-mini',
|
|
90
|
+
prompt: 'A serene mountain lake at sunrise, photorealistic',
|
|
91
|
+
settings: {
|
|
92
|
+
width: 1024,
|
|
93
|
+
height: 1024,
|
|
94
|
+
quality: 'high'
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
if (result.object === 'image.result') {
|
|
99
|
+
require('fs').writeFileSync('output.png', result.data[0].data);
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Documentation
|
|
104
|
+
|
|
105
|
+
Comprehensive documentation is available in the **[`genai-lite-docs`](./genai-lite-docs/index.md)** folder.
|
|
106
|
+
|
|
107
|
+
### Getting Started
|
|
108
|
+
- **[Documentation Hub](./genai-lite-docs/index.md)** - Navigation and overview
|
|
109
|
+
- **[Core Concepts](./genai-lite-docs/core-concepts.md)** - API keys, presets, settings, errors
|
|
110
|
+
|
|
111
|
+
### API Reference
|
|
112
|
+
- **[LLM Service](./genai-lite-docs/llm-service.md)** - Text generation and chat
|
|
113
|
+
- **[Image Service](./genai-lite-docs/image-service.md)** - Image generation (cloud and local)
|
|
114
|
+
- **[llama.cpp Integration](./genai-lite-docs/llamacpp-integration.md)** - Local LLM inference
|
|
115
|
+
|
|
116
|
+
### Utilities & Advanced
|
|
117
|
+
- **[Prompting Utilities](./genai-lite-docs/prompting-utilities.md)** - Template engine, token counting, content parsing
|
|
118
|
+
- **[Logging](./genai-lite-docs/logging.md)** - Configure logging and debugging
|
|
119
|
+
- **[TypeScript Reference](./genai-lite-docs/typescript-reference.md)** - Type definitions
|
|
120
|
+
|
|
121
|
+
### Provider Reference
|
|
122
|
+
- **[Providers & Models](./genai-lite-docs/providers-and-models.md)** - Supported providers and models
|
|
123
|
+
|
|
124
|
+
### Examples & Help
|
|
125
|
+
- **[Example: Chat Demo](./genai-lite-docs/example-chat-demo.md)** - Reference implementation for chat applications
|
|
126
|
+
- **[Example: Image Demo](./genai-lite-docs/example-image-demo.md)** - Reference implementation for image generation applications
|
|
127
|
+
- **[Troubleshooting](./genai-lite-docs/troubleshooting.md)** - Common issues and solutions
|
|
128
|
+
|
|
129
|
+
## Supported Providers
|
|
130
|
+
|
|
131
|
+
### LLM Providers
|
|
132
|
+
- **OpenAI** - GPT-5 (5.2, 5.1, mini, nano), GPT-4.1, o4-mini
|
|
133
|
+
- **Anthropic** - Claude 4.5 (Opus, Sonnet, Haiku), Claude 4, Claude 3.7, Claude 3.5
|
|
134
|
+
- **Google Gemini** - Gemini 3 (Pro, Flash preview), Gemini 2.5, Gemma 3 & 4 (free)
|
|
135
|
+
- **Mistral** - Codestral, Devstral
|
|
136
|
+
- **OpenRouter** - Unified gateway to 100+ models (unknown models assumed reasoning-capable)
|
|
137
|
+
- **llama.cpp** - Run any GGUF model locally (no API keys required); local reasoning toggle for detected models
|
|
138
|
+
|
|
139
|
+
### Image Providers
|
|
140
|
+
- **OpenAI Images** - gpt-image-1, dall-e-3, dall-e-2
|
|
141
|
+
- **genai-electron** - Local Stable Diffusion models
|
|
142
|
+
|
|
143
|
+
See **[Providers & Models](./genai-lite-docs/providers-and-models.md)** for complete model listings and capabilities.
|
|
144
|
+
|
|
145
|
+
## API Key Management
|
|
146
|
+
|
|
147
|
+
genai-lite uses a flexible API key provider pattern. Use the built-in `fromEnvironment` provider or create your own:
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
import { ApiKeyProvider, LLMService } from 'genai-lite';
|
|
151
|
+
|
|
152
|
+
const myKeyProvider: ApiKeyProvider = async (providerId: string) => {
|
|
153
|
+
const key = await mySecureStorage.getKey(providerId);
|
|
154
|
+
return key || null;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const llmService = new LLMService(myKeyProvider);
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
See **[Core Concepts](./genai-lite-docs/core-concepts.md#api-key-management)** for detailed examples including Electron integration.
|
|
161
|
+
|
|
162
|
+
## Logging Configuration
|
|
163
|
+
|
|
164
|
+
Control logging verbosity via environment variable or service options:
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
# Environment variable (applies to all services)
|
|
168
|
+
export GENAI_LITE_LOG_LEVEL=debug # Options: silent, error, warn, info, debug
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
// Per-service configuration
|
|
173
|
+
const llmService = new LLMService(fromEnvironment, {
|
|
174
|
+
logLevel: 'debug', // Override env var
|
|
175
|
+
logger: customPinoLogger // Inject pino/winston/etc.
|
|
176
|
+
});
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
See **[Logging](./genai-lite-docs/logging.md)** for custom logger integration and testing patterns.
|
|
180
|
+
|
|
181
|
+
## Example Applications
|
|
182
|
+
|
|
183
|
+
The library includes two complete demo applications showcasing all features:
|
|
184
|
+
|
|
185
|
+
- **[chat-demo](examples/chat-demo)** - Interactive chat application with all LLM providers, template rendering, and advanced features
|
|
186
|
+
- **[image-gen-demo](examples/image-gen-demo)** - Interactive image generation UI with OpenAI and local diffusion support
|
|
187
|
+
|
|
188
|
+
Both demos are production-ready React + Express applications that serve as reference implementations and testing environments. See **[Example: Chat Demo](./genai-lite-docs/example-chat-demo.md)** and **[Example: Image Demo](./genai-lite-docs/example-image-demo.md)** for detailed documentation.
|
|
189
|
+
|
|
190
|
+
## Contributing
|
|
191
|
+
|
|
192
|
+
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
|
|
193
|
+
|
|
194
|
+
### Development
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
npm install
|
|
198
|
+
npm run build
|
|
199
|
+
npm test
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
See **[Troubleshooting](./genai-lite-docs/troubleshooting.md)** for information about E2E tests and development workflows.
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
|
|
206
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
207
|
+
|
|
208
|
+
## Acknowledgments
|
|
209
|
+
|
|
210
|
+
Originally developed as part of the Athanor project, genai-lite has been extracted and made standalone to benefit the wider developer community.
|
|
@@ -24,6 +24,7 @@ export declare class GenaiElectronImageAdapter implements ImageProviderAdapter {
|
|
|
24
24
|
private baseURL;
|
|
25
25
|
private timeout;
|
|
26
26
|
private pollInterval;
|
|
27
|
+
private logger;
|
|
27
28
|
constructor(config?: ImageProviderAdapterConfig);
|
|
28
29
|
/**
|
|
29
30
|
* Generates images using genai-electron's async API with progress polling
|
|
@@ -19,7 +19,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
19
19
|
exports.GenaiElectronImageAdapter = void 0;
|
|
20
20
|
const errorUtils_1 = require("../../shared/adapters/errorUtils");
|
|
21
21
|
const defaultLogger_1 = require("../../logging/defaultLogger");
|
|
22
|
-
const logger = (0, defaultLogger_1.createDefaultLogger)();
|
|
23
22
|
/**
|
|
24
23
|
* Adapter for genai-electron's local diffusion image generation
|
|
25
24
|
*/
|
|
@@ -37,6 +36,7 @@ class GenaiElectronImageAdapter {
|
|
|
37
36
|
this.baseURL = config?.baseURL || 'http://localhost:8081';
|
|
38
37
|
this.timeout = config?.timeout || 120000; // 120 seconds for diffusion
|
|
39
38
|
this.pollInterval = 500; // Poll every 500ms
|
|
39
|
+
this.logger = config?.logger ?? (0, defaultLogger_1.createDefaultLogger)();
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* Generates images using genai-electron's async API with progress polling
|
|
@@ -46,7 +46,7 @@ class GenaiElectronImageAdapter {
|
|
|
46
46
|
try {
|
|
47
47
|
// Build request payload
|
|
48
48
|
const payload = this.buildRequestPayload(resolvedPrompt, request, settings);
|
|
49
|
-
logger.debug(`GenaiElectron Image API: Starting generation`, {
|
|
49
|
+
this.logger.debug(`GenaiElectron Image API: Starting generation`, {
|
|
50
50
|
prompt: resolvedPrompt.substring(0, 100),
|
|
51
51
|
count: payload.count,
|
|
52
52
|
dimensions: `${payload.width}x${payload.height}`,
|
|
@@ -54,15 +54,15 @@ class GenaiElectronImageAdapter {
|
|
|
54
54
|
});
|
|
55
55
|
// Start generation (returns immediately with ID)
|
|
56
56
|
const generationId = await this.startGeneration(payload);
|
|
57
|
-
logger.info(`GenaiElectron Image API: Generation started with ID: ${generationId}`);
|
|
57
|
+
this.logger.info(`GenaiElectron Image API: Generation started with ID: ${generationId}`);
|
|
58
58
|
// Poll for completion
|
|
59
59
|
const result = await this.pollForCompletion(generationId, settings.diffusion?.onProgress);
|
|
60
|
-
logger.info(`GenaiElectron Image API: Generation complete (${result.timeTaken}ms)`);
|
|
60
|
+
this.logger.info(`GenaiElectron Image API: Generation complete (${result.timeTaken}ms)`);
|
|
61
61
|
// Convert to ImageGenerationResponse
|
|
62
62
|
return this.convertToResponse(result, request);
|
|
63
63
|
}
|
|
64
64
|
catch (error) {
|
|
65
|
-
logger.error('GenaiElectron Image API error:', error);
|
|
65
|
+
this.logger.error('GenaiElectron Image API error:', error);
|
|
66
66
|
throw this.handleError(error, request);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
@@ -21,6 +21,7 @@ export declare class OpenAIImageAdapter implements ImageProviderAdapter {
|
|
|
21
21
|
readonly supports: ImageProviderCapabilities;
|
|
22
22
|
private baseURL?;
|
|
23
23
|
private timeout;
|
|
24
|
+
private logger;
|
|
24
25
|
constructor(config?: ImageProviderAdapterConfig);
|
|
25
26
|
/**
|
|
26
27
|
* Validates OpenAI API key format
|
|
@@ -21,7 +21,6 @@ exports.OpenAIImageAdapter = void 0;
|
|
|
21
21
|
const openai_1 = __importDefault(require("openai"));
|
|
22
22
|
const errorUtils_1 = require("../../shared/adapters/errorUtils");
|
|
23
23
|
const defaultLogger_1 = require("../../logging/defaultLogger");
|
|
24
|
-
const logger = (0, defaultLogger_1.createDefaultLogger)();
|
|
25
24
|
/**
|
|
26
25
|
* Prompt length limits per model
|
|
27
26
|
*/
|
|
@@ -47,6 +46,7 @@ class OpenAIImageAdapter {
|
|
|
47
46
|
};
|
|
48
47
|
this.baseURL = config?.baseURL;
|
|
49
48
|
this.timeout = config?.timeout || 60000;
|
|
49
|
+
this.logger = config?.logger ?? (0, defaultLogger_1.createDefaultLogger)();
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* Validates OpenAI API key format
|
|
@@ -96,7 +96,7 @@ class OpenAIImageAdapter {
|
|
|
96
96
|
// dall-e-2/dall-e-3: use traditional parameters
|
|
97
97
|
this.addDalleParams(params, settings);
|
|
98
98
|
}
|
|
99
|
-
logger.debug(`OpenAI Image API call for model: ${request.modelId}`, {
|
|
99
|
+
this.logger.debug(`OpenAI Image API call for model: ${request.modelId}`, {
|
|
100
100
|
model: params.model,
|
|
101
101
|
promptLength: resolvedPrompt.length,
|
|
102
102
|
n: params.n,
|
|
@@ -107,12 +107,12 @@ class OpenAIImageAdapter {
|
|
|
107
107
|
if (!response.data || response.data.length === 0) {
|
|
108
108
|
throw new Error('OpenAI API returned no images in response');
|
|
109
109
|
}
|
|
110
|
-
logger.info(`OpenAI Image API call successful, generated ${response.data.length} images`);
|
|
110
|
+
this.logger.info(`OpenAI Image API call successful, generated ${response.data.length} images`);
|
|
111
111
|
// Process response
|
|
112
112
|
return await this.processResponse(response, request, isGptImageModel);
|
|
113
113
|
}
|
|
114
114
|
catch (error) {
|
|
115
|
-
logger.error('OpenAI Image API error:', error);
|
|
115
|
+
this.logger.error('OpenAI Image API error:', error);
|
|
116
116
|
throw this.handleError(error, request);
|
|
117
117
|
}
|
|
118
118
|
}
|
|
@@ -1,4 +1,28 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"id": "llamacpp-local-default",
|
|
4
|
+
"displayName": "llama.cpp - Local Model",
|
|
5
|
+
"description": "Local GGUF model via llama.cpp server. Vendor sampling defaults and thinking-off are applied automatically for recognized models (Qwen 3.x, Gemma 3/4, GPT-OSS, Ministral 3, Granite 4.1, ...).",
|
|
6
|
+
"providerId": "llamacpp",
|
|
7
|
+
"modelId": "llamacpp",
|
|
8
|
+
"settings": {
|
|
9
|
+
"reasoning": {
|
|
10
|
+
"enabled": false
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"id": "llamacpp-local-thinking",
|
|
16
|
+
"displayName": "llama.cpp - Local Model (Thinking)",
|
|
17
|
+
"description": "Local GGUF model with reasoning/thinking enabled. For hybrid models (Qwen 3.5/3.6, Gemma 4) this sends enable_thinking=true; the reasoning trace is returned on choice.reasoning.",
|
|
18
|
+
"providerId": "llamacpp",
|
|
19
|
+
"modelId": "llamacpp",
|
|
20
|
+
"settings": {
|
|
21
|
+
"reasoning": {
|
|
22
|
+
"enabled": true
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
2
26
|
{
|
|
3
27
|
"id": "anthropic-claude-opus-4-5-20251101-default",
|
|
4
28
|
"displayName": "Anthropic - Claude Opus 4.5",
|
|
@@ -44,6 +44,7 @@ class ImageService {
|
|
|
44
44
|
this.adapterRegistry.registerAdapter('openai-images', new OpenAIImageAdapter_1.OpenAIImageAdapter({
|
|
45
45
|
baseURL: openaiBaseURL,
|
|
46
46
|
timeout: openaiConfig.timeout,
|
|
47
|
+
logger: this.logger,
|
|
47
48
|
}));
|
|
48
49
|
// Register genai-electron-images adapter
|
|
49
50
|
const electronConfig = config_1.IMAGE_ADAPTER_CONFIGS['genai-electron-images'];
|
|
@@ -51,6 +52,7 @@ class ImageService {
|
|
|
51
52
|
this.adapterRegistry.registerAdapter('genai-electron-images', new GenaiElectronImageAdapter_1.GenaiElectronImageAdapter({
|
|
52
53
|
baseURL: electronBaseURL,
|
|
53
54
|
timeout: electronConfig.timeout,
|
|
55
|
+
logger: this.logger,
|
|
54
56
|
}));
|
|
55
57
|
// Register custom adapters if provided
|
|
56
58
|
if (options.adapters) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export type { ApiKeyProvider, PresetMode } from "./types";
|
|
2
2
|
export { LLMService } from "./llm/LLMService";
|
|
3
|
-
export type { LLMServiceOptions, CreateMessagesResult } from "./llm/LLMService";
|
|
3
|
+
export type { LLMServiceOptions, SendMessageOptions, CreateMessagesResult } from "./llm/LLMService";
|
|
4
|
+
export { withRetry, DEFAULT_RETRY_POLICY } from "./shared/services/withRetry";
|
|
5
|
+
export type { RetryPolicy, RetryVerdict, WithRetryOptions } from "./shared/services/withRetry";
|
|
4
6
|
export type { ModelPreset } from "./types/presets";
|
|
5
7
|
export * from "./llm/types";
|
|
6
8
|
export * from "./llm/clients/types";
|
|
@@ -17,7 +19,7 @@ export { ImageService } from "./image/ImageService";
|
|
|
17
19
|
export type { ImageProviderId, ImageMimeType, ImageResponseFormat, ImageQuality, ImageStyle, DiffusionSampler, ImageProgressStage, ImageProgressCallback, DiffusionSettings, OpenAISpecificSettings, ImageGenerationSettings, ResolvedImageGenerationSettings, ImageUsage, GeneratedImage, ImageGenerationRequestBase, ImageGenerationRequest, ImageGenerationRequestWithPreset, ImageGenerationResponse, ImageFailureResponse, ImageProviderCapabilities, ImageModelInfo, ImageProviderInfo, ImagePreset, ImageProviderAdapterConfig, ImageProviderAdapter, ImageServiceOptions, CreatePromptResult, } from "./types/image";
|
|
18
20
|
export { renderTemplate } from "./prompting/template";
|
|
19
21
|
export { countTokens, getSmartPreview, extractRandomVariables } from "./prompting/content";
|
|
20
|
-
export { parseStructuredContent, parseRoleTags, extractInitialTaggedContent, parseTemplateWithMetadata } from "./prompting/parser";
|
|
22
|
+
export { parseStructuredContent, parseRoleTags, extractInitialTaggedContent, extractMarkerDelimitedContent, parseTemplateWithMetadata } from "./prompting/parser";
|
|
21
23
|
export type { TemplateMetadata } from "./prompting/parser";
|
|
22
24
|
export { createFallbackModelInfo, detectGgufCapabilities, KNOWN_GGUF_MODELS } from "./llm/config";
|
|
23
25
|
export type { GgufModelPattern } from "./llm/config";
|