@aeye/ai 0.3.9 → 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 +79 -1
- package/dist/ai.d.ts +7 -1
- package/dist/ai.d.ts.map +1 -1
- package/dist/ai.js +50 -77
- package/dist/ai.js.map +1 -1
- package/dist/apis/batch.d.ts +74 -0
- package/dist/apis/batch.d.ts.map +1 -0
- package/dist/apis/batch.js +127 -0
- package/dist/apis/batch.js.map +1 -0
- package/dist/apis/chat.d.ts.map +1 -1
- package/dist/apis/chat.js +55 -35
- package/dist/apis/chat.js.map +1 -1
- package/dist/apis/decide.d.ts +33 -0
- package/dist/apis/decide.d.ts.map +1 -0
- package/dist/apis/decide.js +52 -0
- package/dist/apis/decide.js.map +1 -0
- package/dist/apis/embed.d.ts +4 -11
- package/dist/apis/embed.d.ts.map +1 -1
- package/dist/apis/embed.js +5 -32
- package/dist/apis/embed.js.map +1 -1
- package/dist/apis/get.d.ts +18 -0
- package/dist/apis/get.d.ts.map +1 -0
- package/dist/apis/get.js +30 -0
- package/dist/apis/get.js.map +1 -0
- package/dist/apis/image.d.ts +2 -2
- package/dist/apis/image.d.ts.map +1 -1
- package/dist/apis/image.js +45 -40
- package/dist/apis/image.js.map +1 -1
- package/dist/apis/rerank.d.ts +24 -0
- package/dist/apis/rerank.d.ts.map +1 -0
- package/dist/apis/rerank.js +40 -0
- package/dist/apis/rerank.js.map +1 -0
- package/dist/apis/schema-fallback.d.ts +9 -14
- package/dist/apis/schema-fallback.d.ts.map +1 -1
- package/dist/apis/schema-fallback.js +15 -64
- package/dist/apis/schema-fallback.js.map +1 -1
- package/dist/common.d.ts +20 -2
- package/dist/common.d.ts.map +1 -1
- package/dist/common.js +36 -0
- package/dist/common.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/registry.d.ts +30 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +61 -1
- package/dist/registry.js.map +1 -1
- package/dist/types.d.ts +177 -40
- package/dist/types.d.ts.map +1 -1
- package/package.json +67 -67
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Batch API
|
|
3
|
+
*
|
|
4
|
+
* Runs many chat requests as one batch at the provider: typically half the
|
|
5
|
+
* price of running them one by one, with results within about a day.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const job = await ai.batch.submit(reviews.map(review => ({
|
|
10
|
+
* messages: [{ role: 'user', content: `Classify: ${review}` }],
|
|
11
|
+
* })), {});
|
|
12
|
+
*
|
|
13
|
+
* const done = await ai.batch.wait(job, {});
|
|
14
|
+
* for (const result of done.results ?? []) {
|
|
15
|
+
* console.log(result.response?.content ?? result.error);
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
import { accumulateUsage } from '@aeye/core';
|
|
20
|
+
/**
|
|
21
|
+
* Statuses a batch never leaves.
|
|
22
|
+
*/
|
|
23
|
+
const FINAL = new Set(['completed', 'failed', 'expired', 'cancelled']);
|
|
24
|
+
/**
|
|
25
|
+
* Batch price as a share of the regular price, for providers that don't
|
|
26
|
+
* report a batch's cost: OpenAI and OpenRouter bill batches at half price.
|
|
27
|
+
*/
|
|
28
|
+
const BATCH_PRICE = 0.5;
|
|
29
|
+
/**
|
|
30
|
+
* BatchAPI submits chat requests as provider batches and collects their results.
|
|
31
|
+
*
|
|
32
|
+
* @template T - AIBaseTypes container with all type information
|
|
33
|
+
*/
|
|
34
|
+
export class BatchAPI {
|
|
35
|
+
ai;
|
|
36
|
+
// Completed batches already reported to the afterBatch hook
|
|
37
|
+
reported = new Set();
|
|
38
|
+
constructor(ai) {
|
|
39
|
+
this.ai = ai;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Submit chat requests to run as one batch on one model. The model is
|
|
43
|
+
* selected for the first request, so pin one with `metadata.model` when
|
|
44
|
+
* the requests differ in what they need. The onModelSelected hook runs
|
|
45
|
+
* once, and beforeRequest runs for each request (so budget checks can
|
|
46
|
+
* stop the batch) with the batch price estimate.
|
|
47
|
+
*
|
|
48
|
+
* @param requests - The chat requests, whose results come back in this order.
|
|
49
|
+
* @param ctx - The context.
|
|
50
|
+
*/
|
|
51
|
+
async submit(requests, ctx) {
|
|
52
|
+
const [first] = requests;
|
|
53
|
+
if (!first) {
|
|
54
|
+
throw new Error('A batch needs at least one request');
|
|
55
|
+
}
|
|
56
|
+
const { hooks } = this.ai;
|
|
57
|
+
const fullCtx = await this.ai.buildContext(ctx);
|
|
58
|
+
const found = await this.ai.chat.getModelFor(first, fullCtx, false);
|
|
59
|
+
const selected = found && ((await hooks.onModelSelected?.(fullCtx, first, found)) || found);
|
|
60
|
+
if (!selected?.provider.submitBatch) {
|
|
61
|
+
throw new Error(`No model found that can run a batch${selected ? `: ${selected.model.provider} does not offer batches` : ''}`);
|
|
62
|
+
}
|
|
63
|
+
for (const request of requests) {
|
|
64
|
+
const usage = this.ai.estimateRequestUsage(request);
|
|
65
|
+
await hooks.beforeRequest?.(fullCtx, request, selected, usage, this.ai.calculateCost(selected.model, usage) * BATCH_PRICE);
|
|
66
|
+
}
|
|
67
|
+
// The provider reads the selected model from the context, as for chat
|
|
68
|
+
const providerCtx = { ...fullCtx, metadata: { ...fullCtx.metadata, model: selected.model } };
|
|
69
|
+
return selected.provider.submitBatch(requests, providerCtx, selected.providerConfig);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The batch as it stands now, with results once it completes. The first
|
|
73
|
+
* time this sees a batch completed, it reports the batch's usage and cost
|
|
74
|
+
* to the afterBatch hook.
|
|
75
|
+
*
|
|
76
|
+
* @param job - A batch from `submit`.
|
|
77
|
+
* @param ctx - The context.
|
|
78
|
+
*/
|
|
79
|
+
async get(job, ctx) {
|
|
80
|
+
const provider = this.ai.registry.getProvider(job.provider);
|
|
81
|
+
if (!provider?.getBatch) {
|
|
82
|
+
throw new Error(`Provider "${job.provider}" does not offer batches`);
|
|
83
|
+
}
|
|
84
|
+
const fullCtx = await this.ai.buildContext(ctx);
|
|
85
|
+
const current = await provider.getBatch(job, fullCtx);
|
|
86
|
+
const key = `${current.provider}:${current.id}`;
|
|
87
|
+
if (current.status === 'completed' && current.results && !this.reported.has(key)) {
|
|
88
|
+
this.reported.add(key);
|
|
89
|
+
await this.report(current, fullCtx);
|
|
90
|
+
}
|
|
91
|
+
return current;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Report a completed batch to the afterBatch hook: the usage of its
|
|
95
|
+
* results, and the cost the provider reported or else the batch price of
|
|
96
|
+
* that usage.
|
|
97
|
+
*/
|
|
98
|
+
async report(job, ctx) {
|
|
99
|
+
const usage = {};
|
|
100
|
+
for (const result of job.results ?? []) {
|
|
101
|
+
accumulateUsage(usage, result.response?.usage);
|
|
102
|
+
}
|
|
103
|
+
const model = this.ai.registry.getModel(job.model);
|
|
104
|
+
const cost = job.cost ?? usage.cost ?? (model ? this.ai.calculateCost(model, usage) * BATCH_PRICE : 0);
|
|
105
|
+
await this.ai.hooks.afterBatch?.(ctx, job, usage, cost);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Check the batch until it finishes, then return it with its results.
|
|
109
|
+
* A running batch is first checked after one interval: a batch just
|
|
110
|
+
* submitted can take a moment to become visible at the provider.
|
|
111
|
+
*
|
|
112
|
+
* @param job - A batch from `submit`.
|
|
113
|
+
* @param ctx - The context.
|
|
114
|
+
* @param options - How often to check, and when to stop.
|
|
115
|
+
*/
|
|
116
|
+
async wait(job, ctx, options = {}) {
|
|
117
|
+
const { interval = 30_000, signal } = options;
|
|
118
|
+
let current = FINAL.has(job.status) ? await this.get(job, ctx) : job;
|
|
119
|
+
while (!FINAL.has(current.status)) {
|
|
120
|
+
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
121
|
+
signal?.throwIfAborted();
|
|
122
|
+
current = await this.get(current, ctx);
|
|
123
|
+
}
|
|
124
|
+
return current;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=batch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch.js","sourceRoot":"","sources":["../../src/apis/batch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAa7C;;GAEG;AACH,MAAM,KAAK,GAA6B,IAAI,GAAG,CAAc,CAAC,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC;AAE9G;;;GAGG;AACH,MAAM,WAAW,GAAG,GAAG,CAAC;AAYxB;;;;GAIG;AACH,MAAM,OAAO,QAAQ;IAIC;IAHpB,4DAA4D;IAC3C,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IAE9C,YAAoB,EAAS;QAAT,OAAE,GAAF,EAAE,CAAO;IAAG,CAAC;IAEjC;;;;;;;;;OASG;IACH,KAAK,CAAC,MAAM,CAAC,QAAmB,EAAE,GAAyB;QACzD,MAAM,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACxD,CAAC;QAED,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QAC1B,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;QAChD,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QACpE,MAAM,QAAQ,GAAG,KAAK,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,eAAe,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,K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AAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,IAAI,CAAC,GAAa,EAAE,GAAyB,EAAE,UAA4B,EAAE;QACjF,MAAM,EAAE,QAAQ,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAC9C,IAAI,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACrE,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAClC,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;YAC9D,MAAM,EAAE,cAAc,EAAE,CAAC;YACzB,OAAO,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QACzC,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
|
package/dist/apis/chat.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/apis/chat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/apis/chat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAAkE,KAAK,QAAQ,EAAgD,KAAK,QAAQ,EAAE,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAEpL,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,KAAK,EACV,WAAW,EACX,SAAS,EACT,iBAAiB,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AAiB,CAAC,CAAC,CAAC,EAC5C,gBAAgB,SAAS,kBAAkB,CAAC,CAAC,CAAC,KAC3C,QAAQ,CAAC,eAAe,EAAE,gBAAgB,CAAC;IAWhD;;;;;;;OAOG;IACH,cAAc,CACZ,eAAe,SAAS,iBAAiB,CAAC,CAAC,CAAC,EAC5C,gBAAgB,SAAS,kBAAkB,CAAC,CAAC,CAAC,KAC3C,QAAQ,CAAC,eAAe,EAAE,gBAAgB,CAAC;CAiBjD"}
|
package/dist/apis/chat.js
CHANGED
|
@@ -34,9 +34,41 @@
|
|
|
34
34
|
* );
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
|
-
import { getChunksFromResponse, getResponseFromChunks } from '@aeye/core';
|
|
37
|
+
import { getChunksFromResponse, getResponseFromChunks, structuredOutput } from '@aeye/core';
|
|
38
|
+
import { INPUT_CAPABILITIES, OUTPUT_CAPABILITIES } from '../common';
|
|
38
39
|
import { BaseAPI } from './base';
|
|
39
40
|
import { applySchemaDeliveryFallback } from './schema-fallback';
|
|
41
|
+
/**
|
|
42
|
+
* Content whose capability is only preferred: most registries don't record
|
|
43
|
+
* document support.
|
|
44
|
+
*/
|
|
45
|
+
const PREFERRED_CONTENT = ['file'];
|
|
46
|
+
/**
|
|
47
|
+
* Adds the capability mapped to each key present in the request.
|
|
48
|
+
*/
|
|
49
|
+
function addMapped(target, map, keys) {
|
|
50
|
+
for (const key of keys) {
|
|
51
|
+
const capability = map[key];
|
|
52
|
+
if (capability) {
|
|
53
|
+
target.add(capability);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Every content part type used across the request messages.
|
|
59
|
+
*/
|
|
60
|
+
function contentTypes(request) {
|
|
61
|
+
return request.messages.flatMap(message => Array.isArray(message.content) ? message.content.map(part => part.type) : []);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* How the request's output reaches the model: as structured output, JSON
|
|
65
|
+
* mode, or neither (text, or a schema delivered as prompt text).
|
|
66
|
+
*/
|
|
67
|
+
function outputMode(format) {
|
|
68
|
+
return structuredOutput(format) ? 'structured'
|
|
69
|
+
: format === 'json' || (typeof format === 'object' && format.schemaDelivery === 'json') ? 'json'
|
|
70
|
+
: undefined;
|
|
71
|
+
}
|
|
40
72
|
/**
|
|
41
73
|
* Returns true when a `strict` field expresses a numeric (best-effort)
|
|
42
74
|
* preference rather than a hard `true` / `false`. Default-omitted (undefined)
|
|
@@ -65,38 +97,17 @@ export class ChatAPI extends BaseAPI {
|
|
|
65
97
|
// ============================================================================
|
|
66
98
|
getRequiredCapabilities(provided, request, forStreaming) {
|
|
67
99
|
const capabilities = new Set(['chat', ...provided]);
|
|
68
|
-
// Check if request contains images - requires vision capability
|
|
69
100
|
if (request) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return message.content.some(part => part.type === 'image');
|
|
73
|
-
}
|
|
74
|
-
return false;
|
|
75
|
-
});
|
|
76
|
-
if (hasImages) {
|
|
77
|
-
capabilities.add('vision');
|
|
78
|
-
}
|
|
79
|
-
const hasAudio = request.messages.some(message => {
|
|
80
|
-
if (Array.isArray(message.content)) {
|
|
81
|
-
return message.content.some(part => part.type === 'audio');
|
|
82
|
-
}
|
|
83
|
-
return false;
|
|
84
|
-
});
|
|
85
|
-
if (hasAudio) {
|
|
86
|
-
capabilities.add('hearing');
|
|
87
|
-
}
|
|
101
|
+
addMapped(capabilities, INPUT_CAPABILITIES, contentTypes(request).filter(type => !PREFERRED_CONTENT.includes(type)));
|
|
102
|
+
addMapped(capabilities, OUTPUT_CAPABILITIES, request.modalities ?? []);
|
|
88
103
|
// Check if request uses reasoning
|
|
89
104
|
if (request.reason !== undefined) {
|
|
90
105
|
capabilities.add('reasoning');
|
|
91
106
|
}
|
|
92
107
|
// Check if request expects JSON output
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
else if (typeof request.responseFormat === 'object') {
|
|
98
|
-
capabilities.add('structured');
|
|
99
|
-
}
|
|
108
|
+
const output = outputMode(request.responseFormat);
|
|
109
|
+
if (output) {
|
|
110
|
+
capabilities.add(output);
|
|
100
111
|
}
|
|
101
112
|
// Check if request uses tools
|
|
102
113
|
if (request.tools && request.tools.length > 0) {
|
|
@@ -140,11 +151,12 @@ export class ChatAPI extends BaseAPI {
|
|
|
140
151
|
if (request.logitBias !== undefined) {
|
|
141
152
|
params.add('logitBias');
|
|
142
153
|
}
|
|
143
|
-
|
|
154
|
+
const output = outputMode(request.responseFormat);
|
|
155
|
+
if (request.responseFormat === 'text' || output) {
|
|
144
156
|
params.add('responseFormat');
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
157
|
+
}
|
|
158
|
+
if (output === 'structured') {
|
|
159
|
+
params.add('structuredOutput');
|
|
148
160
|
}
|
|
149
161
|
if (request.reason !== undefined) {
|
|
150
162
|
params.add('reason');
|
|
@@ -168,6 +180,7 @@ export class ChatAPI extends BaseAPI {
|
|
|
168
180
|
*/
|
|
169
181
|
getOptionalCapabilities(provided, request, forStreaming) {
|
|
170
182
|
const optional = new Set(provided);
|
|
183
|
+
addMapped(optional, INPUT_CAPABILITIES, contentTypes(request).filter(type => PREFERRED_CONTENT.includes(type)));
|
|
171
184
|
if ((request.tools?.length ?? 0) > 0) {
|
|
172
185
|
const wantsStrictPreference = request.tools.some(t => isNumericStrictPreference(t.strict));
|
|
173
186
|
if (wantsStrictPreference) {
|
|
@@ -185,6 +198,15 @@ export class ChatAPI extends BaseAPI {
|
|
|
185
198
|
if (request.tools?.some(t => isNumericStrictPreference(t.strict))) {
|
|
186
199
|
params.add('toolsStrict');
|
|
187
200
|
}
|
|
201
|
+
if (request.seed !== undefined) {
|
|
202
|
+
params.add('seed');
|
|
203
|
+
}
|
|
204
|
+
if (request.verbosity !== undefined) {
|
|
205
|
+
params.add('verbosity');
|
|
206
|
+
}
|
|
207
|
+
if (request.serviceTier !== undefined) {
|
|
208
|
+
params.add('serviceTier');
|
|
209
|
+
}
|
|
188
210
|
return Array.from(params);
|
|
189
211
|
}
|
|
190
212
|
getNoModelFoundError() {
|
|
@@ -206,18 +228,16 @@ export class ChatAPI extends BaseAPI {
|
|
|
206
228
|
// Provider-agnostic schema-delivery fallback: if the selected model's
|
|
207
229
|
// dialect can't express the structured schema (or delivery is forced to
|
|
208
230
|
// prompt), drop `response_format` and deliver the schema as prompt text.
|
|
209
|
-
applySchemaDeliveryFallback(request, selected.model);
|
|
210
231
|
const executor = selected.provider.createExecutor(selected.providerConfig);
|
|
211
|
-
return await executor(request, ctx, ctx.metadata);
|
|
232
|
+
return await executor(applySchemaDeliveryFallback(request, selected.model), ctx, ctx.metadata);
|
|
212
233
|
}
|
|
213
234
|
async *executeStreamRequest(request, selected, ctx) {
|
|
214
235
|
if (!selected.provider.createStreamer) {
|
|
215
236
|
throw new Error(`Provider ${selected.provider.name} does not support chat streaming`);
|
|
216
237
|
}
|
|
217
238
|
// Provider-agnostic schema-delivery fallback (see executeRequest).
|
|
218
|
-
applySchemaDeliveryFallback(request, selected.model);
|
|
219
239
|
const streamer = selected.provider.createStreamer(selected.providerConfig);
|
|
220
|
-
return yield* streamer(request, ctx, ctx.metadata);
|
|
240
|
+
return yield* streamer(applySchemaDeliveryFallback(request, selected.model), ctx, ctx.metadata);
|
|
221
241
|
}
|
|
222
242
|
responseToChunks(response, model) {
|
|
223
243
|
return getChunksFromResponse(response);
|
package/dist/apis/chat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../../src/apis/chat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,
|
|
1
|
+
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../../src/apis/chat.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAAE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,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,GAAG,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;gBAChF,MAAM,KAAK,CAAC;gBACZ,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACrB,CAAC;YAED,OAAO,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;QAC1C,CAAC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decide API
|
|
3
|
+
*
|
|
4
|
+
* Typed answers about an input from a decision model: the probability a
|
|
5
|
+
* condition holds, one choice from a set, or a score on ordered levels.
|
|
6
|
+
* Far faster and cheaper than asking a chat model for structured output.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const { answers } = await ai.decide.get({
|
|
11
|
+
* input: 'I was charged twice for my order.',
|
|
12
|
+
* questions: {
|
|
13
|
+
* billing: { type: 'predicate', instructions: 'Is this a billing problem?' },
|
|
14
|
+
* team: { type: 'choice', instructions: 'Which team handles it?', choices: { payments: 'Charges and refunds', web: 'Website bugs' } },
|
|
15
|
+
* urgency: { type: 'score', instructions: 'How urgent is it?', levels: ['Can wait', 'This week', 'Now'] },
|
|
16
|
+
* },
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
import type { Usage } from '@aeye/core';
|
|
21
|
+
import type { AIBaseTypes, AIContext, DecisionRequest, DecisionResponse, ModelCapability, ModelHandlerFor, SelectedModelFor } from '../types';
|
|
22
|
+
import { GetAPI } from './get';
|
|
23
|
+
export declare class DecideAPI<T extends AIBaseTypes> extends GetAPI<T, DecisionRequest, DecisionResponse> {
|
|
24
|
+
protected getRequiredCapabilities(provided: ModelCapability[]): ModelCapability[];
|
|
25
|
+
protected getNoModelFoundError(): string;
|
|
26
|
+
protected getErrorType(): string;
|
|
27
|
+
protected getErrorMessage(): string;
|
|
28
|
+
protected executeRequest(request: DecisionRequest, selected: SelectedModelFor<T>, ctx: AIContext<T>): Promise<DecisionResponse>;
|
|
29
|
+
protected estimateRequestUsage(request: DecisionRequest): Usage;
|
|
30
|
+
protected getHandlerGetMethod(handler?: ModelHandlerFor<T>): ((request: DecisionRequest, ctx: AIContext<T>) => Promise<DecisionResponse>) | undefined;
|
|
31
|
+
protected hasProviderExecutor(selected: SelectedModelFor<T>): boolean;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=decide.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decide.d.ts","sourceRoot":"","sources":["../../src/apis/decide.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAW,KAAK,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EACV,WAAW,EACX,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE/B,qBAAa,SAAS,CAAC,CAAC,SAAS,WAAW,CAAE,SAAQ,MAAM,CAAC,CAAC,EAAE,eAAe,EAAE,gBAAgB,CAAC;IAChG,SAAS,CAAC,uBAAuB,CAAC,QAAQ,EAAE,eAAe,EAAE,GAAG,eAAe,EAAE;IAIjF,SAAS,CAAC,oBAAoB,IAAI,MAAM;IAIxC,SAAS,CAAC,YAAY,IAAI,MAAM;IAIhC,SAAS,CAAC,eAAe,IAAI,MAAM;IAInC,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAO/H,SAAS,CAAC,oBAAoB,CAAC,OAAO,EAAE,eAAe,GAAG,KAAK;IAM/D,SAAS,CAAC,mBAAmB,CAAC,OAAO,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC,GAAG,SAAS;IAIrJ,SAAS,CAAC,mBAAmB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,OAAO;CAGtE"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decide API
|
|
3
|
+
*
|
|
4
|
+
* Typed answers about an input from a decision model: the probability a
|
|
5
|
+
* condition holds, one choice from a set, or a score on ordered levels.
|
|
6
|
+
* Far faster and cheaper than asking a chat model for structured output.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const { answers } = await ai.decide.get({
|
|
11
|
+
* input: 'I was charged twice for my order.',
|
|
12
|
+
* questions: {
|
|
13
|
+
* billing: { type: 'predicate', instructions: 'Is this a billing problem?' },
|
|
14
|
+
* team: { type: 'choice', instructions: 'Which team handles it?', choices: { payments: 'Charges and refunds', web: 'Website bugs' } },
|
|
15
|
+
* urgency: { type: 'score', instructions: 'How urgent is it?', levels: ['Can wait', 'This week', 'Now'] },
|
|
16
|
+
* },
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
import { GetAPI } from './get';
|
|
21
|
+
export class DecideAPI extends GetAPI {
|
|
22
|
+
getRequiredCapabilities(provided) {
|
|
23
|
+
return ['decision', ...provided];
|
|
24
|
+
}
|
|
25
|
+
getNoModelFoundError() {
|
|
26
|
+
return 'No compatible model found for decisions';
|
|
27
|
+
}
|
|
28
|
+
getErrorType() {
|
|
29
|
+
return 'decision-failed';
|
|
30
|
+
}
|
|
31
|
+
getErrorMessage() {
|
|
32
|
+
return 'Decision failed';
|
|
33
|
+
}
|
|
34
|
+
executeRequest(request, selected, ctx) {
|
|
35
|
+
if (!selected.provider.decide) {
|
|
36
|
+
throw new Error(`Provider ${selected.provider.name} does not support decisions`);
|
|
37
|
+
}
|
|
38
|
+
return selected.provider.decide(request, ctx, selected.providerConfig);
|
|
39
|
+
}
|
|
40
|
+
estimateRequestUsage(request) {
|
|
41
|
+
const questions = { role: 'user', content: JSON.stringify(request.questions) };
|
|
42
|
+
const input = typeof request.input === 'string' ? [{ role: 'user', content: request.input }] : request.input;
|
|
43
|
+
return this.ai.estimateRequestUsage({ messages: [...input, questions] });
|
|
44
|
+
}
|
|
45
|
+
getHandlerGetMethod(handler) {
|
|
46
|
+
return handler?.decide?.get;
|
|
47
|
+
}
|
|
48
|
+
hasProviderExecutor(selected) {
|
|
49
|
+
return !!selected.provider.decide;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=decide.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decide.js","sourceRoot":"","sources":["../../src/apis/decide.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAYH,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE/B,MAAM,OAAO,SAAiC,SAAQ,MAA4C;IACtF,uBAAuB,CAAC,QAA2B;QAC3D,OAAO,CAAC,UAAU,EAAE,GAAG,QAAQ,CAAC,CAAC;IACnC,CAAC;IAES,oBAAoB;QAC5B,OAAO,yCAAyC,CAAC;IACnD,CAAC;IAES,YAAY;QACpB,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAES,eAAe;QACvB,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAES,cAAc,CAAC,OAAwB,EAAE,QAA6B,EAAE,GAAiB;QACjG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,YAAY,QAAQ,CAAC,QAAQ,CAAC,IAAI,6BAA6B,CAAC,CAAC;QACnF,CAAC;QACD,OAAO,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC;IACzE,CAAC;IAES,oBAAoB,CAAC,OAAwB;QACrD,MAAM,SAAS,GAAY,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACxF,MAAM,KAAK,GAAc,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;QACxH,OAAO,IAAI,CAAC,EAAE,CAAC,oBAAoB,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,KAAK,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC;IAC3E,CAAC;IAES,mBAAmB,CAAC,OAA4B;QACxD,OAAO,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC;IAC9B,CAAC;IAES,mBAAmB,CAAC,QAA6B;QACzD,OAAO,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC;IACpC,CAAC;CACF"}
|
package/dist/apis/embed.d.ts
CHANGED
|
@@ -4,24 +4,17 @@
|
|
|
4
4
|
* Provides text embedding functionality.
|
|
5
5
|
*/
|
|
6
6
|
import type { Usage } from '@aeye/core';
|
|
7
|
-
import type { AI } from '../ai';
|
|
8
7
|
import type { AIBaseTypes, AIContext, EmbeddingRequest, EmbeddingResponse, ModelCapability, ModelParameter, ModelHandlerFor, SelectedModelFor } from '../types';
|
|
9
|
-
import {
|
|
10
|
-
export declare class EmbedAPI<T extends AIBaseTypes> extends
|
|
11
|
-
|
|
12
|
-
protected
|
|
13
|
-
protected getRequiredParameters(provided: ModelParameter[], request: EmbeddingRequest, forStreaming: boolean): ModelParameter[];
|
|
8
|
+
import { GetAPI } from './get';
|
|
9
|
+
export declare class EmbedAPI<T extends AIBaseTypes> extends GetAPI<T, EmbeddingRequest, EmbeddingResponse> {
|
|
10
|
+
protected getRequiredCapabilities(provided: ModelCapability[]): ModelCapability[];
|
|
11
|
+
protected getRequiredParameters(provided: ModelParameter[], request: EmbeddingRequest): ModelParameter[];
|
|
14
12
|
protected getNoModelFoundError(): string;
|
|
15
13
|
protected getErrorType(): string;
|
|
16
14
|
protected getErrorMessage(): string;
|
|
17
15
|
protected executeRequest(request: EmbeddingRequest, selected: SelectedModelFor<T>, ctx: AIContext<T>): Promise<EmbeddingResponse>;
|
|
18
|
-
protected executeStreamRequest(request: EmbeddingRequest, selected: SelectedModelFor<T>, ctx: AIContext<T>): AsyncIterable<never>;
|
|
19
16
|
protected estimateRequestUsage(request: EmbeddingRequest): Usage;
|
|
20
|
-
protected responseToChunks(response: EmbeddingResponse): never;
|
|
21
|
-
protected chunksToResponse(chunks: never[]): EmbeddingResponse;
|
|
22
17
|
protected getHandlerGetMethod(handler?: ModelHandlerFor<T>): ((request: EmbeddingRequest, ctx: AIContext<T>) => Promise<EmbeddingResponse>) | undefined;
|
|
23
|
-
protected getHandlerStreamMethod(handler?: ModelHandlerFor<T>): ((request: EmbeddingRequest, ctx: AIContext<T>) => AsyncIterable<never>) | undefined;
|
|
24
18
|
protected hasProviderExecutor(selected: SelectedModelFor<T>): boolean;
|
|
25
|
-
protected hasProviderStreamer(selected: SelectedModelFor<T>): boolean;
|
|
26
19
|
}
|
|
27
20
|
//# sourceMappingURL=embed.d.ts.map
|
package/dist/apis/embed.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embed.d.ts","sourceRoot":"","sources":["../../src/apis/embed.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,
|
|
1
|
+
{"version":3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C,GAAG,OAAO;CAGtE"}
|
package/dist/apis/embed.js
CHANGED
|
@@ -3,22 +3,13 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Provides text embedding functionality.
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
export class EmbedAPI extends
|
|
8
|
-
|
|
9
|
-
super(ai);
|
|
10
|
-
}
|
|
11
|
-
// ============================================================================
|
|
12
|
-
// REQUIRED ABSTRACT METHOD IMPLEMENTATIONS
|
|
13
|
-
// ============================================================================
|
|
14
|
-
getRequiredCapabilities(provided, request, forStreaming) {
|
|
6
|
+
import { GetAPI } from './get';
|
|
7
|
+
export class EmbedAPI extends GetAPI {
|
|
8
|
+
getRequiredCapabilities(provided) {
|
|
15
9
|
return ['embedding', ...provided];
|
|
16
10
|
}
|
|
17
|
-
getRequiredParameters(provided, request
|
|
18
|
-
|
|
19
|
-
if (request.dimensions !== undefined)
|
|
20
|
-
params.add('embeddingDimensions');
|
|
21
|
-
return Array.from(params);
|
|
11
|
+
getRequiredParameters(provided, request) {
|
|
12
|
+
return request.dimensions !== undefined ? [...new Set([...provided, 'embeddingDimensions'])] : provided;
|
|
22
13
|
}
|
|
23
14
|
getNoModelFoundError() {
|
|
24
15
|
return 'No compatible model found for embeddings';
|
|
@@ -32,12 +23,6 @@ export class EmbedAPI extends BaseAPI {
|
|
|
32
23
|
async executeRequest(request, selected, ctx) {
|
|
33
24
|
return await selected.provider.embed(request, ctx, selected.providerConfig);
|
|
34
25
|
}
|
|
35
|
-
async *executeStreamRequest(request, selected, ctx) {
|
|
36
|
-
throw new Error('Streaming not supported for embeddings');
|
|
37
|
-
}
|
|
38
|
-
// ============================================================================
|
|
39
|
-
// OPTIONAL OVERRIDES
|
|
40
|
-
// ============================================================================
|
|
41
26
|
estimateRequestUsage(request) {
|
|
42
27
|
const totalTextLength = request.texts.reduce((sum, text) => sum + text.length, 0);
|
|
43
28
|
const tokens = Math.ceil(totalTextLength / 4);
|
|
@@ -48,23 +33,11 @@ export class EmbedAPI extends BaseAPI {
|
|
|
48
33
|
}
|
|
49
34
|
};
|
|
50
35
|
}
|
|
51
|
-
responseToChunks(response) {
|
|
52
|
-
throw new Error('Embeddings do not support chunking');
|
|
53
|
-
}
|
|
54
|
-
chunksToResponse(chunks) {
|
|
55
|
-
throw new Error('Embeddings do not support chunking');
|
|
56
|
-
}
|
|
57
36
|
getHandlerGetMethod(handler) {
|
|
58
37
|
return handler?.embed?.get;
|
|
59
38
|
}
|
|
60
|
-
getHandlerStreamMethod(handler) {
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
39
|
hasProviderExecutor(selected) {
|
|
64
40
|
return !!selected.provider.embed;
|
|
65
41
|
}
|
|
66
|
-
hasProviderStreamer(selected) {
|
|
67
|
-
return false; // Embed API doesn't support streaming
|
|
68
|
-
}
|
|
69
42
|
}
|
|
70
43
|
//# sourceMappingURL=embed.js.map
|
package/dist/apis/embed.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embed.js","sourceRoot":"","sources":["../../src/apis/embed.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"embed.js","sourceRoot":"","sources":["../../src/apis/embed.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAaH,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE/B,MAAM,OAAO,QAAgC,SAAQ,MAA8C;IACvF,uBAAuB,CAAC,QAA2B;QAC3D,OAAO,CAAC,WAAW,EAAE,GAAG,QAAQ,CAAC,CAAC;IACpC,CAAC;IAES,qBAAqB,CAAC,QAA0B,EAAE,OAAyB;QACnF,OAAO,OAAO,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAiB,CAAC,GAAG,QAAQ,EAAE,qBAAqB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IAC1H,CAAC;IAES,oBAAoB;QAC5B,OAAO,0CAA0C,CAAC;IACpD,CAAC;IAES,YAAY;QACpB,OAAO,6BAA6B,CAAC;IACvC,CAAC;IAES,eAAe;QACvB,OAAO,6BAA6B,CAAC;IACvC,CAAC;IAES,KAAK,CAAC,cAAc,CAC5B,OAAyB,EACzB,QAA6B,EAC7B,GAAiB;QAEjB,OAAO,MAAM,QAAQ,CAAC,QAAQ,CAAC,KAAM,CACnC,OAAO,EACP,GAAG,EACH,QAAQ,CAAC,cAAc,CACxB,CAAC;IACJ,CAAC;IAES,oBAAoB,CAAC,OAAyB;QACtD,MAAM,eAAe,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QAClF,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,GAAG,CAAC,CAAC,CAAC;QAC9C,OAAO;YACL,UAAU,EAAE;gBACV,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM;gBAC3B,MAAM;aACP;SACF,CAAC;IACJ,CAAC;IAES,mBAAmB,CAC3B,OAA4B;QAE5B,OAAO,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC;IAC7B,CAAC;IAES,mBAAmB,CAAC,QAA6B;QACzD,OAAO,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get API
|
|
3
|
+
*
|
|
4
|
+
* Base for APIs that answer with one response and never stream.
|
|
5
|
+
*/
|
|
6
|
+
import type { BaseRequest, BaseResponse } from '@aeye/core';
|
|
7
|
+
import type { AIBaseTypes, ModelParameter } from '../types';
|
|
8
|
+
import { BaseAPI } from './base';
|
|
9
|
+
export declare abstract class GetAPI<T extends AIBaseTypes, TRequest extends BaseRequest, TResponse extends BaseResponse> extends BaseAPI<T, TRequest, TResponse, never> {
|
|
10
|
+
protected getRequiredParameters(provided: ModelParameter[], request: TRequest): ModelParameter[];
|
|
11
|
+
protected executeStreamRequest(): AsyncIterable<never>;
|
|
12
|
+
protected responseToChunks(): never;
|
|
13
|
+
protected chunksToResponse(): never;
|
|
14
|
+
protected getHandlerStreamMethod(): undefined;
|
|
15
|
+
protected hasProviderStreamer(): boolean;
|
|
16
|
+
private noStreaming;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=get.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get.d.ts","sourceRoot":"","sources":["../../src/apis/get.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,8BAAsB,MAAM,CAC1B,CAAC,SAAS,WAAW,EACrB,QAAQ,SAAS,WAAW,EAC5B,SAAS,SAAS,YAAY,CAC9B,SAAQ,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,CAAC;IAC9C,SAAS,CAAC,qBAAqB,CAAC,QAAQ,EAAE,cAAc,EAAE,EAAE,OAAO,EAAE,QAAQ,GAAG,cAAc,EAAE;cAI/E,oBAAoB,IAAI,aAAa,CAAC,KAAK,CAAC;IAI7D,SAAS,CAAC,gBAAgB,IAAI,KAAK;IAInC,SAAS,CAAC,gBAAgB,IAAI,KAAK;IAInC,SAAS,CAAC,sBAAsB,IAAI,SAAS;IAI7C,SAAS,CAAC,mBAAmB,IAAI,OAAO;IAIxC,OAAO,CAAC,WAAW;CAGpB"}
|
package/dist/apis/get.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get API
|
|
3
|
+
*
|
|
4
|
+
* Base for APIs that answer with one response and never stream.
|
|
5
|
+
*/
|
|
6
|
+
import { BaseAPI } from './base';
|
|
7
|
+
export class GetAPI extends BaseAPI {
|
|
8
|
+
getRequiredParameters(provided, request) {
|
|
9
|
+
return provided;
|
|
10
|
+
}
|
|
11
|
+
async *executeStreamRequest() {
|
|
12
|
+
this.noStreaming();
|
|
13
|
+
}
|
|
14
|
+
responseToChunks() {
|
|
15
|
+
return this.noStreaming();
|
|
16
|
+
}
|
|
17
|
+
chunksToResponse() {
|
|
18
|
+
return this.noStreaming();
|
|
19
|
+
}
|
|
20
|
+
getHandlerStreamMethod() {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
hasProviderStreamer() {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
noStreaming() {
|
|
27
|
+
throw new Error(`${this.getErrorMessage('request')}: streaming is not supported`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=get.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../src/apis/get.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,MAAM,OAAgB,MAIpB,SAAQ,OAAsC;IACpC,qBAAqB,CAAC,QAA0B,EAAE,OAAiB;QAC3E,OAAO,QAAQ,CAAC;IAClB,CAAC;IAES,KAAK,CAAC,CAAC,oBAAoB;QACnC,IAAI,CAAC,WAAW,EAAE,CAAC;IACrB,CAAC;IAES,gBAAgB;QACxB,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;IAES,gBAAgB;QACxB,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;IAES,sBAAsB;QAC9B,OAAO,SAAS,CAAC;IACnB,CAAC;IAES,mBAAmB;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IAEO,WAAW;QACjB,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,8BAA8B,CAAC,CAAC;IACpF,CAAC;CACF"}
|
package/dist/apis/image.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ declare class ImageGenerateAPI<T extends AIBaseTypes> extends BaseAPI<T, ImageGe
|
|
|
14
14
|
protected getNoModelFoundError(): string;
|
|
15
15
|
protected getErrorType(operation: 'request' | 'stream'): string;
|
|
16
16
|
protected getErrorMessage(operation: 'request' | 'stream'): string;
|
|
17
|
-
protected estimateRequestUsage(request: ImageGenerationRequest): Usage;
|
|
17
|
+
protected estimateRequestUsage(request: ImageGenerationRequest, selected: SelectedModelFor<T>): Usage;
|
|
18
18
|
protected executeRequest(request: ImageGenerationRequest, selected: SelectedModelFor<T>, ctx: AIContext<T>): Promise<ImageGenerationResponse>;
|
|
19
19
|
protected executeStreamRequest(request: ImageGenerationRequest, selected: SelectedModelFor<T>, ctx: AIContext<T>): AsyncIterable<ImageGenerationChunk>;
|
|
20
20
|
protected responseToChunks(response: ImageGenerationResponse): ImageGenerationChunk[];
|
|
@@ -32,7 +32,7 @@ declare class ImageEditAPI<T extends AIBaseTypes> extends BaseAPI<T, ImageEditRe
|
|
|
32
32
|
protected getNoModelFoundError(): string;
|
|
33
33
|
protected getErrorType(operation: 'request' | 'stream'): string;
|
|
34
34
|
protected getErrorMessage(operation: 'request' | 'stream'): string;
|
|
35
|
-
protected estimateRequestUsage(request: ImageEditRequest): Usage;
|
|
35
|
+
protected estimateRequestUsage(request: ImageEditRequest, selected: SelectedModelFor<T>): Usage;
|
|
36
36
|
protected executeRequest(request: ImageEditRequest, selected: SelectedModelFor<T>, ctx: AIContext<T>): Promise<ImageGenerationResponse>;
|
|
37
37
|
protected executeStreamRequest(request: ImageEditRequest, selected: SelectedModelFor<T>, ctx: AIContext<T>): AsyncIterable<ImageGenerationChunk>;
|
|
38
38
|
protected responseToChunks(response: ImageGenerationResponse): ImageGenerationChunk[];
|