@ai-sdk/openai-compatible 3.0.0-beta.2 → 3.0.0-beta.21
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 +153 -8
- package/README.md +2 -0
- package/dist/index.d.mts +27 -27
- package/dist/index.d.ts +27 -27
- package/dist/index.js +110 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +110 -37
- 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 +8 -3
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +7 -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 +11 -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 +69 -36
- 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 +41 -25
- package/src/embedding/openai-compatible-embedding-model.ts +18 -9
- package/src/image/openai-compatible-image-model.ts +22 -17
- package/src/openai-compatible-provider.ts +13 -13
- package/src/utils/to-camel-case.ts +43 -0
|
@@ -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;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { SharedV4Warning } from '@ai-sdk/provider';
|
|
2
|
+
|
|
3
|
+
export function toCamelCase(str: string): string {
|
|
4
|
+
return str.replace(/[_-]([a-z])/g, g => g[1].toUpperCase());
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
Resolves which key to use for providerMetadata based on what the caller
|
|
9
|
+
passed in providerOptions. Returns the camelCase variant when the caller
|
|
10
|
+
supplied it, otherwise falls back to the raw name.
|
|
11
|
+
*/
|
|
12
|
+
export function resolveProviderOptionsKey(
|
|
13
|
+
rawName: string,
|
|
14
|
+
providerOptions: Record<string, unknown> | undefined,
|
|
15
|
+
): string {
|
|
16
|
+
const camelName = toCamelCase(rawName);
|
|
17
|
+
if (camelName !== rawName && providerOptions?.[camelName] != null) {
|
|
18
|
+
return camelName;
|
|
19
|
+
}
|
|
20
|
+
return rawName;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
Pushes a deprecation warning when the user supplies providerOptions under a non-camelCase key
|
|
25
|
+
*/
|
|
26
|
+
export function warnIfDeprecatedProviderOptionsKey({
|
|
27
|
+
rawName,
|
|
28
|
+
providerOptions,
|
|
29
|
+
warnings,
|
|
30
|
+
}: {
|
|
31
|
+
rawName: string;
|
|
32
|
+
providerOptions: Record<string, unknown> | undefined;
|
|
33
|
+
warnings: SharedV4Warning[];
|
|
34
|
+
}): void {
|
|
35
|
+
const camelName = toCamelCase(rawName);
|
|
36
|
+
if (camelName !== rawName && providerOptions?.[rawName] != null) {
|
|
37
|
+
warnings.push({
|
|
38
|
+
type: 'deprecated',
|
|
39
|
+
setting: `providerOptions key '${rawName}'`,
|
|
40
|
+
message: `Use '${camelName}' instead.`,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|