@ai-sdk/deepinfra 0.2.15 → 1.0.0-alpha.2

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/CHANGELOG.md CHANGED
@@ -1,81 +1,284 @@
1
1
  # @ai-sdk/deepinfra
2
2
 
3
- ## 0.2.15
3
+ ## 1.0.0-alpha.2
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - Updated dependencies [d87b9d1]
8
- - @ai-sdk/provider-utils@2.2.8
9
- - @ai-sdk/openai-compatible@0.2.14
7
+ - Updated dependencies [26535e0]
8
+ - @ai-sdk/provider@2.0.0-alpha.2
9
+ - @ai-sdk/openai-compatible@1.0.0-alpha.2
10
+ - @ai-sdk/provider-utils@3.0.0-alpha.2
10
11
 
11
- ## 0.2.14
12
+ ## 1.0.0-alpha.1
12
13
 
13
14
  ### Patch Changes
14
15
 
15
- - Updated dependencies [23571c9]
16
- - @ai-sdk/openai-compatible@0.2.13
16
+ - Updated dependencies [3f2f00c]
17
+ - @ai-sdk/provider@2.0.0-alpha.1
18
+ - @ai-sdk/openai-compatible@1.0.0-alpha.1
19
+ - @ai-sdk/provider-utils@3.0.0-alpha.1
17
20
 
18
- ## 0.2.13
21
+ ## 1.0.0-canary.19
19
22
 
20
23
  ### Patch Changes
21
24
 
22
- - Updated dependencies [13492fe]
23
- - @ai-sdk/openai-compatible@0.2.12
25
+ - Updated dependencies [faf8446]
26
+ - @ai-sdk/provider-utils@3.0.0-canary.19
27
+ - @ai-sdk/openai-compatible@1.0.0-canary.19
24
28
 
25
- ## 0.2.12
29
+ ## 1.0.0-canary.18
26
30
 
27
31
  ### Patch Changes
28
32
 
29
- - Updated dependencies [b5c9cd4]
30
- - @ai-sdk/openai-compatible@0.2.11
33
+ - Updated dependencies [40acf9b]
34
+ - @ai-sdk/provider-utils@3.0.0-canary.18
35
+ - @ai-sdk/openai-compatible@1.0.0-canary.18
31
36
 
32
- ## 0.2.11
37
+ ## 1.0.0-canary.17
38
+
39
+ ### Major Changes
40
+
41
+ - 516be5b: ### Move Image Model Settings into generate options
42
+
43
+ Image Models no longer have settings. Instead, `maxImagesPerCall` can be passed directly to `generateImage()`. All other image settings can be passed to `providerOptions[provider]`.
44
+
45
+ Before
46
+
47
+ ```js
48
+ await generateImage({
49
+ model: luma.image('photon-flash-1', {
50
+ maxImagesPerCall: 5,
51
+ pollIntervalMillis: 500,
52
+ }),
53
+ prompt,
54
+ n: 10,
55
+ });
56
+ ```
57
+
58
+ After
59
+
60
+ ```js
61
+ await generateImage({
62
+ model: luma.image('photon-flash-1'),
63
+ prompt,
64
+ n: 10,
65
+ maxImagesPerCall: 5,
66
+ providerOptions: {
67
+ luma: { pollIntervalMillis: 5 },
68
+ },
69
+ });
70
+ ```
71
+
72
+ Pull Request: https://github.com/vercel/ai/pull/6180
73
+
74
+ ### Patch Changes
75
+
76
+ - Updated dependencies [516be5b]
77
+ - Updated dependencies [ea7a7c9]
78
+ - @ai-sdk/openai-compatible@1.0.0-canary.17
79
+ - @ai-sdk/provider-utils@3.0.0-canary.17
80
+
81
+ ## 1.0.0-canary.16
82
+
83
+ ### Patch Changes
84
+
85
+ - Updated dependencies [87b828f]
86
+ - @ai-sdk/provider-utils@3.0.0-canary.16
87
+ - @ai-sdk/openai-compatible@1.0.0-canary.16
88
+
89
+ ## 1.0.0-canary.15
90
+
91
+ ### Patch Changes
92
+
93
+ - Updated dependencies [a571d6e]
94
+ - Updated dependencies [a8c8bd5]
95
+ - Updated dependencies [7979f7f]
96
+ - Updated dependencies [41fa418]
97
+ - @ai-sdk/provider-utils@3.0.0-canary.15
98
+ - @ai-sdk/provider@2.0.0-canary.14
99
+ - @ai-sdk/openai-compatible@1.0.0-canary.15
100
+
101
+ ## 1.0.0-canary.14
102
+
103
+ ### Patch Changes
104
+
105
+ - Updated dependencies [957b739]
106
+ - Updated dependencies [9bd5ab5]
107
+ - @ai-sdk/provider-utils@3.0.0-canary.14
108
+ - @ai-sdk/provider@2.0.0-canary.13
109
+ - @ai-sdk/openai-compatible@1.0.0-canary.14
110
+
111
+ ## 1.0.0-canary.13
112
+
113
+ ### Patch Changes
114
+
115
+ - d9209ca: fix (image-model): `specificationVersion: v1` -> `v2`
116
+ - Updated dependencies [7b3ae3f]
117
+ - Updated dependencies [d9209ca]
118
+ - Updated dependencies [0ff02bb]
119
+ - @ai-sdk/provider@2.0.0-canary.12
120
+ - @ai-sdk/openai-compatible@1.0.0-canary.13
121
+ - @ai-sdk/provider-utils@3.0.0-canary.13
122
+
123
+ ## 1.0.0-canary.12
124
+
125
+ ### Patch Changes
126
+
127
+ - Updated dependencies [9bf7291]
128
+ - Updated dependencies [4617fab]
129
+ - Updated dependencies [e030615]
130
+ - @ai-sdk/provider@2.0.0-canary.11
131
+ - @ai-sdk/openai-compatible@1.0.0-canary.12
132
+ - @ai-sdk/provider-utils@3.0.0-canary.12
133
+
134
+ ## 1.0.0-canary.11
135
+
136
+ ### Patch Changes
137
+
138
+ - 9301f86: refactor (image-model): rename `ImageModelV1` to `ImageModelV2`
139
+ - Updated dependencies [db72adc]
140
+ - Updated dependencies [42e32b0]
141
+ - Updated dependencies [66962ed]
142
+ - Updated dependencies [9301f86]
143
+ - Updated dependencies [a3f768e]
144
+ - @ai-sdk/openai-compatible@1.0.0-canary.11
145
+ - @ai-sdk/provider-utils@3.0.0-canary.11
146
+ - @ai-sdk/provider@2.0.0-canary.10
147
+
148
+ ## 1.0.0-canary.10
149
+
150
+ ### Patch Changes
151
+
152
+ - Updated dependencies [cf8280e]
153
+ - Updated dependencies [e86be6f]
154
+ - @ai-sdk/openai-compatible@1.0.0-canary.10
155
+ - @ai-sdk/provider@2.0.0-canary.9
156
+ - @ai-sdk/provider-utils@3.0.0-canary.10
157
+
158
+ ## 1.0.0-canary.9
159
+
160
+ ### Patch Changes
161
+
162
+ - Updated dependencies [95857aa]
163
+ - Updated dependencies [7ea4132]
164
+ - @ai-sdk/provider@2.0.0-canary.8
165
+ - @ai-sdk/openai-compatible@1.0.0-canary.9
166
+ - @ai-sdk/provider-utils@3.0.0-canary.9
167
+
168
+ ## 1.0.0-canary.8
33
169
 
34
170
  ### Patch Changes
35
171
 
36
- - Updated dependencies [beef951]
37
- - @ai-sdk/provider@1.1.3
38
- - @ai-sdk/openai-compatible@0.2.10
39
- - @ai-sdk/provider-utils@2.2.7
172
+ - Updated dependencies [5d142ab]
173
+ - Updated dependencies [b6b43c7]
174
+ - Updated dependencies [b9a6121]
175
+ - Updated dependencies [8aa9e20]
176
+ - Updated dependencies [3795467]
177
+ - @ai-sdk/provider-utils@3.0.0-canary.8
178
+ - @ai-sdk/provider@2.0.0-canary.7
179
+ - @ai-sdk/openai-compatible@1.0.0-canary.8
40
180
 
41
- ## 0.2.10
181
+ ## 1.0.0-canary.7
42
182
 
43
183
  ### Patch Changes
44
184
 
45
- - Updated dependencies [1bbc698]
46
- - @ai-sdk/openai-compatible@0.2.9
185
+ - fa49207: feat(providers/openai-compatible): convert to providerOptions
186
+ - 26735b5: chore(embedding-model): add v2 interface
187
+ - Updated dependencies [fa49207]
188
+ - Updated dependencies [26735b5]
189
+ - Updated dependencies [443d8ec]
190
+ - Updated dependencies [14c9410]
191
+ - Updated dependencies [d9c98f4]
192
+ - Updated dependencies [c4a2fec]
193
+ - Updated dependencies [0054544]
194
+ - Updated dependencies [9e9c809]
195
+ - Updated dependencies [32831c6]
196
+ - Updated dependencies [d0f9495]
197
+ - Updated dependencies [fd65bc6]
198
+ - Updated dependencies [393138b]
199
+ - Updated dependencies [7182d14]
200
+ - @ai-sdk/openai-compatible@1.0.0-canary.7
201
+ - @ai-sdk/provider@2.0.0-canary.6
202
+ - @ai-sdk/provider-utils@3.0.0-canary.7
47
203
 
48
- ## 0.2.9
204
+ ## 1.0.0-canary.6
49
205
 
50
206
  ### Patch Changes
51
207
 
52
- - Updated dependencies [013faa8]
53
- - @ai-sdk/provider@1.1.2
54
- - @ai-sdk/openai-compatible@0.2.8
55
- - @ai-sdk/provider-utils@2.2.6
208
+ - Updated dependencies [6db02c9]
209
+ - Updated dependencies [411e483]
210
+ - Updated dependencies [79457bd]
211
+ - Updated dependencies [ad80501]
212
+ - Updated dependencies [1766ede]
213
+ - Updated dependencies [f10304b]
214
+ - @ai-sdk/openai-compatible@1.0.0-canary.6
215
+ - @ai-sdk/provider@2.0.0-canary.5
216
+ - @ai-sdk/provider-utils@3.0.0-canary.6
56
217
 
