@ai-sdk/deepinfra 0.2.14 → 1.0.0-alpha.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/CHANGELOG.md CHANGED
@@ -1,73 +1,275 @@
1
1
  # @ai-sdk/deepinfra
2
2
 
3
- ## 0.2.14
3
+ ## 1.0.0-alpha.1
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - Updated dependencies [23571c9]
8
- - @ai-sdk/openai-compatible@0.2.13
7
+ - Updated dependencies [3f2f00c]
8
+ - @ai-sdk/provider@2.0.0-alpha.1
9
+ - @ai-sdk/openai-compatible@1.0.0-alpha.1
10
+ - @ai-sdk/provider-utils@3.0.0-alpha.1
9
11
 
10
- ## 0.2.13
12
+ ## 1.0.0-canary.19
11
13
 
12
14
  ### Patch Changes
13
15
 
14
- - Updated dependencies [13492fe]
15
- - @ai-sdk/openai-compatible@0.2.12
16
+ - Updated dependencies [faf8446]
17
+ - @ai-sdk/provider-utils@3.0.0-canary.19
18
+ - @ai-sdk/openai-compatible@1.0.0-canary.19
16
19
 
17
- ## 0.2.12
20
+ ## 1.0.0-canary.18
18
21
 
19
22
  ### Patch Changes
20
23
 
21
- - Updated dependencies [b5c9cd4]
22
- - @ai-sdk/openai-compatible@0.2.11
24
+ - Updated dependencies [40acf9b]
25
+ - @ai-sdk/provider-utils@3.0.0-canary.18
26
+ - @ai-sdk/openai-compatible@1.0.0-canary.18
23
27
 
