@aeye/models 0.1.0 → 0.2.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/ReplicateScrape.md +260 -23
- package/dist/scripts/scrape.js +1 -1
- package/dist/scripts/scrape.js.map +1 -1
- package/dist/scripts/scrapers/aws.d.ts.map +1 -1
- package/dist/scripts/scrapers/aws.js +2 -236
- package/dist/scripts/scrapers/aws.js.map +1 -1
- package/dist/scripts/scrapers/replicate.d.ts +4 -0
- package/dist/scripts/scrapers/replicate.d.ts.map +1 -1
- package/dist/scripts/scrapers/replicate.js +343 -10
- package/dist/scripts/scrapers/replicate.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/models/aws.d.ts.map +1 -1
- package/dist/src/models/aws.js +266 -1478
- package/dist/src/models/aws.js.map +1 -1
- package/dist/src/models/index.d.ts +2 -1
- package/dist/src/models/index.d.ts.map +1 -1
- package/dist/src/models/index.js +3 -1
- package/dist/src/models/index.js.map +1 -1
- package/dist/src/models/replicate.d.ts.map +1 -1
- package/dist/src/models/replicate.js +2042 -1880
- package/dist/src/models/replicate.js.map +1 -1
- package/package.json +6 -4
- package/scripts/scrape.ts +1 -1
- package/scripts/scrapers/aws.ts +3 -266
- package/scripts/scrapers/extract.md +274 -0
- package/scripts/scrapers/replicate.ts +382 -11
- package/src/index.ts +1 -1
- package/src/models/aws.ts +266 -1478
- package/src/models/index.ts +3 -1
- package/src/models/replicate.ts +2042 -1880
- package/tsconfig.json +2 -1
package/scripts/scrapers/aws.ts
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* Fetches model information from AWS Bedrock using the AWS SDK
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import type {
|
|
7
|
+
import type { ModelInfo } from '@aeye/ai';
|
|
8
|
+
import { convertAWSModel } from '@aeye/aws';
|
|
8
9
|
import {
|
|
9
10
|
BedrockClient,
|
|
10
11
|
ListFoundationModelsCommand,
|
|
11
|
-
type FoundationModelSummary,
|
|
12
12
|
} from '@aws-sdk/client-bedrock';
|
|
13
13
|
import * as fs from 'fs/promises';
|
|
14
14
|
import * as path from 'path';
|
|
@@ -18,269 +18,6 @@ import { writeModelTS } from '../codegen';
|
|
|
18
18
|
const __filename = url.fileURLToPath(import.meta.url);
|
|
19
19
|
const __dirname = path.dirname(__filename);
|
|
20
20
|
|
|
21
|
-
/**
|
|
22
|
-
* Model pricing information (per million tokens)
|
|
23
|
-
* Source: https://aws.amazon.com/bedrock/pricing/
|
|
24
|
-
*/
|
|
25
|
-
const MODEL_PRICING: Record<string, { input: number; output: number }> = {
|
|
26
|
-
// Anthropic Claude 3.5 Sonnet
|
|
27
|
-
'anthropic.claude-3-5-sonnet-20240620-v1:0': { input: 3, output: 15 },
|
|
28
|
-
'anthropic.claude-3-5-sonnet-20241022-v2:0': { input: 3, output: 15 },
|
|
29
|
-
|
|
30
|
-
// Anthropic Claude 3 Opus
|
|
31
|
-
'anthropic.claude-3-opus-20240229-v1:0': { input: 15, output: 75 },
|
|
32
|
-
|
|
33
|
-
// Anthropic Claude 3 Sonnet
|
|
34
|
-
'anthropic.claude-3-sonnet-20240229-v1:0': { input: 3, output: 15 },
|
|
35
|
-
|
|
36
|
-
// Anthropic Claude 3 Haiku
|
|
37
|
-
'anthropic.claude-3-haiku-20240307-v1:0': { input: 0.25, output: 1.25 },
|
|
38
|
-
|
|
39
|
-
// Anthropic Claude 2.x
|
|
40
|
-
'anthropic.claude-v2:1': { input: 8, output: 24 },
|
|
41
|
-
'anthropic.claude-v2': { input: 8, output: 24 },
|
|
42
|
-
'anthropic.claude-instant-v1': { input: 0.8, output: 2.4 },
|
|
43
|
-
|
|
44
|
-
// Meta Llama 3.2
|
|
45
|
-
'meta.llama3-2-1b-instruct-v1:0': { input: 0.1, output: 0.1 },
|
|
46
|
-
'meta.llama3-2-3b-instruct-v1:0': { input: 0.15, output: 0.15 },
|
|
47
|
-
'meta.llama3-2-11b-instruct-v1:0': { input: 0.35, output: 0.35 },
|
|
48
|
-
'meta.llama3-2-90b-instruct-v1:0': { input: 2.65, output: 2.65 },
|
|
49
|
-
|
|
50
|
-
// Meta Llama 3.1
|
|
51
|
-
'meta.llama3-1-8b-instruct-v1:0': { input: 0.3, output: 0.6 },
|
|
52
|
-
'meta.llama3-1-70b-instruct-v1:0': { input: 2.65, output: 3.5 },
|
|
53
|
-
'meta.llama3-1-405b-instruct-v1:0': { input: 5.32, output: 16 },
|
|
54
|
-
|
|
55
|
-
// Meta Llama 3
|
|
56
|
-
'meta.llama3-8b-instruct-v1:0': { input: 0.3, output: 0.6 },
|
|
57
|
-
'meta.llama3-70b-instruct-v1:0': { input: 2.65, output: 3.5 },
|
|
58
|
-
|
|
59
|
-
// Meta Llama 2
|
|
60
|
-
'meta.llama2-13b-chat-v1': { input: 0.75, output: 1 },
|
|
61
|
-
'meta.llama2-70b-chat-v1': { input: 1.95, output: 2.56 },
|
|
62
|
-
|
|
63
|
-
// Mistral AI
|
|
64
|
-
'mistral.mistral-7b-instruct-v0:2': { input: 0.15, output: 0.2 },
|
|
65
|
-
'mistral.mixtral-8x7b-instruct-v0:1': { input: 0.45, output: 0.7 },
|
|
66
|
-
'mistral.mistral-large-2402-v1:0': { input: 4, output: 12 },
|
|
67
|
-
'mistral.mistral-large-2407-v1:0': { input: 3, output: 9 },
|
|
68
|
-
|
|
69
|
-
// Cohere
|
|
70
|
-
'cohere.command-text-v14': { input: 1.5, output: 2 },
|
|
71
|
-
'cohere.command-light-text-v14': { input: 0.3, output: 0.6 },
|
|
72
|
-
'cohere.command-r-v1:0': { input: 0.5, output: 1.5 },
|
|
73
|
-
'cohere.command-r-plus-v1:0': { input: 3, output: 15 },
|
|
74
|
-
|
|
75
|
-
// Amazon Titan Text
|
|
76
|
-
'amazon.titan-text-lite-v1': { input: 0.15, output: 0.2 },
|
|
77
|
-
'amazon.titan-text-express-v1': { input: 0.2, output: 0.6 },
|
|
78
|
-
'amazon.titan-text-premier-v1:0': { input: 0.5, output: 1.5 },
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Model context window information (in tokens)
|
|
83
|
-
* Source: AWS Bedrock documentation
|
|
84
|
-
*/
|
|
85
|
-
const MODEL_CONTEXT_WINDOWS: Record<string, { context: number; maxOutput?: number }> = {
|
|
86
|
-
// Anthropic Claude 3.5 Sonnet
|
|
87
|
-
'anthropic.claude-3-5-sonnet-20240620-v1:0': { context: 200000, maxOutput: 8192 },
|
|
88
|
-
'anthropic.claude-3-5-sonnet-20241022-v2:0': { context: 200000, maxOutput: 8192 },
|
|
89
|
-
|
|
90
|
-
// Anthropic Claude 3 Opus
|
|
91
|
-
'anthropic.claude-3-opus-20240229-v1:0': { context: 200000, maxOutput: 4096 },
|
|
92
|
-
|
|
93
|
-
// Anthropic Claude 3 Sonnet
|
|
94
|
-
'anthropic.claude-3-sonnet-20240229-v1:0': { context: 200000, maxOutput: 4096 },
|
|
95
|
-
|
|
96
|
-
// Anthropic Claude 3 Haiku
|
|
97
|
-
'anthropic.claude-3-haiku-20240307-v1:0': { context: 200000, maxOutput: 4096 },
|
|
98
|
-
|
|
99
|
-
// Anthropic Claude 2.x
|
|
100
|
-
'anthropic.claude-v2:1': { context: 100000, maxOutput: 4096 },
|
|
101
|
-
'anthropic.claude-v2': { context: 100000, maxOutput: 4096 },
|
|
102
|
-
'anthropic.claude-instant-v1': { context: 100000, maxOutput: 4096 },
|
|
103
|
-
|
|
104
|
-
// Meta Llama 3.2
|
|
105
|
-
'meta.llama3-2-1b-instruct-v1:0': { context: 128000, maxOutput: 2048 },
|
|
106
|
-
'meta.llama3-2-3b-instruct-v1:0': { context: 128000, maxOutput: 2048 },
|
|
107
|
-
'meta.llama3-2-11b-instruct-v1:0': { context: 128000, maxOutput: 2048 },
|
|
108
|
-
'meta.llama3-2-90b-instruct-v1:0': { context: 128000, maxOutput: 2048 },
|
|
109
|
-
|
|
110
|
-
// Meta Llama 3.1
|
|
111
|
-
'meta.llama3-1-8b-instruct-v1:0': { context: 128000, maxOutput: 2048 },
|
|
112
|
-
'meta.llama3-1-70b-instruct-v1:0': { context: 128000, maxOutput: 2048 },
|
|
113
|
-
'meta.llama3-1-405b-instruct-v1:0': { context: 128000, maxOutput: 4096 },
|
|
114
|
-
|
|
115
|
-
// Meta Llama 3
|
|
116
|
-
'meta.llama3-8b-instruct-v1:0': { context: 8192, maxOutput: 2048 },
|
|
117
|
-
'meta.llama3-70b-instruct-v1:0': { context: 8192, maxOutput: 2048 },
|
|
118
|
-
|
|
119
|
-
// Meta Llama 2
|
|
120
|
-
'meta.llama2-13b-chat-v1': { context: 4096, maxOutput: 2048 },
|
|
121
|
-
'meta.llama2-70b-chat-v1': { context: 4096, maxOutput: 2048 },
|
|
122
|
-
|
|
123
|
-
// Mistral AI
|
|
124
|
-
'mistral.mistral-7b-instruct-v0:2': { context: 32000, maxOutput: 8192 },
|
|
125
|
-
'mistral.mixtral-8x7b-instruct-v0:1': { context: 32000, maxOutput: 8192 },
|
|
126
|
-
'mistral.mistral-large-2402-v1:0': { context: 32000, maxOutput: 8192 },
|
|
127
|
-
'mistral.mistral-large-2407-v1:0': { context: 128000, maxOutput: 8192 },
|
|
128
|
-
|
|
129
|
-
// Cohere
|
|
130
|
-
'cohere.command-text-v14': { context: 4096, maxOutput: 4096 },
|
|
131
|
-
'cohere.command-light-text-v14': { context: 4096, maxOutput: 4096 },
|
|
132
|
-
'cohere.command-r-v1:0': { context: 128000, maxOutput: 4096 },
|
|
133
|
-
'cohere.command-r-plus-v1:0': { context: 128000, maxOutput: 4096 },
|
|
134
|
-
|
|
135
|
-
// Amazon Titan Text
|
|
136
|
-
'amazon.titan-text-lite-v1': { context: 4096, maxOutput: 4096 },
|
|
137
|
-
'amazon.titan-text-express-v1': { context: 8192, maxOutput: 8192 },
|
|
138
|
-
'amazon.titan-text-premier-v1:0': { context: 32000, maxOutput: 3072 },
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Detect model family from model ID
|
|
143
|
-
*/
|
|
144
|
-
function detectModelFamily(modelId: string): string {
|
|
145
|
-
if (modelId.startsWith('anthropic.')) return 'anthropic';
|
|
146
|
-
if (modelId.startsWith('meta.')) return 'meta';
|
|
147
|
-
if (modelId.startsWith('mistral.')) return 'mistral';
|
|
148
|
-
if (modelId.startsWith('cohere.')) return 'cohere';
|
|
149
|
-
if (modelId.startsWith('ai21.')) return 'ai21';
|
|
150
|
-
if (modelId.startsWith('amazon.')) return 'amazon';
|
|
151
|
-
if (modelId.startsWith('stability.')) return 'stability';
|
|
152
|
-
return 'unknown';
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Detect capabilities from model information
|
|
157
|
-
*/
|
|
158
|
-
function detectCapabilities(model: FoundationModelSummary): Set<ModelCapability> {
|
|
159
|
-
const capabilities = new Set<ModelCapability>();
|
|
160
|
-
const modelId = model.modelId || '';
|
|
161
|
-
const family = detectModelFamily(modelId);
|
|
162
|
-
|
|
163
|
-
// Check for chat capability (text-to-text models)
|
|
164
|
-
if (
|
|
165
|
-
model.inputModalities?.includes('TEXT') &&
|
|
166
|
-
model.outputModalities?.includes('TEXT')
|
|
167
|
-
) {
|
|
168
|
-
// Chat models
|
|
169
|
-
if (
|
|
170
|
-
family === 'anthropic' ||
|
|
171
|
-
family === 'meta' ||
|
|
172
|
-
family === 'mistral' ||
|
|
173
|
-
family === 'cohere' ||
|
|
174
|
-
family === 'ai21' ||
|
|
175
|
-
(family === 'amazon' && modelId.includes('text'))
|
|
176
|
-
) {
|
|
177
|
-
capabilities.add('chat');
|
|
178
|
-
|
|
179
|
-
// Streaming support
|
|
180
|
-
if (model.responseStreamingSupported) {
|
|
181
|
-
capabilities.add('streaming');
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// Image generation
|
|
187
|
-
if (
|
|
188
|
-
model.inputModalities?.includes('TEXT') &&
|
|
189
|
-
model.outputModalities?.includes('IMAGE')
|
|
190
|
-
) {
|
|
191
|
-
capabilities.add('image');
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// Vision (image understanding)
|
|
195
|
-
if (
|
|
196
|
-
model.inputModalities?.includes('IMAGE') &&
|
|
197
|
-
model.outputModalities?.includes('TEXT')
|
|
198
|
-
) {
|
|
199
|
-
capabilities.add('vision');
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// Embeddings
|
|
203
|
-
if (family === 'amazon' && modelId.includes('embed')) {
|
|
204
|
-
capabilities.add('embedding');
|
|
205
|
-
}
|
|
206
|
-
if (family === 'cohere' && modelId.includes('embed')) {
|
|
207
|
-
capabilities.add('embedding');
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// Tool calling for supported models
|
|
211
|
-
if (family === 'anthropic' && modelId.includes('claude-3')) {
|
|
212
|
-
capabilities.add('tools');
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
return capabilities;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Convert AWS Bedrock model to ModelInfo format
|
|
220
|
-
*/
|
|
221
|
-
function convertAWSModel(model: FoundationModelSummary): ModelInfo | null {
|
|
222
|
-
const modelId = model.modelId;
|
|
223
|
-
if (!modelId) return null;
|
|
224
|
-
|
|
225
|
-
const family = detectModelFamily(modelId);
|
|
226
|
-
const capabilities = detectCapabilities(model);
|
|
227
|
-
|
|
228
|
-
// Determine tier based on model family and name
|
|
229
|
-
let tier: ModelTier = 'efficient';
|
|
230
|
-
if (family === 'anthropic' && modelId.includes('opus')) {
|
|
231
|
-
tier = 'flagship';
|
|
232
|
-
} else if (family === 'anthropic' && modelId.includes('sonnet')) {
|
|
233
|
-
tier = 'efficient';
|
|
234
|
-
} else if (family === 'anthropic' && modelId.includes('haiku')) {
|
|
235
|
-
tier = 'efficient';
|
|
236
|
-
} else if (family === 'meta' && (modelId.includes('405b') || modelId.includes('90b'))) {
|
|
237
|
-
tier = 'flagship';
|
|
238
|
-
} else if (family === 'meta' && (modelId.includes('70b') || modelId.includes('13b'))) {
|
|
239
|
-
tier = 'efficient';
|
|
240
|
-
} else if (family === 'meta' && (modelId.includes('8b') || modelId.includes('7b') || modelId.includes('3b') || modelId.includes('1b'))) {
|
|
241
|
-
tier = 'efficient';
|
|
242
|
-
} else if (family === 'mistral' && modelId.includes('large')) {
|
|
243
|
-
tier = 'flagship';
|
|
244
|
-
} else if (family === 'mistral' && modelId.includes('mixtral')) {
|
|
245
|
-
tier = 'efficient';
|
|
246
|
-
} else if (family === 'mistral' && modelId.includes('7b')) {
|
|
247
|
-
tier = 'efficient';
|
|
248
|
-
} else if (family === 'cohere' && modelId.includes('plus')) {
|
|
249
|
-
tier = 'flagship';
|
|
250
|
-
} else {
|
|
251
|
-
tier = 'efficient';
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// Get pricing information
|
|
255
|
-
const pricing = MODEL_PRICING[modelId];
|
|
256
|
-
const contextInfo = MODEL_CONTEXT_WINDOWS[modelId];
|
|
257
|
-
|
|
258
|
-
return {
|
|
259
|
-
provider: 'aws',
|
|
260
|
-
id: modelId,
|
|
261
|
-
name: model.modelName || modelId,
|
|
262
|
-
capabilities,
|
|
263
|
-
tier,
|
|
264
|
-
pricing: pricing ? {
|
|
265
|
-
text: {
|
|
266
|
-
input: pricing.input,
|
|
267
|
-
output: pricing.output,
|
|
268
|
-
},
|
|
269
|
-
} : {},
|
|
270
|
-
contextWindow: contextInfo?.context || 0,
|
|
271
|
-
maxOutputTokens: contextInfo?.maxOutput,
|
|
272
|
-
metadata: {
|
|
273
|
-
modelArn: model.modelArn,
|
|
274
|
-
providerName: model.providerName,
|
|
275
|
-
responseStreamingSupported: model.responseStreamingSupported,
|
|
276
|
-
customizationsSupported: model.customizationsSupported,
|
|
277
|
-
inferenceTypesSupported: model.inferenceTypesSupported,
|
|
278
|
-
inputModalities: model.inputModalities,
|
|
279
|
-
outputModalities: model.outputModalities,
|
|
280
|
-
},
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
|
|
284
21
|
/**
|
|
285
22
|
* Main scraper function
|
|
286
23
|
*/
|
|
@@ -288,7 +25,7 @@ export async function scrapeAWS(
|
|
|
288
25
|
outputDir: string,
|
|
289
26
|
options: { region?: string } = {}
|
|
290
27
|
): Promise<void> {
|
|
291
|
-
const { region = process.env.AWS_REGION || 'us-east-
|
|
28
|
+
const { region = process.env.AWS_REGION || 'us-east-2' } = options;
|
|
292
29
|
|
|
293
30
|
console.log('\n=== AWS Bedrock Scraper ===\n');
|
|
294
31
|
console.log(`Using region: ${region}`);
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
Run `npm run scrape:replicate`
|
|
2
|
+
|
|
3
|
+
I want you to consume one model chunk file at a time. They are in cache/replicate-schemas-chunk-#.json. Each model has latest_version and in the components of the schema has Input & Output. You need to do one at a time because each file is ~ 20k tokens.
|
|
4
|
+
|
|
5
|
+
What you need to do is replace/create a src/replicate.ts file with all model handlers that make sense for each model. A model handler allows you to link a particular model ID with a set of supported functions. Like chat prediction, image generation, etc.
|
|
6
|
+
|
|
7
|
+
Here's the shape of the ModelHandler from the `@aeye/ai` package:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
export interface ModelTransformer {
|
|
11
|
+
chat?: {
|
|
12
|
+
convertRequest?: (request: Request, ctx: AIContextAny) => Promise<object>;
|
|
13
|
+
parseResponse?: (response: object, ctx: AIContextAny) => Promise<Response>;
|
|
14
|
+
parseChunk?: (chunk: object, ctx: AIContextAny) => Promise<Chunk>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
imageGenerate?: {
|
|
18
|
+
convertRequest?: (request: ImageGenerationRequest, ctx: AIContextAny) => Promise<object>;
|
|
19
|
+
parseResponse?: (response: object, ctx: AIContextAny) => Promise<ImageGenerationResponse>;
|
|
20
|
+
parseChunk?: (chunk: object, ctx: AIContextAny) => Promise<ImageGenerationChunk>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
imageEdit?: {
|
|
24
|
+
convertRequest?: (request: ImageEditRequest, ctx: AIContextAny) => Promise<object>;
|
|
25
|
+
parseResponse?: (response: object, ctx: AIContextAny) => Promise<ImageGenerationResponse>;
|
|
26
|
+
parseChunk?: (chunk: object, ctx: AIContextAny) => Promise<ImageGenerationChunk>;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
imageAnalyze?: {
|
|
30
|
+
convertRequest?: (request: ImageAnalyzeRequest, ctx: AIContextAny) => Promise<object>;
|
|
31
|
+
parseResponse?: (response: object, ctx: AIContextAny) => Promise<Response>;
|
|
32
|
+
parseChunk?: (chunk: object, ctx: AIContextAny) => Promise<Chunk>;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
transcribe?: {
|
|
36
|
+
convertRequest?: (request: TranscriptionRequest, ctx: AIContextAny) => Promise<object>;
|
|
37
|
+
parseResponse?: (response: object, ctx: AIContextAny) => Promise<TranscriptionResponse>;
|
|
38
|
+
parseChunk?: (chunk: object, ctx: AIContextAny) => Promise<TranscriptionChunk>;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
speech?: {
|
|
42
|
+
convertRequest?: (request: SpeechRequest, ctx: AIContextAny) => Promise<object>;
|
|
43
|
+
parseResponse?: (response: object, ctx: AIContextAny) => Promise<SpeechResponse>;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
embed?: {
|
|
47
|
+
convertRequest?: (request: EmbeddingRequest, ctx: AIContextAny) => Promise<object>;
|
|
48
|
+
parseResponse?: (response: object, ctx: AIContextAny) => Promise<EmbeddingResponse>;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
And here are the referenced types:
|
|
54
|
+
```ts
|
|
55
|
+
export type MessageRole = 'system' | 'user' | 'assistant' | 'tool';
|
|
56
|
+
export interface Message {
|
|
57
|
+
role: MessageRole;
|
|
58
|
+
content: string | MessageContent[];
|
|
59
|
+
tokens?: number;
|
|
60
|
+
name?: string;
|
|
61
|
+
toolCallId?: string;
|
|
62
|
+
toolCalls?: ToolCall[];
|
|
63
|
+
refusal?: string;
|
|
64
|
+
cache?: Record<string, any>;
|
|
65
|
+
}
|
|
66
|
+
export type MessageContentType = 'text' | 'image' | 'file' | 'audio';
|
|
67
|
+
export interface MessageContent {
|
|
68
|
+
type: MessageContentType;
|
|
69
|
+
content: Resource;
|
|
70
|
+
format?: string;
|
|
71
|
+
}
|
|
72
|
+
export interface ToolDefinition {
|
|
73
|
+
name: string;
|
|
74
|
+
description?: string;
|
|
75
|
+
parameters: z.ZodType<object>;
|
|
76
|
+
strict?: boolean;
|
|
77
|
+
}
|
|
78
|
+
export interface ToolCall {
|
|
79
|
+
id: string;
|
|
80
|
+
name: string;
|
|
81
|
+
arguments: string;
|
|
82
|
+
}
|
|
83
|
+
export type ToolChoice =
|
|
84
|
+
| 'auto'
|
|
85
|
+
| 'none'
|
|
86
|
+
| 'required'
|
|
87
|
+
| { tool: string };
|
|
88
|
+
export type ResponseFormat =
|
|
89
|
+
| 'text'
|
|
90
|
+
| 'json'
|
|
91
|
+
| { type: z.ZodType<object, object>, strict: boolean };
|
|
92
|
+
export interface Usage {
|
|
93
|
+
text?: {
|
|
94
|
+
input?: number;
|
|
95
|
+
output?: number;
|
|
96
|
+
cached?: number;
|
|
97
|
+
};
|
|
98
|
+
audio?: {
|
|
99
|
+
input?: number;
|
|
100
|
+
output?: number;
|
|
101
|
+
seconds?: number;
|
|
102
|
+
};
|
|
103
|
+
image?: {
|
|
104
|
+
input?: number;
|
|
105
|
+
output?: {
|
|
106
|
+
quality: string;
|
|
107
|
+
size: { width: number; height: number; };
|
|
108
|
+
count: number;
|
|
109
|
+
}[];
|
|
110
|
+
};
|
|
111
|
+
reasoning?: {
|
|
112
|
+
input?: number;
|
|
113
|
+
output?: number;
|
|
114
|
+
cached?: number;
|
|
115
|
+
};
|
|
116
|
+
embeddings?: {
|
|
117
|
+
count?: number;
|
|
118
|
+
tokens?: number;
|
|
119
|
+
};
|
|
120
|
+
cost?: number;
|
|
121
|
+
}
|
|
122
|
+
export type ReasoningEffort = 'low' | 'medium' | 'high';
|
|
123
|
+
export interface Request extends BaseRequest {
|
|
124
|
+
name?: string;
|
|
125
|
+
messages: Message[];
|
|
126
|
+
temperature?: number;
|
|
127
|
+
maxTokens?: number;
|
|
128
|
+
topP?: number;
|
|
129
|
+
frequencyPenalty?: number;
|
|
130
|
+
presencePenalty?: number;
|
|
131
|
+
stop?: string | string[];
|
|
132
|
+
logProbabilities?: boolean;
|
|
133
|
+
logitBias?: Record<string, number>;
|
|
134
|
+
tools?: ToolDefinition[];
|
|
135
|
+
toolsOneAtATime?: boolean;
|
|
136
|
+
toolChoice?: ToolChoice;
|
|
137
|
+
responseFormat?: ResponseFormat;
|
|
138
|
+
reason?: { effort?: ReasoningEffort, maxTokens?: number };
|
|
139
|
+
cacheKey?: string;
|
|
140
|
+
userKey?: string;
|
|
141
|
+
}
|
|
142
|
+
export type FinishReason = 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'refusal';
|
|
143
|
+
export interface Model {
|
|
144
|
+
id: string;
|
|
145
|
+
contextWindow?: number;
|
|
146
|
+
maxOutputTokens?: number;
|
|
147
|
+
}
|
|
148
|
+
export type ModelInput = string | Model;
|
|
149
|
+
export interface BaseRequest {
|
|
150
|
+
model?: ModelInput;
|
|
151
|
+
extra?: Record<string, any>;
|
|
152
|
+
}
|
|
153
|
+
export interface BaseResponse {
|
|
154
|
+
usage?: Usage;
|
|
155
|
+
model: ModelInput;
|
|
156
|
+
}
|
|
157
|
+
export interface BaseChunk {
|
|
158
|
+
usage?: Usage;
|
|
159
|
+
model?: ModelInput;
|
|
160
|
+
}
|
|
161
|
+
export interface Response extends BaseResponse {
|
|
162
|
+
content: string;
|
|
163
|
+
toolCalls?: ToolCall[];
|
|
164
|
+
finishReason: FinishReason;
|
|
165
|
+
refusal?: string;
|
|
166
|
+
reasoning?: string;
|
|
167
|
+
}
|
|
168
|
+
export interface Chunk extends BaseChunk {
|
|
169
|
+
content?: string;
|
|
170
|
+
toolCallNamed?: ToolCall;
|
|
171
|
+
toolCallArguments?: ToolCall;
|
|
172
|
+
toolCall?: ToolCall;
|
|
173
|
+
finishReason?: FinishReason;
|
|
174
|
+
refusal?: string;
|
|
175
|
+
reasoning?: string;
|
|
176
|
+
}
|
|
177
|
+
export interface ImageGenerationRequest extends BaseRequest {
|
|
178
|
+
prompt: string;
|
|
179
|
+
n?: number;
|
|
180
|
+
size?: string;
|
|
181
|
+
quality?: 'low' | 'medium' | 'high';
|
|
182
|
+
style?: 'vivid' | 'natural';
|
|
183
|
+
responseFormat?: 'url' | 'b64_json';
|
|
184
|
+
background?: 'transparent' | 'opaque' | 'auto';
|
|
185
|
+
streamCount?: number;
|
|
186
|
+
seed?: number;
|
|
187
|
+
userIdentifier?: string;
|
|
188
|
+
}
|
|
189
|
+
export interface ImageEditRequest extends BaseRequest {
|
|
190
|
+
prompt: string;
|
|
191
|
+
image: Resource;
|
|
192
|
+
mask?: Resource;
|
|
193
|
+
n?: number;
|
|
194
|
+
size?: string;
|
|
195
|
+
responseFormat?: 'url' | 'b64_json';
|
|
196
|
+
seed?: number;
|
|
197
|
+
streamCount?: number;
|
|
198
|
+
userIdentifier?: string;
|
|
199
|
+
}
|
|
200
|
+
export interface ImageGenerationResponse extends BaseResponse {
|
|
201
|
+
images: Array<{
|
|
202
|
+
url?: string;
|
|
203
|
+
b64_json?: string;
|
|
204
|
+
revisedPrompt?: string;
|
|
205
|
+
}>;
|
|
206
|
+
}
|
|
207
|
+
export interface ImageGenerationChunk extends BaseChunk {
|
|
208
|
+
imageData?: string;
|
|
209
|
+
progress?: number;
|
|
210
|
+
done?: boolean;
|
|
211
|
+
image?: {
|
|
212
|
+
url?: string;
|
|
213
|
+
b64_json?: string;
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
export interface TranscriptionRequest extends BaseRequest {
|
|
217
|
+
audio: Resource;
|
|
218
|
+
language?: string;
|
|
219
|
+
prompt?: string;
|
|
220
|
+
temperature?: number;
|
|
221
|
+
responseFormat?: 'json' | 'text' | 'srt' | 'vtt' | 'verbose_json';
|
|
222
|
+
timestampGranularities?: Array<'word' | 'segment'>;
|
|
223
|
+
}
|
|
224
|
+
export interface TranscriptionResponse extends BaseResponse {
|
|
225
|
+
text: string;
|
|
226
|
+
}
|
|
227
|
+
export interface TranscriptionChunk extends BaseChunk {
|
|
228
|
+
delta?: string;
|
|
229
|
+
text?: string;
|
|
230
|
+
segment?: { start: number; end: number; speaker: string, text: string, id: string };
|
|
231
|
+
status?: string;
|
|
232
|
+
}
|
|
233
|
+
export interface SpeechRequest extends BaseRequest{
|
|
234
|
+
text: string;
|
|
235
|
+
instructions?: string;
|
|
236
|
+
voice?: string;
|
|
237
|
+
speed?: number;
|
|
238
|
+
responseFormat?: 'mp3' | 'opus' | 'aac' | 'flac' | 'wav' | 'pcm';
|
|
239
|
+
}
|
|
240
|
+
export interface SpeechResponse extends BaseResponse {
|
|
241
|
+
audio: ReadableStream<any>;
|
|
242
|
+
responseFormat?: 'mp3' | 'opus' | 'aac' | 'flac' | 'wav' | 'pcm';
|
|
243
|
+
}
|
|
244
|
+
export interface EmbeddingRequest extends BaseRequest {
|
|
245
|
+
texts: string[];
|
|
246
|
+
dimensions?: number;
|
|
247
|
+
encodingFormat?: 'float' | 'base64';
|
|
248
|
+
userIdentifier?: string;
|
|
249
|
+
}
|
|
250
|
+
export interface EmbeddingResponse extends BaseResponse {
|
|
251
|
+
embeddings: Array<{
|
|
252
|
+
embedding: number[];
|
|
253
|
+
index: number;
|
|
254
|
+
}>;
|
|
255
|
+
}
|
|
256
|
+
export interface ImageAnalyzeRequest extends BaseRequest{
|
|
257
|
+
prompt: string;
|
|
258
|
+
images: string[];
|
|
259
|
+
maxTokens?: number;
|
|
260
|
+
temperature?: number;
|
|
261
|
+
}
|
|
262
|
+
export type Resource =
|
|
263
|
+
| string // plain text, or data URL, or http(s) URL, or file:// URL
|
|
264
|
+
| AsyncIterable<Uint8Array> // fs.ReadStream, ReadableStream
|
|
265
|
+
| Blob // File
|
|
266
|
+
| Uint8Array
|
|
267
|
+
| URL
|
|
268
|
+
| ArrayBuffer
|
|
269
|
+
| DataView
|
|
270
|
+
| Buffer
|
|
271
|
+
| { blob(): Promise<Blob> | Blob }
|
|
272
|
+
| { url(): string }
|
|
273
|
+
| { read(): Promise<ReadableStream> | ReadableStream }
|
|
274
|
+
```
|