@ai-sdk/openai-compatible 3.0.0-beta.2 → 3.0.0-beta.4
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/dist/index.d.mts +27 -27
- package/dist/index.d.ts +27 -27
- package/dist/index.js +9 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -6
- 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 -3
- 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-chat-language-model.ts +23 -23
- 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 -20
- 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
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,13 @@ 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
51
|
export class OpenAICompatibleCompletionLanguageModel
|
|
52
|
-
implements
|
|
52
|
+
implements LanguageModelV4
|
|
53
53
|
{
|
|
54
|
-
readonly specificationVersion = '
|
|
54
|
+
readonly specificationVersion = 'v4';
|
|
55
55
|
|
|
56
56
|
readonly modelId: OpenAICompatibleCompletionModelId;
|
|
57
57
|
private readonly config: OpenAICompatibleCompletionConfig;
|
|
@@ -100,8 +100,8 @@ export class OpenAICompatibleCompletionLanguageModel
|
|
|
100
100
|
providerOptions,
|
|
101
101
|
tools,
|
|
102
102
|
toolChoice,
|
|
103
|
-
}:
|
|
104
|
-
const warnings:
|
|
103
|
+
}: LanguageModelV4CallOptions) {
|
|
104
|
+
const warnings: SharedV4Warning[] = [];
|
|
105
105
|
|
|
106
106
|
// Parse provider options
|
|
107
107
|
const completionOptions =
|
|
@@ -167,8 +167,8 @@ export class OpenAICompatibleCompletionLanguageModel
|
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
async doGenerate(
|
|
170
|
-
options:
|
|
171
|
-
): Promise<
|
|
170
|
+
options: LanguageModelV4CallOptions,
|
|
171
|
+
): Promise<LanguageModelV4GenerateResult> {
|
|
172
172
|
const { args, warnings } = await this.getArgs(options);
|
|
173
173
|
|
|
174
174
|
const {
|
|
@@ -191,7 +191,7 @@ export class OpenAICompatibleCompletionLanguageModel
|
|
|
191
191
|
});
|
|
192
192
|
|
|
193
193
|
const choice = response.choices[0];
|
|
194
|
-
const content: Array<
|
|
194
|
+
const content: Array<LanguageModelV4Content> = [];
|
|
195
195
|
|
|
196
196
|
// text content:
|
|
197
197
|
if (choice.text != null && choice.text.length > 0) {
|
|
@@ -216,8 +216,8 @@ export class OpenAICompatibleCompletionLanguageModel
|
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
async doStream(
|
|
219
|
-
options:
|
|
220
|
-
): Promise<
|
|
219
|
+
options: LanguageModelV4CallOptions,
|
|
220
|
+
): Promise<LanguageModelV4StreamResult> {
|
|
221
221
|
const { args, warnings } = await this.getArgs(options);
|
|
222
222
|
|
|
223
223
|
const body = {
|
|
@@ -245,7 +245,7 @@ export class OpenAICompatibleCompletionLanguageModel
|
|
|
245
245
|
fetch: this.config.fetch,
|
|
246
246
|
});
|
|
247
247
|
|
|
248
|
-
let finishReason:
|
|
248
|
+
let finishReason: LanguageModelV4FinishReason = {
|
|
249
249
|
unified: 'other',
|
|
250
250
|
raw: undefined,
|
|
251
251
|
};
|
|
@@ -262,7 +262,7 @@ export class OpenAICompatibleCompletionLanguageModel
|
|
|
262
262
|
stream: response.pipeThrough(
|
|
263
263
|
new TransformStream<
|
|
264
264
|
ParseResult<z.infer<typeof this.chunkSchema>>,
|
|
265
|
-
|
|
265
|
+
LanguageModelV4StreamPart
|
|
266
266
|
>({
|
|
267
267
|
start(controller) {
|
|
268
268
|
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;
|