24
- ## 0.2.11
28
+ ## 1.0.0-canary.17
29
+
30
+ ### Major Changes
31
+
32
+ - 516be5b: ### Move Image Model Settings into generate options
33
+
34
+ Image Models no longer have settings. Instead, `maxImagesPerCall` can be passed directly to `generateImage()`. All other image settings can be passed to `providerOptions[provider]`.
35
+
36
+ Before
37
+
38
+ ```js
39
+ await generateImage({
40
+ model: luma.image('photon-flash-1', {
41
+ maxImagesPerCall: 5,
42
+ pollIntervalMillis: 500,
43
+ }),
44
+ prompt,
45
+ n: 10,
46
+ });
47
+ ```
48
+
49
+ After
50
+
51
+ ```js
52
+ await generateImage({
53
+ model: luma.image('photon-flash-1'),
54
+ prompt,
55
+ n: 10,
56
+ maxImagesPerCall: 5,
57
+ providerOptions: {
58
+ luma: { pollIntervalMillis: 5 },
59
+ },
60
+ });
61
+ ```
62
+
63
+ Pull Request: https://github.com/vercel/ai/pull/6180
64
+
65
+ ### Patch Changes
66
+
67
+ - Updated dependencies [516be5b]
68
+ - Updated dependencies [ea7a7c9]
69
+ - @ai-sdk/openai-compatible@1.0.0-canary.17
70
+ - @ai-sdk/provider-utils@3.0.0-canary.17
71
+
72
+ ## 1.0.0-canary.16
73
+
74
+ ### Patch Changes
75
+
76
+ - Updated dependencies [87b828f]
77
+ - @ai-sdk/provider-utils@3.0.0-canary.16
78
+ - @ai-sdk/openai-compatible@1.0.0-canary.16
79
+
80
+ ## 1.0.0-canary.15
81
+
82
+ ### Patch Changes
83
+
84
+ - Updated dependencies [a571d6e]
85
+ - Updated dependencies [a8c8bd5]
86
+ - Updated dependencies [7979f7f]
87
+ - Updated dependencies [41fa418]
88
+ - @ai-sdk/provider-utils@3.0.0-canary.15
89
+ - @ai-sdk/provider@2.0.0-canary.14
90
+ - @ai-sdk/openai-compatible@1.0.0-canary.15
91
+
92
+ ## 1.0.0-canary.14
93
+
94
+ ### Patch Changes
95
+
96
+ - Updated dependencies [957b739]
97
+ - Updated dependencies [9bd5ab5]
98
+ - @ai-sdk/provider-utils@3.0.0-canary.14
99
+ - @ai-sdk/provider@2.0.0-canary.13
100
+ - @ai-sdk/openai-compatible@1.0.0-canary.14
101
+
102
+ ## 1.0.0-canary.13
103
+
104
+ ### Patch Changes
105
+
106
+ - d9209ca: fix (image-model): `specificationVersion: v1` -> `v2`
107
+ - Updated dependencies [7b3ae3f]
108
+ - Updated dependencies [d9209ca]
109
+ - Updated dependencies [0ff02bb]
110
+ - @ai-sdk/provider@2.0.0-canary.12
111
+ - @ai-sdk/openai-compatible@1.0.0-canary.13
112
+ - @ai-sdk/provider-utils@3.0.0-canary.13
113
+
114
+ ## 1.0.0-canary.12
115
+
116
+ ### Patch Changes
117
+
118
+ - Updated dependencies [9bf7291]
119
+ - Updated dependencies [4617fab]
120
+ - Updated dependencies [e030615]
121
+ - @ai-sdk/provider@2.0.0-canary.11
122
+ - @ai-sdk/openai-compatible@1.0.0-canary.12
123
+ - @ai-sdk/provider-utils@3.0.0-canary.12
124
+
125
+ ## 1.0.0-canary.11
126
+
127
+ ### Patch Changes
128
+
129
+ - 9301f86: refactor (image-model): rename `ImageModelV1` to `ImageModelV2`
130
+ - Updated dependencies [db72adc]
131
+ - Updated dependencies [42e32b0]
132
+ - Updated dependencies [66962ed]
133
+ - Updated dependencies [9301f86]
134
+ - Updated dependencies [a3f768e]
135
+ - @ai-sdk/openai-compatible@1.0.0-canary.11
136
+ - @ai-sdk/provider-utils@3.0.0-canary.11
137
+ - @ai-sdk/provider@2.0.0-canary.10
138
+
139
+ ## 1.0.0-canary.10
140
+
141
+ ### Patch Changes
142
+
143
+ - Updated dependencies [cf8280e]
144
+ - Updated dependencies [e86be6f]
145
+ - @ai-sdk/openai-compatible@1.0.0-canary.10
146
+ - @ai-sdk/provider@2.0.0-canary.9
147
+ - @ai-sdk/provider-utils@3.0.0-canary.10
148
+
149
+ ## 1.0.0-canary.9
150
+
151
+ ### Patch Changes
152
+
153
+ - Updated dependencies [95857aa]
154
+ - Updated dependencies [7ea4132]
155
+ - @ai-sdk/provider@2.0.0-canary.8
156
+ - @ai-sdk/openai-compatible@1.0.0-canary.9
157
+ - @ai-sdk/provider-utils@3.0.0-canary.9
158
+
159
+ ## 1.0.0-canary.8
25
160
 
26
161
  ### Patch Changes
27
162
 
28
- - Updated dependencies [beef951]
29
- - @ai-sdk/provider@1.1.3
30
- - @ai-sdk/openai-compatible@0.2.10
31
- - @ai-sdk/provider-utils@2.2.7
163
+ - Updated dependencies [5d142ab]
164
+ - Updated dependencies [b6b43c7]
165
+ - Updated dependencies [b9a6121]
166
+ - Updated dependencies [8aa9e20]
167
+ - Updated dependencies [3795467]
168
+ - @ai-sdk/provider-utils@3.0.0-canary.8
169
+ - @ai-sdk/provider@2.0.0-canary.7
170
+ - @ai-sdk/openai-compatible@1.0.0-canary.8
32
171
 
33
- ## 0.2.10
172
+ ## 1.0.0-canary.7
34
173
 
35
174
  ### Patch Changes
36
175
 
