@ordis-dev/ordis 0.2.0 → 0.4.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/README.md +47 -0
- package/dist/cli.js +20 -4
- package/dist/cli.js.map +1 -1
- package/dist/core/error-formatter.d.ts +35 -0
- package/dist/core/error-formatter.d.ts.map +1 -0
- package/dist/core/error-formatter.js +319 -0
- package/dist/core/error-formatter.js.map +1 -0
- package/dist/core/pipeline.d.ts.map +1 -1
- package/dist/core/pipeline.js +3 -2
- package/dist/core/pipeline.js.map +1 -1
- package/dist/core/types.d.ts +2 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/validator.d.ts +3 -1
- package/dist/core/validator.d.ts.map +1 -1
- package/dist/core/validator.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/llm/client.d.ts.map +1 -1
- package/dist/llm/client.js +23 -3
- package/dist/llm/client.js.map +1 -1
- package/dist/llm/types.d.ts +2 -0
- package/dist/llm/types.d.ts.map +1 -1
- package/dist/schemas/types.d.ts +3 -1
- package/dist/schemas/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/__tests__/api.test.d.ts +0 -5
- package/dist/__tests__/api.test.d.ts.map +0 -1
- package/dist/__tests__/api.test.js +0 -95
- package/dist/__tests__/api.test.js.map +0 -1
- package/dist/__tests__/cli.test.d.ts +0 -6
- package/dist/__tests__/cli.test.d.ts.map +0 -1
- package/dist/__tests__/cli.test.js +0 -103
- package/dist/__tests__/cli.test.js.map +0 -1
- package/dist/cli/__tests__/cli.test.d.ts +0 -5
- package/dist/cli/__tests__/cli.test.d.ts.map +0 -1
- package/dist/cli/__tests__/cli.test.js +0 -13
- package/dist/cli/__tests__/cli.test.js.map +0 -1
- package/dist/core/__tests__/pipeline.test.d.ts +0 -5
- package/dist/core/__tests__/pipeline.test.d.ts.map +0 -1
- package/dist/core/__tests__/pipeline.test.js +0 -334
- package/dist/core/__tests__/pipeline.test.js.map +0 -1
- package/dist/core/__tests__/validator.test.d.ts +0 -5
- package/dist/core/__tests__/validator.test.d.ts.map +0 -1
- package/dist/core/__tests__/validator.test.js +0 -124
- package/dist/core/__tests__/validator.test.js.map +0 -1
- package/dist/llm/__tests__/client.test.d.ts +0 -5
- package/dist/llm/__tests__/client.test.d.ts.map +0 -1
- package/dist/llm/__tests__/client.test.js +0 -350
- package/dist/llm/__tests__/client.test.js.map +0 -1
- package/dist/llm/__tests__/prompt-builder.test.d.ts +0 -5
- package/dist/llm/__tests__/prompt-builder.test.d.ts.map +0 -1
- package/dist/llm/__tests__/prompt-builder.test.js +0 -171
- package/dist/llm/__tests__/prompt-builder.test.js.map +0 -1
- package/dist/llm/__tests__/retry.test.d.ts +0 -5
- package/dist/llm/__tests__/retry.test.d.ts.map +0 -1
- package/dist/llm/__tests__/retry.test.js +0 -350
- package/dist/llm/__tests__/retry.test.js.map +0 -1
- package/dist/llm/__tests__/token-counter.test.d.ts +0 -5
- package/dist/llm/__tests__/token-counter.test.d.ts.map +0 -1
- package/dist/llm/__tests__/token-counter.test.js +0 -166
- package/dist/llm/__tests__/token-counter.test.js.map +0 -1
- package/dist/schemas/__tests__/integration.test.d.ts +0 -5
- package/dist/schemas/__tests__/integration.test.d.ts.map +0 -1
- package/dist/schemas/__tests__/integration.test.js +0 -366
- package/dist/schemas/__tests__/integration.test.js.map +0 -1
- package/dist/schemas/__tests__/loader.test.d.ts +0 -5
- package/dist/schemas/__tests__/loader.test.d.ts.map +0 -1
- package/dist/schemas/__tests__/loader.test.js +0 -271
- package/dist/schemas/__tests__/loader.test.js.map +0 -1
- package/dist/schemas/__tests__/validator.test.d.ts +0 -5
- package/dist/schemas/__tests__/validator.test.d.ts.map +0 -1
- package/dist/schemas/__tests__/validator.test.js +0 -592
- package/dist/schemas/__tests__/validator.test.js.map +0 -1
|
@@ -1,350 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for LLM client
|
|
3
|
-
*/
|
|
4
|
-
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
5
|
-
import { LLMClient, LLMPresets } from '../client.js';
|
|
6
|
-
import { LLMError, LLMErrorCodes } from '../errors.js';
|
|
7
|
-
// Mock fetch globally
|
|
8
|
-
global.fetch = vi.fn();
|
|
9
|
-
describe('LLMClient', () => {
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
vi.clearAllMocks();
|
|
12
|
-
});
|
|
13
|
-
describe('extract', () => {
|
|
14
|
-
it('should extract data successfully', async () => {
|
|
15
|
-
const mockResponse = {
|
|
16
|
-
id: 'test-id',
|
|
17
|
-
object: 'chat.completion',
|
|
18
|
-
created: Date.now(),
|
|
19
|
-
model: 'test-model',
|
|
20
|
-
choices: [
|
|
21
|
-
{
|
|
22
|
-
index: 0,
|
|
23
|
-
message: {
|
|
24
|
-
role: 'assistant',
|
|
25
|
-
content: JSON.stringify({
|
|
26
|
-
data: { name: 'John Doe', age: 30 },
|
|
27
|
-
confidence: 95,
|
|
28
|
-
confidenceByField: { name: 98, age: 92 },
|
|
29
|
-
}),
|
|
30
|
-
},
|
|
31
|
-
finish_reason: 'stop',
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
};
|
|
35
|
-
vi.mocked(fetch).mockResolvedValueOnce({
|
|
36
|
-
ok: true,
|
|
37
|
-
json: async () => mockResponse,
|
|
38
|
-
});
|
|
39
|
-
const client = new LLMClient({
|
|
40
|
-
baseURL: 'http://localhost:11434/v1',
|
|
41
|
-
model: 'llama3',
|
|
42
|
-
});
|
|
43
|
-
const schema = {
|
|
44
|
-
fields: {
|
|
45
|
-
name: { type: 'string' },
|
|
46
|
-
age: { type: 'number' },
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
const result = await client.extract({
|
|
50
|
-
schema,
|
|
51
|
-
input: 'My name is John Doe and I am 30 years old',
|
|
52
|
-
});
|
|
53
|
-
expect(result.data.name).toBe('John Doe');
|
|
54
|
-
expect(result.data.age).toBe(30);
|
|
55
|
-
expect(result.confidence).toBe(95);
|
|
56
|
-
expect(result.confidenceByField.name).toBe(98);
|
|
57
|
-
});
|
|
58
|
-
it('should handle markdown code blocks in response', async () => {
|
|
59
|
-
const mockResponse = {
|
|
60
|
-
id: 'test-id',
|
|
61
|
-
object: 'chat.completion',
|
|
62
|
-
created: Date.now(),
|
|
63
|
-
model: 'test-model',
|
|
64
|
-
choices: [
|
|
65
|
-
{
|
|
66
|
-
index: 0,
|
|
67
|
-
message: {
|
|
68
|
-
role: 'assistant',
|
|
69
|
-
content: '```json\n{"data":{"name":"Alice"},"confidence":90,"confidenceByField":{"name":90}}\n```',
|
|
70
|
-
},
|
|
71
|
-
finish_reason: 'stop',
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
};
|
|
75
|
-
vi.mocked(fetch).mockResolvedValueOnce({
|
|
76
|
-
ok: true,
|
|
77
|
-
json: async () => mockResponse,
|
|
78
|
-
});
|
|
79
|
-
const client = new LLMClient({
|
|
80
|
-
baseURL: 'http://localhost:11434/v1',
|
|
81
|
-
model: 'llama3',
|
|
82
|
-
});
|
|
83
|
-
const schema = {
|
|
84
|
-
fields: {
|
|
85
|
-
name: { type: 'string' },
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
const result = await client.extract({
|
|
89
|
-
schema,
|
|
90
|
-
input: 'Name: Alice',
|
|
91
|
-
});
|
|
92
|
-
expect(result.data.name).toBe('Alice');
|
|
93
|
-
});
|
|
94
|
-
it('should throw on invalid JSON response', async () => {
|
|
95
|
-
const mockResponse = {
|
|
96
|
-
id: 'test-id',
|
|
97
|
-
object: 'chat.completion',
|
|
98
|
-
created: Date.now(),
|
|
99
|
-
model: 'test-model',
|
|
100
|
-
choices: [
|
|
101
|
-
{
|
|
102
|
-
index: 0,
|
|
103
|
-
message: {
|
|
104
|
-
role: 'assistant',
|
|
105
|
-
content: 'This is not JSON',
|
|
106
|
-
},
|
|
107
|
-
finish_reason: 'stop',
|
|
108
|
-
},
|
|
109
|
-
],
|
|
110
|
-
};
|
|
111
|
-
vi.mocked(fetch).mockResolvedValueOnce({
|
|
112
|
-
ok: true,
|
|
113
|
-
json: async () => mockResponse,
|
|
114
|
-
});
|
|
115
|
-
const client = new LLMClient({
|
|
116
|
-
baseURL: 'http://localhost:11434/v1',
|
|
117
|
-
model: 'llama3',
|
|
118
|
-
});
|
|
119
|
-
const schema = {
|
|
120
|
-
fields: {
|
|
121
|
-
name: { type: 'string' },
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
await expect(client.extract({
|
|
125
|
-
schema,
|
|
126
|
-
input: 'test',
|
|
127
|
-
})).rejects.toThrow(LLMError);
|
|
128
|
-
});
|
|
129
|
-
it('should throw on missing data field', async () => {
|
|
130
|
-
const mockResponse = {
|
|
131
|
-
id: 'test-id',
|
|
132
|
-
object: 'chat.completion',
|
|
133
|
-
created: Date.now(),
|
|
134
|
-
model: 'test-model',
|
|
135
|
-
choices: [
|
|
136
|
-
{
|
|
137
|
-
index: 0,
|
|
138
|
-
message: {
|
|
139
|
-
role: 'assistant',
|
|
140
|
-
content: JSON.stringify({
|
|
141
|
-
confidence: 95,
|
|
142
|
-
confidenceByField: {},
|
|
143
|
-
}),
|
|
144
|
-
},
|
|
145
|
-
finish_reason: 'stop',
|
|
146
|
-
},
|
|
147
|
-
],
|
|
148
|
-
};
|
|
149
|
-
vi.mocked(fetch).mockResolvedValueOnce({
|
|
150
|
-
ok: true,
|
|
151
|
-
json: async () => mockResponse,
|
|
152
|
-
});
|
|
153
|
-
const client = new LLMClient({
|
|
154
|
-
baseURL: 'http://localhost:11434/v1',
|
|
155
|
-
model: 'llama3',
|
|
156
|
-
});
|
|
157
|
-
const schema = {
|
|
158
|
-
fields: {
|
|
159
|
-
name: { type: 'string' },
|
|
160
|
-
},
|
|
161
|
-
};
|
|
162
|
-
await expect(client.extract({
|
|
163
|
-
schema,
|
|
164
|
-
input: 'test',
|
|
165
|
-
})).rejects.toThrow('missing data object');
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
describe('error handling', () => {
|
|
169
|
-
it('should handle 401 authentication error', async () => {
|
|
170
|
-
vi.mocked(fetch).mockResolvedValueOnce({
|
|
171
|
-
ok: false,
|
|
172
|
-
status: 401,
|
|
173
|
-
statusText: 'Unauthorized',
|
|
174
|
-
json: async () => ({ error: { message: 'Invalid API key' } }),
|
|
175
|
-
});
|
|
176
|
-
const client = new LLMClient({
|
|
177
|
-
baseURL: 'https://api.openai.com/v1',
|
|
178
|
-
apiKey: 'invalid-key',
|
|
179
|
-
model: 'gpt-4',
|
|
180
|
-
});
|
|
181
|
-
const schema = {
|
|
182
|
-
fields: {
|
|
183
|
-
name: { type: 'string' },
|
|
184
|
-
},
|
|
185
|
-
};
|
|
186
|
-
try {
|
|
187
|
-
await client.extract({ schema, input: 'test' });
|
|
188
|
-
expect.fail('Should have thrown');
|
|
189
|
-
}
|
|
190
|
-
catch (error) {
|
|
191
|
-
expect(error).toBeInstanceOf(LLMError);
|
|
192
|
-
expect(error.code).toBe(LLMErrorCodes.AUTHENTICATION_ERROR);
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
it('should handle 429 rate limit error', async () => {
|
|
196
|
-
// Mock all retries to fail with 429
|
|
197
|
-
vi.mocked(fetch).mockResolvedValue({
|
|
198
|
-
ok: false,
|
|
199
|
-
status: 429,
|
|
200
|
-
statusText: 'Too Many Requests',
|
|
201
|
-
headers: new Headers(),
|
|
202
|
-
json: async () => ({ error: { message: 'Rate limit exceeded' } }),
|
|
203
|
-
});
|
|
204
|
-
const client = new LLMClient({
|
|
205
|
-
baseURL: 'https://api.openai.com/v1',
|
|
206
|
-
apiKey: 'key',
|
|
207
|
-
model: 'gpt-4',
|
|
208
|
-
retries: {
|
|
209
|
-
maxRetries: 2,
|
|
210
|
-
initialDelay: 10,
|
|
211
|
-
maxDelay: 100,
|
|
212
|
-
backoffFactor: 2,
|
|
213
|
-
},
|
|
214
|
-
});
|
|
215
|
-
const schema = {
|
|
216
|
-
fields: {
|
|
217
|
-
name: { type: 'string' },
|
|
218
|
-
},
|
|
219
|
-
};
|
|
220
|
-
try {
|
|
221
|
-
await client.extract({ schema, input: 'test' });
|
|
222
|
-
}
|
|
223
|
-
catch (error) {
|
|
224
|
-
expect(error.code).toBe(LLMErrorCodes.RATE_LIMIT);
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
it('should handle network errors', async () => {
|
|
228
|
-
// Mock all retries to fail with network error
|
|
229
|
-
vi.mocked(fetch).mockRejectedValue(new Error('Network failure'));
|
|
230
|
-
const client = new LLMClient({
|
|
231
|
-
baseURL: 'http://localhost:11434/v1',
|
|
232
|
-
model: 'llama3',
|
|
233
|
-
retries: {
|
|
234
|
-
maxRetries: 2,
|
|
235
|
-
initialDelay: 10,
|
|
236
|
-
maxDelay: 100,
|
|
237
|
-
backoffFactor: 2,
|
|
238
|
-
},
|
|
239
|
-
});
|
|
240
|
-
const schema = {
|
|
241
|
-
fields: {
|
|
242
|
-
name: { type: 'string' },
|
|
243
|
-
},
|
|
244
|
-
};
|
|
245
|
-
try {
|
|
246
|
-
await client.extract({ schema, input: 'test' });
|
|
247
|
-
}
|
|
248
|
-
catch (error) {
|
|
249
|
-
expect(error.code).toBe(LLMErrorCodes.NETWORK_ERROR);
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
describe('LLMPresets', () => {
|
|
254
|
-
it('should create Ollama config', () => {
|
|
255
|
-
const config = LLMPresets.ollama('llama3');
|
|
256
|
-
expect(config.baseURL).toBe('http://localhost:11434/v1');
|
|
257
|
-
expect(config.model).toBe('llama3');
|
|
258
|
-
expect(config.apiKey).toBeUndefined();
|
|
259
|
-
});
|
|
260
|
-
it('should throw TOKEN_LIMIT_EXCEEDED when token budget exceeded', async () => {
|
|
261
|
-
const client = new LLMClient({
|
|
262
|
-
baseURL: 'http://localhost:11434/v1',
|
|
263
|
-
model: 'llama3',
|
|
264
|
-
maxContextTokens: 100, // Very small limit
|
|
265
|
-
});
|
|
266
|
-
const schema = {
|
|
267
|
-
fields: {
|
|
268
|
-
name: { type: 'string' },
|
|
269
|
-
age: { type: 'number' },
|
|
270
|
-
},
|
|
271
|
-
};
|
|
272
|
-
// Large input that will exceed 100 token limit
|
|
273
|
-
const largeInput = 'test '.repeat(200); // ~1000 chars = ~250 tokens
|
|
274
|
-
await expect(client.extract({
|
|
275
|
-
schema,
|
|
276
|
-
input: largeInput,
|
|
277
|
-
})).rejects.toThrow(LLMError);
|
|
278
|
-
try {
|
|
279
|
-
await client.extract({
|
|
280
|
-
schema,
|
|
281
|
-
input: largeInput,
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
catch (error) {
|
|
285
|
-
expect(error).toBeInstanceOf(LLMError);
|
|
286
|
-
expect(error.code).toBe(LLMErrorCodes.TOKEN_LIMIT_EXCEEDED);
|
|
287
|
-
expect(error.message).toContain('Token budget exceeded');
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
it('should succeed when token budget is sufficient', async () => {
|
|
291
|
-
const mockResponse = {
|
|
292
|
-
id: 'test-id',
|
|
293
|
-
object: 'chat.completion',
|
|
294
|
-
created: Date.now(),
|
|
295
|
-
model: 'test-model',
|
|
296
|
-
choices: [
|
|
297
|
-
{
|
|
298
|
-
index: 0,
|
|
299
|
-
message: {
|
|
300
|
-
role: 'assistant',
|
|
301
|
-
content: JSON.stringify({
|
|
302
|
-
data: { name: 'Test' },
|
|
303
|
-
confidence: 90,
|
|
304
|
-
confidenceByField: { name: 90 },
|
|
305
|
-
}),
|
|
306
|
-
},
|
|
307
|
-
finish_reason: 'stop',
|
|
308
|
-
},
|
|
309
|
-
],
|
|
310
|
-
};
|
|
311
|
-
vi.mocked(fetch).mockResolvedValueOnce({
|
|
312
|
-
ok: true,
|
|
313
|
-
json: async () => mockResponse,
|
|
314
|
-
});
|
|
315
|
-
const client = new LLMClient({
|
|
316
|
-
baseURL: 'http://localhost:11434/v1',
|
|
317
|
-
model: 'llama3',
|
|
318
|
-
maxContextTokens: 8192, // Large limit
|
|
319
|
-
});
|
|
320
|
-
const schema = {
|
|
321
|
-
fields: {
|
|
322
|
-
name: { type: 'string' },
|
|
323
|
-
},
|
|
324
|
-
};
|
|
325
|
-
const result = await client.extract({
|
|
326
|
-
schema,
|
|
327
|
-
input: 'Short input',
|
|
328
|
-
});
|
|
329
|
-
expect(result.data.name).toBe('Test');
|
|
330
|
-
});
|
|
331
|
-
it('should create LM Studio config', () => {
|
|
332
|
-
const config = LLMPresets.lmStudio('my-model');
|
|
333
|
-
expect(config.baseURL).toBe('http://localhost:1234/v1');
|
|
334
|
-
expect(config.model).toBe('my-model');
|
|
335
|
-
});
|
|
336
|
-
it('should create OpenAI config', () => {
|
|
337
|
-
const config = LLMPresets.openai('sk-test', 'gpt-4');
|
|
338
|
-
expect(config.baseURL).toBe('https://api.openai.com/v1');
|
|
339
|
-
expect(config.model).toBe('gpt-4');
|
|
340
|
-
expect(config.apiKey).toBe('sk-test');
|
|
341
|
-
});
|
|
342
|
-
it('should create OpenRouter config', () => {
|
|
343
|
-
const config = LLMPresets.openrouter('key', 'openai/gpt-4o-mini');
|
|
344
|
-
expect(config.baseURL).toBe('https://openrouter.ai/api/v1');
|
|
345
|
-
expect(config.model).toBe('openai/gpt-4o-mini');
|
|
346
|
-
expect(config.apiKey).toBe('key');
|
|
347
|
-
});
|
|
348
|
-
});
|
|
349
|
-
});
|
|
350
|
-
//# sourceMappingURL=client.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.test.js","sourceRoot":"","sources":["../../../src/llm/__tests__/client.test.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACrD,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C,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;YAC5D,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;YAChD,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-builder.test.d.ts","sourceRoot":"","sources":["../../../src/llm/__tests__/prompt-builder.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for prompt builder
|
|
3
|
-
*/
|
|
4
|
-
import { describe, it, expect } from 'vitest';
|
|
5
|
-
import { buildSystemPrompt, buildUserPrompt } from '../prompt-builder.js';
|
|
6
|
-
describe('Prompt Builder', () => {
|
|
7
|
-
describe('buildSystemPrompt', () => {
|
|
8
|
-
it('should build basic system prompt', () => {
|
|
9
|
-
const schema = {
|
|
10
|
-
fields: {
|
|
11
|
-
name: { type: 'string' },
|
|
12
|
-
age: { type: 'number' },
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
const prompt = buildSystemPrompt(schema);
|
|
16
|
-
expect(prompt).toContain('data extraction');
|
|
17
|
-
expect(prompt).toContain('name: string');
|
|
18
|
-
expect(prompt).toContain('age: number');
|
|
19
|
-
expect(prompt).toContain('only valid JSON');
|
|
20
|
-
});
|
|
21
|
-
it('should include field descriptions', () => {
|
|
22
|
-
const schema = {
|
|
23
|
-
fields: {
|
|
24
|
-
email: {
|
|
25
|
-
type: 'string',
|
|
26
|
-
description: 'User email address',
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
const prompt = buildSystemPrompt(schema);
|
|
31
|
-
expect(prompt).toContain('User email address');
|
|
32
|
-
});
|
|
33
|
-
it('should mark optional fields', () => {
|
|
34
|
-
const schema = {
|
|
35
|
-
fields: {
|
|
36
|
-
name: { type: 'string' },
|
|
37
|
-
nickname: { type: 'string', optional: true },
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
const prompt = buildSystemPrompt(schema);
|
|
41
|
-
expect(prompt).toContain('nickname: string (optional)');
|
|
42
|
-
});
|
|
43
|
-
it('should include enum values', () => {
|
|
44
|
-
const schema = {
|
|
45
|
-
fields: {
|
|
46
|
-
status: {
|
|
47
|
-
type: 'enum',
|
|
48
|
-
enum: ['active', 'inactive', 'pending'],
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
const prompt = buildSystemPrompt(schema);
|
|
53
|
-
expect(prompt).toContain('active, inactive, pending');
|
|
54
|
-
});
|
|
55
|
-
it('should include number constraints', () => {
|
|
56
|
-
const schema = {
|
|
57
|
-
fields: {
|
|
58
|
-
age: { type: 'number', min: 0, max: 120 },
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
const prompt = buildSystemPrompt(schema);
|
|
62
|
-
expect(prompt).toContain('range: 0 to 120');
|
|
63
|
-
});
|
|
64
|
-
it('should include pattern for strings', () => {
|
|
65
|
-
const schema = {
|
|
66
|
-
fields: {
|
|
67
|
-
zipcode: {
|
|
68
|
-
type: 'string',
|
|
69
|
-
pattern: '^\\d{5}$',
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
const prompt = buildSystemPrompt(schema);
|
|
74
|
-
expect(prompt).toContain('pattern: ^\\d{5}$');
|
|
75
|
-
});
|
|
76
|
-
it('should include confidence requirements', () => {
|
|
77
|
-
const schema = {
|
|
78
|
-
fields: {
|
|
79
|
-
name: { type: 'string' },
|
|
80
|
-
},
|
|
81
|
-
confidence: {
|
|
82
|
-
threshold: 85,
|
|
83
|
-
failOnLowConfidence: true,
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
const prompt = buildSystemPrompt(schema);
|
|
87
|
-
expect(prompt).toContain('threshold: 85%');
|
|
88
|
-
expect(prompt).toContain('confidence score');
|
|
89
|
-
});
|
|
90
|
-
it('should include response format', () => {
|
|
91
|
-
const schema = {
|
|
92
|
-
fields: {
|
|
93
|
-
id: { type: 'string' },
|
|
94
|
-
count: { type: 'number' },
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
const prompt = buildSystemPrompt(schema);
|
|
98
|
-
expect(prompt).toContain('"data"');
|
|
99
|
-
expect(prompt).toContain('"confidence"');
|
|
100
|
-
expect(prompt).toContain('"confidenceByField"');
|
|
101
|
-
});
|
|
102
|
-
it('should NOT include few-shot examples by default', () => {
|
|
103
|
-
const schema = {
|
|
104
|
-
fields: {
|
|
105
|
-
name: { type: 'string' },
|
|
106
|
-
age: { type: 'number' },
|
|
107
|
-
},
|
|
108
|
-
};
|
|
109
|
-
const prompt = buildSystemPrompt(schema);
|
|
110
|
-
expect(prompt).not.toContain('Example extraction:');
|
|
111
|
-
expect(prompt).not.toContain('INV-2024-0042');
|
|
112
|
-
});
|
|
113
|
-
it('should include few-shot examples when explicitly enabled', () => {
|
|
114
|
-
const schema = {
|
|
115
|
-
fields: {
|
|
116
|
-
name: { type: 'string' },
|
|
117
|
-
age: { type: 'number' },
|
|
118
|
-
},
|
|
119
|
-
prompt: {
|
|
120
|
-
includeFewShotExamples: true,
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
const prompt = buildSystemPrompt(schema);
|
|
124
|
-
expect(prompt).toContain('Example extraction:');
|
|
125
|
-
expect(prompt).toContain('Input text:');
|
|
126
|
-
expect(prompt).toContain('Output:');
|
|
127
|
-
});
|
|
128
|
-
it('should include example with null values when enabled', () => {
|
|
129
|
-
const schema = {
|
|
130
|
-
fields: {
|
|
131
|
-
email: { type: 'string' },
|
|
132
|
-
phone: { type: 'string', optional: true },
|
|
133
|
-
},
|
|
134
|
-
prompt: {
|
|
135
|
-
includeFewShotExamples: true,
|
|
136
|
-
},
|
|
137
|
-
};
|
|
138
|
-
const prompt = buildSystemPrompt(schema);
|
|
139
|
-
expect(prompt).toContain('null');
|
|
140
|
-
expect(prompt).toContain('missing or uncertain');
|
|
141
|
-
});
|
|
142
|
-
it('should include invoice example when enabled', () => {
|
|
143
|
-
const schema = {
|
|
144
|
-
fields: {
|
|
145
|
-
invoice_id: { type: 'string' },
|
|
146
|
-
amount: { type: 'number' },
|
|
147
|
-
},
|
|
148
|
-
prompt: {
|
|
149
|
-
includeFewShotExamples: true,
|
|
150
|
-
},
|
|
151
|
-
};
|
|
152
|
-
const prompt = buildSystemPrompt(schema);
|
|
153
|
-
expect(prompt).toContain('INV-2024-0042');
|
|
154
|
-
expect(prompt).toContain('1250.00');
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
describe('buildUserPrompt', () => {
|
|
158
|
-
it('should wrap input text', () => {
|
|
159
|
-
const input = 'Name: John Doe\nAge: 30';
|
|
160
|
-
const prompt = buildUserPrompt(input);
|
|
161
|
-
expect(prompt).toContain('Extract data');
|
|
162
|
-
expect(prompt).toContain(input);
|
|
163
|
-
});
|
|
164
|
-
it('should handle multiline input', () => {
|
|
165
|
-
const input = 'Line 1\nLine 2\nLine 3';
|
|
166
|
-
const prompt = buildUserPrompt(input);
|
|
167
|
-
expect(prompt).toContain(input);
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
//# sourceMappingURL=prompt-builder.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-builder.test.js","sourceRoot":"","sources":["../../../src/llm/__tests__/prompt-builder.test.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG1E,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAA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