genai-lite 0.1.0 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +194 -1
- package/dist/config/presets.json +222 -0
- package/dist/index.d.ts +2 -0
- package/dist/llm/LLMService.d.ts +25 -1
- package/dist/llm/LLMService.js +34 -1
- package/dist/llm/LLMService.presets.test.d.ts +1 -0
- package/dist/llm/LLMService.presets.test.js +210 -0
- package/dist/llm/LLMService.test.d.ts +1 -0
- package/dist/llm/LLMService.test.js +279 -0
- package/dist/llm/clients/AnthropicClientAdapter.test.d.ts +1 -0
- package/dist/llm/clients/AnthropicClientAdapter.test.js +263 -0
- package/dist/llm/clients/GeminiClientAdapter.test.d.ts +1 -0
- package/dist/llm/clients/GeminiClientAdapter.test.js +281 -0
- package/dist/llm/clients/MockClientAdapter.test.d.ts +1 -0
- package/dist/llm/clients/MockClientAdapter.test.js +240 -0
- package/dist/llm/clients/OpenAIClientAdapter.test.d.ts +1 -0
- package/dist/llm/clients/OpenAIClientAdapter.test.js +248 -0
- package/dist/llm/clients/adapterErrorUtils.test.d.ts +1 -0
- package/dist/llm/clients/adapterErrorUtils.test.js +123 -0
- package/dist/llm/config.test.d.ts +1 -0
- package/dist/llm/config.test.js +159 -0
- package/dist/providers/fromEnvironment.test.d.ts +1 -0
- package/dist/providers/fromEnvironment.test.js +46 -0
- package/dist/types/presets.d.ts +19 -0
- package/dist/types/presets.js +2 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +17 -0
- package/dist/utils/prompt.d.ts +6 -0
- package/dist/utils/prompt.js +55 -0
- package/dist/utils/prompt.test.d.ts +1 -0
- package/dist/utils/prompt.test.js +115 -0
- package/package.json +22 -4
- package/src/config/presets.json +222 -0
package/README.md
CHANGED
|
@@ -10,6 +10,7 @@ A lightweight, portable Node.js/TypeScript library providing a unified interface
|
|
|
10
10
|
- 🎯 **TypeScript First** - Full type safety and IntelliSense support
|
|
11
11
|
- ⚡ **Lightweight** - Minimal dependencies, focused functionality
|
|
12
12
|
- 🛡️ **Provider Normalization** - Consistent responses across different AI APIs
|
|
13
|
+
- 🎨 **Configurable Model Presets** - Built-in presets with full customization options
|
|
13
14
|
|
|
14
15
|
## Installation
|
|
15
16
|
|
|
@@ -135,6 +136,80 @@ const providers = await llmService.getProviders();
|
|
|
135
136
|
|
|
136
137
|
// Get models for a specific provider
|
|
137
138
|
const models = await llmService.getModels('anthropic');
|
|
139
|
+
|
|
140
|
+
// Get configured model presets
|
|
141
|
+
const presets = llmService.getPresets();
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Model Presets
|
|
145
|
+
|
|
146
|
+
genai-lite includes a built-in set of model presets for common use cases. You can use these defaults, extend them with your own, or replace them entirely.
|
|
147
|
+
|
|
148
|
+
#### Using Default Presets
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
const llmService = new LLMService(fromEnvironment);
|
|
152
|
+
|
|
153
|
+
// Get all default presets
|
|
154
|
+
const presets = llmService.getPresets();
|
|
155
|
+
// Returns presets like:
|
|
156
|
+
// - anthropic-claude-3-5-sonnet-20241022-default
|
|
157
|
+
// - openai-gpt-4.1-default
|
|
158
|
+
// - google-gemini-2.5-pro
|
|
159
|
+
// ... and more
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
#### Extending Default Presets
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
import { LLMService, fromEnvironment, ModelPreset } from 'genai-lite';
|
|
166
|
+
|
|
167
|
+
const customPresets: ModelPreset[] = [
|
|
168
|
+
{
|
|
169
|
+
id: 'my-creative-preset',
|
|
170
|
+
displayName: 'Creative Writing Assistant',
|
|
171
|
+
providerId: 'openai',
|
|
172
|
+
modelId: 'gpt-4.1',
|
|
173
|
+
settings: {
|
|
174
|
+
temperature: 0.9,
|
|
175
|
+
maxTokens: 2000,
|
|
176
|
+
topP: 0.95
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
];
|
|
180
|
+
|
|
181
|
+
const llmService = new LLMService(fromEnvironment, {
|
|
182
|
+
presets: customPresets,
|
|
183
|
+
presetMode: 'extend' // Default behavior - adds to existing presets
|
|
184
|
+
});
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
#### Replacing Default Presets
|
|
188
|
+
|
|
189
|
+
For applications that need full control over available presets:
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
const applicationPresets: ModelPreset[] = [
|
|
193
|
+
{
|
|
194
|
+
id: 'app-gpt4-default',
|
|
195
|
+
displayName: 'GPT-4 Standard',
|
|
196
|
+
providerId: 'openai',
|
|
197
|
+
modelId: 'gpt-4.1',
|
|
198
|
+
settings: { temperature: 0.7 }
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
id: 'app-claude-creative',
|
|
202
|
+
displayName: 'Claude Creative',
|
|
203
|
+
providerId: 'anthropic',
|
|
204
|
+
modelId: 'claude-3-5-sonnet-20241022',
|
|
205
|
+
settings: { temperature: 0.8, maxTokens: 4000 }
|
|
206
|
+
}
|
|
207
|
+
];
|
|
208
|
+
|
|
209
|
+
const llmService = new LLMService(fromEnvironment, {
|
|
210
|
+
presets: applicationPresets,
|
|
211
|
+
presetMode: 'replace' // Use ONLY these presets, ignore defaults
|
|
212
|
+
});
|
|
138
213
|
```
|
|
139
214
|
|
|
140
215
|
### Error Handling
|
|
@@ -211,10 +286,108 @@ import type {
|
|
|
211
286
|
LLMResponse,
|
|
212
287
|
LLMFailureResponse,
|
|
213
288
|
LLMSettings,
|
|
214
|
-
ApiKeyProvider
|
|
289
|
+
ApiKeyProvider,
|
|
290
|
+
ModelPreset,
|
|
291
|
+
LLMServiceOptions,
|
|
292
|
+
PresetMode
|
|
215
293
|
} from 'genai-lite';
|
|
216
294
|
```
|
|
217
295
|
|
|
296
|
+
## Utilities
|
|
297
|
+
|
|
298
|
+
genai-lite includes useful utilities for working with LLMs, available through the `genai-lite/utils` subpath:
|
|
299
|
+
|
|
300
|
+
### Token Counting
|
|
301
|
+
|
|
302
|
+
Count the number of tokens in a string using OpenAI's tiktoken library:
|
|
303
|
+
|
|
304
|
+
```typescript
|
|
305
|
+
import { countTokens } from 'genai-lite/utils';
|
|
306
|
+
|
|
307
|
+
const text = 'Hello, this is a sample text for token counting.';
|
|
308
|
+
const tokenCount = countTokens(text); // Uses gpt-4 tokenizer by default
|
|
309
|
+
console.log(`Token count: ${tokenCount}`);
|
|
310
|
+
|
|
311
|
+
// Specify a different model's tokenizer
|
|
312
|
+
const gpt35Tokens = countTokens(text, 'gpt-3.5-turbo');
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
**Note:** The `countTokens` function uses the `js-tiktoken` library and supports all models that have tiktoken encodings.
|
|
316
|
+
|
|
317
|
+
### Smart Text Preview
|
|
318
|
+
|
|
319
|
+
Generate intelligent previews of large text blocks that preserve context:
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
import { getSmartPreview } from 'genai-lite/utils';
|
|
323
|
+
|
|
324
|
+
const largeCodeFile = `
|
|
325
|
+
function calculateTotal(items) {
|
|
326
|
+
let total = 0;
|
|
327
|
+
|
|
328
|
+
for (const item of items) {
|
|
329
|
+
total += item.price * item.quantity;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return total;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function applyDiscount(total, discountPercent) {
|
|
336
|
+
return total * (1 - discountPercent / 100);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// ... many more lines of code ...
|
|
340
|
+
`;
|
|
341
|
+
|
|
342
|
+
// Get a preview that shows at least 5 lines but extends to a logical break point
|
|
343
|
+
const preview = getSmartPreview(largeCodeFile, {
|
|
344
|
+
minLines: 5,
|
|
345
|
+
maxLines: 10
|
|
346
|
+
});
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
The `getSmartPreview` function intelligently truncates text:
|
|
350
|
+
- Returns the full content if it's shorter than `maxLines`
|
|
351
|
+
- Shows at least `minLines` of content
|
|
352
|
+
- Extends to the next blank line (up to `maxLines`) to avoid cutting off in the middle of a code block or paragraph
|
|
353
|
+
- Adds `... (content truncated)` when content is truncated
|
|
354
|
+
|
|
355
|
+
### Example: Building Token-Aware Prompts
|
|
356
|
+
|
|
357
|
+
Combine these utilities to build prompts that fit within model context windows:
|
|
358
|
+
|
|
359
|
+
```typescript
|
|
360
|
+
import { LLMService, fromEnvironment } from 'genai-lite';
|
|
361
|
+
import { countTokens, getSmartPreview } from 'genai-lite/utils';
|
|
362
|
+
|
|
363
|
+
const llm = new LLMService(fromEnvironment);
|
|
364
|
+
|
|
365
|
+
// Large source file
|
|
366
|
+
const sourceCode = await fs.readFile('large-file.js', 'utf-8');
|
|
367
|
+
|
|
368
|
+
// Get a smart preview that fits within token budget
|
|
369
|
+
let preview = getSmartPreview(sourceCode, { minLines: 20, maxLines: 50 });
|
|
370
|
+
let tokenCount = countTokens(preview, 'gpt-4.1-mini');
|
|
371
|
+
|
|
372
|
+
// Adjust preview if needed to fit token budget
|
|
373
|
+
const maxTokens = 4000;
|
|
374
|
+
if (tokenCount > maxTokens) {
|
|
375
|
+
preview = getSmartPreview(sourceCode, { minLines: 10, maxLines: 30 });
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// Send to LLM
|
|
379
|
+
const response = await llm.sendMessage({
|
|
380
|
+
providerId: 'openai',
|
|
381
|
+
modelId: 'gpt-4.1-mini',
|
|
382
|
+
messages: [
|
|
383
|
+
{
|
|
384
|
+
role: 'user',
|
|
385
|
+
content: `Analyze this code:\n\n${preview}`
|
|
386
|
+
}
|
|
387
|
+
]
|
|
388
|
+
});
|
|
389
|
+
```
|
|
390
|
+
|
|
218
391
|
## Contributing
|
|
219
392
|
|
|
220
393
|
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.
|
|
@@ -232,6 +405,26 @@ npm run build
|
|
|
232
405
|
npm test
|
|
233
406
|
```
|
|
234
407
|
|
|
408
|
+
### End-to-End Testing
|
|
409
|
+
|
|
410
|
+
The project includes an end-to-end test suite that makes real API calls to providers. These tests are separate from the main unit test suite and are not run in CI by default.
|
|
411
|
+
|
|
412
|
+
To run these tests locally, you must first provide API keys as environment variables with the `E2E_` prefix:
|
|
413
|
+
|
|
414
|
+
```bash
|
|
415
|
+
export E2E_OPENAI_API_KEY="sk-..."
|
|
416
|
+
export E2E_ANTHROPIC_API_KEY="sk-ant-..."
|
|
417
|
+
export E2E_GEMINI_API_KEY="AIza..."
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
Then, run the E2E test script:
|
|
421
|
+
|
|
422
|
+
```bash
|
|
423
|
+
npm run test:e2e
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
The tests will automatically skip any provider for which an API key is not found.
|
|
427
|
+
|
|
235
428
|
## License
|
|
236
429
|
|
|
237
430
|
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "anthropic-claude-sonnet-4-20250514-default",
|
|
4
|
+
"displayName": "Anthropic - Claude Sonnet 4",
|
|
5
|
+
"description": "Default preset for Claude Sonnet 4.",
|
|
6
|
+
"providerId": "anthropic",
|
|
7
|
+
"modelId": "claude-sonnet-4-20250514",
|
|
8
|
+
"settings": {
|
|
9
|
+
"temperature": 0.3
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"id": "anthropic-claude-opus-4-20250514-default",
|
|
14
|
+
"displayName": "Anthropic - Claude Opus 4",
|
|
15
|
+
"description": "Default preset for Claude Opus 4.",
|
|
16
|
+
"providerId": "anthropic",
|
|
17
|
+
"modelId": "claude-opus-4-20250514",
|
|
18
|
+
"settings": {
|
|
19
|
+
"temperature": 0.3
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"id": "anthropic-claude-3-7-sonnet-20250219-default",
|
|
24
|
+
"displayName": "Anthropic - Claude 3.7 Sonnet",
|
|
25
|
+
"description": "Default preset for Claude 3.7 Sonnet.",
|
|
26
|
+
"providerId": "anthropic",
|
|
27
|
+
"modelId": "claude-3-7-sonnet-20250219",
|
|
28
|
+
"settings": {
|
|
29
|
+
"temperature": 0.3
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"id": "anthropic-claude-3-5-sonnet-20241022-default",
|
|
34
|
+
"displayName": "Anthropic - Claude 3.5 Sonnet",
|
|
35
|
+
"description": "Default preset for Claude 3.5 Sonnet.",
|
|
36
|
+
"providerId": "anthropic",
|
|
37
|
+
"modelId": "claude-3-5-sonnet-20241022",
|
|
38
|
+
"settings": {
|
|
39
|
+
"temperature": 0.3
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"id": "anthropic-claude-3-5-haiku-20241022-default",
|
|
44
|
+
"displayName": "Anthropic - Claude 3.5 Haiku",
|
|
45
|
+
"description": "Default preset for Claude 3.5 Haiku.",
|
|
46
|
+
"providerId": "anthropic",
|
|
47
|
+
"modelId": "claude-3-5-haiku-20241022",
|
|
48
|
+
"settings": {
|
|
49
|
+
"temperature": 0.3
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"id": "google-gemini-2.5-pro",
|
|
54
|
+
"displayName": "Google - Gemini 2.5 Pro",
|
|
55
|
+
"description": "Default preset for Gemini 2.5 Pro.",
|
|
56
|
+
"providerId": "gemini",
|
|
57
|
+
"modelId": "gemini-2.5-pro",
|
|
58
|
+
"settings": {
|
|
59
|
+
"temperature": 0.3,
|
|
60
|
+
"geminiSafetySettings": [
|
|
61
|
+
{ "category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE" },
|
|
62
|
+
{
|
|
63
|
+
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
|
64
|
+
"threshold": "BLOCK_NONE"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
|
68
|
+
"threshold": "BLOCK_NONE"
|
|
69
|
+
},
|
|
70
|
+
{ "category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_NONE" }
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"id": "google-gemini-2.5-flash",
|
|
76
|
+
"displayName": "Google - Gemini 2.5 Flash",
|
|
77
|
+
"description": "Default preset for Gemini 2.5 Flash.",
|
|
78
|
+
"providerId": "gemini",
|
|
79
|
+
"modelId": "gemini-2.5-flash",
|
|
80
|
+
"settings": {
|
|
81
|
+
"temperature": 0.3,
|
|
82
|
+
"geminiSafetySettings": [
|
|
83
|
+
{ "category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE" },
|
|
84
|
+
{
|
|
85
|
+
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
|
86
|
+
"threshold": "BLOCK_NONE"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
|
90
|
+
"threshold": "BLOCK_NONE"
|
|
91
|
+
},
|
|
92
|
+
{ "category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_NONE" }
|
|
93
|
+
]
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"id": "google-gemini-2.5-flash-lite-preview",
|
|
98
|
+
"displayName": "Google - Gemini 2.5 Flash-Lite Preview",
|
|
99
|
+
"description": "Default preset for Gemini 2.5 Flash-Lite.",
|
|
100
|
+
"providerId": "gemini",
|
|
101
|
+
"modelId": "gemini-2.5-flash-lite-preview-06-17",
|
|
102
|
+
"settings": {
|
|
103
|
+
"temperature": 0.3,
|
|
104
|
+
"geminiSafetySettings": [
|
|
105
|
+
{ "category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE" },
|
|
106
|
+
{
|
|
107
|
+
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
|
108
|
+
"threshold": "BLOCK_NONE"
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
|
112
|
+
"threshold": "BLOCK_NONE"
|
|
113
|
+
},
|
|
114
|
+
{ "category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_NONE" }
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"id": "google-gemini-2.0-flash-default",
|
|
120
|
+
"displayName": "Google - Gemini 2.0 Flash",
|
|
121
|
+
"description": "Default preset for Gemini 2.0 Flash.",
|
|
122
|
+
"providerId": "gemini",
|
|
123
|
+
"modelId": "gemini-2.0-flash",
|
|
124
|
+
"settings": {
|
|
125
|
+
"temperature": 0.3,
|
|
126
|
+
"geminiSafetySettings": [
|
|
127
|
+
{ "category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE" },
|
|
128
|
+
{
|
|
129
|
+
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
|
130
|
+
"threshold": "BLOCK_NONE"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
|
134
|
+
"threshold": "BLOCK_NONE"
|
|
135
|
+
},
|
|
136
|
+
{ "category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_NONE" }
|
|
137
|
+
]
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
"id": "google-gemini-2.0-flash-lite-default",
|
|
142
|
+
"displayName": "Google - Gemini 2.0 Flash Lite",
|
|
143
|
+
"description": "Default preset for Gemini 2.0 Flash Lite.",
|
|
144
|
+
"providerId": "gemini",
|
|
145
|
+
"modelId": "gemini-2.0-flash-lite",
|
|
146
|
+
"settings": {
|
|
147
|
+
"temperature": 0.3,
|
|
148
|
+
"geminiSafetySettings": [
|
|
149
|
+
{ "category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE" },
|
|
150
|
+
{
|
|
151
|
+
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
|
152
|
+
"threshold": "BLOCK_NONE"
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
|
|
156
|
+
"threshold": "BLOCK_NONE"
|
|
157
|
+
},
|
|
158
|
+
{ "category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_NONE" }
|
|
159
|
+
]
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
"id": "openai-o4-mini-default",
|
|
164
|
+
"displayName": "OpenAI - o4-mini",
|
|
165
|
+
"description": "Default preset for o4-mini.",
|
|
166
|
+
"providerId": "openai",
|
|
167
|
+
"modelId": "o4-mini",
|
|
168
|
+
"settings": {
|
|
169
|
+
"temperature": 1.0
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
"id": "openai-gpt-4.1-default",
|
|
174
|
+
"displayName": "OpenAI - GPT-4.1",
|
|
175
|
+
"description": "Default preset for GPT-4.1.",
|
|
176
|
+
"providerId": "openai",
|
|
177
|
+
"modelId": "gpt-4.1",
|
|
178
|
+
"settings": {
|
|
179
|
+
"temperature": 0.3
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
"id": "openai-gpt-4.1-mini-default",
|
|
184
|
+
"displayName": "OpenAI - GPT-4.1 Mini",
|
|
185
|
+
"description": "Default preset for GPT-4.1 Mini.",
|
|
186
|
+
"providerId": "openai",
|
|
187
|
+
"modelId": "gpt-4.1-mini",
|
|
188
|
+
"settings": {
|
|
189
|
+
"temperature": 0.3
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
"id": "openai-gpt-4.1-nano-default",
|
|
194
|
+
"displayName": "OpenAI - GPT-4.1 Nano",
|
|
195
|
+
"description": "Default preset for GPT-4.1 Nano.",
|
|
196
|
+
"providerId": "openai",
|
|
197
|
+
"modelId": "gpt-4.1-nano",
|
|
198
|
+
"settings": {
|
|
199
|
+
"temperature": 0.3
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
"id": "mistral-codestral-2501-default",
|
|
204
|
+
"displayName": "Mistral AI - Codestral",
|
|
205
|
+
"description": "Default preset for Codestral.",
|
|
206
|
+
"providerId": "mistral",
|
|
207
|
+
"modelId": "codestral-2501",
|
|
208
|
+
"settings": {
|
|
209
|
+
"temperature": 0.3
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
"id": "mistral-devstral-small-2505-default",
|
|
214
|
+
"displayName": "Mistral AI - Devstral Small",
|
|
215
|
+
"description": "Default preset for Devstral Small.",
|
|
216
|
+
"providerId": "mistral",
|
|
217
|
+
"modelId": "devstral-small-2505",
|
|
218
|
+
"settings": {
|
|
219
|
+
"temperature": 0.3
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
]
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export type { ApiKeyProvider } from "./types";
|
|
2
2
|
export { LLMService } from "./llm/LLMService";
|
|
3
|
+
export type { LLMServiceOptions, PresetMode } from "./llm/LLMService";
|
|
4
|
+
export type { ModelPreset } from "./types/presets";
|
|
3
5
|
export * from "./llm/types";
|
|
4
6
|
export * from "./llm/clients/types";
|
|
5
7
|
export { fromEnvironment } from "./providers/fromEnvironment";
|
package/dist/llm/LLMService.d.ts
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import type { ApiKeyProvider } from '../types';
|
|
2
2
|
import type { LLMChatRequest, LLMResponse, LLMFailureResponse, ProviderInfo, ModelInfo, ApiProviderId } from "./types";
|
|
3
3
|
import type { ILLMClientAdapter } from "./clients/types";
|
|
4
|
+
import type { ModelPreset } from "../types/presets";
|
|
5
|
+
/**
|
|
6
|
+
* Defines how custom presets interact with the default presets.
|
|
7
|
+
* 'replace': Use only the custom presets provided. The default set is ignored.
|
|
8
|
+
* 'extend': Use the default presets, and add/override them with the custom presets. This is the default behavior.
|
|
9
|
+
*/
|
|
10
|
+
export type PresetMode = 'replace' | 'extend';
|
|
11
|
+
/**
|
|
12
|
+
* Options for configuring the LLMService
|
|
13
|
+
*/
|
|
14
|
+
export interface LLMServiceOptions {
|
|
15
|
+
/** An array of custom presets to integrate. */
|
|
16
|
+
presets?: ModelPreset[];
|
|
17
|
+
/** The strategy for integrating custom presets. Defaults to 'extend'. */
|
|
18
|
+
presetMode?: PresetMode;
|
|
19
|
+
}
|
|
4
20
|
/**
|
|
5
21
|
* Main process service for LLM operations
|
|
6
22
|
*
|
|
@@ -10,12 +26,14 @@ import type { ILLMClientAdapter } from "./clients/types";
|
|
|
10
26
|
* - Validates requests and applies default settings
|
|
11
27
|
* - Routes requests to appropriate provider adapters
|
|
12
28
|
* - Handles errors and provides standardized responses
|
|
29
|
+
* - Provides configurable model presets for common use cases
|
|
13
30
|
*/
|
|
14
31
|
export declare class LLMService {
|
|
15
32
|
private getApiKey;
|
|
16
33
|
private clientAdapters;
|
|
17
34
|
private mockClientAdapter;
|
|
18
|
-
|
|
35
|
+
private presets;
|
|
36
|
+
constructor(getApiKey: ApiKeyProvider, options?: LLMServiceOptions);
|
|
19
37
|
/**
|
|
20
38
|
* Gets list of supported LLM providers
|
|
21
39
|
*
|
|
@@ -83,4 +101,10 @@ export declare class LLMService {
|
|
|
83
101
|
availableProviders: string[];
|
|
84
102
|
unavailableProviders: string[];
|
|
85
103
|
};
|
|
104
|
+
/**
|
|
105
|
+
* Gets all configured model presets
|
|
106
|
+
*
|
|
107
|
+
* @returns Array of model presets
|
|
108
|
+
*/
|
|
109
|
+
getPresets(): ModelPreset[];
|
|
86
110
|
}
|
package/dist/llm/LLMService.js
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// AI Summary: Main process service for LLM operations, integrating with ApiKeyProvider for secure key access.
|
|
3
3
|
// Orchestrates LLM requests through provider-specific client adapters with proper error handling.
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
4
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
8
|
exports.LLMService = void 0;
|
|
6
9
|
const MockClientAdapter_1 = require("./clients/MockClientAdapter");
|
|
7
10
|
const config_1 = require("./config");
|
|
11
|
+
const presets_json_1 = __importDefault(require("../config/presets.json"));
|
|
8
12
|
/**
|
|
9
13
|
* Main process service for LLM operations
|
|
10
14
|
*
|
|
@@ -14,12 +18,33 @@ const config_1 = require("./config");
|
|
|
14
18
|
* - Validates requests and applies default settings
|
|
15
19
|
* - Routes requests to appropriate provider adapters
|
|
16
20
|
* - Handles errors and provides standardized responses
|
|
21
|
+
* - Provides configurable model presets for common use cases
|
|
17
22
|
*/
|
|
18
23
|
class LLMService {
|
|
19
|
-
constructor(getApiKey) {
|
|
24
|
+
constructor(getApiKey, options = {}) {
|
|
20
25
|
this.getApiKey = getApiKey;
|
|
21
26
|
this.clientAdapters = new Map();
|
|
22
27
|
this.mockClientAdapter = new MockClientAdapter_1.MockClientAdapter();
|
|
28
|
+
// Initialize presets based on mode
|
|
29
|
+
const finalPresets = new Map();
|
|
30
|
+
const customPresets = options.presets || [];
|
|
31
|
+
const mode = options.presetMode || 'extend';
|
|
32
|
+
if (mode === 'replace') {
|
|
33
|
+
// Replace Mode: Only use custom presets.
|
|
34
|
+
for (const preset of customPresets) {
|
|
35
|
+
finalPresets.set(preset.id, preset);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
// Extend Mode: Load defaults first, then add/override.
|
|
40
|
+
for (const preset of presets_json_1.default) {
|
|
41
|
+
finalPresets.set(preset.id, preset);
|
|
42
|
+
}
|
|
43
|
+
for (const preset of customPresets) {
|
|
44
|
+
finalPresets.set(preset.id, preset);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
this.presets = Array.from(finalPresets.values());
|
|
23
48
|
// Dynamically register client adapters based on configuration
|
|
24
49
|
let registeredCount = 0;
|
|
25
50
|
const successfullyRegisteredProviders = [];
|
|
@@ -406,5 +431,13 @@ class LLMService {
|
|
|
406
431
|
unavailableProviders,
|
|
407
432
|
};
|
|
408
433
|
}
|
|
434
|
+
/**
|
|
435
|
+
* Gets all configured model presets
|
|
436
|
+
*
|
|
437
|
+
* @returns Array of model presets
|
|
438
|
+
*/
|
|
439
|
+
getPresets() {
|
|
440
|
+
return [...this.presets]; // Return a copy to prevent external modification
|
|
441
|
+
}
|
|
409
442
|
}
|
|
410
443
|
exports.LLMService = LLMService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|