@aihubmix/ai-sdk-provider 0.0.1 → 0.0.3

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,5 +1,12 @@
1
1
  # @ai-sdk/aihubmix
2
2
 
3
+ ## 0.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - change llm V1 to V2
8
+ - 8e1ca80: Aihubmix Provider for Vercel AI SDK
9
+
3
10
  ## 0.0.1
4
11
 
5
12
  ### Patch Changes
package/README.ja.md ADDED
@@ -0,0 +1,301 @@
1
+ # AI SDK - Aihubmix Provider
2
+
3
+ <div align="center">
4
+ <a href="README.md">🇺🇸 English</a> |
5
+ <a href="README.zh.md">🇨🇳 中文</a> |
6
+ <a href="README.ja.md">🇯🇵 日本語</a>
7
+ </div>
8
+
9
+ > **🎉 10% 割引!**
10
+ app-codeが内蔵されており、この方法でモデルをリクエストすると10%割引になります。
11
+
12
+ **[Aihubmix 公式サイト](https://aihubmix.com/)** | **[モデルスクエア](https://aihubmix.com/models)**
13
+
14
+ [AI SDK](https://ai-sdk.dev/docs)用の **[Aihubmix provider](https://v5.ai-sdk.dev/providers/community-providers/aihubmix)**
15
+ 一つのゲートウェイ、無限のモデル;ワンストップリクエスト:OpenAI、Claude、Gemini、DeepSeek、Qwen、そして500以上のAIモデル。
16
+
17
+ ## サポートされている機能
18
+
19
+ Aihubmix providerは以下のAI機能をサポートしています:
20
+
21
+ - **テキスト生成**:様々なモデルでのチャット完了
22
+ - **ストリーミングテキスト**:リアルタイムテキストストリーミング
23
+ - **画像生成**:テキストプロンプトから画像を作成
24
+ - **埋め込み**:単一およびバッチテキスト埋め込み
25
+ - **オブジェクト生成**:スキーマを使用した構造化データ生成
26
+ - **ストリーミングオブジェクト**:リアルタイム構造化データストリーミング
27
+ - **音声合成**:テキストから音声への変換
28
+ - **転写**:音声からテキストへの変換
29
+ - **ツール**:ウェブ検索およびその他のツール
30
+
31
+ ## セットアップ
32
+
33
+ Aihubmix providerは`@aihubmix/ai-sdk-provider`モジュールで利用可能です。[@aihubmix/ai-sdk-provider](https://www.npmjs.com/package/@aihubmix/ai-sdk-provider)でインストールできます
34
+
35
+ ```bash
36
+ npm i @aihubmix/ai-sdk-provider
37
+ ```
38
+
39
+ ## Provider インスタンス
40
+
41
+ `@aihubmix/ai-sdk-provider`からデフォルトのproviderインスタンス`aihubmix`をインポートできます:
42
+
43
+ ```ts
44
+ import { aihubmix } from '@aihubmix/ai-sdk-provider';
45
+ ```
46
+
47
+ ## 設定
48
+
49
+ Aihubmix APIキーを環境変数として設定:
50
+
51
+ ```bash
52
+ export AIHUBMIX_API_KEY="your-api-key-here"
53
+ ```
54
+
55
+ または直接providerに渡す:
56
+
57
+ ```ts
58
+ import { createAihubmix } from '@aihubmix/ai-sdk-provider';
59
+
60
+ const aihubmix = createAihubmix({
61
+ apiKey: 'your-api-key-here',
62
+ });
63
+ ```
64
+
65
+ ## 使用
66
+
67
+ まず、必要な関数をインポートします:
68
+
69
+ ```ts
70
+ import { createAihubmix } from '@aihubmix/ai-sdk-provider';
71
+ import {
72
+ generateText,
73
+ streamText,
74
+ generateImage,
75
+ embed,
76
+ embedMany,
77
+ generateObject,
78
+ streamObject,
79
+ generateSpeech,
80
+ transcribe
81
+ } from 'ai';
82
+ import { z } from 'zod';
83
+ ```
84
+
85
+ ### テキスト生成
86
+
87
+ ```ts
88
+ import { aihubmix } from '@aihubmix/ai-sdk-provider';
89
+ import { generateText } from 'ai';
90
+
91
+ const { text } = await generateText({
92
+ model: aihubmix('o4-mini'),
93
+ prompt: '4人用のベジタリアンラザニアのレシピを書いてください。',
94
+ });
95
+ ```
96
+
97
+ ### Claudeモデル
98
+
99
+ ```ts
100
+ import { aihubmix } from '@aihubmix/ai-sdk-provider';
101
+ import { generateText } from 'ai';
102
+
103
+ const { text } = await generateText({
104
+ model: aihubmix('claude-3-7-sonnet-20250219'),
105
+ prompt: '簡単な言葉で量子コンピューティングを説明してください。',
106
+ });
107
+ ```
108
+
109
+ ### Geminiモデル
110
+
111
+ ```ts
112
+ import { aihubmix } from '@aihubmix/ai-sdk-provider';
113
+ import { generateText } from 'ai';
114
+
115
+ const { text } = await generateText({
116
+ model: aihubmix('gemini-2.5-flash'),
117
+ prompt: '数字のリストをソートするPythonスクリプトを作成してください。',
118
+ });
119
+ ```
120
+
121
+ ### 画像生成
122
+
123
+ ```ts
124
+ import { aihubmix } from '@aihubmix/ai-sdk-provider';
125
+ import { generateImage } from 'ai';
126
+
127
+ const { image } = await generateImage({
128
+ model: aihubmix.image('gpt-image-1'),
129
+ prompt: '山々の上に美しい夕日',
130
+ });
131
+ ```
132
+
133
+ ### 埋め込み
134
+
135
+ ```ts
136
+ import { aihubmix } from '@aihubmix/ai-sdk-provider';
137
+ import { embed } from 'ai';
138
+
139
+ const { embedding } = await embed({
140
+ model: aihubmix.embedding('text-embedding-ada-002'),
141
+ value: 'こんにちは、世界!',
142
+ });
143
+ ```
144
+
145
+ ### 転写
146
+
147
+ ```ts
148
+ import { aihubmix } from '@aihubmix/ai-sdk-provider';
149
+ import { transcribe } from 'ai';
150
+
151
+ const { text } = await transcribe({
152
+ model: aihubmix.transcription('whisper-1'),
153
+ audio: audioFile,
154
+ });
155
+ ```
156
+
157
+ ### ストリーミングテキスト
158
+
159
+ ```ts
160
+ import { aihubmix } from '@aihubmix/ai-sdk-provider';
161
+ import { streamText } from 'ai';
162
+
163
+ const result = streamText({
164
+ model: aihubmix('gpt-3.5-turbo'),
165
+ prompt: 'ロボットが絵を学ぶ短編小説を書いてください。',
166
+ maxOutputTokens: 256,
167
+ temperature: 0.3,
168
+ maxRetries: 3,
169
+ });
170
+
171
+ let fullText = '';
172
+ for await (const textPart of result.textStream) {
173
+ fullText += textPart;
174
+ process.stdout.write(textPart);
175
+ }
176
+
177
+ console.log('\n使用量:', await result.usage);
178
+ console.log('完了理由:', await result.finishReason);
179
+ ```
180
+
181
+ ### オブジェクト生成
182
+
183
+ ```ts
184
+ import { aihubmix } from '@aihubmix/ai-sdk-provider';
185
+ import { generateObject } from 'ai';
186
+ import { z } from 'zod';
187
+
188
+ const result = await generateObject({
189
+ model: aihubmix('gpt-4o-mini'),
190
+ schema: z.object({
191
+ recipe: z.object({
192
+ name: z.string(),
193
+ ingredients: z.array(
194
+ z.object({
195
+ name: z.string(),
196
+ amount: z.string(),
197
+ }),
198
+ ),
199
+ steps: z.array(z.string()),
200
+ }),
201
+ }),
202
+ prompt: 'ラザニアのレシピを生成してください。',
203
+ });
204
+
205
+ console.log(JSON.stringify(result.object.recipe, null, 2));
206
+ console.log('Token使用量:', result.usage);
207
+ console.log('完了理由:', result.finishReason);
208
+ ```
209
+
210
+ ### ストリーミングオブジェクト
211
+
212
+ ```ts
213
+ import { aihubmix } from '@aihubmix/ai-sdk-provider';
214
+ import { streamObject } from 'ai';
215
+ import { z } from 'zod';
216
+
217
+ const result = await streamObject({
218
+ model: aihubmix('gpt-4o-mini'),
219
+ schema: z.object({
220
+ recipe: z.object({
221
+ name: z.string(),
222
+ ingredients: z.array(
223
+ z.object({
224
+ name: z.string(),
225
+ amount: z.string(),
226
+ }),
227
+ ),
228
+ steps: z.array(z.string()),
229
+ }),
230
+ }),
231
+ prompt: 'ラザニアのレシピを生成してください。',
232
+ });
233
+
234
+ for await (const objectPart of result.partialObjectStream) {
235
+ console.log(objectPart);
236
+ }
237
+
238
+ console.log('Token使用量:', result.usage);
239
+ console.log('最終オブジェクト:', result.object);
240
+ ```
241
+
242
+ ### バッチ埋め込み
243
+
244
+ ```ts
245
+ import { aihubmix } from '@aihubmix/ai-sdk-provider';
246
+ import { embedMany } from 'ai';
247
+
248
+ const { embeddings, usage } = await embedMany({
249
+ model: aihubmix.embedding('text-embedding-3-small'),
250
+ values: [
251
+ 'ビーチでの晴れた日',
252
+ '街での雨の午後',
253
+ '山での雪の夜',
254
+ ],
255
+ });
256
+
257
+ console.log('埋め込み:', embeddings);
258
+ console.log('使用量:', usage);
259
+ ```
260
+
261
+ ### 音声合成
262
+
263
+ ```ts
264
+ import { aihubmix } from '@aihubmix/ai-sdk-provider';
265
+ import { generateSpeech } from 'ai';
266
+
267
+ const { audio } = await generateSpeech({
268
+ model: aihubmix.speech('tts-1'),
269
+ text: 'こんにちは、これは音声合成のテストです。',
270
+ });
271
+
272
+ // 音声ファイルを保存
273
+ await saveAudioFile(audio);
274
+ console.log('音声生成成功:', audio);
275
+ ```
276
+
277
+ ### ツール
278
+
279
+ Aihubmix providerはウェブ検索を含む様々なツールをサポートしています:
280
+
281
+ ```ts
282
+ import { aihubmix } from '@aihubmix/ai-sdk-provider';
283
+ import { generateText } from 'ai';
284
+
285
+ const { text } = await generateText({
286
+ model: aihubmix('gpt-4'),
287
+ prompt: 'AIの最新の進歩は何ですか?',
288
+ tools: {
289
+ webSearchPreview: aihubmix.tools.webSearchPreview({
290
+ searchContextSize: 'high',
291
+ }),
292
+ },
293
+ });
294
+ ```
295
+
296
+ ## 追加リソース
297
+
298
+ - [Aihubmix Provider リポジトリ](https://github.com/inferera/aihubmix)
299
+ - [Aihubmix ドキュメント](https://docs.aihubmix.com/en)
300
+ - [Aihubmix ダッシュボード](https://aihubmix.com)
301
+ - [Aihubmix ビジネス協力](mailto:business@aihubmix.com)
package/README.md CHANGED
@@ -1,16 +1,38 @@
1
1
  # AI SDK - Aihubmix Provider
2
2
 
3
+ <div align="center">
4
+ <a href="README.md">🇺🇸 English</a> |
5
+ <a href="README.zh.md">🇨🇳 中文</a> |
6
+ <a href="README.ja.md">🇯🇵 日本語</a>
7
+ </div>
8
+
3
9
  > **🎉 10% discount!**
4
- Added app-code; this way, requesting all models through ai-sdk offers a 10% discount.
10
+ Built-in app-code; using this method to request all models offers a 10% discount.
5
11
 
6
12
  **[Aihubmix Official Website](https://aihubmix.com/)** | **[Model Square](https://aihubmix.com/models)**
7
13
 
8
- The **[Aihubmix provider](https://ai-sdk.dev/providers/ai-sdk-providers/aihubmix)** for the [AI SDK](https://ai-sdk.dev/docs)
14
+ The **[Aihubmix provider](https://v5.ai-sdk.dev/providers/community-providers/aihubmix)** for the [AI SDK](https://ai-sdk.dev/docs)
9
15
  One Gateway, Infinite Models;one-stop request: OpenAI, Claude, Gemini, DeepSeek, Qwen, and over 500 AI models.
10
16
 
17
+
18
+ ## Supported Features
19
+
20
+ The Aihubmix provider supports the following AI features:
21
+
22
+ - **Text Generation**: Chat completion with various models
23
+ - **Streaming Text**: Real-time text streaming
24
+ - **Image Generation**: Create images from text prompts
25
+ - **Embeddings**: Single and batch text embeddings
26
+ - **Object Generation**: Structured data generation with schemas
27
+ - **Streaming Objects**: Real-time structured data streaming
28
+ - **Speech Synthesis**: Text-to-speech conversion
29
+ - **Transcription**: Speech-to-text conversion
30
+ - **Tools**: Web search and other tools
31
+
32
+
11
33
  ## Setup
12
34
 
13
- The Aihubmix provider is available in the `@aihubmix/ai-sdk-provider` module. You can install it with
35
+ The Aihubmix provider is available in the `@aihubmix/ai-sdk-provider` module. You can install it with [@aihubmix/ai-sdk-provider](https://www.npmjs.com/package/@aihubmix/ai-sdk-provider)
14
36
 
15
37
  ```bash
16
38
  npm i @aihubmix/ai-sdk-provider
@@ -42,32 +64,27 @@ const aihubmix = createAihubmix({
42
64
  });
43
65
  ```
44
66
 
45
- ## Supported Models
46
-
47
- ### OpenAI-Compatible Models
67
+ ## Usage
48
68
 
49
- - GPT-4, GPT-3.5, and other OpenAI models
50
- - Image generation models
51
- - Embedding models
52
- - Transcription models
53
- - Speech synthesis models
69
+ First, import the necessary functions:
54
70
 
55
- ### Anthropic Claude Models
56
-
57
- - Claude-3 models (claude-3-opus, claude-3-sonnet, claude-3-haiku)
58
- - Claude-2 models
59
-
60
- ### Google Gemini Models
61
-
62
- - Gemini Pro models
63
- - Gemini Flash models
64
- - Imagen models
65
-
66
- ### Other Models => [Model Square](https://aihubmix.com/models)
67
-
68
- ## Examples
71
+ ```ts
72
+ import { createAihubmix } from '@aihubmix/ai-sdk-provider';
73
+ import {
74
+ generateText,
75
+ streamText,
76
+ generateImage,
77
+ embed,
78
+ embedMany,
79
+ generateObject,
80
+ streamObject,
81
+ generateSpeech,
82
+ transcribe
83
+ } from 'ai';
84
+ import { z } from 'zod';
85
+ ```
69
86
 
70
- ### Chat Completion
87
+ ### Generate Text
71
88
 
72
89
  ```ts
73
90
  import { aihubmix } from '@aihubmix/ai-sdk-provider';
@@ -139,7 +156,127 @@ const { text } = await transcribe({
139
156
  });
140
157
  ```
141
158
 
142
- ## Tools
159
+ ### Stream Text
160
+
161
+ ```ts
162
+ import { aihubmix } from '@aihubmix/ai-sdk-provider';
163
+ import { streamText } from 'ai';
164
+
165
+ const result = streamText({
166
+ model: aihubmix('gpt-3.5-turbo'),
167
+ prompt: 'Write a short story about a robot learning to paint.',
168
+ maxOutputTokens: 256,
169
+ temperature: 0.3,
170
+ maxRetries: 3,
171
+ });
172
+
173
+ let fullText = '';
174
+ for await (const textPart of result.textStream) {
175
+ fullText += textPart;
176
+ process.stdout.write(textPart);
177
+ }
178
+
179
+ console.log('\nUsage:', await result.usage);
180
+ console.log('Finish reason:', await result.finishReason);
181
+ ```
182
+
183
+ ### Generate Object
184
+
185
+ ```ts
186
+ import { aihubmix } from '@aihubmix/ai-sdk-provider';
187
+ import { generateObject } from 'ai';
188
+ import { z } from 'zod';
189
+
190
+ const result = await generateObject({
191
+ model: aihubmix('gpt-4o-mini'),
192
+ schema: z.object({
193
+ recipe: z.object({
194
+ name: z.string(),
195
+ ingredients: z.array(
196
+ z.object({
197
+ name: z.string(),
198
+ amount: z.string(),
199
+ }),
200
+ ),
201
+ steps: z.array(z.string()),
202
+ }),
203
+ }),
204
+ prompt: 'Generate a lasagna recipe.',
205
+ });
206
+
207
+ console.log(JSON.stringify(result.object.recipe, null, 2));
208
+ console.log('Token usage:', result.usage);
209
+ console.log('Finish reason:', result.finishReason);
210
+ ```
211
+
212
+ ### Stream Object
213
+
214
+ ```ts
215
+ import { aihubmix } from '@aihubmix/ai-sdk-provider';
216
+ import { streamObject } from 'ai';
217
+ import { z } from 'zod';
218
+
219
+ const result = await streamObject({
220
+ model: aihubmix('gpt-4o-mini'),
221
+ schema: z.object({
222
+ recipe: z.object({
223
+ name: z.string(),
224
+ ingredients: z.array(
225
+ z.object({
226
+ name: z.string(),
227
+ amount: z.string(),
228
+ }),
229
+ ),
230
+ steps: z.array(z.string()),
231
+ }),
232
+ }),
233
+ prompt: 'Generate a lasagna recipe.',
234
+ });
235
+
236
+ for await (const objectPart of result.partialObjectStream) {
237
+ console.log(objectPart);
238
+ }
239
+
240
+ console.log('Token usage:', result.usage);
241
+ console.log('Final object:', result.object);
242
+ ```
243
+
244
+ ### Embed Many
245
+
246
+ ```ts
247
+ import { aihubmix } from '@aihubmix/ai-sdk-provider';
248
+ import { embedMany } from 'ai';
249
+
250
+ const { embeddings, usage } = await embedMany({
251
+ model: aihubmix.embedding('text-embedding-3-small'),
252
+ values: [
253
+ 'sunny day at the beach',
254
+ 'rainy afternoon in the city',
255
+ 'snowy night in the mountains',
256
+ ],
257
+ });
258
+
259
+ console.log('Embeddings:', embeddings);
260
+ console.log('Usage:', usage);
261
+ ```
262
+
263
+ ### Speech Synthesis
264
+
265
+ ```ts
266
+ import { aihubmix } from '@aihubmix/ai-sdk-provider';
267
+ import { generateSpeech } from 'ai';
268
+
269
+ const { audio } = await generateSpeech({
270
+ model: aihubmix.speech('tts-1'),
271
+ text: 'Hello, this is a test for speech synthesis.',
272
+ });
273
+
274
+ // Save the audio file
275
+ await saveAudioFile(audio);
276
+ console.log('Audio generated successfully:', audio);
277
+ ```
278
+
279
+ ### Tools
143
280
 
144
281
  The Aihubmix provider supports various tools including web search:
145
282
 
@@ -158,6 +295,10 @@ const { text } = await generateText({
158
295
  });
159
296
  ```
160
297
 
161
- ## Documentation
162
298
 
163
- Please check out the **[Aihubmix provider documentation](https://ai-sdk.dev/providers/ai-sdk-providers/aihubmix)** for more information.
299
+ ## Additional Resources
300
+
301
+ - [Aihubmix Provider Repository](https://github.com/inferera/aihubmix)
302
+ - [Aihubmix Documentation](https://docs.aihubmix.com/en)
303
+ - [Aihubmix Dashboard](https://aihubmix.com)
304
+ - [Aihubmix Cooperation](mailto:business@aihubmix.com)