@llmgateway/models 0.0.1
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/dist/get-cheapest-from-available-providers.d.ts +30 -0
- package/dist/get-cheapest-from-available-providers.js +183 -0
- package/dist/get-cheapest-from-available-providers.js.map +1 -0
- package/dist/get-cheapest-model-for-provider.d.ts +2 -0
- package/dist/get-cheapest-model-for-provider.js +49 -0
- package/dist/get-cheapest-model-for-provider.js.map +1 -0
- package/dist/get-provider-endpoint.d.ts +3 -0
- package/dist/get-provider-endpoint.js +243 -0
- package/dist/get-provider-endpoint.js.map +1 -0
- package/dist/get-provider-headers.d.ts +5 -0
- package/dist/get-provider-headers.js +45 -0
- package/dist/get-provider-headers.js.map +1 -0
- package/dist/helpers.d.ts +1 -0
- package/dist/helpers.js +27 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/models/alibaba.d.ts +686 -0
- package/dist/models/alibaba.js +789 -0
- package/dist/models/alibaba.js.map +1 -0
- package/dist/models/anthropic.d.ts +572 -0
- package/dist/models/anthropic.js +638 -0
- package/dist/models/anthropic.js.map +1 -0
- package/dist/models/aws-bedrock.d.ts +1 -0
- package/dist/models/aws-bedrock.js +2 -0
- package/dist/models/aws-bedrock.js.map +1 -0
- package/dist/models/bytedance.d.ts +131 -0
- package/dist/models/bytedance.js +151 -0
- package/dist/models/bytedance.js.map +1 -0
- package/dist/models/deepseek.d.ts +175 -0
- package/dist/models/deepseek.js +197 -0
- package/dist/models/deepseek.js.map +1 -0
- package/dist/models/google.d.ts +1065 -0
- package/dist/models/google.js +1201 -0
- package/dist/models/google.js.map +1 -0
- package/dist/models/llmgateway.d.ts +39 -0
- package/dist/models/llmgateway.js +59 -0
- package/dist/models/llmgateway.js.map +1 -0
- package/dist/models/meta.d.ts +263 -0
- package/dist/models/meta.js +300 -0
- package/dist/models/meta.js.map +1 -0
- package/dist/models/microsoft.d.ts +1 -0
- package/dist/models/microsoft.js +2 -0
- package/dist/models/microsoft.js.map +1 -0
- package/dist/models/minimax.d.ts +59 -0
- package/dist/models/minimax.js +68 -0
- package/dist/models/minimax.js.map +1 -0
- package/dist/models/mistral.d.ts +78 -0
- package/dist/models/mistral.js +92 -0
- package/dist/models/mistral.js.map +1 -0
- package/dist/models/moonshot.d.ts +165 -0
- package/dist/models/moonshot.js +184 -0
- package/dist/models/moonshot.js.map +1 -0
- package/dist/models/nousresearch.d.ts +21 -0
- package/dist/models/nousresearch.js +26 -0
- package/dist/models/nousresearch.js.map +1 -0
- package/dist/models/openai.d.ts +1018 -0
- package/dist/models/openai.js +1213 -0
- package/dist/models/openai.js.map +1 -0
- package/dist/models/perplexity.d.ts +67 -0
- package/dist/models/perplexity.js +78 -0
- package/dist/models/perplexity.js.map +1 -0
- package/dist/models/routeway.d.ts +161 -0
- package/dist/models/routeway.js +187 -0
- package/dist/models/routeway.js.map +1 -0
- package/dist/models/xai.d.ts +270 -0
- package/dist/models/xai.js +311 -0
- package/dist/models/xai.js.map +1 -0
- package/dist/models/zai.d.ts +492 -0
- package/dist/models/zai.js +551 -0
- package/dist/models/zai.js.map +1 -0
- package/dist/models.d.ts +5304 -0
- package/dist/models.js +37 -0
- package/dist/models.js.map +1 -0
- package/dist/models.spec.d.ts +1 -0
- package/dist/models.spec.js +263 -0
- package/dist/models.spec.js.map +1 -0
- package/dist/prepare-request-body.d.ts +10 -0
- package/dist/prepare-request-body.js +1081 -0
- package/dist/prepare-request-body.js.map +1 -0
- package/dist/prepare-request-body.spec.d.ts +1 -0
- package/dist/prepare-request-body.spec.js +231 -0
- package/dist/prepare-request-body.spec.js.map +1 -0
- package/dist/process-image-url.d.ts +4 -0
- package/dist/process-image-url.js +121 -0
- package/dist/process-image-url.js.map +1 -0
- package/dist/provider.d.ts +9 -0
- package/dist/provider.js +64 -0
- package/dist/provider.js.map +1 -0
- package/dist/providers.d.ts +405 -0
- package/dist/providers.js +413 -0
- package/dist/providers.js.map +1 -0
- package/dist/testing.d.ts +7 -0
- package/dist/testing.js +19 -0
- package/dist/testing.js.map +1 -0
- package/dist/transform-anthropic-messages.d.ts +2 -0
- package/dist/transform-anthropic-messages.js +185 -0
- package/dist/transform-anthropic-messages.js.map +1 -0
- package/dist/transform-google-messages.d.ts +25 -0
- package/dist/transform-google-messages.js +122 -0
- package/dist/transform-google-messages.js.map +1 -0
- package/dist/type-guards.d.ts +20 -0
- package/dist/type-guards.js +35 -0
- package/dist/type-guards.js.map +1 -0
- package/dist/types.d.ts +291 -0
- package/dist/types.js +28 -0
- package/dist/types.js.map +1 -0
- package/dist/validate-provider-key.d.ts +4 -0
- package/dist/validate-provider-key.js +113 -0
- package/dist/validate-provider-key.js.map +1 -0
- package/package.json +29 -0
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
export const providers = [
|
|
2
|
+
{
|
|
3
|
+
id: "llmgateway",
|
|
4
|
+
name: "LLM Gateway",
|
|
5
|
+
description: "LLMGateway is a framework for building and deploying large language models.",
|
|
6
|
+
env: {
|
|
7
|
+
required: {
|
|
8
|
+
apiKey: "LLM_LLMGATEWAY_API_KEY",
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
streaming: true,
|
|
12
|
+
cancellation: true,
|
|
13
|
+
color: "#6366f1",
|
|
14
|
+
website: "https://llmgateway.io",
|
|
15
|
+
announcement: null,
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
id: "openai",
|
|
19
|
+
name: "OpenAI",
|
|
20
|
+
description: "OpenAI is an AI research and deployment company. Our mission is to ensure that artificial general intelligence benefits all of humanity.",
|
|
21
|
+
env: {
|
|
22
|
+
required: {
|
|
23
|
+
apiKey: "LLM_OPENAI_API_KEY",
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
streaming: true,
|
|
27
|
+
cancellation: true,
|
|
28
|
+
color: "#0ea5e9",
|
|
29
|
+
website: "https://openai.com",
|
|
30
|
+
announcement: null,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: "anthropic",
|
|
34
|
+
name: "Anthropic",
|
|
35
|
+
description: "Anthropic is a research and deployment company focused on building safe and useful AI.",
|
|
36
|
+
env: {
|
|
37
|
+
required: {
|
|
38
|
+
apiKey: "LLM_ANTHROPIC_API_KEY",
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
streaming: true,
|
|
42
|
+
cancellation: true,
|
|
43
|
+
color: "#8b5cf6",
|
|
44
|
+
website: "https://anthropic.com",
|
|
45
|
+
announcement: null,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: "google-ai-studio",
|
|
49
|
+
name: "Google AI Studio",
|
|
50
|
+
description: "Google AI Studio is a platform for accessing Google's Gemini models.",
|
|
51
|
+
env: {
|
|
52
|
+
required: {
|
|
53
|
+
apiKey: "LLM_GOOGLE_AI_STUDIO_API_KEY",
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
streaming: true,
|
|
57
|
+
cancellation: true,
|
|
58
|
+
color: "#4285f4",
|
|
59
|
+
website: "https://ai.google.com",
|
|
60
|
+
announcement: null,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
id: "google-vertex",
|
|
64
|
+
name: "Google Vertex AI",
|
|
65
|
+
description: "Google Vertex AI is a platform for accessing Google's Gemini models via Vertex AI.",
|
|
66
|
+
env: {
|
|
67
|
+
required: {
|
|
68
|
+
apiKey: "LLM_GOOGLE_VERTEX_API_KEY",
|
|
69
|
+
project: "LLM_GOOGLE_CLOUD_PROJECT",
|
|
70
|
+
},
|
|
71
|
+
optional: {
|
|
72
|
+
region: "LLM_GOOGLE_VERTEX_REGION",
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
streaming: true,
|
|
76
|
+
cancellation: true,
|
|
77
|
+
color: "#4285f4",
|
|
78
|
+
website: "https://cloud.google.com/vertex-ai",
|
|
79
|
+
announcement: null,
|
|
80
|
+
priority: 0.5,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: "groq",
|
|
84
|
+
name: "Groq",
|
|
85
|
+
description: "Groq's ultra-fast LPU inference with various models",
|
|
86
|
+
env: {
|
|
87
|
+
required: {
|
|
88
|
+
apiKey: "LLM_GROQ_API_KEY",
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
streaming: true,
|
|
92
|
+
cancellation: true,
|
|
93
|
+
color: "#F55036",
|
|
94
|
+
website: "https://groq.com",
|
|
95
|
+
announcement: null,
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
id: "cerebras",
|
|
99
|
+
name: "Cerebras",
|
|
100
|
+
description: "Cerebras high-performance inference with ultra-fast throughput",
|
|
101
|
+
env: {
|
|
102
|
+
required: {
|
|
103
|
+
apiKey: "LLM_CEREBRAS_API_KEY",
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
streaming: true,
|
|
107
|
+
cancellation: true,
|
|
108
|
+
color: "#6b46c1",
|
|
109
|
+
website: "https://cerebras.ai",
|
|
110
|
+
announcement: null,
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
id: "xai",
|
|
114
|
+
name: "xAI",
|
|
115
|
+
description: "xAI's Grok large language models",
|
|
116
|
+
env: {
|
|
117
|
+
required: {
|
|
118
|
+
apiKey: "LLM_X_AI_API_KEY",
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
streaming: true,
|
|
122
|
+
cancellation: true,
|
|
123
|
+
color: "#000000",
|
|
124
|
+
website: "https://x.ai",
|
|
125
|
+
announcement: null,
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
id: "deepseek",
|
|
129
|
+
name: "DeepSeek",
|
|
130
|
+
description: "DeepSeek's high-performance language models with OpenAI-compatible API",
|
|
131
|
+
env: {
|
|
132
|
+
required: {
|
|
133
|
+
apiKey: "LLM_DEEPSEEK_API_KEY",
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
streaming: true,
|
|
137
|
+
cancellation: true,
|
|
138
|
+
color: "#FF6B00",
|
|
139
|
+
website: "https://deepseek.com",
|
|
140
|
+
announcement: null,
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
id: "alibaba",
|
|
144
|
+
name: "Alibaba Cloud",
|
|
145
|
+
description: "Alibaba Cloud's Qwen large language models with OpenAI-compatible API",
|
|
146
|
+
env: {
|
|
147
|
+
required: {
|
|
148
|
+
apiKey: "LLM_ALIBABA_API_KEY",
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
streaming: true,
|
|
152
|
+
cancellation: true,
|
|
153
|
+
color: "#FF6A00",
|
|
154
|
+
website: "https://www.alibabacloud.com",
|
|
155
|
+
announcement: null,
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
id: "novita",
|
|
159
|
+
name: "NovitaAI",
|
|
160
|
+
description: "NovitaAI's OpenAI-compatible large language models",
|
|
161
|
+
env: {
|
|
162
|
+
required: {
|
|
163
|
+
apiKey: "LLM_NOVITA_AI_API_KEY",
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
streaming: true,
|
|
167
|
+
cancellation: true,
|
|
168
|
+
color: "#9333ea",
|
|
169
|
+
website: "https://novita.ai",
|
|
170
|
+
announcement: null,
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
id: "aws-bedrock",
|
|
174
|
+
name: "AWS Bedrock",
|
|
175
|
+
description: "Amazon Bedrock - fully managed service for foundation models",
|
|
176
|
+
env: {
|
|
177
|
+
required: {
|
|
178
|
+
apiKey: "LLM_AWS_BEDROCK_API_KEY",
|
|
179
|
+
},
|
|
180
|
+
optional: {
|
|
181
|
+
baseUrl: "LLM_AWS_BEDROCK_BASE_URL",
|
|
182
|
+
region: "LLM_AWS_BEDROCK_REGION",
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
priority: 0.9,
|
|
186
|
+
streaming: true,
|
|
187
|
+
cancellation: true,
|
|
188
|
+
color: "#FF9900",
|
|
189
|
+
website: "https://aws.amazon.com/bedrock",
|
|
190
|
+
announcement: null,
|
|
191
|
+
apiKeyInstructions: "Use AWS Bedrock Long-Term API Keys (not IAM service account or private keys)",
|
|
192
|
+
learnMore: "https://docs.llmgateway.io/integrations/aws-bedrock",
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
id: "azure",
|
|
196
|
+
name: "Azure",
|
|
197
|
+
description: "Microsoft Azure - enterprise-grade OpenAI models",
|
|
198
|
+
env: {
|
|
199
|
+
required: {
|
|
200
|
+
apiKey: "LLM_AZURE_API_KEY",
|
|
201
|
+
resource: "LLM_AZURE_RESOURCE",
|
|
202
|
+
},
|
|
203
|
+
optional: {
|
|
204
|
+
deploymentType: "LLM_AZURE_DEPLOYMENT_TYPE",
|
|
205
|
+
apiVersion: "LLM_AZURE_API_VERSION",
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
streaming: true,
|
|
209
|
+
cancellation: true,
|
|
210
|
+
color: "#0078D4",
|
|
211
|
+
website: "https://azure.microsoft.com/en-us/products/ai-services/openai-service",
|
|
212
|
+
announcement: null,
|
|
213
|
+
apiKeyInstructions: "The resource name can be found in your Azure base URL: https://<resource-name>.openai.azure.com",
|
|
214
|
+
learnMore: "https://docs.llmgateway.io/integrations/azure",
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
id: "zai",
|
|
218
|
+
name: "Z AI",
|
|
219
|
+
description: "Z AI's OpenAI-compatible large language models",
|
|
220
|
+
env: {
|
|
221
|
+
required: {
|
|
222
|
+
apiKey: "LLM_Z_AI_API_KEY",
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
streaming: true,
|
|
226
|
+
cancellation: true,
|
|
227
|
+
color: "#22c55e",
|
|
228
|
+
website: "https://z.ai",
|
|
229
|
+
announcement: null,
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
id: "moonshot",
|
|
233
|
+
name: "Moonshot AI",
|
|
234
|
+
description: "Moonshot AI's OpenAI-compatible large language models",
|
|
235
|
+
env: {
|
|
236
|
+
required: {
|
|
237
|
+
apiKey: "LLM_MOONSHOT_API_KEY",
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
streaming: true,
|
|
241
|
+
cancellation: true,
|
|
242
|
+
color: "#4B9EFF",
|
|
243
|
+
website: "https://moonshot.ai",
|
|
244
|
+
announcement: null,
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
id: "perplexity",
|
|
248
|
+
name: "Perplexity",
|
|
249
|
+
description: "Perplexity's AI models for search and conversation with real-time web access",
|
|
250
|
+
env: {
|
|
251
|
+
required: {
|
|
252
|
+
apiKey: "LLM_PERPLEXITY_API_KEY",
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
streaming: true,
|
|
256
|
+
cancellation: true,
|
|
257
|
+
color: "#20B2AA",
|
|
258
|
+
website: "https://perplexity.ai",
|
|
259
|
+
announcement: null,
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
id: "nebius",
|
|
263
|
+
name: "Nebius AI",
|
|
264
|
+
description: "Nebius AI Studio - OpenAI-compatible API for large language models",
|
|
265
|
+
env: {
|
|
266
|
+
required: {
|
|
267
|
+
apiKey: "LLM_NEBIUS_API_KEY",
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
streaming: true,
|
|
271
|
+
cancellation: true,
|
|
272
|
+
color: "#3b82f6",
|
|
273
|
+
website: "https://nebius.com",
|
|
274
|
+
announcement: null,
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
id: "mistral",
|
|
278
|
+
name: "Mistral AI",
|
|
279
|
+
description: "Mistral AI's large language models",
|
|
280
|
+
env: {
|
|
281
|
+
required: {
|
|
282
|
+
apiKey: "LLM_MISTRAL_API_KEY",
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
streaming: true,
|
|
286
|
+
cancellation: true,
|
|
287
|
+
color: "#FF7000",
|
|
288
|
+
website: "https://mistral.ai",
|
|
289
|
+
announcement: null,
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
id: "canopywave",
|
|
293
|
+
name: "CanopyWave",
|
|
294
|
+
description: "CanopyWave is a platform for running large language models with OpenAI-compatible API",
|
|
295
|
+
env: {
|
|
296
|
+
required: {
|
|
297
|
+
apiKey: "LLM_CANOPY_WAVE_API_KEY",
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
streaming: true,
|
|
301
|
+
cancellation: true,
|
|
302
|
+
color: "#10b981",
|
|
303
|
+
website: "https://canopywave.io",
|
|
304
|
+
announcement: null,
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
id: "inference.net",
|
|
308
|
+
name: "Inference.net",
|
|
309
|
+
description: "Inference.net is a platform for running large language models in the cloud.",
|
|
310
|
+
env: {
|
|
311
|
+
required: {
|
|
312
|
+
apiKey: "LLM_INFERENCE_NET_API_KEY",
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
streaming: true,
|
|
316
|
+
cancellation: true,
|
|
317
|
+
color: "#10b981",
|
|
318
|
+
website: "https://inference.net",
|
|
319
|
+
announcement: null,
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
id: "together.ai",
|
|
323
|
+
name: "Together AI",
|
|
324
|
+
description: "Together AI is a platform for running large language models in the cloud with fast inference.",
|
|
325
|
+
env: {
|
|
326
|
+
required: {
|
|
327
|
+
apiKey: "LLM_TOGETHER_AI_API_KEY",
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
streaming: true,
|
|
331
|
+
cancellation: true,
|
|
332
|
+
color: "#ff6b35",
|
|
333
|
+
website: "https://together.ai",
|
|
334
|
+
announcement: null,
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
id: "routeway",
|
|
338
|
+
name: "RouteWay",
|
|
339
|
+
description: "RouteWay's OpenAI-compatible large language models",
|
|
340
|
+
env: {
|
|
341
|
+
required: {
|
|
342
|
+
apiKey: "LLM_ROUTEWAY_API_KEY",
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
streaming: true,
|
|
346
|
+
cancellation: true,
|
|
347
|
+
color: "#4f46e5",
|
|
348
|
+
website: "https://routeway.ai",
|
|
349
|
+
announcement: null,
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
id: "custom",
|
|
353
|
+
name: "Custom",
|
|
354
|
+
description: "Custom OpenAI-compatible provider with configurable base URL",
|
|
355
|
+
env: {
|
|
356
|
+
required: {},
|
|
357
|
+
},
|
|
358
|
+
streaming: true,
|
|
359
|
+
cancellation: true,
|
|
360
|
+
color: "#6b7280",
|
|
361
|
+
website: null,
|
|
362
|
+
announcement: null,
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
id: "cloudrift",
|
|
366
|
+
name: "CloudRift",
|
|
367
|
+
description: "CloudRift is a platform for running large language models in the cloud with fast inference.",
|
|
368
|
+
env: {
|
|
369
|
+
required: {
|
|
370
|
+
apiKey: "LLM_CLOUD_RIFT_API_KEY",
|
|
371
|
+
},
|
|
372
|
+
},
|
|
373
|
+
streaming: true,
|
|
374
|
+
cancellation: true,
|
|
375
|
+
color: "#00d4aa",
|
|
376
|
+
website: "https://www.cloudrift.ai",
|
|
377
|
+
announcement: "DeepSeek & Kimi K2 are 30-50% cheaper than the competition!",
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
id: "nanogpt",
|
|
381
|
+
name: "NanoGPT",
|
|
382
|
+
description: "NanoGPT offers a large selection of models",
|
|
383
|
+
env: {
|
|
384
|
+
required: {
|
|
385
|
+
apiKey: "LLM_NANO_GPT_API_KEY",
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
streaming: true,
|
|
389
|
+
cancellation: true,
|
|
390
|
+
color: "#10b981",
|
|
391
|
+
website: "https://nano-gpt.com",
|
|
392
|
+
announcement: null,
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
id: "bytedance",
|
|
396
|
+
name: "ByteDance",
|
|
397
|
+
description: "ByteDance's ModelArk platform with OpenAI-compatible API for large language models",
|
|
398
|
+
env: {
|
|
399
|
+
required: {
|
|
400
|
+
apiKey: "LLM_BYTEDANCE_API_KEY",
|
|
401
|
+
},
|
|
402
|
+
},
|
|
403
|
+
streaming: true,
|
|
404
|
+
cancellation: true,
|
|
405
|
+
color: "#FF4757",
|
|
406
|
+
website: "https://www.byteplus.com/en/product/modelark",
|
|
407
|
+
announcement: null,
|
|
408
|
+
},
|
|
409
|
+
];
|
|
410
|
+
export function getProviderDefinition(providerId) {
|
|
411
|
+
return providers.find((p) => p.id === providerId);
|
|
412
|
+
}
|
|
413
|
+
//# sourceMappingURL=providers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.js","sourceRoot":"","sources":["../src/providers.ts"],"names":[],"mappings":"AAiCA,MAAM,CAAC,MAAM,SAAS,GAAG;IACxB;QACC,EAAE,EAAE,YAAY;QAChB,IAAI,EAAE,aAAa;QACnB,WAAW,EACV,6EAA6E;QAC9E,GAAG,EAAE;YACJ,QAAQ,EAAE;gBACT,MAAM,EAAE,wBAAwB;aAChC;SACD;QACD,SAAS,EAAE,IAAI;QACf,YAAY,EAAE,IAAI;QAClB,KAAK,EAAE,SAAS;QAChB,OAAO,EAAE,uBAAuB;QAChC,YAAY,EAAE,IAAI;KAClB;IACD;QACC,EAAE,EAAE,QAAQ;QACZ,IAAI,EAAE,QAAQ;QACd,WAAW,EACV,0IAA0I;QAC3I,GAAG,EAAE;YACJ,QAAQ,EAAE;gBACT,MAAM,EAAE,oBAAoB;aAC5B;SACD;QACD,SAAS,EAAE,IAAI;QACf,YAAY,EAAE,IAAI;QAClB,KAAK,EAAE,SAAS;QAChB,OAAO,EAAE,oBAAoB;QAC7B,YAAY,EAAE,IAAI;KAClB;IACD;QACC,EAAE,EAAE,WAAW;QACf,IAAI,EAAE,WAAW;QACjB,WAAW,EACV,wFAAwF;QACzF,GAAG,EAAE;YACJ,QAAQ,EAAE;gBACT,MAAM,EAAE,uBAAuB;aAC/B;SACD;QACD,SAAS,EA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jB,WAAW,EACV,6FAA6F;QAC9F,GAAG,EAAE;YACJ,QAAQ,EAAE;gBACT,MAAM,EAAE,wBAAwB;aAChC;SACD;QACD,SAAS,EAAE,IAAI;QACf,YAAY,EAAE,IAAI;QAClB,KAAK,EAAE,SAAS;QAChB,OAAO,EAAE,0BAA0B;QACnC,YAAY,EAAE,6DAA6D;KAC3E;IACD;QACC,EAAE,EAAE,SAAS;QACb,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,4CAA4C;QACzD,GAAG,EAAE;YACJ,QAAQ,EAAE;gBACT,MAAM,EAAE,sBAAsB;aAC9B;SACD;QACD,SAAS,EAAE,IAAI;QACf,YAAY,EAAE,IAAI;QAClB,KAAK,EAAE,SAAS;QAChB,OAAO,EAAE,sBAAsB;QAC/B,YAAY,EAAE,IAAI;KAClB;IACD;QACC,EAAE,EAAE,WAAW;QACf,IAAI,EAAE,WAAW;QACjB,WAAW,EACV,oFAAoF;QACrF,GAAG,EAAE;YACJ,QAAQ,EAAE;gBACT,MAAM,EAAE,uBAAuB;aAC/B;SACD;QACD,SAAS,EAAE,IAAI;QACf,YAAY,EAAE,IAAI;QAClB,KAAK,EAAE,SAAS;QAChB,OAAO,EAAE,8CAA8C;QACvD,YAAY,EAAE,IAAI;KAClB;CACuC,CAAC;AAI1C,MAAM,UAAU,qBAAqB,CACpC,UAA+B;IAE/B,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,UAAU,CAAC,CAAC;AACnD,CAAC"}
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { models } from "./models.js";
|
|
2
|
+
export function getTestOptions(opts = {
|
|
3
|
+
completions: true,
|
|
4
|
+
}) {
|
|
5
|
+
const hasTestOnly = models.some((model) => model.providers.some((provider) => provider.test === "only"));
|
|
6
|
+
return process.env.CI || opts?.completions
|
|
7
|
+
? {
|
|
8
|
+
retry: process.env.CI ? 3 : 0,
|
|
9
|
+
timeout: process.env.CI ? 180000 : 60000,
|
|
10
|
+
}
|
|
11
|
+
: { skip: hasTestOnly || !!process.env.TEST_MODELS };
|
|
12
|
+
}
|
|
13
|
+
export function getConcurrentTestOptions(opts) {
|
|
14
|
+
return {
|
|
15
|
+
concurrent: process.env.CONCURRENT_TESTS !== "false",
|
|
16
|
+
...getTestOptions(opts),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAQrC,MAAM,UAAU,cAAc,CAC7B,OAAkC;IACjC,WAAW,EAAE,IAAI;CACjB;IAED,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CACzC,KAAK,CAAC,SAAS,CAAC,IAAI,CACnB,CAAC,QAA8B,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,MAAM,CAC5D,CACD,CAAC;IACF,OAAO,OAAO,CAAC,GAAG,CAAC,EAAE,IAAI,IAAI,EAAE,WAAW;QACzC,CAAC,CAAC;YACA,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7B,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK;SACxC;QACF,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;AACvD,CAAC;AAMD,MAAM,UAAU,wBAAwB,CAAC,IAExC;IACA,OAAO;QACN,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,gBAAgB,KAAK,OAAO;QACpD,GAAG,cAAc,CAAC,IAAI,CAAC;KACvB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { type AnthropicMessage, type BaseMessage } from "./types.js";
|
|
2
|
+
export declare function transformAnthropicMessages(messages: BaseMessage[], isProd?: boolean, provider?: string, _model?: string, maxImageSizeMB?: number, userPlan?: "free" | "pro" | null, initialCacheControlCount?: number, minCacheableChars?: number): Promise<AnthropicMessage[]>;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { logger } from "@llmgateway/logger";
|
|
2
|
+
import { processImageUrl } from "./process-image-url.js";
|
|
3
|
+
import { isImageUrlContent, isTextContent, } from "./types.js";
|
|
4
|
+
export async function transformAnthropicMessages(messages, isProd = false, provider, _model, maxImageSizeMB = 20, userPlan = null, initialCacheControlCount = 0, minCacheableChars = 1024 * 4) {
|
|
5
|
+
const results = [];
|
|
6
|
+
const shouldApplyCacheControl = provider === "anthropic";
|
|
7
|
+
let cacheControlCount = initialCacheControlCount;
|
|
8
|
+
const maxCacheControlBlocks = 4;
|
|
9
|
+
const seenToolUseIds = new Set();
|
|
10
|
+
const idMapping = new Map();
|
|
11
|
+
const toolResultCount = new Map();
|
|
12
|
+
const groupedMessages = [];
|
|
13
|
+
const toolMessageGroups = new Map();
|
|
14
|
+
for (const message of messages) {
|
|
15
|
+
const originalRole = message.role === "user" && message.tool_call_id ? "tool" : message.role;
|
|
16
|
+
if (originalRole === "tool" && message.tool_call_id) {
|
|
17
|
+
if (!toolMessageGroups.has(message.tool_call_id)) {
|
|
18
|
+
toolMessageGroups.set(message.tool_call_id, []);
|
|
19
|
+
}
|
|
20
|
+
toolMessageGroups.get(message.tool_call_id).push(message);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
for (const [_toolCallId, toolMessages] of Array.from(toolMessageGroups)) {
|
|
24
|
+
if (toolMessages.length > 0) {
|
|
25
|
+
toolMessages.forEach((toolMessage) => {
|
|
26
|
+
groupedMessages.push(toolMessage);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
toolMessageGroups.clear();
|
|
31
|
+
groupedMessages.push(message);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
for (const [_toolCallId, toolMessages] of Array.from(toolMessageGroups)) {
|
|
35
|
+
if (toolMessages.length > 0) {
|
|
36
|
+
toolMessages.forEach((toolMessage) => {
|
|
37
|
+
groupedMessages.push(toolMessage);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
for (const m of groupedMessages) {
|
|
42
|
+
let content = [];
|
|
43
|
+
if (Array.isArray(m.content)) {
|
|
44
|
+
content = await Promise.all(m.content.map(async (part) => {
|
|
45
|
+
if (isImageUrlContent(part)) {
|
|
46
|
+
try {
|
|
47
|
+
const { data, mimeType } = await processImageUrl(part.image_url.url, isProd, maxImageSizeMB, userPlan);
|
|
48
|
+
return {
|
|
49
|
+
type: "image",
|
|
50
|
+
source: {
|
|
51
|
+
type: "base64",
|
|
52
|
+
media_type: mimeType,
|
|
53
|
+
data: data,
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
logger.error(`Failed to fetch image ${part.image_url.url}`, {
|
|
59
|
+
err: error instanceof Error ? error : new Error(String(error)),
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
type: "text",
|
|
63
|
+
text: `[Image failed to load: ${part.image_url.url}]`,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (isTextContent(part) && part.text && !part.cache_control) {
|
|
68
|
+
const shouldCache = shouldApplyCacheControl &&
|
|
69
|
+
part.text.length >= minCacheableChars &&
|
|
70
|
+
cacheControlCount < maxCacheControlBlocks;
|
|
71
|
+
if (shouldCache) {
|
|
72
|
+
cacheControlCount++;
|
|
73
|
+
return {
|
|
74
|
+
...part,
|
|
75
|
+
cache_control: { type: "ephemeral" },
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return part;
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
else if (m.content && typeof m.content === "string") {
|
|
83
|
+
const shouldCache = shouldApplyCacheControl &&
|
|
84
|
+
m.content.length >= minCacheableChars &&
|
|
85
|
+
cacheControlCount < maxCacheControlBlocks;
|
|
86
|
+
const textContent = {
|
|
87
|
+
type: "text",
|
|
88
|
+
text: m.content,
|
|
89
|
+
...(shouldCache && { cache_control: { type: "ephemeral" } }),
|
|
90
|
+
};
|
|
91
|
+
if (shouldCache) {
|
|
92
|
+
cacheControlCount++;
|
|
93
|
+
}
|
|
94
|
+
content = [textContent];
|
|
95
|
+
}
|
|
96
|
+
if (m.tool_calls && Array.isArray(m.tool_calls)) {
|
|
97
|
+
const toolUseBlocks = m.tool_calls.map((toolCall, index) => {
|
|
98
|
+
let uniqueId = toolCall.id;
|
|
99
|
+
const duplicatesInSameMessage = m
|
|
100
|
+
.tool_calls.slice(0, index)
|
|
101
|
+
.filter((tc) => tc.id === toolCall.id);
|
|
102
|
+
if (duplicatesInSameMessage.length > 0) {
|
|
103
|
+
uniqueId = `${toolCall.id}_${duplicatesInSameMessage.length + 1}`;
|
|
104
|
+
}
|
|
105
|
+
if (seenToolUseIds.has(uniqueId)) {
|
|
106
|
+
let counter = 1;
|
|
107
|
+
let newId = `${uniqueId}_${counter}`;
|
|
108
|
+
while (seenToolUseIds.has(newId)) {
|
|
109
|
+
counter++;
|
|
110
|
+
newId = `${uniqueId}_${counter}`;
|
|
111
|
+
}
|
|
112
|
+
uniqueId = newId;
|
|
113
|
+
}
|
|
114
|
+
if (!idMapping.has(toolCall.id)) {
|
|
115
|
+
idMapping.set(toolCall.id, []);
|
|
116
|
+
}
|
|
117
|
+
idMapping.get(toolCall.id).push(uniqueId);
|
|
118
|
+
seenToolUseIds.add(uniqueId);
|
|
119
|
+
return {
|
|
120
|
+
type: "tool_use",
|
|
121
|
+
id: uniqueId,
|
|
122
|
+
name: toolCall.function.name,
|
|
123
|
+
input: JSON.parse(toolCall.function.arguments),
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
content = content.concat(toolUseBlocks);
|
|
127
|
+
}
|
|
128
|
+
const originalRole = m.role === "user" && m.tool_call_id ? "tool" : m.role;
|
|
129
|
+
if (originalRole === "tool" && m.tool_call_id && m.content !== undefined) {
|
|
130
|
+
let toolResultContent;
|
|
131
|
+
const contentStr = typeof m.content === "string" ? m.content : JSON.stringify(m.content);
|
|
132
|
+
try {
|
|
133
|
+
const parsed = JSON.parse(contentStr);
|
|
134
|
+
if (typeof parsed === "object") {
|
|
135
|
+
toolResultContent = contentStr;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
toolResultContent = String(parsed);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
toolResultContent = contentStr;
|
|
143
|
+
}
|
|
144
|
+
if (!toolResultContent || toolResultContent.trim() === "") {
|
|
145
|
+
toolResultContent = "No output";
|
|
146
|
+
}
|
|
147
|
+
const mappedToolUseIds = idMapping.get(m.tool_call_id) || [
|
|
148
|
+
m.tool_call_id,
|
|
149
|
+
];
|
|
150
|
+
const currentCount = toolResultCount.get(m.tool_call_id) || 0;
|
|
151
|
+
toolResultCount.set(m.tool_call_id, currentCount + 1);
|
|
152
|
+
if (mappedToolUseIds.length > 1 && currentCount === 0) {
|
|
153
|
+
content = mappedToolUseIds.map((mappedId) => ({
|
|
154
|
+
type: "tool_result",
|
|
155
|
+
tool_use_id: mappedId,
|
|
156
|
+
content: toolResultContent,
|
|
157
|
+
}));
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
const toolUseId = mappedToolUseIds[currentCount] || mappedToolUseIds[0];
|
|
161
|
+
content = [
|
|
162
|
+
{
|
|
163
|
+
type: "tool_result",
|
|
164
|
+
tool_use_id: toolUseId,
|
|
165
|
+
content: toolResultContent,
|
|
166
|
+
},
|
|
167
|
+
];
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const filteredContent = content.filter((part) => !(isTextContent(part) && (!part.text || part.text.trim() === "")));
|
|
171
|
+
if (filteredContent.length === 0 &&
|
|
172
|
+
(!m.tool_calls || m.tool_calls.length === 0)) {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const { tool_calls: _, tool_call_id: __, ...messageWithoutToolFields } = m;
|
|
176
|
+
const anthropicRole = messageWithoutToolFields.role === "assistant" ? "assistant" : "user";
|
|
177
|
+
results.push({
|
|
178
|
+
...messageWithoutToolFields,
|
|
179
|
+
content: filteredContent,
|
|
180
|
+
role: anthropicRole,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
return results;
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=transform-anthropic-messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform-anthropic-messages.js","sourceRoot":"","sources":["../src/transform-anthropic-messages.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAGN,iBAAiB,EACjB,aAAa,GAKb,MAAM,YAAY,CAAC;AAOpB,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC/C,QAAuB,EACvB,MAAM,GAAG,KAAK,EACd,QAAiB,EACjB,MAAe,EACf,cAAc,GAAG,EAAE,EACnB,WAAkC,IAAI,EACtC,wBAAwB,GAAG,CAAC,EAC5B,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAE5B,MAAM,OAAO,GAAuB,EAAE,CAAC;IAIvC,MAAM,uBAAuB,GAAG,QAAQ,KAAK,WAAW,CAAC;IAGzD,IAAI,iBAAiB,GAAG,wBAAwB,CAAC;IACjD,MAAM,qBAAqB,GAAG,CAAC,CAAC;IAGhC,MAAM,cAAc,GAAG,IAAI,GAAG,EAAU,CAAC;IAEzC,MAAM,SAAS,GAAG,IAAI,GAAG,EA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