37
- - Updated dependencies [1bbc698]
38
- - @ai-sdk/openai-compatible@0.2.9
176
+ - fa49207: feat(providers/openai-compatible): convert to providerOptions
177
+ - 26735b5: chore(embedding-model): add v2 interface
178
+ - Updated dependencies [fa49207]
179
+ - Updated dependencies [26735b5]
180
+ - Updated dependencies [443d8ec]
181
+ - Updated dependencies [14c9410]
182
+ - Updated dependencies [d9c98f4]
183
+ - Updated dependencies [c4a2fec]
184
+ - Updated dependencies [0054544]
185
+ - Updated dependencies [9e9c809]
186
+ - Updated dependencies [32831c6]
187
+ - Updated dependencies [d0f9495]
188
+ - Updated dependencies [fd65bc6]
189
+ - Updated dependencies [393138b]
190
+ - Updated dependencies [7182d14]
191
+ - @ai-sdk/openai-compatible@1.0.0-canary.7
192
+ - @ai-sdk/provider@2.0.0-canary.6
193
+ - @ai-sdk/provider-utils@3.0.0-canary.7
39
194
 
40
- ## 0.2.9
195
+ ## 1.0.0-canary.6
41
196
 
42
197
  ### Patch Changes
43
198
 
44
- - Updated dependencies [013faa8]
45
- - @ai-sdk/provider@1.1.2
46
- - @ai-sdk/openai-compatible@0.2.8
47
- - @ai-sdk/provider-utils@2.2.6
199
+ - Updated dependencies [6db02c9]
200
+ - Updated dependencies [411e483]
201
+ - Updated dependencies [79457bd]
202
+ - Updated dependencies [ad80501]
203
+ - Updated dependencies [1766ede]
204
+ - Updated dependencies [f10304b]
205
+ - @ai-sdk/openai-compatible@1.0.0-canary.6
206
+ - @ai-sdk/provider@2.0.0-canary.5
207
+ - @ai-sdk/provider-utils@3.0.0-canary.6
48
208
 
49
- ## 0.2.8
209
+ ## 1.0.0-canary.5
50
210
 
51
211
  ### Patch Changes
52
212
 
53
- - Updated dependencies [c21fa6d]
54
- - @ai-sdk/provider-utils@2.2.5
55
- - @ai-sdk/provider@1.1.1
56
- - @ai-sdk/openai-compatible@0.2.7
213
+ - Updated dependencies [6f6bb89]
214
+ - @ai-sdk/provider@2.0.0-canary.4
215
+ - @ai-sdk/openai-compatible@1.0.0-canary.5
216
+ - @ai-sdk/provider-utils@3.0.0-canary.5
57
217
 
58
- ## 0.2.7
218
+ ## 1.0.0-canary.4
59
219
 
60
220
  ### Patch Changes
61
221
 
62
- - 264b1e0: feat (providers/deepinfra): add llama 4 models
222
+ - Updated dependencies [d1a1aa1]
223
+ - @ai-sdk/provider@2.0.0-canary.3
224
+ - @ai-sdk/openai-compatible@1.0.0-canary.4
225
+ - @ai-sdk/provider-utils@3.0.0-canary.4
226
+
227
+ ## 1.0.0-canary.3
228
+
229
+ ### Patch Changes
230
+
231
+ - Updated dependencies [a166433]
232
+ - Updated dependencies [abf9a79]
233
+ - Updated dependencies [9f95b35]
234
+ - Updated dependencies [0a87932]
235
+ - Updated dependencies [6dc848c]
236
+ - @ai-sdk/provider-utils@3.0.0-canary.3
237
+ - @ai-sdk/provider@2.0.0-canary.2
238
+ - @ai-sdk/openai-compatible@1.0.0-canary.3
239
+
240
+ ## 1.0.0-canary.2
241
+
242
+ ### Patch Changes
243
+
244
+ - 7677477: feat (providers/deepinfra): add llama 4 models
245
+ - Updated dependencies [c57e248]
246
+ - Updated dependencies [33f4a6a]
247
+ - @ai-sdk/provider@2.0.0-canary.1
248
+ - @ai-sdk/openai-compatible@1.0.0-canary.2
249
+ - @ai-sdk/provider-utils@3.0.0-canary.2
250
+
251
+ ## 1.0.0-canary.1
252
+
253
+ ### Patch Changes
254
+
255
+ - Updated dependencies [060370c]
256
+ - Updated dependencies [0c0c0b3]
257
+ - Updated dependencies [63d791d]
258
+ - @ai-sdk/provider-utils@3.0.0-canary.1
259
+ - @ai-sdk/openai-compatible@1.0.0-canary.1
260
+
261
+ ## 1.0.0-canary.0
262
+
263
+ ### Major Changes
63
264
 
