genai-lite 0.8.3 β 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/config/llm-presets.json +24 -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 +42 -4
- package/dist/llm/clients/AnthropicClientAdapter.d.ts +2 -2
- package/dist/llm/clients/AnthropicClientAdapter.js +17 -3
- package/dist/llm/clients/GeminiClientAdapter.d.ts +2 -2
- package/dist/llm/clients/GeminiClientAdapter.js +14 -3
- package/dist/llm/clients/LlamaCppClientAdapter.d.ts +4 -4
- package/dist/llm/clients/LlamaCppClientAdapter.js +118 -15
- package/dist/llm/clients/MistralClientAdapter.d.ts +2 -2
- package/dist/llm/clients/MistralClientAdapter.js +15 -4
- package/dist/llm/clients/MockClientAdapter.d.ts +2 -2
- package/dist/llm/clients/MockClientAdapter.js +36 -19
- package/dist/llm/clients/OpenAIClientAdapter.d.ts +2 -2
- package/dist/llm/clients/OpenAIClientAdapter.js +26 -3
- package/dist/llm/clients/OpenRouterClientAdapter.d.ts +2 -2
- package/dist/llm/clients/OpenRouterClientAdapter.js +81 -10
- 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/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/withRetry.d.ts +50 -0
- package/dist/shared/services/withRetry.js +78 -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.
|
|
@@ -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",
|
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";
|
package/dist/index.js
CHANGED
|
@@ -14,10 +14,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.silentLogger = exports.DEFAULT_LOG_LEVEL = exports.createDefaultLogger = exports.KNOWN_GGUF_MODELS = exports.detectGgufCapabilities = exports.createFallbackModelInfo = exports.parseTemplateWithMetadata = exports.extractInitialTaggedContent = exports.parseRoleTags = exports.parseStructuredContent = exports.extractRandomVariables = exports.getSmartPreview = exports.countTokens = exports.renderTemplate = exports.ImageService = exports.MistralClientAdapter = exports.OpenRouterClientAdapter = exports.LlamaCppServerClient = exports.LlamaCppClientAdapter = exports.fromEnvironment = exports.LLMService = void 0;
|
|
17
|
+
exports.silentLogger = exports.DEFAULT_LOG_LEVEL = exports.createDefaultLogger = exports.KNOWN_GGUF_MODELS = exports.detectGgufCapabilities = exports.createFallbackModelInfo = exports.parseTemplateWithMetadata = exports.extractMarkerDelimitedContent = exports.extractInitialTaggedContent = exports.parseRoleTags = exports.parseStructuredContent = exports.extractRandomVariables = exports.getSmartPreview = exports.countTokens = exports.renderTemplate = exports.ImageService = exports.MistralClientAdapter = exports.OpenRouterClientAdapter = exports.LlamaCppServerClient = exports.LlamaCppClientAdapter = exports.fromEnvironment = exports.DEFAULT_RETRY_POLICY = exports.withRetry = exports.LLMService = void 0;
|
|
18
18
|
// --- LLM Service ---
|
|
19
19
|
var LLMService_1 = require("./llm/LLMService");
|
|
20
20
|
Object.defineProperty(exports, "LLMService", { enumerable: true, get: function () { return LLMService_1.LLMService; } });
|
|
21
|
+
// --- Retry Utilities ---
|
|
22
|
+
var withRetry_1 = require("./shared/services/withRetry");
|
|
23
|
+
Object.defineProperty(exports, "withRetry", { enumerable: true, get: function () { return withRetry_1.withRetry; } });
|
|
24
|
+
Object.defineProperty(exports, "DEFAULT_RETRY_POLICY", { enumerable: true, get: function () { return withRetry_1.DEFAULT_RETRY_POLICY; } });
|
|
21
25
|
// Export all core request/response/config types from the LLM module
|
|
22
26
|
__exportStar(require("./llm/types"), exports);
|
|
23
27
|
// Export all client adapter types
|
|
@@ -51,6 +55,7 @@ var parser_1 = require("./prompting/parser");
|
|
|
51
55
|
Object.defineProperty(exports, "parseStructuredContent", { enumerable: true, get: function () { return parser_1.parseStructuredContent; } });
|
|
52
56
|
Object.defineProperty(exports, "parseRoleTags", { enumerable: true, get: function () { return parser_1.parseRoleTags; } });
|
|
53
57
|
Object.defineProperty(exports, "extractInitialTaggedContent", { enumerable: true, get: function () { return parser_1.extractInitialTaggedContent; } });
|
|
58
|
+
Object.defineProperty(exports, "extractMarkerDelimitedContent", { enumerable: true, get: function () { return parser_1.extractMarkerDelimitedContent; } });
|
|
54
59
|
Object.defineProperty(exports, "parseTemplateWithMetadata", { enumerable: true, get: function () { return parser_1.parseTemplateWithMetadata; } });
|
|
55
60
|
var config_1 = require("./llm/config");
|
|
56
61
|
Object.defineProperty(exports, "createFallbackModelInfo", { enumerable: true, get: function () { return config_1.createFallbackModelInfo; } });
|
package/dist/llm/LLMService.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { ApiKeyProvider, PresetMode } from '../types';
|
|
|
2
2
|
import type { Logger, LogLevel } from '../logging/types';
|
|
3
3
|
import type { LLMChatRequest, LLMChatRequestWithPreset, LLMResponse, LLMFailureResponse, ProviderInfo, ModelInfo, ApiProviderId, LLMSettings, ModelContext, LLMMessage } from "./types";
|
|
4
4
|
import type { ModelPreset } from "../types/presets";
|
|
5
|
+
import { type RetryPolicy } from "../shared/services/withRetry";
|
|
5
6
|
export type { PresetMode };
|
|
6
7
|
/**
|
|
7
8
|
* Options for configuring the LLMService
|
|
@@ -15,6 +16,32 @@ export interface LLMServiceOptions {
|
|
|
15
16
|
logLevel?: LogLevel;
|
|
16
17
|
/** Custom logger implementation. If provided, logLevel is ignored. */
|
|
17
18
|
logger?: Logger;
|
|
19
|
+
/**
|
|
20
|
+
* Retry policy for transient failures (rate limits, 5xx, network errors, timeouts).
|
|
21
|
+
* Defaults: maxRetries 2, initialDelayMs 500, maxDelayMs 10000, backoffFactor 2,
|
|
22
|
+
* retryOnTimeout true. Provider SDK-internal retries are disabled β this layer
|
|
23
|
+
* is the single owner of retry behavior. Set `maxRetries: 0` to disable.
|
|
24
|
+
*/
|
|
25
|
+
retry?: Partial<RetryPolicy> & {
|
|
26
|
+
/** Whether REQUEST_TIMEOUT failures are retryable (default true) */
|
|
27
|
+
retryOnTimeout?: boolean;
|
|
28
|
+
};
|
|
29
|
+
/** Default per-request timeout in ms (overridable per call). SDK defaults apply when unset. */
|
|
30
|
+
timeoutMs?: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Per-call options for LLMService.sendMessage
|
|
34
|
+
*/
|
|
35
|
+
export interface SendMessageOptions {
|
|
36
|
+
/**
|
|
37
|
+
* Abort signal to cancel the request (client-side β the provider may still
|
|
38
|
+
* process and bill an already-dispatched request). Aborts are never retried.
|
|
39
|
+
*/
|
|
40
|
+
signal?: AbortSignal;
|
|
41
|
+
/** Per-request timeout in ms (overrides the service-level timeoutMs) */
|
|
42
|
+
timeoutMs?: number;
|
|
43
|
+
/** Per-request retry cap (overrides the service-level retry.maxRetries) */
|
|
44
|
+
maxRetries?: number;
|
|
18
45
|
}
|
|
19
46
|
/**
|
|
20
47
|
* Result from createMessages method
|
|
@@ -46,6 +73,8 @@ export declare class LLMService {
|
|
|
46
73
|
private requestValidator;
|
|
47
74
|
private settingsManager;
|
|
48
75
|
private modelResolver;
|
|
76
|
+
private retryOptions;
|
|
77
|
+
private defaultTimeoutMs?;
|
|
49
78
|
constructor(getApiKey: ApiKeyProvider, options?: LLMServiceOptions);
|
|
50
79
|
/**
|
|
51
80
|
* Gets list of supported LLM providers
|
|
@@ -66,7 +95,7 @@ export declare class LLMService {
|
|
|
66
95
|
* @param request - The LLM chat request
|
|
67
96
|
* @returns Promise resolving to either success or failure response
|
|
68
97
|
*/
|
|
69
|
-
sendMessage(request: LLMChatRequest | LLMChatRequestWithPreset): Promise<LLMResponse | LLMFailureResponse>;
|
|
98
|
+
sendMessage(request: LLMChatRequest | LLMChatRequestWithPreset, callOptions?: SendMessageOptions): Promise<LLMResponse | LLMFailureResponse>;
|
|
70
99
|
/**
|
|
71
100
|
* Gets all configured model presets
|
|
72
101
|
*
|