@ai-sdk/minimax 0.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/LICENSE +13 -0
- package/README.md +62 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/package.json +73 -1
- package/src/index.ts +12 -0
- package/src/minimax-chat-options.ts +25 -0
- package/src/minimax-provider.ts +110 -0
- package/src/version.ts +6 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# @ai-sdk/minimax
|
|
2
|
+
|
|
3
|
+
## 3.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 5b5335f: Add MiniMax provider with language model support for the MiniMax-M model series.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [d8210b6]
|
|
12
|
+
- Updated dependencies [b192878]
|
|
13
|
+
- @ai-sdk/provider-utils@5.0.16
|
|
14
|
+
- @ai-sdk/anthropic@4.0.25
|
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2023 Vercel, Inc.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# AI SDK - MiniMax Provider
|
|
2
|
+
|
|
3
|
+
The **[MiniMax provider](https://ai-sdk.dev/providers/ai-sdk-providers/minimax)** for the [AI SDK](https://ai-sdk.dev/docs) contains language model support for the [MiniMax](https://www.minimax.io/) platform, including the MiniMax-M model series.
|
|
4
|
+
|
|
5
|
+
> **Deploying to Vercel?** With Vercel's AI Gateway you can access MiniMax (and hundreds of models from other providers) — no additional packages, API keys, or extra cost. [Get started with AI Gateway](https://vercel.com/ai-gateway).
|
|
6
|
+
|
|
7
|
+
## Setup
|
|
8
|
+
|
|
9
|
+
The MiniMax provider is available in the `@ai-sdk/minimax` module. You can install it with
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm i @ai-sdk/minimax
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Skill for Coding Agents
|
|
16
|
+
|
|
17
|
+
If you use coding agents such as Claude Code or Cursor, we highly recommend adding the AI SDK skill to your repository:
|
|
18
|
+
|
|
19
|
+
```shell
|
|
20
|
+
npx skills add vercel/ai
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Provider Instance
|
|
24
|
+
|
|
25
|
+
You can import the default provider instance `minimax` from `@ai-sdk/minimax`:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { minimax } from '@ai-sdk/minimax';
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Language Model Example
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { minimax } from '@ai-sdk/minimax';
|
|
35
|
+
import { generateText } from 'ai';
|
|
36
|
+
|
|
37
|
+
const { text } = await generateText({
|
|
38
|
+
model: minimax('minimax-m3'),
|
|
39
|
+
prompt: 'Write a JavaScript function that sorts a list:',
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Thinking Mode Example
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { minimax } from '@ai-sdk/minimax';
|
|
47
|
+
import { generateText } from 'ai';
|
|
48
|
+
|
|
49
|
+
const { text } = await generateText({
|
|
50
|
+
model: minimax('minimax-m3'),
|
|
51
|
+
prompt: 'Solve this problem step by step: What is 15% of 240?',
|
|
52
|
+
providerOptions: {
|
|
53
|
+
minimax: {
|
|
54
|
+
thinking: { type: 'adaptive' },
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Documentation
|
|
61
|
+
|
|
62
|
+
Please check out the **[MiniMax provider](https://ai-sdk.dev/providers/ai-sdk-providers/minimax)** for more information.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ProviderV4, LanguageModelV4 } from '@ai-sdk/provider';
|
|
2
|
+
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
+
import { z } from 'zod/v4';
|
|
4
|
+
|
|
5
|
+
type MiniMaxChatModelId = 'minimax-m3' | 'minimax-m2.7' | 'minimax-m2.7-highspeed' | 'minimax-m2.5' | 'minimax-m2.5-highspeed' | 'minimax-m2.1' | 'minimax-m2.1-highspeed' | 'minimax-m2' | (string & {});
|
|
6
|
+
declare const minimaxLanguageModelOptions: z.ZodObject<{
|
|
7
|
+
thinking: z.ZodOptional<z.ZodObject<{
|
|
8
|
+
type: z.ZodEnum<{
|
|
9
|
+
adaptive: "adaptive";
|
|
10
|
+
disabled: "disabled";
|
|
11
|
+
}>;
|
|
12
|
+
}, z.core.$strip>>;
|
|
13
|
+
}, z.core.$strip>;
|
|
14
|
+
type MiniMaxLanguageModelOptions = z.infer<typeof minimaxLanguageModelOptions>;
|
|
15
|
+
|
|
16
|
+
interface MiniMaxProviderSettings {
|
|
17
|
+
/**
|
|
18
|
+
* MiniMax API key. Default value is taken from the `MINIMAX_API_KEY`
|
|
19
|
+
* environment variable.
|
|
20
|
+
*/
|
|
21
|
+
apiKey?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Base URL for the API calls. Defaults to MiniMax's Anthropic-compatible
|
|
24
|
+
* endpoint (`https://api.minimax.io/anthropic/v1`).
|
|
25
|
+
*/
|
|
26
|
+
baseURL?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Custom headers to include in the requests.
|
|
29
|
+
*/
|
|
30
|
+
headers?: Record<string, string>;
|
|
31
|
+
/**
|
|
32
|
+
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
33
|
+
* or to provide a custom fetch implementation for e.g. testing.
|
|
34
|
+
*/
|
|
35
|
+
fetch?: FetchFunction;
|
|
36
|
+
}
|
|
37
|
+
interface MiniMaxProvider extends ProviderV4 {
|
|
38
|
+
/**
|
|
39
|
+
* Creates a MiniMax model for text generation.
|
|
40
|
+
*/
|
|
41
|
+
(modelId: MiniMaxChatModelId): LanguageModelV4;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a MiniMax language model for text generation.
|
|
44
|
+
*/
|
|
45
|
+
languageModel(modelId: MiniMaxChatModelId): LanguageModelV4;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a MiniMax chat model for text generation.
|
|
48
|
+
*/
|
|
49
|
+
chat(modelId: MiniMaxChatModelId): LanguageModelV4;
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated Use `embeddingModel` instead.
|
|
52
|
+
*/
|
|
53
|
+
textEmbeddingModel(modelId: string): never;
|
|
54
|
+
}
|
|
55
|
+
declare function createMiniMax(options?: MiniMaxProviderSettings): MiniMaxProvider;
|
|
56
|
+
declare const minimax: MiniMaxProvider;
|
|
57
|
+
|
|
58
|
+
declare const VERSION: string;
|
|
59
|
+
|
|
60
|
+
export { type MiniMaxChatModelId, type MiniMaxLanguageModelOptions, type MiniMaxProvider, type MiniMaxLanguageModelOptions as MiniMaxProviderOptions, type MiniMaxProviderSettings, VERSION, createMiniMax, minimax };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// src/minimax-provider.ts
|
|
2
|
+
import {
|
|
3
|
+
NoSuchModelError
|
|
4
|
+
} from "@ai-sdk/provider";
|
|
5
|
+
import {
|
|
6
|
+
generateId,
|
|
7
|
+
loadApiKey,
|
|
8
|
+
withoutTrailingSlash,
|
|
9
|
+
withUserAgentSuffix
|
|
10
|
+
} from "@ai-sdk/provider-utils";
|
|
11
|
+
import { AnthropicLanguageModel } from "@ai-sdk/anthropic/internal";
|
|
12
|
+
|
|
13
|
+
// src/version.ts
|
|
14
|
+
var VERSION = true ? "3.0.0" : "0.0.0-test";
|
|
15
|
+
|
|
16
|
+
// src/minimax-provider.ts
|
|
17
|
+
var defaultBaseURL = "https://api.minimax.io/anthropic/v1";
|
|
18
|
+
function createMiniMax(options = {}) {
|
|
19
|
+
var _a, _b;
|
|
20
|
+
const baseURL = (_b = withoutTrailingSlash((_a = options.baseURL) != null ? _a : defaultBaseURL)) != null ? _b : defaultBaseURL;
|
|
21
|
+
const getHeaders = () => withUserAgentSuffix(
|
|
22
|
+
{
|
|
23
|
+
"anthropic-version": "2023-06-01",
|
|
24
|
+
"x-api-key": loadApiKey({
|
|
25
|
+
apiKey: options.apiKey,
|
|
26
|
+
environmentVariableName: "MINIMAX_API_KEY",
|
|
27
|
+
description: "MiniMax API key"
|
|
28
|
+
}),
|
|
29
|
+
...options.headers
|
|
30
|
+
},
|
|
31
|
+
`ai-sdk/minimax/${VERSION}`
|
|
32
|
+
);
|
|
33
|
+
const createChatModel = (modelId) => new AnthropicLanguageModel(modelId, {
|
|
34
|
+
provider: "minimax.messages",
|
|
35
|
+
baseURL,
|
|
36
|
+
headers: getHeaders,
|
|
37
|
+
fetch: options.fetch,
|
|
38
|
+
generateId,
|
|
39
|
+
supportedUrls: () => ({})
|
|
40
|
+
});
|
|
41
|
+
const provider = (modelId) => createChatModel(modelId);
|
|
42
|
+
provider.specificationVersion = "v4";
|
|
43
|
+
provider.languageModel = createChatModel;
|
|
44
|
+
provider.chat = createChatModel;
|
|
45
|
+
provider.embeddingModel = (modelId) => {
|
|
46
|
+
throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
|
|
47
|
+
};
|
|
48
|
+
provider.textEmbeddingModel = provider.embeddingModel;
|
|
49
|
+
provider.imageModel = (modelId) => {
|
|
50
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
51
|
+
};
|
|
52
|
+
return provider;
|
|
53
|
+
}
|
|
54
|
+
var minimax = createMiniMax();
|
|
55
|
+
export {
|
|
56
|
+
VERSION,
|
|
57
|
+
createMiniMax,
|
|
58
|
+
minimax
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/minimax-provider.ts","../src/version.ts"],"sourcesContent":["import {\n NoSuchModelError,\n type LanguageModelV4,\n type ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n generateId,\n loadApiKey,\n withoutTrailingSlash,\n withUserAgentSuffix,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport { AnthropicLanguageModel } from '@ai-sdk/anthropic/internal';\nimport type { MiniMaxChatModelId } from './minimax-chat-options';\nimport { VERSION } from './version';\n\nexport interface MiniMaxProviderSettings {\n /**\n * MiniMax API key. Default value is taken from the `MINIMAX_API_KEY`\n * environment variable.\n */\n apiKey?: string;\n /**\n * Base URL for the API calls. Defaults to MiniMax's Anthropic-compatible\n * endpoint (`https://api.minimax.io/anthropic/v1`).\n */\n baseURL?: string;\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string>;\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface MiniMaxProvider extends ProviderV4 {\n /**\n * Creates a MiniMax model for text generation.\n */\n (modelId: MiniMaxChatModelId): LanguageModelV4;\n\n /**\n * Creates a MiniMax language model for text generation.\n */\n languageModel(modelId: MiniMaxChatModelId): LanguageModelV4;\n\n /**\n * Creates a MiniMax chat model for text generation.\n */\n chat(modelId: MiniMaxChatModelId): LanguageModelV4;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nconst defaultBaseURL = 'https://api.minimax.io/anthropic/v1';\n\nexport function createMiniMax(\n options: MiniMaxProviderSettings = {},\n): MiniMaxProvider {\n const baseURL =\n withoutTrailingSlash(options.baseURL ?? defaultBaseURL) ?? defaultBaseURL;\n\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n 'anthropic-version': '2023-06-01',\n 'x-api-key': loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'MINIMAX_API_KEY',\n description: 'MiniMax API key',\n }),\n ...options.headers,\n },\n `ai-sdk/minimax/${VERSION}`,\n );\n\n const createChatModel = (modelId: MiniMaxChatModelId) =>\n new AnthropicLanguageModel(modelId, {\n provider: 'minimax.messages',\n baseURL,\n headers: getHeaders,\n fetch: options.fetch,\n generateId,\n supportedUrls: () => ({}),\n });\n\n const provider = (modelId: MiniMaxChatModelId) => createChatModel(modelId);\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = createChatModel;\n provider.chat = createChatModel;\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n return provider;\n}\n\nexport const minimax = createMiniMax();\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,OAGK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,8BAA8B;;;ACVhC,IAAM,UACX,OACI,UACA;;;ADuDN,IAAM,iBAAiB;AAEhB,SAAS,cACd,UAAmC,CAAC,GACnB;AAhEnB;AAiEE,QAAM,WACJ,2BAAqB,aAAQ,YAAR,YAAmB,cAAc,MAAtD,YAA2D;AAE7D,QAAM,aAAa,MACjB;AAAA,IACE;AAAA,MACE,qBAAqB;AAAA,MACrB,aAAa,WAAW;AAAA,QACtB,QAAQ,QAAQ;AAAA,QAChB,yBAAyB;AAAA,QACzB,aAAa;AAAA,MACf,CAAC;AAAA,MACD,GAAG,QAAQ;AAAA,IACb;AAAA,IACA,kBAAkB,OAAO;AAAA,EAC3B;AAEF,QAAM,kBAAkB,CAAC,YACvB,IAAI,uBAAuB,SAAS;AAAA,IAClC,UAAU;AAAA,IACV;AAAA,IACA,SAAS;AAAA,IACT,OAAO,QAAQ;AAAA,IACf;AAAA,IACA,eAAe,OAAO,CAAC;AAAA,EACzB,CAAC;AAEH,QAAM,WAAW,CAAC,YAAgC,gBAAgB,OAAO;AAEzE,WAAS,uBAAuB;AAChC,WAAS,gBAAgB;AACzB,WAAS,OAAO;AAEhB,WAAS,iBAAiB,CAAC,YAAoB;AAC7C,UAAM,IAAI,iBAAiB,EAAE,SAAS,WAAW,iBAAiB,CAAC;AAAA,EACrE;AACA,WAAS,qBAAqB,SAAS;AACvC,WAAS,aAAa,CAAC,YAAoB;AACzC,UAAM,IAAI,iBAAiB,EAAE,SAAS,WAAW,aAAa,CAAC;AAAA,EACjE;AAEA,SAAO;AACT;AAEO,IAAM,UAAU,cAAc;","names":[]}
|
package/package.json
CHANGED
|
@@ -1 +1,73 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"name": "@ai-sdk/minimax",
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/**/*",
|
|
11
|
+
"src",
|
|
12
|
+
"!src/**/*.test.ts",
|
|
13
|
+
"!src/**/*.test-d.ts",
|
|
14
|
+
"!src/**/__snapshots__",
|
|
15
|
+
"!src/**/__fixtures__",
|
|
16
|
+
"CHANGELOG.md",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"exports": {
|
|
20
|
+
"./package.json": "./package.json",
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@ai-sdk/anthropic": "4.0.25",
|
|
29
|
+
"@ai-sdk/provider": "4.0.4",
|
|
30
|
+
"@ai-sdk/provider-utils": "5.0.16"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "22.19.19",
|
|
34
|
+
"tsup": "^8.5.1",
|
|
35
|
+
"typescript": "5.8.3",
|
|
36
|
+
"zod": "3.25.76",
|
|
37
|
+
"@ai-sdk/test-server": "2.0.1",
|
|
38
|
+
"@vercel/ai-tsconfig": "0.0.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"zod": "^3.25.76 || ^4.1.8"
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=22"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public",
|
|
48
|
+
"provenance": true
|
|
49
|
+
},
|
|
50
|
+
"homepage": "https://ai-sdk.dev/docs",
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "https://github.com/vercel/ai",
|
|
54
|
+
"directory": "packages/minimax"
|
|
55
|
+
},
|
|
56
|
+
"bugs": {
|
|
57
|
+
"url": "https://github.com/vercel/ai/issues"
|
|
58
|
+
},
|
|
59
|
+
"keywords": [
|
|
60
|
+
"ai"
|
|
61
|
+
],
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "pnpm clean && tsup --tsconfig tsconfig.build.json",
|
|
64
|
+
"build:watch": "pnpm clean && tsup --watch",
|
|
65
|
+
"clean": "del-cli dist *.tsbuildinfo",
|
|
66
|
+
"type-check": "tsc --build",
|
|
67
|
+
"test": "pnpm test:node && pnpm test:edge",
|
|
68
|
+
"test:update": "pnpm test:node -u",
|
|
69
|
+
"test:watch": "vitest --config vitest.node.config.js",
|
|
70
|
+
"test:edge": "vitest --config vitest.edge.config.js --run",
|
|
71
|
+
"test:node": "vitest --config vitest.node.config.js --run"
|
|
72
|
+
}
|
|
73
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { createMiniMax, minimax } from './minimax-provider';
|
|
2
|
+
export type {
|
|
3
|
+
MiniMaxProvider,
|
|
4
|
+
MiniMaxProviderSettings,
|
|
5
|
+
} from './minimax-provider';
|
|
6
|
+
export type {
|
|
7
|
+
MiniMaxChatModelId,
|
|
8
|
+
MiniMaxLanguageModelOptions,
|
|
9
|
+
/** @deprecated Use `MiniMaxLanguageModelOptions` instead. */
|
|
10
|
+
MiniMaxLanguageModelOptions as MiniMaxProviderOptions,
|
|
11
|
+
} from './minimax-chat-options';
|
|
12
|
+
export { VERSION } from './version';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from 'zod/v4';
|
|
2
|
+
|
|
3
|
+
// https://platform.minimax.io/docs/api-reference/text-chat-anthropic
|
|
4
|
+
export type MiniMaxChatModelId =
|
|
5
|
+
| 'minimax-m3'
|
|
6
|
+
| 'minimax-m2.7'
|
|
7
|
+
| 'minimax-m2.7-highspeed'
|
|
8
|
+
| 'minimax-m2.5'
|
|
9
|
+
| 'minimax-m2.5-highspeed'
|
|
10
|
+
| 'minimax-m2.1'
|
|
11
|
+
| 'minimax-m2.1-highspeed'
|
|
12
|
+
| 'minimax-m2'
|
|
13
|
+
| (string & {});
|
|
14
|
+
|
|
15
|
+
export const minimaxLanguageModelOptions = z.object({
|
|
16
|
+
thinking: z
|
|
17
|
+
.object({
|
|
18
|
+
type: z.enum(['adaptive', 'disabled']),
|
|
19
|
+
})
|
|
20
|
+
.optional(),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export type MiniMaxLanguageModelOptions = z.infer<
|
|
24
|
+
typeof minimaxLanguageModelOptions
|
|
25
|
+
>;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NoSuchModelError,
|
|
3
|
+
type LanguageModelV4,
|
|
4
|
+
type ProviderV4,
|
|
5
|
+
} from '@ai-sdk/provider';
|
|
6
|
+
import {
|
|
7
|
+
generateId,
|
|
8
|
+
loadApiKey,
|
|
9
|
+
withoutTrailingSlash,
|
|
10
|
+
withUserAgentSuffix,
|
|
11
|
+
type FetchFunction,
|
|
12
|
+
} from '@ai-sdk/provider-utils';
|
|
13
|
+
import { AnthropicLanguageModel } from '@ai-sdk/anthropic/internal';
|
|
14
|
+
import type { MiniMaxChatModelId } from './minimax-chat-options';
|
|
15
|
+
import { VERSION } from './version';
|
|
16
|
+
|
|
17
|
+
export interface MiniMaxProviderSettings {
|
|
18
|
+
/**
|
|
19
|
+
* MiniMax API key. Default value is taken from the `MINIMAX_API_KEY`
|
|
20
|
+
* environment variable.
|
|
21
|
+
*/
|
|
22
|
+
apiKey?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Base URL for the API calls. Defaults to MiniMax's Anthropic-compatible
|
|
25
|
+
* endpoint (`https://api.minimax.io/anthropic/v1`).
|
|
26
|
+
*/
|
|
27
|
+
baseURL?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Custom headers to include in the requests.
|
|
30
|
+
*/
|
|
31
|
+
headers?: Record<string, string>;
|
|
32
|
+
/**
|
|
33
|
+
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
34
|
+
* or to provide a custom fetch implementation for e.g. testing.
|
|
35
|
+
*/
|
|
36
|
+
fetch?: FetchFunction;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface MiniMaxProvider extends ProviderV4 {
|
|
40
|
+
/**
|
|
41
|
+
* Creates a MiniMax model for text generation.
|
|
42
|
+
*/
|
|
43
|
+
(modelId: MiniMaxChatModelId): LanguageModelV4;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Creates a MiniMax language model for text generation.
|
|
47
|
+
*/
|
|
48
|
+
languageModel(modelId: MiniMaxChatModelId): LanguageModelV4;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Creates a MiniMax chat model for text generation.
|
|
52
|
+
*/
|
|
53
|
+
chat(modelId: MiniMaxChatModelId): LanguageModelV4;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @deprecated Use `embeddingModel` instead.
|
|
57
|
+
*/
|
|
58
|
+
textEmbeddingModel(modelId: string): never;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const defaultBaseURL = 'https://api.minimax.io/anthropic/v1';
|
|
62
|
+
|
|
63
|
+
export function createMiniMax(
|
|
64
|
+
options: MiniMaxProviderSettings = {},
|
|
65
|
+
): MiniMaxProvider {
|
|
66
|
+
const baseURL =
|
|
67
|
+
withoutTrailingSlash(options.baseURL ?? defaultBaseURL) ?? defaultBaseURL;
|
|
68
|
+
|
|
69
|
+
const getHeaders = () =>
|
|
70
|
+
withUserAgentSuffix(
|
|
71
|
+
{
|
|
72
|
+
'anthropic-version': '2023-06-01',
|
|
73
|
+
'x-api-key': loadApiKey({
|
|
74
|
+
apiKey: options.apiKey,
|
|
75
|
+
environmentVariableName: 'MINIMAX_API_KEY',
|
|
76
|
+
description: 'MiniMax API key',
|
|
77
|
+
}),
|
|
78
|
+
...options.headers,
|
|
79
|
+
},
|
|
80
|
+
`ai-sdk/minimax/${VERSION}`,
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const createChatModel = (modelId: MiniMaxChatModelId) =>
|
|
84
|
+
new AnthropicLanguageModel(modelId, {
|
|
85
|
+
provider: 'minimax.messages',
|
|
86
|
+
baseURL,
|
|
87
|
+
headers: getHeaders,
|
|
88
|
+
fetch: options.fetch,
|
|
89
|
+
generateId,
|
|
90
|
+
supportedUrls: () => ({}),
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const provider = (modelId: MiniMaxChatModelId) => createChatModel(modelId);
|
|
94
|
+
|
|
95
|
+
provider.specificationVersion = 'v4' as const;
|
|
96
|
+
provider.languageModel = createChatModel;
|
|
97
|
+
provider.chat = createChatModel;
|
|
98
|
+
|
|
99
|
+
provider.embeddingModel = (modelId: string) => {
|
|
100
|
+
throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });
|
|
101
|
+
};
|
|
102
|
+
provider.textEmbeddingModel = provider.embeddingModel;
|
|
103
|
+
provider.imageModel = (modelId: string) => {
|
|
104
|
+
throw new NoSuchModelError({ modelId, modelType: 'imageModel' });
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
return provider;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export const minimax = createMiniMax();
|