@aeye/ai 0.1.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 +1324 -0
- package/dist/ai.d.ts +204 -0
- package/dist/ai.d.ts.map +1 -0
- package/dist/ai.js +837 -0
- package/dist/ai.js.map +1 -0
- package/dist/apis/base.d.ts +181 -0
- package/dist/apis/base.d.ts.map +1 -0
- package/dist/apis/base.js +359 -0
- package/dist/apis/base.js.map +1 -0
- package/dist/apis/chat.d.ts +82 -0
- package/dist/apis/chat.d.ts.map +1 -0
- package/dist/apis/chat.js +214 -0
- package/dist/apis/chat.js.map +1 -0
- package/dist/apis/embed.d.ts +27 -0
- package/dist/apis/embed.d.ts.map +1 -0
- package/dist/apis/embed.js +70 -0
- package/dist/apis/embed.js.map +1 -0
- package/dist/apis/image.d.ts +77 -0
- package/dist/apis/image.d.ts.map +1 -0
- package/dist/apis/image.js +313 -0
- package/dist/apis/image.js.map +1 -0
- package/dist/apis/models.d.ts +108 -0
- package/dist/apis/models.d.ts.map +1 -0
- package/dist/apis/models.js +118 -0
- package/dist/apis/models.js.map +1 -0
- package/dist/apis/speech.d.ts +27 -0
- package/dist/apis/speech.d.ts.map +1 -0
- package/dist/apis/speech.js +79 -0
- package/dist/apis/speech.js.map +1 -0
- package/dist/apis/transcribe.d.ts +26 -0
- package/dist/apis/transcribe.d.ts.map +1 -0
- package/dist/apis/transcribe.js +103 -0
- package/dist/apis/transcribe.js.map +1 -0
- package/dist/common.d.ts +10 -0
- package/dist/common.d.ts.map +1 -0
- package/dist/common.js +17 -0
- package/dist/common.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/modelDetection.d.ts +31 -0
- package/dist/modelDetection.d.ts.map +1 -0
- package/dist/modelDetection.js +78 -0
- package/dist/modelDetection.js.map +1 -0
- package/dist/registry.d.ts +150 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +639 -0
- package/dist/registry.js.map +1 -0
- package/dist/types.d.ts +767 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +53 -0
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image API
|
|
3
|
+
*
|
|
4
|
+
* Provides image generation, editing, and analysis functionality.
|
|
5
|
+
*/
|
|
6
|
+
import { getChunksFromResponse, getResponseFromChunks } from '@aeye/core';
|
|
7
|
+
import { BaseAPI } from './base';
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// Image Generate API
|
|
10
|
+
// ============================================================================
|
|
11
|
+
class ImageGenerateAPI extends BaseAPI {
|
|
12
|
+
constructor(ai) {
|
|
13
|
+
super(ai);
|
|
14
|
+
}
|
|
15
|
+
getRequiredCapabilities(provided, request) {
|
|
16
|
+
return ['image', ...provided];
|
|
17
|
+
}
|
|
18
|
+
getRequiredParameters(provided, request, forStreaming) {
|
|
19
|
+
const params = new Set(provided);
|
|
20
|
+
if (request.n !== undefined && request.n !== 1) {
|
|
21
|
+
params.add('imageMultiple');
|
|
22
|
+
}
|
|
23
|
+
if (request.background !== undefined) {
|
|
24
|
+
params.add('imageBackground');
|
|
25
|
+
}
|
|
26
|
+
if (request.responseFormat !== undefined) {
|
|
27
|
+
params.add('imageFormat');
|
|
28
|
+
}
|
|
29
|
+
if (request.style !== undefined) {
|
|
30
|
+
params.add('imageStyle');
|
|
31
|
+
}
|
|
32
|
+
if (forStreaming && request.streamCount !== 0) {
|
|
33
|
+
params.add('imageStream');
|
|
34
|
+
}
|
|
35
|
+
return Array.from(params);
|
|
36
|
+
}
|
|
37
|
+
getNoModelFoundError() {
|
|
38
|
+
return 'No compatible model found for image generation';
|
|
39
|
+
}
|
|
40
|
+
getErrorType(operation) {
|
|
41
|
+
return operation === 'request'
|
|
42
|
+
? 'image-generation-failed'
|
|
43
|
+
: 'image-generation-stream-failed';
|
|
44
|
+
}
|
|
45
|
+
getErrorMessage(operation) {
|
|
46
|
+
return operation === 'request'
|
|
47
|
+
? 'Image generation failed'
|
|
48
|
+
: 'Image generation streaming failed';
|
|
49
|
+
}
|
|
50
|
+
estimateRequestUsage(request) {
|
|
51
|
+
// Parse size from request (e.g., "1024x1024", "1536x1024")
|
|
52
|
+
const [width, height] = (request.size || '1024x1024').split('x').map(Number);
|
|
53
|
+
const quality = request.quality || 'standard';
|
|
54
|
+
const count = request.n || 1;
|
|
55
|
+
// Prompt tokens (text input)
|
|
56
|
+
const promptTokens = Math.ceil(request.prompt.length / 4);
|
|
57
|
+
return {
|
|
58
|
+
text: {
|
|
59
|
+
input: promptTokens
|
|
60
|
+
},
|
|
61
|
+
image: {
|
|
62
|
+
output: [{
|
|
63
|
+
quality,
|
|
64
|
+
size: { width, height },
|
|
65
|
+
count
|
|
66
|
+
}]
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
async executeRequest(request, selected, ctx) {
|
|
71
|
+
return await selected.provider.generateImage(request, ctx, selected.providerConfig);
|
|
72
|
+
}
|
|
73
|
+
async *executeStreamRequest(request, selected, ctx) {
|
|
74
|
+
yield* selected.provider.generateImageStream(request, ctx, selected.providerConfig);
|
|
75
|
+
}
|
|
76
|
+
responseToChunks(response) {
|
|
77
|
+
return response.images.map((img) => ({
|
|
78
|
+
progress: 1,
|
|
79
|
+
done: true,
|
|
80
|
+
image: img,
|
|
81
|
+
model: response.model,
|
|
82
|
+
usage: response.usage,
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
chunksToResponse(chunks, model) {
|
|
86
|
+
const images = chunks
|
|
87
|
+
.filter(c => c.image)
|
|
88
|
+
.map(c => c.image);
|
|
89
|
+
return {
|
|
90
|
+
images: images,
|
|
91
|
+
model: chunks.find(c => c.model)?.model || model,
|
|
92
|
+
usage: chunks.find(c => c.usage)?.usage,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
getHandlerGetMethod(handler) {
|
|
96
|
+
return handler?.imageGenerate?.get;
|
|
97
|
+
}
|
|
98
|
+
getHandlerStreamMethod(handler) {
|
|
99
|
+
return handler?.imageGenerate?.stream;
|
|
100
|
+
}
|
|
101
|
+
hasProviderExecutor(selected) {
|
|
102
|
+
return !!selected.provider.generateImage;
|
|
103
|
+
}
|
|
104
|
+
hasProviderStreamer(selected) {
|
|
105
|
+
return !!selected.provider.generateImageStream;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// ============================================================================
|
|
109
|
+
// Image Edit API
|
|
110
|
+
// ============================================================================
|
|
111
|
+
class ImageEditAPI extends BaseAPI {
|
|
112
|
+
constructor(ai) {
|
|
113
|
+
super(ai);
|
|
114
|
+
}
|
|
115
|
+
getModel(request) {
|
|
116
|
+
return request.model;
|
|
117
|
+
}
|
|
118
|
+
getRequiredCapabilities(provided, request, forStreaming) {
|
|
119
|
+
return ['image', ...provided];
|
|
120
|
+
}
|
|
121
|
+
getRequiredParameters(provided, request, forStreaming) {
|
|
122
|
+
const params = new Set(provided);
|
|
123
|
+
if (request.n !== undefined && request.n !== 1) {
|
|
124
|
+
params.add('imageMultiple');
|
|
125
|
+
}
|
|
126
|
+
if (request.responseFormat !== undefined) {
|
|
127
|
+
params.add('imageFormat');
|
|
128
|
+
}
|
|
129
|
+
if (forStreaming && request.streamCount !== 0) {
|
|
130
|
+
params.add('imageStream');
|
|
131
|
+
}
|
|
132
|
+
return Array.from(params);
|
|
133
|
+
}
|
|
134
|
+
getNoModelFoundError() {
|
|
135
|
+
return 'No compatible model found for image editing';
|
|
136
|
+
}
|
|
137
|
+
getErrorType(operation) {
|
|
138
|
+
return operation === 'request'
|
|
139
|
+
? 'image-edit-failed'
|
|
140
|
+
: 'image-edit-stream-failed';
|
|
141
|
+
}
|
|
142
|
+
getErrorMessage(operation) {
|
|
143
|
+
return operation === 'request'
|
|
144
|
+
? 'Image editing failed'
|
|
145
|
+
: 'Image editing streaming failed';
|
|
146
|
+
}
|
|
147
|
+
estimateRequestUsage(request) {
|
|
148
|
+
// Parse size from request
|
|
149
|
+
const [width, height] = (request.size || '1024x1024').split('x').map(Number);
|
|
150
|
+
const count = request.n || 1;
|
|
151
|
+
// Prompt tokens (text input)
|
|
152
|
+
const promptTokens = Math.ceil(request.prompt.length / 4);
|
|
153
|
+
// Estimate input image tokens (assuming standard quality)
|
|
154
|
+
const imageInputTokens = 1000; // Rough estimate for input image processing
|
|
155
|
+
return {
|
|
156
|
+
text: {
|
|
157
|
+
input: promptTokens
|
|
158
|
+
},
|
|
159
|
+
image: {
|
|
160
|
+
input: imageInputTokens,
|
|
161
|
+
output: [{
|
|
162
|
+
quality: 'standard',
|
|
163
|
+
size: { width, height },
|
|
164
|
+
count
|
|
165
|
+
}]
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
async executeRequest(request, selected, ctx) {
|
|
170
|
+
return await selected.provider.editImage(request, ctx, selected.providerConfig);
|
|
171
|
+
}
|
|
172
|
+
async *executeStreamRequest(request, selected, ctx) {
|
|
173
|
+
yield* selected.provider.editImageStream(request, ctx, selected.providerConfig);
|
|
174
|
+
}
|
|
175
|
+
responseToChunks(response) {
|
|
176
|
+
return response.images.map((img) => ({
|
|
177
|
+
progress: 1,
|
|
178
|
+
done: true,
|
|
179
|
+
image: img,
|
|
180
|
+
model: response.model,
|
|
181
|
+
usage: response.usage,
|
|
182
|
+
}));
|
|
183
|
+
}
|
|
184
|
+
chunksToResponse(chunks, model) {
|
|
185
|
+
const images = chunks
|
|
186
|
+
.filter(c => c.image)
|
|
187
|
+
.map(c => c.image);
|
|
188
|
+
return {
|
|
189
|
+
images: images,
|
|
190
|
+
model: chunks.find(c => c.model)?.model || model,
|
|
191
|
+
usage: chunks.find(c => c.usage)?.usage,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
getHandlerGetMethod(handler) {
|
|
195
|
+
return handler?.imageEdit?.get;
|
|
196
|
+
}
|
|
197
|
+
getHandlerStreamMethod(handler) {
|
|
198
|
+
return handler?.imageEdit?.stream;
|
|
199
|
+
}
|
|
200
|
+
hasProviderExecutor(selected) {
|
|
201
|
+
return !!selected.provider.editImage;
|
|
202
|
+
}
|
|
203
|
+
hasProviderStreamer(selected) {
|
|
204
|
+
return !!selected.provider.editImageStream;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// ============================================================================
|
|
208
|
+
// Image Analyze API
|
|
209
|
+
// ============================================================================
|
|
210
|
+
class ImageAnalyzeAPI extends BaseAPI {
|
|
211
|
+
constructor(ai) {
|
|
212
|
+
super(ai);
|
|
213
|
+
}
|
|
214
|
+
getRequiredCapabilities(provided, request, forStreaming) {
|
|
215
|
+
return ['chat', 'vision', ...provided];
|
|
216
|
+
}
|
|
217
|
+
getRequiredParameters(provided, request, forStreaming) {
|
|
218
|
+
const params = new Set(provided);
|
|
219
|
+
if (request.maxTokens !== undefined) {
|
|
220
|
+
params.add('maxTokens');
|
|
221
|
+
}
|
|
222
|
+
if (request.temperature !== undefined) {
|
|
223
|
+
params.add('temperature');
|
|
224
|
+
}
|
|
225
|
+
return Array.from(params);
|
|
226
|
+
}
|
|
227
|
+
getNoModelFoundError() {
|
|
228
|
+
return 'No compatible vision model found for image analysis';
|
|
229
|
+
}
|
|
230
|
+
getErrorType(operation) {
|
|
231
|
+
return operation === 'request'
|
|
232
|
+
? 'image-analyze-failed'
|
|
233
|
+
: 'image-analyze-stream-failed';
|
|
234
|
+
}
|
|
235
|
+
getErrorMessage(operation) {
|
|
236
|
+
return operation === 'request'
|
|
237
|
+
? 'Image analysis failed'
|
|
238
|
+
: 'Image analysis streaming failed';
|
|
239
|
+
}
|
|
240
|
+
getNoModelFoundErrorForStreaming() {
|
|
241
|
+
return 'No compatible vision model found for streaming image analysis';
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Convert ImageAnalyzeRequest to chat Request with multimodal content
|
|
245
|
+
*/
|
|
246
|
+
convertToChatRequest(request) {
|
|
247
|
+
return {
|
|
248
|
+
messages: [
|
|
249
|
+
{
|
|
250
|
+
role: 'user',
|
|
251
|
+
content: [
|
|
252
|
+
{ type: 'text', content: request.prompt },
|
|
253
|
+
...request.images.map((img) => ({
|
|
254
|
+
type: 'image',
|
|
255
|
+
content: img,
|
|
256
|
+
})),
|
|
257
|
+
],
|
|
258
|
+
},
|
|
259
|
+
],
|
|
260
|
+
maxTokens: request.maxTokens,
|
|
261
|
+
temperature: request.temperature,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
estimateRequestUsage(request, selected) {
|
|
265
|
+
const chatRequest = this.convertToChatRequest(request);
|
|
266
|
+
return this.ai.estimateRequestUsage(chatRequest);
|
|
267
|
+
}
|
|
268
|
+
async executeRequest(request, selected, ctx) {
|
|
269
|
+
const chatRequest = this.convertToChatRequest(request);
|
|
270
|
+
const executor = selected.provider.createExecutor(selected.providerConfig);
|
|
271
|
+
return await executor(chatRequest, ctx, ctx.metadata);
|
|
272
|
+
}
|
|
273
|
+
async *executeStreamRequest(request, selected, ctx) {
|
|
274
|
+
const chatRequest = this.convertToChatRequest(request);
|
|
275
|
+
const streamer = selected.provider.createStreamer(selected.providerConfig);
|
|
276
|
+
yield* streamer(chatRequest, ctx, ctx.metadata);
|
|
277
|
+
}
|
|
278
|
+
responseToChunks(response) {
|
|
279
|
+
return getChunksFromResponse(response);
|
|
280
|
+
}
|
|
281
|
+
chunksToResponse(chunks, model) {
|
|
282
|
+
return getResponseFromChunks(chunks);
|
|
283
|
+
}
|
|
284
|
+
getHandlerGetMethod(handler) {
|
|
285
|
+
return handler?.imageAnalyze?.get;
|
|
286
|
+
}
|
|
287
|
+
getHandlerStreamMethod(handler) {
|
|
288
|
+
return undefined; // Image analyze doesn't have streaming handler
|
|
289
|
+
}
|
|
290
|
+
hasProviderExecutor(selected) {
|
|
291
|
+
return !!selected.provider.createExecutor;
|
|
292
|
+
}
|
|
293
|
+
hasProviderStreamer(selected) {
|
|
294
|
+
return !!selected.provider.createStreamer;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
// ============================================================================
|
|
298
|
+
// Image API Facade
|
|
299
|
+
// ============================================================================
|
|
300
|
+
/**
|
|
301
|
+
* Image API - Facade providing access to generate, edit, and analyze sub-APIs
|
|
302
|
+
*/
|
|
303
|
+
export class ImageAPI {
|
|
304
|
+
generate;
|
|
305
|
+
edit;
|
|
306
|
+
analyze;
|
|
307
|
+
constructor(ai) {
|
|
308
|
+
this.generate = new ImageGenerateAPI(ai);
|
|
309
|
+
this.edit = new ImageEditAPI(ai);
|
|
310
|
+
this.analyze = new ImageAnalyzeAPI(ai);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
//# sourceMappingURL=image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.js","sourceRoot":"","sources":["../../src/apis/image.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAc,MAAM,YAAY,CAAC;AAmBtF,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,+EAA+E;AAC/E,qBAAqB;AACrB,+EAA+E;AAE/E,MAAM,gBAAwC,SAAQ,OAKrD;IACC,YAAY,EAAS;QACnB,KAAK,CAAC,EAAE,CAAC,CAAC;IACZ,CAAC;IAES,uBAAuB,CAAC,QAA2B,EAAE,OAAgC;QAC7F,OAAO,CAAC,OAAO,EAAE,GAAG,QAAQ,CAAC,CAAC;IAChC,CAAC;IAES,qBAAqB,CAAC,QAA0B,EAAE,OAA+B,EAAE,YAAqB;QAChH,MAAM,MAAM,GAAG,IAAI,GAAG,CAAiB,QAAQ,CAAC,CAAC;QAEjD,IAAI,OAAO,CAAC,CAAC,KAAK,SAAS,IAAI,OAAO,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/C,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QAC9B,CAAC;QACD,IAAI,OAAO,CAAC,UAAU,KA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1
|
+
/**
|
|
2
|
+
* Models API
|
|
3
|
+
*
|
|
4
|
+
* Provides access to model information, search, and discovery.
|
|
5
|
+
* Use this API to explore available models, find models with specific capabilities,
|
|
6
|
+
* or refresh model listings from providers.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // List all models
|
|
11
|
+
* const models = ai.models.list();
|
|
12
|
+
* console.log(`Found ${models.length} models`);
|
|
13
|
+
*
|
|
14
|
+
* // Get specific model
|
|
15
|
+
* const gpt4 = ai.models.get('gpt-4');
|
|
16
|
+
* console.log(gpt4?.capabilities);
|
|
17
|
+
*
|
|
18
|
+
* // Search for vision models
|
|
19
|
+
* const visionModels = ai.models.search({
|
|
20
|
+
* required: ['chat', 'vision'],
|
|
21
|
+
* weights: { cost: 0.7, speed: 0.3 }
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Refresh model listings
|
|
25
|
+
* await ai.models.refresh();
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
import type { ModelRegistry } from '../registry';
|
|
29
|
+
import type { AIBaseMetadata, ModelInfo, Providers, ScoredModel, SelectedModel } from '../types';
|
|
30
|
+
/**
|
|
31
|
+
* ModelsAPI provides methods for browsing and searching AI models.
|
|
32
|
+
*/
|
|
33
|
+
export declare class ModelsAPI<TProviders extends Providers> {
|
|
34
|
+
private registry;
|
|
35
|
+
constructor(registry: ModelRegistry<TProviders>);
|
|
36
|
+
/**
|
|
37
|
+
* List all available models across all providers.
|
|
38
|
+
*
|
|
39
|
+
* @returns Array of all registered models
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const models = ai.models.list();
|
|
44
|
+
* models.forEach(model => {
|
|
45
|
+
* console.log(`${model.provider}/${model.id}: ${model.capabilities}`);
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
list(providedOnly?: boolean): ModelInfo[];
|
|
50
|
+
/**
|
|
51
|
+
* Get a specific model by ID.
|
|
52
|
+
* Supports both "provider/model" (e.g., "openai/gpt-4") and "model" formats.
|
|
53
|
+
* When using just the model name, provider order determines which one is returned.
|
|
54
|
+
*
|
|
55
|
+
* @param id - Model identifier
|
|
56
|
+
* @returns Model info or undefined if not found
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const model = ai.models.get('gpt-4');
|
|
61
|
+
* // or
|
|
62
|
+
* const model = ai.models.get('openai/gpt-4');
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
get(id: string): ModelInfo | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Search models based on criteria and get scored results.
|
|
68
|
+
* Models are scored based on capability matching and selection weights.
|
|
69
|
+
*
|
|
70
|
+
* @param criteria - Search criteria including capabilities, providers, and weights
|
|
71
|
+
* @returns Array of models with scores, sorted by descending score
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* // Find best model for structured output
|
|
76
|
+
* const results = ai.models.search({
|
|
77
|
+
* required: ['chat', 'structured'],
|
|
78
|
+
* optional: ['vision'],
|
|
79
|
+
* weights: { cost: 0.6, speed: 0.4 },
|
|
80
|
+
* providers: { allow: ['openai', 'anthropic'] }
|
|
81
|
+
* });
|
|
82
|
+
*
|
|
83
|
+
* console.log(`Best match: ${results[0].model.id} (score: ${results[0].score})`);
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
search(criteria: AIBaseMetadata<TProviders>): ScoredModel[];
|
|
87
|
+
/**
|
|
88
|
+
* Select a model based on criteria.
|
|
89
|
+
* Returns the highest scored model or undefined if none match.
|
|
90
|
+
*
|
|
91
|
+
* @param criteria
|
|
92
|
+
*/
|
|
93
|
+
select(criteria: AIBaseMetadata<TProviders>): SelectedModel<TProviders, keyof TProviders> | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Refresh models from all providers and model sources.
|
|
96
|
+
* This re-fetches model information, useful for discovering new models
|
|
97
|
+
* or updating pricing information.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* console.log('Refreshing models...');
|
|
102
|
+
* await ai.models.refresh();
|
|
103
|
+
* console.log(`Now have ${ai.models.list().length} models`);
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
refresh(): Promise<void>;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../src/apis/models.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,SAAS,EACT,WAAW,EACX,aAAa,EACd,MAAM,UAAU,CAAC;AAElB;;GAEG;AACH,qBAAa,SAAS,CAAC,UAAU,SAAS,SAAS;IACrC,OAAO,CAAC,QAAQ;gBAAR,QAAQ,EAAE,aAAa,CAAC,UAAU,CAAC;IAEvD;;;;;;;;;;;;OAYG;IACH,IAAI,CAAC,YAAY,GAAE,OAAe,GAAG,SAAS,EAAE;IAIhD;;;;;;;;;;;;;;OAcG;IACH,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;IAItC;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,WAAW,EAAE;IAI3D;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,aAAa,CAAC,UAAU,EAAE,MAAM,UAAU,CAAC,GAAG,SAAS;IAIrG;;;;;;;;;;;OAWG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAG/B"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Models API
|
|
3
|
+
*
|
|
4
|
+
* Provides access to model information, search, and discovery.
|
|
5
|
+
* Use this API to explore available models, find models with specific capabilities,
|
|
6
|
+
* or refresh model listings from providers.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // List all models
|
|
11
|
+
* const models = ai.models.list();
|
|
12
|
+
* console.log(`Found ${models.length} models`);
|
|
13
|
+
*
|
|
14
|
+
* // Get specific model
|
|
15
|
+
* const gpt4 = ai.models.get('gpt-4');
|
|
16
|
+
* console.log(gpt4?.capabilities);
|
|
17
|
+
*
|
|
18
|
+
* // Search for vision models
|
|
19
|
+
* const visionModels = ai.models.search({
|
|
20
|
+
* required: ['chat', 'vision'],
|
|
21
|
+
* weights: { cost: 0.7, speed: 0.3 }
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* // Refresh model listings
|
|
25
|
+
* await ai.models.refresh();
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* ModelsAPI provides methods for browsing and searching AI models.
|
|
30
|
+
*/
|
|
31
|
+
export class ModelsAPI {
|
|
32
|
+
registry;
|
|
33
|
+
constructor(registry) {
|
|
34
|
+
this.registry = registry;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* List all available models across all providers.
|
|
38
|
+
*
|
|
39
|
+
* @returns Array of all registered models
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const models = ai.models.list();
|
|
44
|
+
* models.forEach(model => {
|
|
45
|
+
* console.log(`${model.provider}/${model.id}: ${model.capabilities}`);
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
list(providedOnly = false) {
|
|
50
|
+
return providedOnly ? this.registry.providedModels() : this.registry.listModels();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get a specific model by ID.
|
|
54
|
+
* Supports both "provider/model" (e.g., "openai/gpt-4") and "model" formats.
|
|
55
|
+
* When using just the model name, provider order determines which one is returned.
|
|
56
|
+
*
|
|
57
|
+
* @param id - Model identifier
|
|
58
|
+
* @returns Model info or undefined if not found
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const model = ai.models.get('gpt-4');
|
|
63
|
+
* // or
|
|
64
|
+
* const model = ai.models.get('openai/gpt-4');
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
get(id) {
|
|
68
|
+
return this.registry.getModel(id);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Search models based on criteria and get scored results.
|
|
72
|
+
* Models are scored based on capability matching and selection weights.
|
|
73
|
+
*
|
|
74
|
+
* @param criteria - Search criteria including capabilities, providers, and weights
|
|
75
|
+
* @returns Array of models with scores, sorted by descending score
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* // Find best model for structured output
|
|
80
|
+
* const results = ai.models.search({
|
|
81
|
+
* required: ['chat', 'structured'],
|
|
82
|
+
* optional: ['vision'],
|
|
83
|
+
* weights: { cost: 0.6, speed: 0.4 },
|
|
84
|
+
* providers: { allow: ['openai', 'anthropic'] }
|
|
85
|
+
* });
|
|
86
|
+
*
|
|
87
|
+
* console.log(`Best match: ${results[0].model.id} (score: ${results[0].score})`);
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
search(criteria) {
|
|
91
|
+
return this.registry.searchModels(criteria);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Select a model based on criteria.
|
|
95
|
+
* Returns the highest scored model or undefined if none match.
|
|
96
|
+
*
|
|
97
|
+
* @param criteria
|
|
98
|
+
*/
|
|
99
|
+
select(criteria) {
|
|
100
|
+
return this.registry.selectModel(criteria);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Refresh models from all providers and model sources.
|
|
104
|
+
* This re-fetches model information, useful for discovering new models
|
|
105
|
+
* or updating pricing information.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* console.log('Refreshing models...');
|
|
110
|
+
* await ai.models.refresh();
|
|
111
|
+
* console.log(`Now have ${ai.models.list().length} models`);
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
async refresh() {
|
|
115
|
+
await this.registry.refresh();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/apis/models.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAWH;;GAEG;AACH,MAAM,OAAO,SAAS;IACA;IAApB,YAAoB,QAAmC;QAAnC,aAAQ,GAAR,QAAQ,CAA2B;IAAG,CAAC;IAE3D;;;;;;;;;;;;OAYG;IACH,IAAI,CAAC,eAAwB,KAAK;QAChC,OAAO,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;IACpF,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,GAAG,CAAC,EAAU;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACpC,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,CAAC,QAAoC;QACzC,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,QAAoC;QACzC,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IAChC,CAAC;CACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Speech API
|
|
3
|
+
*
|
|
4
|
+
* Provides text-to-speech functionality.
|
|
5
|
+
*/
|
|
6
|
+
import type { Usage } from '@aeye/core';
|
|
7
|
+
import type { AI } from '../ai';
|
|
8
|
+
import type { AIBaseTypes, AIContext, ModelCapability, ModelHandlerFor, ModelParameter, SelectedModelFor, SpeechRequest, SpeechResponse } from '../types';
|
|
9
|
+
import { BaseAPI } from './base';
|
|
10
|
+
export declare class SpeechAPI<T extends AIBaseTypes> extends BaseAPI<T, SpeechRequest, SpeechResponse, SpeechResponse> {
|
|
11
|
+
constructor(ai: AI<T>);
|
|
12
|
+
protected getRequiredCapabilities(provided: ModelCapability[], request: SpeechRequest, forStreaming: boolean): ModelCapability[];
|
|
13
|
+
protected getRequiredParameters(provided: ModelParameter[], request: SpeechRequest, forStreaming: boolean): ModelParameter[];
|
|
14
|
+
protected getNoModelFoundError(): string;
|
|
15
|
+
protected getErrorType(operation: 'request' | 'stream'): string;
|
|
16
|
+
protected getErrorMessage(operation: 'request' | 'stream'): string;
|
|
17
|
+
protected executeRequest(request: SpeechRequest, selected: SelectedModelFor<T>, ctx: AIContext<T>): Promise<SpeechResponse>;
|
|
18
|
+
protected executeStreamRequest(request: SpeechRequest, selected: SelectedModelFor<T>, ctx: AIContext<T>): AsyncIterable<SpeechResponse>;
|
|
19
|
+
protected estimateRequestUsage(request: SpeechRequest): Usage;
|
|
20
|
+
protected responseToChunks(response: SpeechResponse): SpeechResponse[];
|
|
21
|
+
protected chunksToResponse(chunks: SpeechResponse[], model: string): SpeechResponse;
|
|
22
|
+
protected getHandlerGetMethod(handler?: ModelHandlerFor<T>): ((request: SpeechRequest, ctx: AIContext<T>) => Promise<SpeechResponse>) | undefined;
|
|
23
|
+
protected getHandlerStreamMethod(handler?: ModelHandlerFor<T>): ((request: SpeechRequest, ctx: AIContext<T>) => AsyncIterable<SpeechResponse>) | undefined;
|
|
24
|
+
protected hasProviderExecutor(selected: SelectedModelFor<T>): boolean;
|
|
25
|
+
protected hasProviderStreamer(selected: SelectedModelFor<T>): boolean;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=speech.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"speech.d.ts","sourceRoot":"","sources":["../../src/apis/speech.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,KAAK,EACV,WAAW,EACX,SAAS,EACT,eAAe,EACf,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,aAAa,EACb,cAAc,EACf,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,qBAAa,SAAS,CAAC,CAAC,SAAS,WAAW,CAAE,SAAQ,OAAO,CAC3D,CAAC,EACD,aAAa,EACb,cAAc,EACd,cAAc,CACf;gBACa,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;IAQrB,SAAS,CAAC,uBAAuB,CAAC,QAAQ,EAAE,eAAe,EAAE,EAAE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,OAAO,GAAG,eAAe,EAAE;IAIhI,SAAS,CAAC,qBAAqB,CAAC,QAAQ,EAAE,cAAc,EAAE,EAAE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,OAAO,GAAG,cAAc,EAAE;IAU5H,SAAS,CAAC,oBAAoB,IAAI,MAAM;IAIxC,SAAS,CAAC,YAAY,CAAC,SAAS,EAAE,SAAS,GAAG,QAAQ,GAAG,MAAM;IAM/D,SAAS,CAAC,eAAe,CAAC,SAAS,EAAE,SAAS,GAAG,QAAQ,GAAG,MAAM;cAMlD,cAAc,CAC5B,OAAO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
6
|
+
import { BaseAPI } from './base';
|
|
7
|
+
export class SpeechAPI extends BaseAPI {
|
|
8
|
+
constructor(ai) {
|
|
9
|
+
super(ai);
|
|
10
|
+
}
|
|
11
|
+
// ============================================================================
|
|
12
|
+
// REQUIRED ABSTRACT METHOD IMPLEMENTATIONS
|
|
13
|
+
// ============================================================================
|
|
14
|
+
getRequiredCapabilities(provided, request, forStreaming) {
|
|
15
|
+
return ['audio', ...provided];
|
|
16
|
+
}
|
|
17
|
+
getRequiredParameters(provided, request, forStreaming) {
|
|
18
|
+
const params = new Set(provided);
|
|
19
|
+
if (request.instructions !== undefined) {
|
|
20
|
+
params.add('speechInstructions');
|
|
21
|
+
}
|
|
22
|
+
return Array.from(params);
|
|
23
|
+
}
|
|
24
|
+
getNoModelFoundError() {
|
|
25
|
+
return 'No compatible model found for speech generation';
|
|
26
|
+
}
|
|
27
|
+
getErrorType(operation) {
|
|
28
|
+
return operation === 'request'
|
|
29
|
+
? 'speech-generation-failed'
|
|
30
|
+
: 'speech-generation-stream-failed';
|
|
31
|
+
}
|
|
32
|
+
getErrorMessage(operation) {
|
|
33
|
+
return operation === 'request'
|
|
34
|
+
? 'Speech generation failed'
|
|
35
|
+
: 'Speech generation streaming failed';
|
|
36
|
+
}
|
|
37
|
+
async executeRequest(request, selected, ctx) {
|
|
38
|
+
return await selected.provider.speech(request, ctx, selected.providerConfig);
|
|
39
|
+
}
|
|
40
|
+
async *executeStreamRequest(request, selected, ctx) {
|
|
41
|
+
yield this.executeRequest(request, selected, ctx);
|
|
42
|
+
}
|
|
43
|
+
// ============================================================================
|
|
44
|
+
// OPTIONAL OVERRIDES
|
|
45
|
+
// ============================================================================
|
|
46
|
+
estimateRequestUsage(request) {
|
|
47
|
+
const tokens = Math.ceil(request.text.length / 4);
|
|
48
|
+
// Estimate output audio duration (rough estimate: 150 words per minute, 4 chars per word)
|
|
49
|
+
const estimatedMinutes = (request.text.length / 4 / 150);
|
|
50
|
+
const estimatedSeconds = estimatedMinutes * 60;
|
|
51
|
+
return {
|
|
52
|
+
text: {
|
|
53
|
+
input: tokens
|
|
54
|
+
},
|
|
55
|
+
audio: {
|
|
56
|
+
seconds: estimatedSeconds
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
responseToChunks(response) {
|
|
61
|
+
return [response];
|
|
62
|
+
}
|
|
63
|
+
chunksToResponse(chunks, model) {
|
|
64
|
+
return chunks[0];
|
|
65
|
+
}
|
|
66
|
+
getHandlerGetMethod(handler) {
|
|
67
|
+
return handler?.speech?.get;
|
|
68
|
+
}
|
|
69
|
+
getHandlerStreamMethod(handler) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
hasProviderExecutor(selected) {
|
|
73
|
+
return !!selected.provider.speech;
|
|
74
|
+
}
|
|
75
|
+
hasProviderStreamer(selected) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=speech.js.map
|