57
- ## 0.2.8
218
+ ## 1.0.0-canary.5
58
219
 
59
220
  ### Patch Changes
60
221
 
61
- - Updated dependencies [c21fa6d]
62
- - @ai-sdk/provider-utils@2.2.5
63
- - @ai-sdk/provider@1.1.1
64
- - @ai-sdk/openai-compatible@0.2.7
222
+ - Updated dependencies [6f6bb89]
223
+ - @ai-sdk/provider@2.0.0-canary.4
224
+ - @ai-sdk/openai-compatible@1.0.0-canary.5
225
+ - @ai-sdk/provider-utils@3.0.0-canary.5
65
226
 
66
- ## 0.2.7
227
+ ## 1.0.0-canary.4
67
228
 
68
229
  ### Patch Changes
69
230
 
70
- - 264b1e0: feat (providers/deepinfra): add llama 4 models
231
+ - Updated dependencies [d1a1aa1]
232
+ - @ai-sdk/provider@2.0.0-canary.3
233
+ - @ai-sdk/openai-compatible@1.0.0-canary.4
234
+ - @ai-sdk/provider-utils@3.0.0-canary.4
235
+
236
+ ## 1.0.0-canary.3
237
+
238
+ ### Patch Changes
239
+
240
+ - Updated dependencies [a166433]
241
+ - Updated dependencies [abf9a79]
242
+ - Updated dependencies [9f95b35]
243
+ - Updated dependencies [0a87932]
244
+ - Updated dependencies [6dc848c]
245
+ - @ai-sdk/provider-utils@3.0.0-canary.3
246
+ - @ai-sdk/provider@2.0.0-canary.2
247
+ - @ai-sdk/openai-compatible@1.0.0-canary.3
248
+
249
+ ## 1.0.0-canary.2
250
+
251
+ ### Patch Changes
252
+
253
+ - 7677477: feat (providers/deepinfra): add llama 4 models
254
+ - Updated dependencies [c57e248]
255
+ - Updated dependencies [33f4a6a]
256
+ - @ai-sdk/provider@2.0.0-canary.1
257
+ - @ai-sdk/openai-compatible@1.0.0-canary.2
258
+ - @ai-sdk/provider-utils@3.0.0-canary.2
259
+
260
+ ## 1.0.0-canary.1
261
+
262
+ ### Patch Changes
263
+
264
+ - Updated dependencies [060370c]
265
+ - Updated dependencies [0c0c0b3]
266
+ - Updated dependencies [63d791d]
267
+ - @ai-sdk/provider-utils@3.0.0-canary.1
268
+ - @ai-sdk/openai-compatible@1.0.0-canary.1
269
+
270
+ ## 1.0.0-canary.0
271
+
272
+ ### Major Changes
71
273
 
72
- ## 0.2.6
274
+ - d5f588f: AI SDK 5
73
275
 
74
276
  ### Patch Changes
75
277
 
76
- - Updated dependencies [2c19b9a]
77
- - @ai-sdk/provider-utils@2.2.4
78
- - @ai-sdk/openai-compatible@0.2.6
278
+ - Updated dependencies [d5f588f]
279
+ - @ai-sdk/provider-utils@3.0.0-canary.0
280
+ - @ai-sdk/openai-compatible@1.0.0-canary.0
281
+ - @ai-sdk/provider@2.0.0-canary.0
79
282
 
80
283
  ## 0.2.5
81
284
 
package/dist/index.d.mts CHANGED
@@ -1,27 +1,14 @@
1
- import { ProviderV1, LanguageModelV1, ImageModelV1, EmbeddingModelV1 } from '@ai-sdk/provider';
1
+ import { ProviderV2, LanguageModelV2, ImageModelV2, EmbeddingModelV2 } from '@ai-sdk/provider';
2
2
  import { FetchFunction } from '@ai-sdk/provider-utils';
3
- import { OpenAICompatibleChatSettings, OpenAICompatibleEmbeddingSettings, OpenAICompatibleCompletionSettings } from '@ai-sdk/openai-compatible';
4
3
  export { OpenAICompatibleErrorData as DeepInfraErrorData } from '@ai-sdk/openai-compatible';
5
4
 
6
5
  type DeepInfraChatModelId = 'meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8' | 'meta-llama/Llama-4-Scout-17B-16E-Instruct' | 'meta-llama/Llama-3.3-70B-Instruct' | 'meta-llama/Llama-3.3-70B-Instruct-Turbo' | 'meta-llama/Meta-Llama-3.1-70B-Instruct' | 'meta-llama/Meta-Llama-3.1-8B-Instruct' | 'meta-llama/Meta-Llama-3.1-405B-Instruct' | 'Qwen/QwQ-32B-Preview' | 'meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo' | 'meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo' | 'Qwen/Qwen2.5-Coder-32B-Instruct' | 'nvidia/Llama-3.1-Nemotron-70B-Instruct' | 'Qwen/Qwen2.5-72B-Instruct' | 'meta-llama/Llama-3.2-90B-Vision-Instruct' | 'meta-llama/Llama-3.2-11B-Vision-Instruct' | 'microsoft/WizardLM-2-8x22B' | '01-ai/Yi-34B-Chat' | 'Austism/chronos-hermes-13b-v2' | 'Gryphe/MythoMax-L2-13b' | 'Gryphe/MythoMax-L2-13b-turbo' | 'HuggingFaceH4/zephyr-orpo-141b-A35b-v0.1' | 'KoboldAI/LLaMA2-13B-Tiefighter' | 'NousResearch/Hermes-3-Llama-3.1-405B' | 'Phind/Phind-CodeLlama-34B-v2' | 'Qwen/Qwen2-72B-Instruct' | 'Qwen/Qwen2-7B-Instruct' | 'Qwen/Qwen2.5-7B-Instruct' | 'Qwen/Qwen2.5-Coder-7B' | 'Sao10K/L3-70B-Euryale-v2.1' | 'Sao10K/L3-8B-Lunaris-v1' | 'Sao10K/L3.1-70B-Euryale-v2.2' | 'bigcode/starcoder2-15b' | 'bigcode/starcoder2-15b-instruct-v0.1' | 'codellama/CodeLlama-34b-Instruct-hf' | 'codellama/CodeLlama-70b-Instruct-hf' | 'cognitivecomputations/dolphin-2.6-mixtral-8x7b' | 'cognitivecomputations/dolphin-2.9.1-llama-3-70b' | 'databricks/dbrx-instruct' | 'deepinfra/airoboros-70b' | 'deepseek-ai/DeepSeek-V3' | 'google/codegemma-7b-it' | 'google/gemma-1.1-7b-it' | 'google/gemma-2-27b-it' | 'google/gemma-2-9b-it' | 'lizpreciatior/lzlv_70b_fp16_hf' | 'mattshumer/Reflection-Llama-3.1-70B' | 'meta-llama/Llama-2-13b-chat-hf' | 'meta-llama/Llama-2-70b-chat-hf' | 'meta-llama/Llama-2-7b-chat-hf' | 'meta-llama/Llama-3.2-1B-Instruct' | 'meta-llama/Llama-3.2-3B-Instruct' | 'meta-llama/Meta-Llama-3-70B-Instruct' | 'meta-llama/Meta-Llama-3-8B-Instruct' | 'microsoft/Phi-3-medium-4k-instruct' | 'microsoft/WizardLM-2-7B' | 'mistralai/Mistral-7B-Instruct-v0.1' | 'mistralai/Mistral-7B-Instruct-v0.2' | 'mistralai/Mistral-7B-Instruct-v0.3' | 'mistralai/Mistral-Nemo-Instruct-2407' | 'mistralai/Mixtral-8x22B-Instruct-v0.1' | 'mistralai/Mixtral-8x22B-v0.1' | 'mistralai/Mixtral-8x7B-Instruct-v0.1' | 'nvidia/Nemotron-4-340B-Instruct' | 'openbmb/MiniCPM-Llama3-V-2_5' | 'openchat/openchat-3.6-8b' | 'openchat/openchat_3.5' | (string & {});
7
- interface DeepInfraChatSettings extends OpenAICompatibleChatSettings {
8
- }
9
6
 
10
7
  type DeepInfraEmbeddingModelId = 'BAAI/bge-base-en-v1.5' | 'BAAI/bge-large-en-v1.5' | 'BAAI/bge-m3' | 'intfloat/e5-base-v2' | 'intfloat/e5-large-v2' | 'intfloat/multilingual-e5-large' | 'sentence-transformers/all-MiniLM-L12-v2' | 'sentence-transformers/all-MiniLM-L6-v2' | 'sentence-transformers/all-mpnet-base-v2' | 'sentence-transformers/clip-ViT-B-32' | 'sentence-transformers/clip-ViT-B-32-multilingual-v1' | 'sentence-transformers/multi-qa-mpnet-base-dot-v1' | 'sentence-transformers/paraphrase-MiniLM-L6-v2' | 'shibing624/text2vec-base-chinese' | 'thenlper/gte-base' | 'thenlper/gte-large' | (string & {});
11
- interface DeepInfraEmbeddingSettings extends OpenAICompatibleEmbeddingSettings {
12
- }
13
8
 
14
9
  type DeepInfraCompletionModelId = DeepInfraChatModelId;
15
- interface DeepInfraCompletionSettings extends OpenAICompatibleCompletionSettings {
16
- }
17
10
 
18
11
  type DeepInfraImageModelId = 'stabilityai/sd3.5' | 'black-forest-labs/FLUX-1.1-pro' | 'black-forest-labs/FLUX-1-schnell' | 'black-forest-labs/FLUX-1-dev' | 'black-forest-labs/FLUX-pro' | 'stabilityai/sd3.5-medium' | 'stabilityai/sdxl-turbo' | (string & {});
19
- interface DeepInfraImageSettings {
20
- /**
21
- * Override the maximum number of images per call (default 1)
22
- */
23
- maxImagesPerCall?: number;
24
- }
25
12
 
