@ai-sdk/openai-compatible 3.0.0-beta.0 → 3.0.0-beta.10
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 +84 -8
- package/dist/index.d.mts +27 -27
- package/dist/index.d.ts +27 -27
- package/dist/index.js +12 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -8
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +10 -10
- package/dist/internal/index.d.ts +10 -10
- package/dist/internal/index.js +3 -3
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -5
- package/src/chat/convert-openai-compatible-chat-usage.ts +2 -2
- package/src/chat/convert-to-openai-compatible-chat-messages.ts +4 -4
- package/src/chat/map-openai-compatible-finish-reason.ts +2 -2
- package/src/chat/openai-compatible-api-types.ts +2 -4
- package/src/chat/openai-compatible-chat-language-model.ts +30 -24
- package/src/chat/openai-compatible-metadata-extractor.ts +3 -3
- package/src/chat/openai-compatible-prepare-tools.ts +6 -6
- package/src/completion/convert-openai-compatible-completion-usage.ts +2 -2
- package/src/completion/convert-to-openai-compatible-completion-prompt.ts +2 -2
- package/src/completion/map-openai-compatible-finish-reason.ts +2 -2
- package/src/completion/openai-compatible-completion-language-model.ts +20 -22
- package/src/embedding/openai-compatible-embedding-model.ts +7 -7
- package/src/image/openai-compatible-image-model.ts +11 -11
- package/src/openai-compatible-provider.ts +13 -13
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
LanguageModelV4CallOptions,
|
|
3
|
+
SharedV4Warning,
|
|
4
4
|
UnsupportedFunctionalityError,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
|
|
@@ -8,8 +8,8 @@ export function prepareTools({
|
|
|
8
8
|
tools,
|
|
9
9
|
toolChoice,
|
|
10
10
|
}: {
|
|
11
|
-
tools:
|
|
12
|
-
toolChoice?:
|
|
11
|
+
tools: LanguageModelV4CallOptions['tools'];
|
|
12
|
+
toolChoice?: LanguageModelV4CallOptions['toolChoice'];
|
|
13
13
|
}): {
|
|
14
14
|
tools:
|
|
15
15
|
| undefined
|
|
@@ -28,12 +28,12 @@ export function prepareTools({
|
|
|
28
28
|
| 'none'
|
|
29
29
|
| 'required'
|
|
30
30
|
| undefined;
|
|
31
|
-
toolWarnings:
|
|
31
|
+
toolWarnings: SharedV4Warning[];
|
|
32
32
|
} {
|
|
33
33
|
// when the tools array is empty, change it to undefined to prevent errors:
|
|
34
34
|
tools = tools?.length ? tools : undefined;
|
|
35
35
|
|
|
36
|
-
const toolWarnings:
|
|
36
|
+
const toolWarnings: SharedV4Warning[] = [];
|
|
37
37
|
|
|
38
38
|
if (tools == null) {
|
|
39
39
|
return { tools: undefined, toolChoice: undefined, toolWarnings };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LanguageModelV4Usage } from '@ai-sdk/provider';
|
|
2
2
|
|
|
3
3
|
export function convertOpenAICompatibleCompletionUsage(
|
|
4
4
|
usage:
|
|
@@ -8,7 +8,7 @@ export function convertOpenAICompatibleCompletionUsage(
|
|
|
8
8
|
}
|
|
9
9
|
| undefined
|
|
10
10
|
| null,
|
|
11
|
-
):
|
|
11
|
+
): LanguageModelV4Usage {
|
|
12
12
|
if (usage == null) {
|
|
13
13
|
return {
|
|
14
14
|
inputTokens: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
InvalidPromptError,
|
|
3
|
-
|
|
3
|
+
LanguageModelV4Prompt,
|
|
4
4
|
UnsupportedFunctionalityError,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
|
|
@@ -9,7 +9,7 @@ export function convertToOpenAICompatibleCompletionPrompt({
|
|
|
9
9
|
user = 'user',
|
|
10
10
|
assistant = 'assistant',
|
|
11
11
|
}: {
|
|
12
|
-
prompt:
|
|
12
|
+
prompt: LanguageModelV4Prompt;
|
|
13
13
|
user?: string;
|
|
14
14
|
assistant?: string;
|
|
15
15
|
}): {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LanguageModelV4FinishReason } from '@ai-sdk/provider';
|
|
2
2
|
|
|
3
3
|
export function mapOpenAICompatibleFinishReason(
|
|
4
4
|
finishReason: string | null | undefined,
|
|
5
|
-
):
|
|
5
|
+
): LanguageModelV4FinishReason['unified'] {
|
|
6
6
|
switch (finishReason) {
|
|
7
7
|
case 'stop':
|
|
8
8
|
return 'stop';
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
APICallError,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
LanguageModelV4,
|
|
4
|
+
LanguageModelV4CallOptions,
|
|
5
|
+
LanguageModelV4Content,
|
|
6
|
+
LanguageModelV4FinishReason,
|
|
7
|
+
LanguageModelV4GenerateResult,
|
|
8
|
+
LanguageModelV4StreamPart,
|
|
9
|
+
LanguageModelV4StreamResult,
|
|
10
|
+
SharedV4Warning,
|
|
11
11
|
} from '@ai-sdk/provider';
|
|
12
12
|
import {
|
|
13
13
|
combineHeaders,
|
|
@@ -45,13 +45,11 @@ type OpenAICompatibleCompletionConfig = {
|
|
|
45
45
|
/**
|
|
46
46
|
* The supported URLs for the model.
|
|
47
47
|
*/
|
|
48
|
-
supportedUrls?: () =>
|
|
48
|
+
supportedUrls?: () => LanguageModelV4['supportedUrls'];
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
export class OpenAICompatibleCompletionLanguageModel
|
|
52
|
-
|
|
53
|
-
{
|
|
54
|
-
readonly specificationVersion = 'v3';
|
|
51
|
+
export class OpenAICompatibleCompletionLanguageModel implements LanguageModelV4 {
|
|
52
|
+
readonly specificationVersion = 'v4';
|
|
55
53
|
|
|
56
54
|
readonly modelId: OpenAICompatibleCompletionModelId;
|
|
57
55
|
private readonly config: OpenAICompatibleCompletionConfig;
|
|
@@ -100,8 +98,8 @@ export class OpenAICompatibleCompletionLanguageModel
|
|
|
100
98
|
providerOptions,
|
|
101
99
|
tools,
|
|
102
100
|
toolChoice,
|
|
103
|
-
}:
|
|
104
|
-
const warnings:
|
|
101
|
+
}: LanguageModelV4CallOptions) {
|
|
102
|
+
const warnings: SharedV4Warning[] = [];
|
|
105
103
|
|
|
106
104
|
// Parse provider options
|
|
107
105
|
const completionOptions =
|
|
@@ -167,8 +165,8 @@ export class OpenAICompatibleCompletionLanguageModel
|
|
|
167
165
|
}
|
|
168
166
|
|
|
169
167
|
async doGenerate(
|
|
170
|
-
options:
|
|
171
|
-
): Promise<
|
|
168
|
+
options: LanguageModelV4CallOptions,
|
|
169
|
+
): Promise<LanguageModelV4GenerateResult> {
|
|
172
170
|
const { args, warnings } = await this.getArgs(options);
|
|
173
171
|
|
|
174
172
|
const {
|
|
@@ -191,7 +189,7 @@ export class OpenAICompatibleCompletionLanguageModel
|
|
|
191
189
|
});
|
|
192
190
|
|
|
193
191
|
const choice = response.choices[0];
|
|
194
|
-
const content: Array<
|
|
192
|
+
const content: Array<LanguageModelV4Content> = [];
|
|
195
193
|
|
|
196
194
|
// text content:
|
|
197
195
|
if (choice.text != null && choice.text.length > 0) {
|
|
@@ -216,8 +214,8 @@ export class OpenAICompatibleCompletionLanguageModel
|
|
|
216
214
|
}
|
|
217
215
|
|
|
218
216
|
async doStream(
|
|
219
|
-
options:
|
|
220
|
-
): Promise<
|
|
217
|
+
options: LanguageModelV4CallOptions,
|
|
218
|
+
): Promise<LanguageModelV4StreamResult> {
|
|
221
219
|
const { args, warnings } = await this.getArgs(options);
|
|
222
220
|
|
|
223
221
|
const body = {
|
|
@@ -245,7 +243,7 @@ export class OpenAICompatibleCompletionLanguageModel
|
|
|
245
243
|
fetch: this.config.fetch,
|
|
246
244
|
});
|
|
247
245
|
|
|
248
|
-
let finishReason:
|
|
246
|
+
let finishReason: LanguageModelV4FinishReason = {
|
|
249
247
|
unified: 'other',
|
|
250
248
|
raw: undefined,
|
|
251
249
|
};
|
|
@@ -262,7 +260,7 @@ export class OpenAICompatibleCompletionLanguageModel
|
|
|
262
260
|
stream: response.pipeThrough(
|
|
263
261
|
new TransformStream<
|
|
264
262
|
ParseResult<z.infer<typeof this.chunkSchema>>,
|
|
265
|
-
|
|
263
|
+
LanguageModelV4StreamPart
|
|
266
264
|
>({
|
|
267
265
|
start(controller) {
|
|
268
266
|
controller.enqueue({ type: 'stream-start', warnings });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
EmbeddingModelV4,
|
|
3
|
+
SharedV4Warning,
|
|
4
4
|
TooManyEmbeddingValuesForCallError,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import {
|
|
@@ -39,8 +39,8 @@ type OpenAICompatibleEmbeddingConfig = {
|
|
|
39
39
|
errorStructure?: ProviderErrorStructure<any>;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
export class OpenAICompatibleEmbeddingModel implements
|
|
43
|
-
readonly specificationVersion = '
|
|
42
|
+
export class OpenAICompatibleEmbeddingModel implements EmbeddingModelV4 {
|
|
43
|
+
readonly specificationVersion = 'v4';
|
|
44
44
|
readonly modelId: OpenAICompatibleEmbeddingModelId;
|
|
45
45
|
|
|
46
46
|
private readonly config: OpenAICompatibleEmbeddingConfig;
|
|
@@ -74,10 +74,10 @@ export class OpenAICompatibleEmbeddingModel implements EmbeddingModelV3 {
|
|
|
74
74
|
headers,
|
|
75
75
|
abortSignal,
|
|
76
76
|
providerOptions,
|
|
77
|
-
}: Parameters<
|
|
78
|
-
Awaited<ReturnType<
|
|
77
|
+
}: Parameters<EmbeddingModelV4['doEmbed']>[0]): Promise<
|
|
78
|
+
Awaited<ReturnType<EmbeddingModelV4['doEmbed']>>
|
|
79
79
|
> {
|
|
80
|
-
const warnings:
|
|
80
|
+
const warnings: SharedV4Warning[] = [];
|
|
81
81
|
|
|
82
82
|
// Parse provider options - check for deprecated 'openai-compatible' key
|
|
83
83
|
const deprecatedOptions = await parseProviderOptions({
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
ImageModelV4,
|
|
3
|
+
ImageModelV4File,
|
|
4
|
+
SharedV4ProviderOptions,
|
|
5
|
+
SharedV4Warning,
|
|
6
6
|
} from '@ai-sdk/provider';
|
|
7
7
|
import {
|
|
8
8
|
combineHeaders,
|
|
@@ -33,8 +33,8 @@ export type OpenAICompatibleImageModelConfig = {
|
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
export class OpenAICompatibleImageModel implements
|
|
37
|
-
readonly specificationVersion = '
|
|
36
|
+
export class OpenAICompatibleImageModel implements ImageModelV4 {
|
|
37
|
+
readonly specificationVersion = 'v4';
|
|
38
38
|
readonly maxImagesPerCall = 10;
|
|
39
39
|
|
|
40
40
|
get provider(): string {
|
|
@@ -55,7 +55,7 @@ export class OpenAICompatibleImageModel implements ImageModelV3 {
|
|
|
55
55
|
|
|
56
56
|
// TODO: deprecate non-camelCase keys and remove in future major version
|
|
57
57
|
private getArgs(
|
|
58
|
-
providerOptions:
|
|
58
|
+
providerOptions: SharedV4ProviderOptions,
|
|
59
59
|
): Record<string, unknown> {
|
|
60
60
|
return {
|
|
61
61
|
...providerOptions[this.providerOptionsKey],
|
|
@@ -74,10 +74,10 @@ export class OpenAICompatibleImageModel implements ImageModelV3 {
|
|
|
74
74
|
abortSignal,
|
|
75
75
|
files,
|
|
76
76
|
mask,
|
|
77
|
-
}: Parameters<
|
|
78
|
-
Awaited<ReturnType<
|
|
77
|
+
}: Parameters<ImageModelV4['doGenerate']>[0]): Promise<
|
|
78
|
+
Awaited<ReturnType<ImageModelV4['doGenerate']>>
|
|
79
79
|
> {
|
|
80
|
-
const warnings: Array<
|
|
80
|
+
const warnings: Array<SharedV4Warning> = [];
|
|
81
81
|
|
|
82
82
|
if (aspectRatio != null) {
|
|
83
83
|
warnings.push({
|
|
@@ -187,7 +187,7 @@ type OpenAICompatibleFormDataInput = {
|
|
|
187
187
|
[key: string]: unknown;
|
|
188
188
|
};
|
|
189
189
|
|
|
190
|
-
async function fileToBlob(file:
|
|
190
|
+
async function fileToBlob(file: ImageModelV4File): Promise<Blob> {
|
|
191
191
|
if (file.type === 'url') {
|
|
192
192
|
return downloadBlob(file.url);
|
|
193
193
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
EmbeddingModelV4,
|
|
3
|
+
ImageModelV4,
|
|
4
|
+
LanguageModelV4,
|
|
5
|
+
ProviderV4,
|
|
6
6
|
} from '@ai-sdk/provider';
|
|
7
7
|
import {
|
|
8
8
|
FetchFunction,
|
|
@@ -24,26 +24,26 @@ export interface OpenAICompatibleProvider<
|
|
|
24
24
|
COMPLETION_MODEL_IDS extends string = string,
|
|
25
25
|
EMBEDDING_MODEL_IDS extends string = string,
|
|
26
26
|
IMAGE_MODEL_IDS extends string = string,
|
|
27
|
-
> extends Omit<
|
|
28
|
-
(modelId: CHAT_MODEL_IDS):
|
|
27
|
+
> extends Omit<ProviderV4, 'imageModel'> {
|
|
28
|
+
(modelId: CHAT_MODEL_IDS): LanguageModelV4;
|
|
29
29
|
|
|
30
30
|
languageModel(
|
|
31
31
|
modelId: CHAT_MODEL_IDS,
|
|
32
32
|
config?: Partial<OpenAICompatibleChatConfig>,
|
|
33
|
-
):
|
|
33
|
+
): LanguageModelV4;
|
|
34
34
|
|
|
35
|
-
chatModel(modelId: CHAT_MODEL_IDS):
|
|
35
|
+
chatModel(modelId: CHAT_MODEL_IDS): LanguageModelV4;
|
|
36
36
|
|
|
37
|
-
completionModel(modelId: COMPLETION_MODEL_IDS):
|
|
37
|
+
completionModel(modelId: COMPLETION_MODEL_IDS): LanguageModelV4;
|
|
38
38
|
|
|
39
|
-
embeddingModel(modelId: EMBEDDING_MODEL_IDS):
|
|
39
|
+
embeddingModel(modelId: EMBEDDING_MODEL_IDS): EmbeddingModelV4;
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* @deprecated Use `embeddingModel` instead.
|
|
43
43
|
*/
|
|
44
|
-
textEmbeddingModel(modelId: EMBEDDING_MODEL_IDS):
|
|
44
|
+
textEmbeddingModel(modelId: EMBEDDING_MODEL_IDS): EmbeddingModelV4;
|
|
45
45
|
|
|
46
|
-
imageModel(modelId: IMAGE_MODEL_IDS):
|
|
46
|
+
imageModel(modelId: IMAGE_MODEL_IDS): ImageModelV4;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
export interface OpenAICompatibleProviderSettings {
|
|
@@ -181,7 +181,7 @@ export function createOpenAICompatible<
|
|
|
181
181
|
|
|
182
182
|
const provider = (modelId: CHAT_MODEL_IDS) => createLanguageModel(modelId);
|
|
183
183
|
|
|
184
|
-
provider.specificationVersion = '
|
|
184
|
+
provider.specificationVersion = 'v4' as const;
|
|
185
185
|
provider.languageModel = createLanguageModel;
|
|
186
186
|
provider.chatModel = createChatModel;
|
|
187
187
|
provider.completionModel = createCompletionModel;
|