64
- ## 0.2.6
265
+ - d5f588f: AI SDK 5
65
266
 
66
267
  ### Patch Changes
67
268
 
68
- - Updated dependencies [2c19b9a]
69
- - @ai-sdk/provider-utils@2.2.4
70
- - @ai-sdk/openai-compatible@0.2.6
269
+ - Updated dependencies [d5f588f]
270
+ - @ai-sdk/provider-utils@3.0.0-canary.0
271
+ - @ai-sdk/openai-compatible@1.0.0-canary.0
272
+ - @ai-sdk/provider@2.0.0-canary.0
71
273
 
72
274
  ## 0.2.5
73
275
 
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # AI SDK - DeepInfra Provider
2
2
 
3
- The **[DeepInfra provider](https://sdk.vercel.ai/providers/ai-sdk-providers/deepinfra)** for the [AI SDK](https://sdk.vercel.ai/docs)
3
+ The **[DeepInfra provider](https://ai-sdk.dev/providers/ai-sdk-providers/deepinfra)** for the [AI SDK](https://ai-sdk.dev/docs)
4
4
  contains language model support for the DeepInfra API, giving you access to models like Llama 3, Mixtral, and other state-of-the-art LLMs.
5
5
 
6
6
  ## Setup
@@ -33,4 +33,4 @@ const { text } = await generateText({
33
33
 
34
34
  ## Documentation
35
35
 
36
- Please check out the **[DeepInfra provider documentation](https://sdk.vercel.ai/providers/ai-sdk-providers/deepinfra)** for more information.
36
+ Please check out the **[DeepInfra provider documentation](https://ai-sdk.dev/providers/ai-sdk-providers/deepinfra)** for more information.
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,yBAIO;;;ACdP,4BAMO;AAKP,iBAAkB;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,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAEE;AApDJ;AAqDI,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,UAAM,qCAAc;AAAA,MAC/D,KAAK,GAAG,KAAK,OAAO,OAAO,IAAI,KAAK,OAAO;AAAA,MAC3C,aAAS,sCAAe,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,GAAG,QAAQ,UAAU,CAAC,EAAE;AAAA,QAC7D,GAAI,QAAQ,QAAQ,EAAE,KAAK;AAAA,QAC3B,IAAI,qBAAgB,cAAh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A,MAC9D,GAAG,qBAAqB,MAAM;AAAA,MAC9B,6BAA6B;AAAA,IAC/B,CAAC;AAAA,EACH;AAEA,QAAM,wBAAwB,CAC5B,SACA,WAAwC,CAAC,MAEzC,IAAI;AAAA,IACF;AAAA,IACA;AAAA,IACA,qBAAqB,YAAY;AAAA,EACnC;AAEF,QAAM,2BAA2B,CAC/B,SACA,WAAuC,CAAC,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,S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ACrB,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,SAC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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":[]}
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,KA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AA,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":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/deepinfra",
3
- "version": "0.2.14",
3
+ "version": "1.0.0-alpha.1",
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.13",
23
- "@ai-sdk/provider": "1.1.3",
24
- "@ai-sdk/provider-utils": "2.2.7"
22
+ "@ai-sdk/openai-compatible": "1.0.0-alpha.1",
23
+ "@ai-sdk/provider": "2.0.0-alpha.1",
24
+ "@ai-sdk/provider-utils": "3.0.0-alpha.1"
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"
@@ -39,7 +39,7 @@
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  },
42
- "homepage": "https://sdk.vercel.ai/docs",
42
+ "homepage": "https://ai-sdk.dev/docs",
43
43
  "repository": {
44
44
  "type": "git",
45
45
  "url": "git+https://github.com/vercel/ai.git"
@@ -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
  }