26
13
  interface DeepInfraProviderSettings {
27
14
  /**
@@ -42,35 +29,36 @@ interface DeepInfraProviderSettings {
42
29
  */
43
30
  fetch?: FetchFunction;
44
31
  }
45
- interface DeepInfraProvider extends ProviderV1 {
32
+ interface DeepInfraProvider extends ProviderV2 {
46
33
  /**
47
34
  Creates a model for text generation.
48
35
  */
49
- (modelId: DeepInfraChatModelId, settings?: DeepInfraChatSettings): LanguageModelV1;
36
+ (modelId: DeepInfraChatModelId): LanguageModelV2;
50
37
  /**
51
38
  Creates a chat model for text generation.
52
39
  */
53
- chatModel(modelId: DeepInfraChatModelId, settings?: DeepInfraChatSettings): LanguageModelV1;
40
+ chatModel(modelId: DeepInfraChatModelId): LanguageModelV2;
54
41
  /**
55
42
  Creates a model for image generation.
43
+ @deprecated Use `imageModel` instead.
56
44
  */
57
- image(modelId: DeepInfraImageModelId, settings?: DeepInfraImageSettings): ImageModelV1;
45
+ image(modelId: DeepInfraImageModelId): ImageModelV2;
58
46
  /**
59
47
  Creates a model for image generation.
60
48
  */
61
- imageModel(modelId: DeepInfraImageModelId, settings?: DeepInfraImageSettings): ImageModelV1;
49
+ imageModel(modelId: DeepInfraImageModelId): ImageModelV2;
62
50
  /**
63
51
  Creates a chat model for text generation.
64
52
  */
65
- languageModel(modelId: DeepInfraChatModelId, settings?: DeepInfraChatSettings): LanguageModelV1;
53
+ languageModel(modelId: DeepInfraChatModelId): LanguageModelV2;
66
54
  /**
67
55
  Creates a completion model for text generation.
68
56
  */
69
- completionModel(modelId: DeepInfraCompletionModelId, settings?: DeepInfraCompletionSettings): LanguageModelV1;
57
+ completionModel(modelId: DeepInfraCompletionModelId): LanguageModelV2;
70
58
  /**
71
59
  Creates a text embedding model for text generation.
72
60
  */
73
- textEmbeddingModel(modelId: DeepInfraEmbeddingModelId, settings?: DeepInfraEmbeddingSettings): EmbeddingModelV1<string>;
61
+ textEmbeddingModel(modelId: DeepInfraEmbeddingModelId): EmbeddingModelV2<string>;
74
62
  }
75
63
  declare function createDeepInfra(options?: DeepInfraProviderSettings): DeepInfraProvider;
76
64
  declare const deepinfra: DeepInfraProvider;
package/dist/index.d.ts CHANGED
@@ -1,27 +1,14 @@
1
- import { ProviderV1, LanguageModelV1, ImageModelV1, EmbeddingModelV1 } from '@ai-sdk/provider';
1
+ import { ProviderV2, LanguageModelV2, ImageModelV2, EmbeddingModelV2 } from '@ai-sdk/provider';
2
2
  import { FetchFunction } from '@ai-sdk/provider-utils';
3
- import { OpenAICompatibleChatSettings, OpenAICompatibleEmbeddingSettings, OpenAICompatibleCompletionSettings } from '@ai-sdk/openai-compatible';
4
3
  export { OpenAICompatibleErrorData as DeepInfraErrorData } from '@ai-sdk/openai-compatible';
5
4
 
6
5
  type DeepInfraChatModelId = 'meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8' | 'meta-llama/Llama-4-Scout-17B-16E-Instruct' | 'meta-llama/Llama-3.3-70B-Instruct' | 'meta-llama/Llama-3.3-70B-Instruct-Turbo' | 'meta-llama/Meta-Llama-3.1-70B-Instruct' | 'meta-llama/Meta-Llama-3.1-8B-Instruct' | 'meta-llama/Meta-Llama-3.1-405B-Instruct' | 'Qwen/QwQ-32B-Preview' | 'meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo' | 'meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo' | 'Qwen/Qwen2.5-Coder-32B-Instruct' | 'nvidia/Llama-3.1-Nemotron-70B-Instruct' | 'Qwen/Qwen2.5-72B-Instruct' | 'meta-llama/Llama-3.2-90B-Vision-Instruct' | 'meta-llama/Llama-3.2-11B-Vision-Instruct' | 'microsoft/WizardLM-2-8x22B' | '01-ai/Yi-34B-Chat' | 'Austism/chronos-hermes-13b-v2' | 'Gryphe/MythoMax-L2-13b' | 'Gryphe/MythoMax-L2-13b-turbo' | 'HuggingFaceH4/zephyr-orpo-141b-A35b-v0.1' | 'KoboldAI/LLaMA2-13B-Tiefighter' | 'NousResearch/Hermes-3-Llama-3.1-405B' | 'Phind/Phind-CodeLlama-34B-v2' | 'Qwen/Qwen2-72B-Instruct' | 'Qwen/Qwen2-7B-Instruct' | 'Qwen/Qwen2.5-7B-Instruct' | 'Qwen/Qwen2.5-Coder-7B' | 'Sao10K/L3-70B-Euryale-v2.1' | 'Sao10K/L3-8B-Lunaris-v1' | 'Sao10K/L3.1-70B-Euryale-v2.2' | 'bigcode/starcoder2-15b' | 'bigcode/starcoder2-15b-instruct-v0.1' | 'codellama/CodeLlama-34b-Instruct-hf' | 'codellama/CodeLlama-70b-Instruct-hf' | 'cognitivecomputations/dolphin-2.6-mixtral-8x7b' | 'cognitivecomputations/dolphin-2.9.1-llama-3-70b' | 'databricks/dbrx-instruct' | 'deepinfra/airoboros-70b' | 'deepseek-ai/DeepSeek-V3' | 'google/codegemma-7b-it' | 'google/gemma-1.1-7b-it' | 'google/gemma-2-27b-it' | 'google/gemma-2-9b-it' | 'lizpreciatior/lzlv_70b_fp16_hf' | 'mattshumer/Reflection-Llama-3.1-70B' | 'meta-llama/Llama-2-13b-chat-hf' | 'meta-llama/Llama-2-70b-chat-hf' | 'meta-llama/Llama-2-7b-chat-hf' | 'meta-llama/Llama-3.2-1B-Instruct' | 'meta-llama/Llama-3.2-3B-Instruct' | 'meta-llama/Meta-Llama-3-70B-Instruct' | 'meta-llama/Meta-Llama-3-8B-Instruct' | 'microsoft/Phi-3-medium-4k-instruct' | 'microsoft/WizardLM-2-7B' | 'mistralai/Mistral-7B-Instruct-v0.1' | 'mistralai/Mistral-7B-Instruct-v0.2' | 'mistralai/Mistral-7B-Instruct-v0.3' | 'mistralai/Mistral-Nemo-Instruct-2407' | 'mistralai/Mixtral-8x22B-Instruct-v0.1' | 'mistralai/Mixtral-8x22B-v0.1' | 'mistralai/Mixtral-8x7B-Instruct-v0.1' | 'nvidia/Nemotron-4-340B-Instruct' | 'openbmb/MiniCPM-Llama3-V-2_5' | 'openchat/openchat-3.6-8b' | 'openchat/openchat_3.5' | (string & {});
7
- interface DeepInfraChatSettings extends OpenAICompatibleChatSettings {
8
- }
9
6
 
10
7
  type DeepInfraEmbeddingModelId = 'BAAI/bge-base-en-v1.5' | 'BAAI/bge-large-en-v1.5' | 'BAAI/bge-m3' | 'intfloat/e5-base-v2' | 'intfloat/e5-large-v2' | 'intfloat/multilingual-e5-large' | 'sentence-transformers/all-MiniLM-L12-v2' | 'sentence-transformers/all-MiniLM-L6-v2' | 'sentence-transformers/all-mpnet-base-v2' | 'sentence-transformers/clip-ViT-B-32' | 'sentence-transformers/clip-ViT-B-32-multilingual-v1' | 'sentence-transformers/multi-qa-mpnet-base-dot-v1' | 'sentence-transformers/paraphrase-MiniLM-L6-v2' | 'shibing624/text2vec-base-chinese' | 'thenlper/gte-base' | 'thenlper/gte-large' | (string & {});
11
- interface DeepInfraEmbeddingSettings extends OpenAICompatibleEmbeddingSettings {
12
- }
13
8
 
14
9
  type DeepInfraCompletionModelId = DeepInfraChatModelId;
15
- interface DeepInfraCompletionSettings extends OpenAICompatibleCompletionSettings {
16
- }
17
10
 
18
11
  type DeepInfraImageModelId = 'stabilityai/sd3.5' | 'black-forest-labs/FLUX-1.1-pro' | 'black-forest-labs/FLUX-1-schnell' | 'black-forest-labs/FLUX-1-dev' | 'black-forest-labs/FLUX-pro' | 'stabilityai/sd3.5-medium' | 'stabilityai/sdxl-turbo' | (string & {});
19
- interface DeepInfraImageSettings {
20
- /**
21
- * Override the maximum number of images per call (default 1)
22
- */
23
- maxImagesPerCall?: number;
24
- }
25
12
 
26
13
  interface DeepInfraProviderSettings {
27
14
  /**
@@ -42,35 +29,36 @@ interface DeepInfraProviderSettings {
42
29
  */
43
30
  fetch?: FetchFunction;
44
31
  }
45
- interface DeepInfraProvider extends ProviderV1 {
32
+ interface DeepInfraProvider extends ProviderV2 {
46
33
  /**
47
34
  Creates a model for text generation.
48
35
  */
49
- (modelId: DeepInfraChatModelId, settings?: DeepInfraChatSettings): LanguageModelV1;
36
+ (modelId: DeepInfraChatModelId): LanguageModelV2;
50
37
  /**
51
38
  Creates a chat model for text generation.
52
39
  */
53
- chatModel(modelId: DeepInfraChatModelId, settings?: DeepInfraChatSettings): LanguageModelV1;
40
+ chatModel(modelId: DeepInfraChatModelId): LanguageModelV2;
54
41
  /**
55
42
  Creates a model for image generation.
43
+ @deprecated Use `imageModel` instead.
56
44
  */
57
- image(modelId: DeepInfraImageModelId, settings?: DeepInfraImageSettings): ImageModelV1;
45
+ image(modelId: DeepInfraImageModelId): ImageModelV2;
58
46
  /**
59
47
  Creates a model for image generation.
60
48
  */
61
- imageModel(modelId: DeepInfraImageModelId, settings?: DeepInfraImageSettings): ImageModelV1;
49
+ imageModel(modelId: DeepInfraImageModelId): ImageModelV2;
62
50
  /**
63
51
  Creates a chat model for text generation.
64
52
  */
65
- languageModel(modelId: DeepInfraChatModelId, settings?: DeepInfraChatSettings): LanguageModelV1;
53
+ languageModel(modelId: DeepInfraChatModelId): LanguageModelV2;
66
54
  /**
67
55
  Creates a completion model for text generation.
68
56
  */
69
- completionModel(modelId: DeepInfraCompletionModelId, settings?: DeepInfraCompletionSettings): LanguageModelV1;
57
+ completionModel(modelId: DeepInfraCompletionModelId): LanguageModelV2;
70
58
  /**
71
59
  Creates a text embedding model for text generation.
72
60
  */
73
- textEmbeddingModel(modelId: DeepInfraEmbeddingModelId, settings?: DeepInfraEmbeddingSettings): EmbeddingModelV1<string>;
61
+ textEmbeddingModel(modelId: DeepInfraEmbeddingModelId): EmbeddingModelV2<string>;
74
62
  }
75
63
  declare function createDeepInfra(options?: DeepInfraProviderSettings): DeepInfraProvider;
76
64
  declare const deepinfra: DeepInfraProvider;
package/dist/index.js CHANGED
@@ -33,19 +33,15 @@ var import_provider_utils2 = require("@ai-sdk/provider-utils");
33
33
  var import_provider_utils = require("@ai-sdk/provider-utils");
34
34
  var import_zod = require("zod");
35
35
  var DeepInfraImageModel = class {
36
- constructor(modelId, settings, config) {
36
+ constructor(modelId, config) {
37
37
  this.modelId = modelId;
38
- this.settings = settings;
39
38
  this.config = config;
40
- this.specificationVersion = "v1";
39
+ this.specificationVersion = "v2";
40
+ this.maxImagesPerCall = 1;
41
41
  }
42
42
  get provider() {
43
43
  return this.config.provider;
44
44
  }
45
- get maxImagesPerCall() {
46
- var _a;
47
- return (_a = this.settings.maxImagesPerCall) != null ? _a : 1;
48
- }
49
45
  async doGenerate({
50
46
  prompt,
51
47
  n,
@@ -123,27 +119,25 @@ function createDeepInfra(options = {}) {
123
119
  headers: getHeaders,
124
120
  fetch: options.fetch
125
121
  });
126
- const createChatModel = (modelId, settings = {}) => {
127
- return new import_openai_compatible.OpenAICompatibleChatLanguageModel(modelId, settings, {
128
- ...getCommonModelConfig("chat"),
129
- defaultObjectGenerationMode: "json"
130
- });
122
+ const createChatModel = (modelId) => {
123
+ return new import_openai_compatible.OpenAICompatibleChatLanguageModel(
124
+ modelId,
125
+ getCommonModelConfig("chat")
126
+ );
131
127
  };
132
- const createCompletionModel = (modelId, settings = {}) => new import_openai_compatible.OpenAICompatibleCompletionLanguageModel(
128
+ const createCompletionModel = (modelId) => new import_openai_compatible.OpenAICompatibleCompletionLanguageModel(
133
129
  modelId,
134
- settings,
135
130
  getCommonModelConfig("completion")
136
131
  );
137
- const createTextEmbeddingModel = (modelId, settings = {}) => new import_openai_compatible.OpenAICompatibleEmbeddingModel(
132
+ const createTextEmbeddingModel = (modelId) => new import_openai_compatible.OpenAICompatibleEmbeddingModel(
138
133
  modelId,
139
- settings,
140
134
  getCommonModelConfig("embedding")
141
135
  );
142
- const createImageModel = (modelId, settings = {}) => new DeepInfraImageModel(modelId, settings, {
136
+ const createImageModel = (modelId) => new DeepInfraImageModel(modelId, {
143
137
  ...getCommonModelConfig("image"),
144
138
  baseURL: baseURL ? `${baseURL}/inference` : "https://api.deepinfra.com/v1/inference"
145
139
  });
146
- const provider = (modelId, settings) => createChatModel(modelId, settings);
140
+ const provider = (modelId) => createChatModel(modelId);
147
141
  provider.completionModel = createCompletionModel;
148
142
  provider.chatModel = createChatModel;
149
143
  provider.image = createImageModel;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/deepinfra-provider.ts","../src/deepinfra-image-model.ts"],"sourcesContent":["export { createDeepInfra, deepinfra } from './deepinfra-provider';\nexport type {\n DeepInfraProvider,\n DeepInfraProviderSettings,\n} from './deepinfra-provider';\nexport type { OpenAICompatibleErrorData as DeepInfraErrorData } from '@ai-sdk/openai-compatible';\n","import {\n LanguageModelV1,\n EmbeddingModelV1,\n ProviderV1,\n ImageModelV1,\n} from '@ai-sdk/provider';\nimport {\n OpenAICompatibleChatLanguageModel,\n OpenAICompatibleCompletionLanguageModel,\n OpenAICompatibleEmbeddingModel,\n} from '@ai-sdk/openai-compatible';\nimport {\n FetchFunction,\n loadApiKey,\n withoutTrailingSlash,\n} from '@ai-sdk/provider-utils';\nimport {\n DeepInfraChatModelId,\n DeepInfraChatSettings,\n} from './deepinfra-chat-settings';\nimport {\n DeepInfraEmbeddingModelId,\n DeepInfraEmbeddingSettings,\n} from './deepinfra-embedding-settings';\nimport {\n DeepInfraCompletionModelId,\n DeepInfraCompletionSettings,\n} from './deepinfra-completion-settings';\nimport {\n DeepInfraImageModelId,\n DeepInfraImageSettings,\n} from './deepinfra-image-settings';\nimport { DeepInfraImageModel } from './deepinfra-image-model';\n\nexport interface DeepInfraProviderSettings {\n /**\nDeepInfra API key.\n*/\n apiKey?: string;\n /**\nBase URL for the API calls.\n*/\n baseURL?: string;\n /**\nCustom headers to include in the requests.\n*/\n headers?: Record<string, string>;\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n*/\n fetch?: FetchFunction;\n}\n\nexport interface DeepInfraProvider extends ProviderV1 {\n /**\nCreates a model for text generation.\n*/\n (\n modelId: DeepInfraChatModelId,\n settings?: DeepInfraChatSettings,\n ): LanguageModelV1;\n\n /**\nCreates a chat model for text generation.\n*/\n chatModel(\n modelId: DeepInfraChatModelId,\n settings?: DeepInfraChatSettings,\n ): LanguageModelV1;\n\n /**\nCreates a model for image generation.\n */\n image(\n modelId: DeepInfraImageModelId,\n settings?: DeepInfraImageSettings,\n ): ImageModelV1;\n\n /**\nCreates a model for image generation.\n */\n imageModel(\n modelId: DeepInfraImageModelId,\n settings?: DeepInfraImageSettings,\n ): ImageModelV1;\n\n /**\nCreates a chat model for text generation.\n*/\n languageModel(\n modelId: DeepInfraChatModelId,\n settings?: DeepInfraChatSettings,\n ): LanguageModelV1;\n\n /**\nCreates a completion model for text generation.\n*/\n completionModel(\n modelId: DeepInfraCompletionModelId,\n settings?: DeepInfraCompletionSettings,\n ): LanguageModelV1;\n\n /**\nCreates a text embedding model for text generation.\n*/\n textEmbeddingModel(\n modelId: DeepInfraEmbeddingModelId,\n settings?: DeepInfraEmbeddingSettings,\n ): EmbeddingModelV1<string>;\n}\n\nexport function createDeepInfra(\n options: DeepInfraProviderSettings = {},\n): DeepInfraProvider {\n const baseURL = withoutTrailingSlash(\n options.baseURL ?? 'https://api.deepinfra.com/v1',\n );\n const getHeaders = () => ({\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'DEEPINFRA_API_KEY',\n description: \"DeepInfra's API key\",\n })}`,\n ...options.headers,\n });\n\n interface CommonModelConfig {\n provider: string;\n url: ({ path }: { path: string }) => string;\n headers: () => Record<string, string>;\n fetch?: FetchFunction;\n }\n\n const getCommonModelConfig = (modelType: string): CommonModelConfig => ({\n provider: `deepinfra.${modelType}`,\n url: ({ path }) => `${baseURL}/openai${path}`,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const createChatModel = (\n modelId: DeepInfraChatModelId,\n settings: DeepInfraChatSettings = {},\n ) => {\n return new OpenAICompatibleChatLanguageModel(modelId, settings, {\n ...getCommonModelConfig('chat'),\n defaultObjectGenerationMode: 'json',\n });\n };\n\n const createCompletionModel = (\n modelId: DeepInfraCompletionModelId,\n settings: DeepInfraCompletionSettings = {},\n ) =>\n new OpenAICompatibleCompletionLanguageModel(\n modelId,\n settings,\n getCommonModelConfig('completion'),\n );\n\n const createTextEmbeddingModel = (\n modelId: DeepInfraEmbeddingModelId,\n settings: DeepInfraEmbeddingSettings = {},\n ) =>\n new OpenAICompatibleEmbeddingModel(\n modelId,\n settings,\n getCommonModelConfig('embedding'),\n );\n\n const createImageModel = (\n modelId: DeepInfraImageModelId,\n settings: DeepInfraImageSettings = {},\n ) =>\n new DeepInfraImageModel(modelId, settings, {\n ...getCommonModelConfig('image'),\n baseURL: baseURL\n ? `${baseURL}/inference`\n : 'https://api.deepinfra.com/v1/inference',\n });\n\n const provider = (\n modelId: DeepInfraChatModelId,\n settings?: DeepInfraChatSettings,\n ) => createChatModel(modelId, settings);\n\n provider.completionModel = createCompletionModel;\n provider.chatModel = createChatModel;\n provider.image = createImageModel;\n provider.imageModel = createImageModel;\n provider.languageModel = createChatModel;\n provider.textEmbeddingModel = createTextEmbeddingModel;\n\n return provider;\n}\n\nexport const deepinfra = createDeepInfra();\n","import { ImageModelV1, ImageModelV1CallWarning } from '@ai-sdk/provider';\nimport {\n FetchFunction,\n combineHeaders,\n createJsonErrorResponseHandler,\n createJsonResponseHandler,\n postJsonToApi,\n} from '@ai-sdk/provider-utils';\nimport {\n DeepInfraImageModelId,\n DeepInfraImageSettings,\n} from './deepinfra-image-settings';\nimport { z } from 'zod';\n\ninterface DeepInfraImageModelConfig {\n provider: string;\n baseURL: string;\n headers: () => Record<string, string>;\n fetch?: FetchFunction;\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nexport class DeepInfraImageModel implements ImageModelV1 {\n readonly specificationVersion = 'v1';\n\n get provider(): string {\n return this.config.provider;\n }\n\n get maxImagesPerCall(): number {\n return this.settings.maxImagesPerCall ?? 1;\n }\n\n constructor(\n readonly modelId: DeepInfraImageModelId,\n readonly settings: DeepInfraImageSettings,\n private config: DeepInfraImageModelConfig,\n ) {}\n\n async doGenerate({\n prompt,\n n,\n size,\n aspectRatio,\n seed,\n providerOptions,\n headers,\n abortSignal,\n }: Parameters<ImageModelV1['doGenerate']>[0]): Promise<\n Awaited<ReturnType<ImageModelV1['doGenerate']>>\n > {\n const warnings: Array<ImageModelV1CallWarning> = [];\n\n // Some deepinfra models support size while others support aspect ratio.\n // Allow passing either and leave it up to the server to validate.\n\n const splitSize = size?.split('x');\n const currentDate = this.config._internal?.currentDate?.() ?? new Date();\n const { value: response, responseHeaders } = await postJsonToApi({\n url: `${this.config.baseURL}/${this.modelId}`,\n headers: combineHeaders(this.config.headers(), headers),\n body: {\n prompt,\n num_images: n,\n ...(aspectRatio && { aspect_ratio: aspectRatio }),\n ...(splitSize && { width: splitSize[0], height: splitSize[1] }),\n ...(seed != null && { seed }),\n ...(providerOptions.deepinfra ?? {}),\n },\n failedResponseHandler: createJsonErrorResponseHandler({\n errorSchema: deepInfraErrorSchema,\n errorToMessage: error => error.detail.error,\n }),\n successfulResponseHandler: createJsonResponseHandler(\n deepInfraImageResponseSchema,\n ),\n abortSignal,\n fetch: this.config.fetch,\n });\n\n return {\n images: response.images.map(image =>\n image.replace(/^data:image\\/\\w+;base64,/, ''),\n ),\n warnings,\n response: {\n timestamp: currentDate,\n modelId: this.modelId,\n headers: responseHeaders,\n },\n };\n }\n}\n\nexport const deepInfraErrorSchema = z.object({\n detail: z.object({\n error: z.string(),\n }),\n});\n\n// limited version of the schema, focussed on what is needed for the implementation\n// this approach limits breakages when the API changes and increases efficiency\nexport const deepInfraImageResponseSchema = z.object({\n images: z.array(z.string()),\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMA,+BAIO;AACP,IAAAA,yB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C,MAExC,IAAI;AAAA,IACF;AAAA,IACA;AAAA,IACA,qBAAqB,WAAW;AAAA,EAClC;AAEF,QAAM,mBAAmB,CACvB,SACA,WAAmC,CAAC,MAEpC,IAAI,oBAAoB,SAAS,UAAU;AAAA,IACzC,GAAG,qBAAqB,OAAO;AAAA,IAC/B,SAAS,UACL,GAAG,OAAO,eACV;AAAA,EACN,CAAC;AAEH,QAAM,WAAW,CACf,SACA,aACG,gBAAgB,SAAS,QAAQ;AAEtC,WAAS,kBAAkB;AAC3B,WAAS,YAAY;AACrB,WAAS,QAAQ;AACjB,WAAS,aAAa;AACtB,WAAS,gBAAgB;AACzB,WAAS,qBAAqB;AAE9B,SAAO;AACT;AAEO,IAAM,YAAY,gBAAgB;","names":["import_provider_utils"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/deepinfra-provider.ts","../src/deepinfra-image-model.ts"],"sourcesContent":["export { createDeepInfra, deepinfra } from './deepinfra-provider';\nexport type {\n DeepInfraProvider,\n DeepInfraProviderSettings,\n} from './deepinfra-provider';\nexport type { OpenAICompatibleErrorData as DeepInfraErrorData } from '@ai-sdk/openai-compatible';\n","import {\n LanguageModelV2,\n EmbeddingModelV2,\n ProviderV2,\n ImageModelV2,\n} from '@ai-sdk/provider';\nimport {\n OpenAICompatibleChatLanguageModel,\n OpenAICompatibleCompletionLanguageModel,\n OpenAICompatibleEmbeddingModel,\n} from '@ai-sdk/openai-compatible';\nimport {\n FetchFunction,\n loadApiKey,\n withoutTrailingSlash,\n} from '@ai-sdk/provider-utils';\nimport { DeepInfraChatModelId } from './deepinfra-chat-options';\nimport { DeepInfraEmbeddingModelId } from './deepinfra-embedding-options';\nimport { DeepInfraCompletionModelId } from './deepinfra-completion-options';\nimport { DeepInfraImageModelId } from './deepinfra-image-settings';\nimport { DeepInfraImageModel } from './deepinfra-image-model';\n\nexport interface DeepInfraProviderSettings {\n /**\nDeepInfra API key.\n*/\n apiKey?: string;\n /**\nBase URL for the API calls.\n*/\n baseURL?: string;\n /**\nCustom headers to include in the requests.\n*/\n headers?: Record<string, string>;\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n*/\n fetch?: FetchFunction;\n}\n\nexport interface DeepInfraProvider extends ProviderV2 {\n /**\nCreates a model for text generation.\n*/\n (modelId: DeepInfraChatModelId): LanguageModelV2;\n\n /**\nCreates a chat model for text generation.\n*/\n chatModel(modelId: DeepInfraChatModelId): LanguageModelV2;\n\n /**\nCreates a model for image generation.\n@deprecated Use `imageModel` instead.\n */\n image(modelId: DeepInfraImageModelId): ImageModelV2;\n\n /**\nCreates a model for image generation.\n */\n imageModel(modelId: DeepInfraImageModelId): ImageModelV2;\n\n /**\nCreates a chat model for text generation.\n*/\n languageModel(modelId: DeepInfraChatModelId): LanguageModelV2;\n\n /**\nCreates a completion model for text generation.\n*/\n completionModel(modelId: DeepInfraCompletionModelId): LanguageModelV2;\n\n /**\nCreates a text embedding model for text generation.\n*/\n textEmbeddingModel(\n modelId: DeepInfraEmbeddingModelId,\n ): EmbeddingModelV2<string>;\n}\n\nexport function createDeepInfra(\n options: DeepInfraProviderSettings = {},\n): DeepInfraProvider {\n const baseURL = withoutTrailingSlash(\n options.baseURL ?? 'https://api.deepinfra.com/v1',\n );\n const getHeaders = () => ({\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'DEEPINFRA_API_KEY',\n description: \"DeepInfra's API key\",\n })}`,\n ...options.headers,\n });\n\n interface CommonModelConfig {\n provider: string;\n url: ({ path }: { path: string }) => string;\n headers: () => Record<string, string>;\n fetch?: FetchFunction;\n }\n\n const getCommonModelConfig = (modelType: string): CommonModelConfig => ({\n provider: `deepinfra.${modelType}`,\n url: ({ path }) => `${baseURL}/openai${path}`,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const createChatModel = (modelId: DeepInfraChatModelId) => {\n return new OpenAICompatibleChatLanguageModel(\n modelId,\n getCommonModelConfig('chat'),\n );\n };\n\n const createCompletionModel = (modelId: DeepInfraCompletionModelId) =>\n new OpenAICompatibleCompletionLanguageModel(\n modelId,\n getCommonModelConfig('completion'),\n );\n\n const createTextEmbeddingModel = (modelId: DeepInfraEmbeddingModelId) =>\n new OpenAICompatibleEmbeddingModel(\n modelId,\n getCommonModelConfig('embedding'),\n );\n\n const createImageModel = (modelId: DeepInfraImageModelId) =>\n new DeepInfraImageModel(modelId, {\n ...getCommonModelConfig('image'),\n baseURL: baseURL\n ? `${baseURL}/inference`\n : 'https://api.deepinfra.com/v1/inference',\n });\n\n const provider = (modelId: DeepInfraChatModelId) => createChatModel(modelId);\n\n provider.completionModel = createCompletionModel;\n provider.chatModel = createChatModel;\n provider.image = createImageModel;\n provider.imageModel = createImageModel;\n provider.languageModel = createChatModel;\n provider.textEmbeddingModel = createTextEmbeddingModel;\n\n return provider;\n}\n\nexport const deepinfra = createDeepInfra();\n","import { ImageModelV2, ImageModelV2CallWarning } from '@ai-sdk/provider';\nimport {\n FetchFunction,\n combineHeaders,\n createJsonErrorResponseHandler,\n createJsonResponseHandler,\n postJsonToApi,\n} from '@ai-sdk/provider-utils';\nimport { DeepInfraImageModelId } from './deepinfra-image-settings';\nimport { z } from 'zod';\n\ninterface DeepInfraImageModelConfig {\n provider: string;\n baseURL: string;\n headers: () => Record<string, string>;\n fetch?: FetchFunction;\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nexport class DeepInfraImageModel implements ImageModelV2 {\n readonly specificationVersion = 'v2';\n readonly maxImagesPerCall = 1;\n\n get provider(): string {\n return this.config.provider;\n }\n\n constructor(\n readonly modelId: DeepInfraImageModelId,\n private config: DeepInfraImageModelConfig,\n ) {}\n\n async doGenerate({\n prompt,\n n,\n size,\n aspectRatio,\n seed,\n providerOptions,\n headers,\n abortSignal,\n }: Parameters<ImageModelV2['doGenerate']>[0]): Promise<\n Awaited<ReturnType<ImageModelV2['doGenerate']>>\n > {\n const warnings: Array<ImageModelV2CallWarning> = [];\n\n // Some deepinfra models support size while others support aspect ratio.\n // Allow passing either and leave it up to the server to validate.\n\n const splitSize = size?.split('x');\n const currentDate = this.config._internal?.currentDate?.() ?? new Date();\n const { value: response, responseHeaders } = await postJsonToApi({\n url: `${this.config.baseURL}/${this.modelId}`,\n headers: combineHeaders(this.config.headers(), headers),\n body: {\n prompt,\n num_images: n,\n ...(aspectRatio && { aspect_ratio: aspectRatio }),\n ...(splitSize && { width: splitSize[0], height: splitSize[1] }),\n ...(seed != null && { seed }),\n ...(providerOptions.deepinfra ?? {}),\n },\n failedResponseHandler: createJsonErrorResponseHandler({\n errorSchema: deepInfraErrorSchema,\n errorToMessage: error => error.detail.error,\n }),\n successfulResponseHandler: createJsonResponseHandler(\n deepInfraImageResponseSchema,\n ),\n abortSignal,\n fetch: this.config.fetch,\n });\n\n return {\n images: response.images.map(image =>\n image.replace(/^data:image\\/\\w+;base64,/, ''),\n ),\n warnings,\n response: {\n timestamp: currentDate,\n modelId: this.modelId,\n headers: responseHeaders,\n },\n };\n }\n}\n\nexport const deepInfraErrorSchema = z.object({\n detail: z.object({\n error: z.string(),\n }),\n});\n\n// limited version of the schema, focussed on what is needed for the implementation\n// this approach limits breakages when the API changes and increases efficiency\nexport const deepInfraImageResponseSchema = z.object({\n images: z.array(z.string()),\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMA,+BAIO;AACP,IAAAA,yBAIO;;;ACdP,4BAMO;AAEP,iBAAkB;AAYX,IAAM,sBAAN,MAAkD;AAAA,EAQvD,YACW,SACD,QACR;AAFS;AACD;AATV,SAAS,uBAAuB;AAChC,SAAS,mBAAmB;AAAA,EASzB;AAAA,EAPH,IAAI,WAAmB;AACrB,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAOA,MAAM,WAAW;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAEE;AA7CJ;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;ADjBM,SAAS,gBACd,UAAqC,CAAC,GACnB;AApFrB;AAqFE,QAAM,cAAU;AAAA,KACd,aAAQ,YAAR,YAAmB;AAAA,EACrB;AACA,QAAM,aAAa,OAAO;AAAA,IACxB,eAAe,cAAU,mCAAW;AAAA,MAClC,QAAQ,QAAQ;AAAA,MAChB,yBAAyB;AAAA,MACzB,aAAa;AAAA,IACf,CAAC,CAAC;AAAA,IACF,GAAG,QAAQ;AAAA,EACb;AASA,QAAM,uBAAuB,CAAC,eAA0C;AAAA,IACtE,UAAU,aAAa,SAAS;AAAA,IAChC,KAAK,CAAC,EAAE,KAAK,MAAM,GAAG,OAAO,UAAU,IAAI;AAAA,IAC3C,SAAS;AAAA,IACT,OAAO,QAAQ;AAAA,EACjB;AAEA,QAAM,kBAAkB,CAAC,YAAkC;AACzD,WAAO,IAAI;AAAA,MACT;AAAA,MACA,qBAAqB,MAAM;AAAA,IAC7B;AAAA,EACF;AAEA,QAAM,wBAAwB,CAAC,YAC7B,IAAI;AAAA,IACF;AAAA,IACA,qBAAqB,YAAY;AAAA,EACnC;AAEF,QAAM,2BAA2B,CAAC,YAChC,IAAI;AAAA,IACF;AAAA,IACA,qBAAqB,WAAW;AAAA,EAClC;AAEF,QAAM,mBAAmB,CAAC,YACxB,IAAI,oBAAoB,SAAS;AAAA,IAC/B,GAAG,qBAAqB,OAAO;AAAA,IAC/B,SAAS,UACL,GAAG,OAAO,eACV;AAAA,EACN,CAAC;AAEH,QAAM,WAAW,CAAC,YAAkC,gBAAgB,OAAO;AAE3E,WAAS,kBAAkB;AAC3B,WAAS,YAAY;AACrB,WAAS,QAAQ;AACjB,WAAS,aAAa;AACtB,WAAS,gBAAgB;AACzB,WAAS,qBAAqB;AAE9B,SAAO;AACT;AAEO,IAAM,YAAY,gBAAgB;","names":["import_provider_utils"]}
package/dist/index.mjs CHANGED
@@ -18,19 +18,15 @@ import {
18
18
  } from "@ai-sdk/provider-utils";
19
19
  import { z } from "zod";
20
20
  var DeepInfraImageModel = class {
21
- constructor(modelId, settings, config) {
21
+ constructor(modelId, config) {
22
22
  this.modelId = modelId;
23
- this.settings = settings;
24
23
  this.config = config;
25
- this.specificationVersion = "v1";
24
+ this.specificationVersion = "v2";
25
+ this.maxImagesPerCall = 1;
26
26
  }
27
27
  get provider() {
28
28
  return this.config.provider;
29
29
  }
30
- get maxImagesPerCall() {
31
- var _a;
32
- return (_a = this.settings.maxImagesPerCall) != null ? _a : 1;
33
- }
34
30
  async doGenerate({
35
31
  prompt,
36
32
  n,
@@ -108,27 +104,25 @@ function createDeepInfra(options = {}) {
108
104
  headers: getHeaders,
109
105
  fetch: options.fetch
110
106
  });
111
- const createChatModel = (modelId, settings = {}) => {
112
- return new OpenAICompatibleChatLanguageModel(modelId, settings, {
113
- ...getCommonModelConfig("chat"),
114
- defaultObjectGenerationMode: "json"
115
- });
107
+ const createChatModel = (modelId) => {
108
+ return new OpenAICompatibleChatLanguageModel(
109
+ modelId,
110
+ getCommonModelConfig("chat")
111
+ );
116
112
  };
117
- const createCompletionModel = (modelId, settings = {}) => new OpenAICompatibleCompletionLanguageModel(
113
+ const createCompletionModel = (modelId) => new OpenAICompatibleCompletionLanguageModel(
118
114
  modelId,
119
- settings,
120
115
  getCommonModelConfig("completion")
121
116
  );
122
- const createTextEmbeddingModel = (modelId, settings = {}) => new OpenAICompatibleEmbeddingModel(
117
+ const createTextEmbeddingModel = (modelId) => new OpenAICompatibleEmbeddingModel(
123
118
  modelId,
124
- settings,
125
119
  getCommonModelConfig("embedding")
126
120
  );
127
- const createImageModel = (modelId, settings = {}) => new DeepInfraImageModel(modelId, settings, {
121
+ const createImageModel = (modelId) => new DeepInfraImageModel(modelId, {
128
122
  ...getCommonModelConfig("image"),
129
123
  baseURL: baseURL ? `${baseURL}/inference` : "https://api.deepinfra.com/v1/inference"
130
124
  });
131
- const provider = (modelId, settings) => createChatModel(modelId, settings);
125
+ const provider = (modelId) => createChatModel(modelId);
132
126
  provider.completionModel = createCompletionModel;
133
127
  provider.chatModel = createChatModel;
134
128
  provider.image = createImageModel;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/deepinfra-provider.ts","../src/deepinfra-image-model.ts"],"sourcesContent":["import {\n LanguageModelV1,\n EmbeddingModelV1,\n ProviderV1,\n ImageModelV1,\n} from '@ai-sdk/provider';\nimport {\n OpenAICompatibleChatLanguageModel,\n OpenAICompatibleCompletionLanguageModel,\n OpenAICompatibleEmbeddingModel,\n} from '@ai-sdk/openai-compatible';\nimport {\n FetchFunction,\n loadApiKey,\n withoutTrailingSlash,\n} from '@ai-sdk/provider-utils';\nimport {\n DeepInfraChatModelId,\n DeepInfraChatSettings,\n} from './deepinfra-chat-settings';\nimport {\n DeepInfraEmbeddingModelId,\n DeepInfraEmbeddingSettings,\n} from './deepinfra-embedding-settings';\nimport {\n DeepInfraCompletionModelId,\n DeepInfraCompletionSettings,\n} from './deepinfra-completion-settings';\nimport {\n DeepInfraImageModelId,\n DeepInfraImageSettings,\n} from './deepinfra-image-settings';\nimport { DeepInfraImageModel } from './deepinfra-image-model';\n\nexport interface DeepInfraProviderSettings {\n /**\nDeepInfra API key.\n*/\n apiKey?: string;\n /**\nBase URL for the API calls.\n*/\n baseURL?: string;\n /**\nCustom headers to include in the requests.\n*/\n headers?: Record<string, string>;\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n*/\n fetch?: FetchFunction;\n}\n\nexport interface DeepInfraProvider extends ProviderV1 {\n /**\nCreates a model for text generation.\n*/\n (\n modelId: DeepInfraChatModelId,\n settings?: DeepInfraChatSettings,\n ): LanguageModelV1;\n\n /**\nCreates a chat model for text generation.\n*/\n chatModel(\n modelId: DeepInfraChatModelId,\n settings?: DeepInfraChatSettings,\n ): LanguageModelV1;\n\n /**\nCreates a model for image generation.\n */\n image(\n modelId: DeepInfraImageModelId,\n settings?: DeepInfraImageSettings,\n ): ImageModelV1;\n\n /**\nCreates a model for image generation.\n */\n imageModel(\n modelId: DeepInfraImageModelId,\n settings?: DeepInfraImageSettings,\n ): ImageModelV1;\n\n /**\nCreates a chat model for text generation.\n*/\n languageModel(\n modelId: DeepInfraChatModelId,\n settings?: DeepInfraChatSettings,\n ): LanguageModelV1;\n\n /**\nCreates a completion model for text generation.\n*/\n completionModel(\n modelId: DeepInfraCompletionModelId,\n settings?: DeepInfraCompletionSettings,\n ): LanguageModelV1;\n\n /**\nCreates a text embedding model for text generation.\n*/\n textEmbeddingModel(\n modelId: DeepInfraEmbeddingModelId,\n settings?: DeepInfraEmbeddingSettings,\n ): EmbeddingModelV1<string>;\n}\n\nexport function createDeepInfra(\n options: DeepInfraProviderSettings = {},\n): DeepInfraProvider {\n const baseURL = withoutTrailingSlash(\n options.baseURL ?? 'https://api.deepinfra.com/v1',\n );\n const getHeaders = () => ({\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'DEEPINFRA_API_KEY',\n description: \"DeepInfra's API key\",\n })}`,\n ...options.headers,\n });\n\n interface CommonModelConfig {\n provider: string;\n url: ({ path }: { path: string }) => string;\n headers: () => Record<string, string>;\n fetch?: FetchFunction;\n }\n\n const getCommonModelConfig = (modelType: string): CommonModelConfig => ({\n provider: `deepinfra.${modelType}`,\n url: ({ path }) => `${baseURL}/openai${path}`,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const createChatModel = (\n modelId: DeepInfraChatModelId,\n settings: DeepInfraChatSettings = {},\n ) => {\n return new OpenAICompatibleChatLanguageModel(modelId, settings, {\n ...getCommonModelConfig('chat'),\n defaultObjectGenerationMode: 'json',\n });\n };\n\n const createCompletionModel = (\n modelId: DeepInfraCompletionModelId,\n settings: DeepInfraCompletionSettings = {},\n ) =>\n new OpenAICompatibleCompletionLanguageModel(\n modelId,\n settings,\n getCommonModelConfig('completion'),\n );\n\n const createTextEmbeddingModel = (\n modelId: DeepInfraEmbeddingModelId,\n settings: DeepInfraEmbeddingSettings = {},\n ) =>\n new OpenAICompatibleEmbeddingModel(\n modelId,\n settings,\n getCommonModelConfig('embedding'),\n );\n\n const createImageModel = (\n modelId: DeepInfraImageModelId,\n settings: DeepInfraImageSettings = {},\n ) =>\n new DeepInfraImageModel(modelId, settings, {\n ...getCommonModelConfig('image'),\n baseURL: baseURL\n ? `${baseURL}/inference`\n : 'https://api.deepinfra.com/v1/inference',\n });\n\n const provider = (\n modelId: DeepInfraChatModelId,\n settings?: DeepInfraChatSettings,\n ) => createChatModel(modelId, settings);\n\n provider.completionModel = createCompletionModel;\n provider.chatModel = createChatModel;\n provider.image = createImageModel;\n provider.imageModel = createImageModel;\n provider.languageModel = createChatModel;\n provider.textEmbeddingModel = createTextEmbeddingModel;\n\n return provider;\n}\n\nexport const deepinfra = createDeepInfra();\n","import { ImageModelV1, ImageModelV1CallWarning } from '@ai-sdk/provider';\nimport {\n FetchFunction,\n combineHeaders,\n createJsonErrorResponseHandler,\n createJsonResponseHandler,\n postJsonToApi,\n} from '@ai-sdk/provider-utils';\nimport {\n DeepInfraImageModelId,\n DeepInfraImageSettings,\n} from './deepinfra-image-settings';\nimport { z } from 'zod';\n\ninterface DeepInfraImageModelConfig {\n provider: string;\n baseURL: string;\n headers: () => Record<string, string>;\n fetch?: FetchFunction;\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nexport class DeepInfraImageModel implements ImageModelV1 {\n readonly specificationVersion = 'v1';\n\n get provider(): string {\n return this.config.provider;\n }\n\n get maxImagesPerCall(): number {\n return this.settings.maxImagesPerCall ?? 1;\n }\n\n constructor(\n readonly modelId: DeepInfraImageModelId,\n readonly settings: DeepInfraImageSettings,\n private config: DeepInfraImageModelConfig,\n ) {}\n\n async doGenerate({\n prompt,\n n,\n size,\n aspectRatio,\n seed,\n providerOptions,\n headers,\n abortSignal,\n }: Parameters<ImageModelV1['doGenerate']>[0]): Promise<\n Awaited<ReturnType<ImageModelV1['doGenerate']>>\n > {\n const warnings: Array<ImageModelV1CallWarning> = [];\n\n // Some deepinfra models support size while others support aspect ratio.\n // Allow passing either and leave it up to the server to validate.\n\n const splitSize = size?.split('x');\n const currentDate = this.config._internal?.currentDate?.() ?? new Date();\n const { value: response, responseHeaders } = await postJsonToApi({\n url: `${this.config.baseURL}/${this.modelId}`,\n headers: combineHeaders(this.config.headers(), headers),\n body: {\n prompt,\n num_images: n,\n ...(aspectRatio && { aspect_ratio: aspectRatio }),\n ...(splitSize && { width: splitSize[0], height: splitSize[1] }),\n ...(seed != null && { seed }),\n ...(providerOptions.deepinfra ?? {}),\n },\n failedResponseHandler: createJsonErrorResponseHandler({\n errorSchema: deepInfraErrorSchema,\n errorToMessage: error => error.detail.error,\n }),\n successfulResponseHandler: createJsonResponseHandler(\n deepInfraImageResponseSchema,\n ),\n abortSignal,\n fetch: this.config.fetch,\n });\n\n return {\n images: response.images.map(image =>\n image.replace(/^data:image\\/\\w+;base64,/, ''),\n ),\n warnings,\n response: {\n timestamp: currentDate,\n modelId: this.modelId,\n headers: responseHeaders,\n },\n };\n }\n}\n\nexport const deepInfraErrorSchema = z.object({\n detail: z.object({\n error: z.string(),\n }),\n});\n\n// limited version of the schema, focussed on what is needed for the implementation\n// this approach limits breakages when the API changes and increases efficiency\nexport const deepInfraImageResponseSchema = z.object({\n images: z.array(z.string()),\n});\n"],"mappings":";AAMA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EAEE;AAAA,EACA;AAAA,OACK;;;ACdP;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAKP,SAAS,SAAS;AAYX,IAAM,sBAAN,MAAkD;AAAA,EAWvD,YACW,SACA,UACD,QACR;AAHS;AACA;AACD;AAbV,SAAS,uBAAuB;AAAA,EAc7B;AAAA,EAZH,IAAI,WAAmB;AACrB,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAEA,IAAI,mBAA2B;AA/BjC;AAgCI,YAAO,UAAK,SAAS,qBAAd,YAAkC;AAAA,EAC3C;AAAA,EAQA,MAAM,WAAW;AAAA,IAC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S,YAAY;AACrB,WAAS,QAAQ;AACjB,WAAS,aAAa;AACtB,WAAS,gBAAgB;AACzB,WAAS,qBAAqB;AAE9B,SAAO;AACT;AAEO,IAAM,YAAY,gBAAgB;","names":[]}
1
+ {"version":3,"sources":["../src/deepinfra-provider.ts","../src/deepinfra-image-model.ts"],"sourcesContent":["import {\n LanguageModelV2,\n EmbeddingModelV2,\n ProviderV2,\n ImageModelV2,\n} from '@ai-sdk/provider';\nimport {\n OpenAICompatibleChatLanguageModel,\n OpenAICompatibleCompletionLanguageModel,\n OpenAICompatibleEmbeddingModel,\n} from '@ai-sdk/openai-compatible';\nimport {\n FetchFunction,\n loadApiKey,\n withoutTrailingSlash,\n} from '@ai-sdk/provider-utils';\nimport { DeepInfraChatModelId } from './deepinfra-chat-options';\nimport { DeepInfraEmbeddingModelId } from './deepinfra-embedding-options';\nimport { DeepInfraCompletionModelId } from './deepinfra-completion-options';\nimport { DeepInfraImageModelId } from './deepinfra-image-settings';\nimport { DeepInfraImageModel } from './deepinfra-image-model';\n\nexport interface DeepInfraProviderSettings {\n /**\nDeepInfra API key.\n*/\n apiKey?: string;\n /**\nBase URL for the API calls.\n*/\n baseURL?: string;\n /**\nCustom headers to include in the requests.\n*/\n headers?: Record<string, string>;\n /**\nCustom fetch implementation. You can use it as a middleware to intercept requests,\nor to provide a custom fetch implementation for e.g. testing.\n*/\n fetch?: FetchFunction;\n}\n\nexport interface DeepInfraProvider extends ProviderV2 {\n /**\nCreates a model for text generation.\n*/\n (modelId: DeepInfraChatModelId): LanguageModelV2;\n\n /**\nCreates a chat model for text generation.\n*/\n chatModel(modelId: DeepInfraChatModelId): LanguageModelV2;\n\n /**\nCreates a model for image generation.\n@deprecated Use `imageModel` instead.\n */\n image(modelId: DeepInfraImageModelId): ImageModelV2;\n\n /**\nCreates a model for image generation.\n */\n imageModel(modelId: DeepInfraImageModelId): ImageModelV2;\n\n /**\nCreates a chat model for text generation.\n*/\n languageModel(modelId: DeepInfraChatModelId): LanguageModelV2;\n\n /**\nCreates a completion model for text generation.\n*/\n completionModel(modelId: DeepInfraCompletionModelId): LanguageModelV2;\n\n /**\nCreates a text embedding model for text generation.\n*/\n textEmbeddingModel(\n modelId: DeepInfraEmbeddingModelId,\n ): EmbeddingModelV2<string>;\n}\n\nexport function createDeepInfra(\n options: DeepInfraProviderSettings = {},\n): DeepInfraProvider {\n const baseURL = withoutTrailingSlash(\n options.baseURL ?? 'https://api.deepinfra.com/v1',\n );\n const getHeaders = () => ({\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'DEEPINFRA_API_KEY',\n description: \"DeepInfra's API key\",\n })}`,\n ...options.headers,\n });\n\n interface CommonModelConfig {\n provider: string;\n url: ({ path }: { path: string }) => string;\n headers: () => Record<string, string>;\n fetch?: FetchFunction;\n }\n\n const getCommonModelConfig = (modelType: string): CommonModelConfig => ({\n provider: `deepinfra.${modelType}`,\n url: ({ path }) => `${baseURL}/openai${path}`,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const createChatModel = (modelId: DeepInfraChatModelId) => {\n return new OpenAICompatibleChatLanguageModel(\n modelId,\n getCommonModelConfig('chat'),\n );\n };\n\n const createCompletionModel = (modelId: DeepInfraCompletionModelId) =>\n new OpenAICompatibleCompletionLanguageModel(\n modelId,\n getCommonModelConfig('completion'),\n );\n\n const createTextEmbeddingModel = (modelId: DeepInfraEmbeddingModelId) =>\n new OpenAICompatibleEmbeddingModel(\n modelId,\n getCommonModelConfig('embedding'),\n );\n\n const createImageModel = (modelId: DeepInfraImageModelId) =>\n new DeepInfraImageModel(modelId, {\n ...getCommonModelConfig('image'),\n baseURL: baseURL\n ? `${baseURL}/inference`\n : 'https://api.deepinfra.com/v1/inference',\n });\n\n const provider = (modelId: DeepInfraChatModelId) => createChatModel(modelId);\n\n provider.completionModel = createCompletionModel;\n provider.chatModel = createChatModel;\n provider.image = createImageModel;\n provider.imageModel = createImageModel;\n provider.languageModel = createChatModel;\n provider.textEmbeddingModel = createTextEmbeddingModel;\n\n return provider;\n}\n\nexport const deepinfra = createDeepInfra();\n","import { ImageModelV2, ImageModelV2CallWarning } from '@ai-sdk/provider';\nimport {\n FetchFunction,\n combineHeaders,\n createJsonErrorResponseHandler,\n createJsonResponseHandler,\n postJsonToApi,\n} from '@ai-sdk/provider-utils';\nimport { DeepInfraImageModelId } from './deepinfra-image-settings';\nimport { z } from 'zod';\n\ninterface DeepInfraImageModelConfig {\n provider: string;\n baseURL: string;\n headers: () => Record<string, string>;\n fetch?: FetchFunction;\n _internal?: {\n currentDate?: () => Date;\n };\n}\n\nexport class DeepInfraImageModel implements ImageModelV2 {\n readonly specificationVersion = 'v2';\n readonly maxImagesPerCall = 1;\n\n get provider(): string {\n return this.config.provider;\n }\n\n constructor(\n readonly modelId: DeepInfraImageModelId,\n private config: DeepInfraImageModelConfig,\n ) {}\n\n async doGenerate({\n prompt,\n n,\n size,\n aspectRatio,\n seed,\n providerOptions,\n headers,\n abortSignal,\n }: Parameters<ImageModelV2['doGenerate']>[0]): Promise<\n Awaited<ReturnType<ImageModelV2['doGenerate']>>\n > {\n const warnings: Array<ImageModelV2CallWarning> = [];\n\n // Some deepinfra models support size while others support aspect ratio.\n // Allow passing either and leave it up to the server to validate.\n\n const splitSize = size?.split('x');\n const currentDate = this.config._internal?.currentDate?.() ?? new Date();\n const { value: response, responseHeaders } = await postJsonToApi({\n url: `${this.config.baseURL}/${this.modelId}`,\n headers: combineHeaders(this.config.headers(), headers),\n body: {\n prompt,\n num_images: n,\n ...(aspectRatio && { aspect_ratio: aspectRatio }),\n ...(splitSize && { width: splitSize[0], height: splitSize[1] }),\n ...(seed != null && { seed }),\n ...(providerOptions.deepinfra ?? {}),\n },\n failedResponseHandler: createJsonErrorResponseHandler({\n errorSchema: deepInfraErrorSchema,\n errorToMessage: error => error.detail.error,\n }),\n successfulResponseHandler: createJsonResponseHandler(\n deepInfraImageResponseSchema,\n ),\n abortSignal,\n fetch: this.config.fetch,\n });\n\n return {\n images: response.images.map(image =>\n image.replace(/^data:image\\/\\w+;base64,/, ''),\n ),\n warnings,\n response: {\n timestamp: currentDate,\n modelId: this.modelId,\n headers: responseHeaders,\n },\n };\n }\n}\n\nexport const deepInfraErrorSchema = z.object({\n detail: z.object({\n error: z.string(),\n }),\n});\n\n// limited version of the schema, focussed on what is needed for the implementation\n// this approach limits breakages when the API changes and increases efficiency\nexport const deepInfraImageResponseSchema = z.object({\n images: z.array(z.string()),\n});\n"],"mappings":";AAMA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EAEE;AAAA,EACA;AAAA,OACK;;;ACdP;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,SAAS;AAYX,IAAM,sBAAN,MAAkD;AAAA,EAQvD,YACW,SACD,QACR;AAFS;AACD;AATV,SAAS,uBAAuB;AAChC,SAAS,mBAAmB;AAAA,EASzB;AAAA,EAPH,IAAI,WAAmB;AACrB,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAOA,MAAM,WAAW;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAEE;AA7CJ;AA8CI,UAAM,WAA2C,CAAC;AAKlD,UAAM,YAAY,6BAAM,MAAM;AAC9B,UAAM,eAAc,sBAAK,OAAO,cAAZ,mBAAuB,gBAAvB,4CAA0C,oBAAI,KAAK;AACvE,UAAM,EAAE,OAAO,UAAU,gBAAgB,IAAI,MAAM,cAAc;AAAA,MAC/D,KAAK,GAAG,KAAK,OAAO,OAAO,IAAI,KAAK,OAAO;AAAA,MAC3C,SAAS,eAAe,KAAK,OAAO,QAAQ,GAAG,OAAO;AAAA,MACtD,MAAM;AAAA,QACJ;AAAA,QACA,YAAY;AAAA,QACZ,GAAI,eAAe,EAAE,cAAc,YAAY;AAAA,QAC/C,GAAI,aAAa,EAAE,OAAO,UAAU,CAAC,GA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;AAAA,EACjB;AAEA,QAAM,kBAAkB,CAAC,YAAkC;AACzD,WAAO,IAAI;AAAA,MACT;AAAA,MACA,qBAAqB,MAAM;AAAA,IAC7B;AAAA,EACF;AAEA,QAAM,wBAAwB,CAAC,YAC7B,IAAI;AAAA,IACF;AAAA,IACA,qBAAqB,YAAY;AAAA,EACnC;AAEF,QAAM,2BAA2B,CAAC,YAChC,IAAI;AAAA,IACF;AAAA,IACA,qBAAqB,WAAW;AAAA,EAClC;AAEF,QAAM,mBAAmB,CAAC,YACxB,IAAI,oBAAoB,SAAS;AAAA,IAC/B,GAAG,qBAAqB,OAAO;AAAA,IAC/B,SAAS,UACL,GAAG,OAAO,eACV;AAAA,EACN,CAAC;AAEH,QAAM,WAAW,CAAC,YAAkC,gBAAgB,OAAO;AAE3E,WAAS,kBAAkB;AAC3B,WAAS,YAAY;AACrB,WAAS,QAAQ;AACjB,WAAS,aAAa;AACtB,WAAS,gBAAgB;AACzB,WAAS,qBAAqB;AAE9B,SAAO;AACT;AAEO,IAAM,YAAY,gBAAgB;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/deepinfra",
3
- "version": "0.2.15",
3
+ "version": "1.0.0-alpha.2",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -19,19 +19,19 @@
19
19
  }
20
20
  },
21
21
  "dependencies": {
22
- "@ai-sdk/openai-compatible": "0.2.14",
23
- "@ai-sdk/provider": "1.1.3",
24
- "@ai-sdk/provider-utils": "2.2.8"
22
+ "@ai-sdk/openai-compatible": "1.0.0-alpha.2",
23
+ "@ai-sdk/provider": "2.0.0-alpha.2",
24
+ "@ai-sdk/provider-utils": "3.0.0-alpha.2"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/node": "20.17.24",
28
28
  "tsup": "^8",
29
- "typescript": "5.6.3",
30
- "zod": "3.23.8",
29
+ "typescript": "5.8.3",
30
+ "zod": "3.24.4",
31
31
  "@vercel/ai-tsconfig": "0.0.0"
32
32
  },
33
33
  "peerDependencies": {
34
- "zod": "^3.0.0"
34
+ "zod": "^3.24.0"
35
35
  },
36
36
  "engines": {
37
37
  "node": ">=18"
@@ -51,13 +51,15 @@
51
51
  "ai"
52
52
  ],
53
53
  "scripts": {
54
- "build": "tsup",
55
- "build:watch": "tsup --watch",
56
- "clean": "rm -rf dist",
54
+ "build": "pnpm clean && tsup --tsconfig tsconfig.build.json",
55
+ "build:watch": "pnpm clean && tsup --watch",
56
+ "clean": "rm -rf dist *.tsbuildinfo",
57
57
  "lint": "eslint \"./**/*.ts*\"",
58
- "type-check": "tsc --noEmit",
58
+ "type-check": "tsc --build",
59
59
  "prettier-check": "prettier --check \"./**/*.ts*\"",
60
60
  "test": "pnpm test:node && pnpm test:edge",
61
+ "test:update": "pnpm test:node -u",
62
+ "test:watch": "vitest --config vitest.node.config.js",
61
63
  "test:edge": "vitest --config vitest.edge.config.js --run",
62
64
  "test:node": "vitest --config vitest.node.config.js --run"
63
65
  }