@ai-sdk/openai-compatible 3.0.74 → 3.0.76
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 +17 -0
- package/dist/index.d.ts +24 -46
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -25
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +2 -2
- package/dist/internal/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/chat/openai-compatible-chat-language-model.ts +126 -114
- package/src/completion/openai-compatible-completion-language-model-options.ts +32 -23
- package/src/completion/openai-compatible-completion-language-model.ts +22 -15
- package/src/embedding/openai-compatible-embedding-model-options.ts +22 -13
- package/src/embedding/openai-compatible-embedding-model.ts +13 -7
- package/src/image/openai-compatible-image-model-options.ts +40 -31
- package/src/image/openai-compatible-image-model.ts +27 -20
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/chat/openai-compatible-api-types.ts","../../src/chat/convert-to-openai-compatible-chat-messages.ts","../../src/chat/convert-openai-compatible-chat-usage.ts","../../src/chat/map-openai-compatible-finish-reason.ts","../../src/chat/get-response-metadata.ts","../../src/chat/openai-compatible-prepare-tools.ts","../../src/openai-compatible-error.ts","../../src/chat/openai-compatible-metadata-extractor.ts","../../src/chat/openai-compatible-chat-language-model.ts"],"mappings":";;;;KAEY,6BAA6B,MAAM;KAEnC,0BACR,gCACA,8BACA,mCACA;KAIC,WAAW,aAAa,eAE3B,YAAY,cAAc,IAAI;UAGf,sCAAsC;EACrD;EACA;;UAGe,oCAAoC,WAAW;EAC9D;EACA,kBAAkB,MAAM;;KAGd,8BACR,kCACA,mCACA,mCACA,wCACA;UAEa,wCAAwC;EACvD;EACA;;UAGe,yCAAyC;EACxD;EACA;IAAa;;;UAIE,yCAAyC;EACxD;EACA;IAAa;;;UAIE,8CAA8C;EAC7D;EACA;IAAe;IAAc;;;UAGd,wCAAwC;EACvD;EACA;IAAQ;IAAkB;;IAAwB;;;UAGnC,yCAAyC,WAAW;EACnE;EACA;EACA;EACA,aAAa,MAAM;;UAGJ,wCAAwC;EACvD;EACA;EACA;IACE;IACA;;;;;;EAMF;IACE;MACE;;;;UAKW,oCAAoC;EACnD;EACA,kBAAkB,MAAM;EACxB;;;;wBCmGc,sCACd,QAAQ,yBAEN,UACA,oBACA;EAEA;EACA;EACA;IAED;;;wBCpMa,iCACd;EAEM;EACA;EACA;IACE;;EAEF;IACE;;uBAKP;;;wBCfa,gCACd,0CACC;;;wBCFa,sBACd,IACA,OACA;EAEA;EACA;EACA;+BACD;;;wBCLe,eACd,OACA;EAEA,OAAO;EACP,aAAa;;EAEb,mBAEI;IACE;IACA;MACE;MACA;MACA;MACA;;;EAGR;IACM;IAAkB;MAAY;;;EAKpC,cAAc;;;;KCXJ,uBAAuB;EACjC,aAAa,QAAQ;EACrB,iBAAiB,OAAO;EACxB,eAAe,UAAU,UAAU,QAAQ;;;;;;;;;KCdjC;;;;;;;;;EASV,oBACE;IAEA;QACI,QAAQ;;;;;;;;EASd;;;;;;;IAOE,aAAa;;;;;;;;IASb,iBAAiB;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/chat/openai-compatible-api-types.ts","../../src/chat/convert-to-openai-compatible-chat-messages.ts","../../src/chat/convert-openai-compatible-chat-usage.ts","../../src/chat/map-openai-compatible-finish-reason.ts","../../src/chat/get-response-metadata.ts","../../src/chat/openai-compatible-prepare-tools.ts","../../src/openai-compatible-error.ts","../../src/chat/openai-compatible-metadata-extractor.ts","../../src/chat/openai-compatible-chat-language-model.ts"],"mappings":";;;;KAEY,6BAA6B,MAAM;KAEnC,0BACR,gCACA,8BACA,mCACA;KAIC,WAAW,aAAa,eAE3B,YAAY,cAAc,IAAI;UAGf,sCAAsC;EACrD;EACA;;UAGe,oCAAoC,WAAW;EAC9D;EACA,kBAAkB,MAAM;;KAGd,8BACR,kCACA,mCACA,mCACA,wCACA;UAEa,wCAAwC;EACvD;EACA;;UAGe,yCAAyC;EACxD;EACA;IAAa;;;UAIE,yCAAyC;EACxD;EACA;IAAa;;;UAIE,8CAA8C;EAC7D;EACA;IAAe;IAAc;;;UAGd,wCAAwC;EACvD;EACA;IAAQ;IAAkB;;IAAwB;;;UAGnC,yCAAyC,WAAW;EACnE;EACA;EACA;EACA,aAAa,MAAM;;UAGJ,wCAAwC;EACvD;EACA;EACA;IACE;IACA;;;;;;EAMF;IACE;MACE;;;;UAKW,oCAAoC;EACnD;EACA,kBAAkB,MAAM;EACxB;;;;wBCmGc,sCACd,QAAQ,yBAEN,UACA,oBACA;EAEA;EACA;EACA;IAED;;;wBCpMa,iCACd;EAEM;EACA;EACA;IACE;;EAEF;IACE;;uBAKP;;;wBCfa,gCACd,0CACC;;;wBCFa,sBACd,IACA,OACA;EAEA;EACA;EACA;+BACD;;;wBCLe,eACd,OACA;EAEA,OAAO;EACP,aAAa;;EAEb,mBAEI;IACE;IACA;MACE;MACA;MACA;MACA;;;EAGR;IACM;IAAkB;MAAY;;;EAKpC,cAAc;;;;KCXJ,uBAAuB;EACjC,aAAa,QAAQ;EACrB,iBAAiB,OAAO;EACxB,eAAe,UAAU,UAAU,QAAQ;;;;;;;;;KCdjC;;;;;;;;;EASV,oBACE;IAEA;QACI,QAAQ;;;;;;;;EASd;;;;;;;IAOE,aAAa;;;;;;;;IASb,iBAAiB;;;;;KCkBT;EACV;EACA,gBAAgB;EAChB,MAAM;IAAW;IAAiB;;EAClC,QAAQ;EACR;EACA,iBAAiB;EACjB,oBAAoB;;;;EAKpB;;;;EAKA;;;;EAKA,sBAAsB;;;;;;;EAQtB,wBACE,MAAM,qBACN,WAAW,sBACR;;;;;EAML,gBACE,OAAO,EAAE,MAAM,kBAAkB,uCAC9B;;cAirBD,wCAAgC,EAAA,YAAA,EAAA,YAAA,EAAA;;;;;;;;;;;;GAmBxB,EAAA,KAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/openai-compatible",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.76",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ai-sdk/provider": "4.0.
|
|
39
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
38
|
+
"@ai-sdk/provider": "4.0.32",
|
|
39
|
+
"@ai-sdk/provider-utils": "5.0.66"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@ai-sdk/test-server": "2.0.4",
|
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
type SharedV4Warning,
|
|
14
14
|
} from '@ai-sdk/provider';
|
|
15
15
|
import {
|
|
16
|
+
lazySchema,
|
|
17
|
+
zodSchema,
|
|
16
18
|
combineHeaders,
|
|
17
19
|
createEventSourceResponseHandler,
|
|
18
20
|
createJsonErrorResponseHandler,
|
|
@@ -99,7 +101,7 @@ export type OpenAICompatibleChatConfig = {
|
|
|
99
101
|
* token accounting semantics.
|
|
100
102
|
*/
|
|
101
103
|
convertUsage?: (
|
|
102
|
-
usage: z.infer<typeof openaiCompatibleTokenUsageSchema
|
|
104
|
+
usage: z.infer<ReturnType<typeof openaiCompatibleTokenUsageSchema>>,
|
|
103
105
|
) => LanguageModelV4Usage;
|
|
104
106
|
};
|
|
105
107
|
|
|
@@ -174,7 +176,7 @@ export class OpenAICompatibleChatLanguageModel implements LanguageModelV4 {
|
|
|
174
176
|
}
|
|
175
177
|
|
|
176
178
|
private convertUsage(
|
|
177
|
-
usage: z.infer<typeof openaiCompatibleTokenUsageSchema
|
|
179
|
+
usage: z.infer<ReturnType<typeof openaiCompatibleTokenUsageSchema>>,
|
|
178
180
|
): LanguageModelV4Usage {
|
|
179
181
|
return (
|
|
180
182
|
this.config.convertUsage?.(usage) ??
|
|
@@ -546,13 +548,14 @@ export class OpenAICompatibleChatLanguageModel implements LanguageModelV4 {
|
|
|
546
548
|
};
|
|
547
549
|
|
|
548
550
|
let finishReason: LanguageModelV4FinishReason | undefined;
|
|
549
|
-
let usage:
|
|
550
|
-
|
|
551
|
+
let usage:
|
|
552
|
+
| z.infer<ReturnType<typeof openaiCompatibleTokenUsageSchema>>
|
|
553
|
+
| undefined = undefined;
|
|
551
554
|
let metadataExtracted = false;
|
|
552
555
|
let isActiveReasoning = false;
|
|
553
556
|
let isActiveText = false;
|
|
554
557
|
const convertUsage = (
|
|
555
|
-
usage: z.infer<typeof openaiCompatibleTokenUsageSchema
|
|
558
|
+
usage: z.infer<ReturnType<typeof openaiCompatibleTokenUsageSchema>>,
|
|
556
559
|
) => this.convertUsage(usage);
|
|
557
560
|
|
|
558
561
|
return {
|
|
@@ -608,7 +611,9 @@ export class OpenAICompatibleChatLanguageModel implements LanguageModelV4 {
|
|
|
608
611
|
|
|
609
612
|
// TODO we lost type safety on Chunk, most likely due to the error schema. MUST FIX
|
|
610
613
|
// remove this workaround when the issue is fixed
|
|
611
|
-
const value = chunk.value as z.infer<
|
|
614
|
+
const value = chunk.value as z.infer<
|
|
615
|
+
ReturnType<typeof chunkBaseSchema>
|
|
616
|
+
>;
|
|
612
617
|
|
|
613
618
|
// Extract and emit response metadata once. Usually it comes in the
|
|
614
619
|
// first chunk, but some providers prepend a placeholder chunk with
|
|
@@ -786,39 +791,41 @@ export class OpenAICompatibleChatLanguageModel implements LanguageModelV4 {
|
|
|
786
791
|
}
|
|
787
792
|
|
|
788
793
|
// Loose, nested objects included: the parsed value is returned as `usage.raw`.
|
|
789
|
-
const openaiCompatibleTokenUsageSchema =
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
z.
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
794
|
+
const openaiCompatibleTokenUsageSchema = () =>
|
|
795
|
+
z
|
|
796
|
+
.looseObject({
|
|
797
|
+
prompt_tokens: z.number().nullish(),
|
|
798
|
+
completion_tokens: z.number().nullish(),
|
|
799
|
+
total_tokens: z.number().nullish(),
|
|
800
|
+
prompt_tokens_details: z
|
|
801
|
+
.looseObject({
|
|
802
|
+
cached_tokens: z.number().nullish(),
|
|
803
|
+
})
|
|
804
|
+
.nullish(),
|
|
805
|
+
completion_tokens_details: z
|
|
806
|
+
.looseObject({
|
|
807
|
+
reasoning_tokens: z.number().nullish(),
|
|
808
|
+
accepted_prediction_tokens: z.number().nullish(),
|
|
809
|
+
rejected_prediction_tokens: z.number().nullish(),
|
|
810
|
+
})
|
|
811
|
+
.nullish(),
|
|
812
|
+
})
|
|
813
|
+
.nullish();
|
|
814
|
+
|
|
815
|
+
const openAICompatibleContentSchema = () =>
|
|
816
|
+
z
|
|
817
|
+
.union([
|
|
818
|
+
z.string(),
|
|
819
|
+
z.array(
|
|
820
|
+
z.looseObject({
|
|
821
|
+
type: z.string(),
|
|
822
|
+
}),
|
|
823
|
+
),
|
|
824
|
+
])
|
|
825
|
+
.nullish();
|
|
819
826
|
|
|
820
827
|
function convertOpenAICompatibleContent(
|
|
821
|
-
content: z.infer<typeof openAICompatibleContentSchema
|
|
828
|
+
content: z.infer<ReturnType<typeof openAICompatibleContentSchema>>,
|
|
822
829
|
): Array<Extract<LanguageModelV4Content, { type: 'text' | 'reasoning' }>> {
|
|
823
830
|
if (content == null) {
|
|
824
831
|
return [];
|
|
@@ -862,88 +869,93 @@ function convertOpenAICompatibleContent(
|
|
|
862
869
|
|
|
863
870
|
// limited version of the schema, focussed on what is needed for the implementation
|
|
864
871
|
// this approach limits breakages when the API changes and increases efficiency
|
|
865
|
-
const OpenAICompatibleChatResponseSchema =
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
z
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
872
|
+
const OpenAICompatibleChatResponseSchema = lazySchema(() =>
|
|
873
|
+
zodSchema(
|
|
874
|
+
z.looseObject({
|
|
875
|
+
id: z.string().nullish(),
|
|
876
|
+
created: z.number().nullish(),
|
|
877
|
+
model: z.string().nullish(),
|
|
878
|
+
choices: z.array(
|
|
879
|
+
z.object({
|
|
880
|
+
message: z.object({
|
|
881
|
+
role: z.literal('assistant').nullish(),
|
|
882
|
+
content: openAICompatibleContentSchema(),
|
|
883
|
+
reasoning_content: z.string().nullish(),
|
|
884
|
+
reasoning: z.string().nullish(),
|
|
885
|
+
tool_calls: z
|
|
886
|
+
.array(
|
|
887
|
+
z.object({
|
|
888
|
+
id: z.string().nullish(),
|
|
889
|
+
function: z.object({
|
|
890
|
+
name: z.string(),
|
|
891
|
+
arguments: z.string(),
|
|
892
|
+
}),
|
|
893
|
+
// Support for Google Gemini thought signatures via OpenAI compatibility
|
|
894
|
+
extra_content: z
|
|
888
895
|
.object({
|
|
889
|
-
|
|
896
|
+
google: z
|
|
897
|
+
.object({
|
|
898
|
+
thought_signature: z.string().nullish(),
|
|
899
|
+
})
|
|
900
|
+
.nullish(),
|
|
890
901
|
})
|
|
891
902
|
.nullish(),
|
|
892
|
-
})
|
|
893
|
-
.nullish(),
|
|
894
|
-
}),
|
|
895
|
-
)
|
|
896
|
-
.nullish(),
|
|
897
|
-
}),
|
|
898
|
-
finish_reason: z.string().nullish(),
|
|
899
|
-
}),
|
|
900
|
-
),
|
|
901
|
-
usage: openaiCompatibleTokenUsageSchema,
|
|
902
|
-
});
|
|
903
|
-
|
|
904
|
-
const chunkBaseSchema = z.looseObject({
|
|
905
|
-
id: z.string().nullish(),
|
|
906
|
-
created: z.number().nullish(),
|
|
907
|
-
model: z.string().nullish(),
|
|
908
|
-
choices: z.array(
|
|
909
|
-
z.object({
|
|
910
|
-
delta: z
|
|
911
|
-
.object({
|
|
912
|
-
role: z.enum(['assistant', '']).nullish(),
|
|
913
|
-
content: openAICompatibleContentSchema,
|
|
914
|
-
// Most openai-compatible models set `reasoning_content`, but some
|
|
915
|
-
// providers serving `gpt-oss` set `reasoning`. See #7866
|
|
916
|
-
reasoning_content: z.string().nullish(),
|
|
917
|
-
reasoning: z.string().nullish(),
|
|
918
|
-
tool_calls: z
|
|
919
|
-
.array(
|
|
920
|
-
z.object({
|
|
921
|
-
index: z.number().nullish(), //google does not send index
|
|
922
|
-
id: z.string().nullish(),
|
|
923
|
-
function: z.object({
|
|
924
|
-
name: z.string().nullish(),
|
|
925
|
-
arguments: z.string().nullish(),
|
|
926
903
|
}),
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
.nullish(),
|
|
935
|
-
})
|
|
936
|
-
.nullish(),
|
|
937
|
-
}),
|
|
938
|
-
)
|
|
939
|
-
.nullish(),
|
|
940
|
-
})
|
|
941
|
-
.nullish(),
|
|
942
|
-
finish_reason: z.string().nullish(),
|
|
904
|
+
)
|
|
905
|
+
.nullish(),
|
|
906
|
+
}),
|
|
907
|
+
finish_reason: z.string().nullish(),
|
|
908
|
+
}),
|
|
909
|
+
),
|
|
910
|
+
usage: openaiCompatibleTokenUsageSchema(),
|
|
943
911
|
}),
|
|
944
912
|
),
|
|
945
|
-
|
|
946
|
-
|
|
913
|
+
);
|
|
914
|
+
|
|
915
|
+
const chunkBaseSchema = () =>
|
|
916
|
+
z.looseObject({
|
|
917
|
+
id: z.string().nullish(),
|
|
918
|
+
created: z.number().nullish(),
|
|
919
|
+
model: z.string().nullish(),
|
|
920
|
+
choices: z.array(
|
|
921
|
+
z.object({
|
|
922
|
+
delta: z
|
|
923
|
+
.object({
|
|
924
|
+
role: z.enum(['assistant', '']).nullish(),
|
|
925
|
+
content: openAICompatibleContentSchema(),
|
|
926
|
+
// Most openai-compatible models set `reasoning_content`, but some
|
|
927
|
+
// providers serving `gpt-oss` set `reasoning`. See #7866
|
|
928
|
+
reasoning_content: z.string().nullish(),
|
|
929
|
+
reasoning: z.string().nullish(),
|
|
930
|
+
tool_calls: z
|
|
931
|
+
.array(
|
|
932
|
+
z.object({
|
|
933
|
+
index: z.number().nullish(), //google does not send index
|
|
934
|
+
id: z.string().nullish(),
|
|
935
|
+
function: z.object({
|
|
936
|
+
name: z.string().nullish(),
|
|
937
|
+
arguments: z.string().nullish(),
|
|
938
|
+
}),
|
|
939
|
+
// Support for Google Gemini thought signatures via OpenAI compatibility
|
|
940
|
+
extra_content: z
|
|
941
|
+
.object({
|
|
942
|
+
google: z
|
|
943
|
+
.object({
|
|
944
|
+
thought_signature: z.string().nullish(),
|
|
945
|
+
})
|
|
946
|
+
.nullish(),
|
|
947
|
+
})
|
|
948
|
+
.nullish(),
|
|
949
|
+
}),
|
|
950
|
+
)
|
|
951
|
+
.nullish(),
|
|
952
|
+
})
|
|
953
|
+
.nullish(),
|
|
954
|
+
finish_reason: z.string().nullish(),
|
|
955
|
+
}),
|
|
956
|
+
),
|
|
957
|
+
usage: openaiCompatibleTokenUsageSchema(),
|
|
958
|
+
});
|
|
947
959
|
|
|
948
960
|
// limited version of the schema, focussed on what is needed for the implementation
|
|
949
961
|
// this approach limits breakages when the API changes and increases efficiency
|
|
@@ -951,4 +963,4 @@ const createOpenAICompatibleChatChunkSchema = <
|
|
|
951
963
|
ERROR_SCHEMA extends z.core.$ZodType,
|
|
952
964
|
>(
|
|
953
965
|
errorSchema: ERROR_SCHEMA,
|
|
954
|
-
) => z.union([chunkBaseSchema, errorSchema]);
|
|
966
|
+
) => z.union([chunkBaseSchema(), errorSchema]);
|
|
@@ -1,33 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
lazySchema,
|
|
3
|
+
zodSchema,
|
|
4
|
+
type InferSchema,
|
|
5
|
+
} from '@ai-sdk/provider-utils';
|
|
1
6
|
import { z } from 'zod/v4';
|
|
2
7
|
|
|
3
8
|
export type OpenAICompatibleCompletionModelId = string;
|
|
4
9
|
|
|
5
|
-
export const openaiCompatibleLanguageModelCompletionOptions =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
export const openaiCompatibleLanguageModelCompletionOptions = lazySchema(() =>
|
|
11
|
+
zodSchema(
|
|
12
|
+
z.object({
|
|
13
|
+
/**
|
|
14
|
+
* Echo back the prompt in addition to the completion.
|
|
15
|
+
*/
|
|
16
|
+
echo: z.boolean().optional(),
|
|
10
17
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Modify the likelihood of specified tokens appearing in the completion.
|
|
20
|
+
*
|
|
21
|
+
* Accepts a JSON object that maps tokens (specified by their token ID in
|
|
22
|
+
* the GPT tokenizer) to an associated bias value from -100 to 100.
|
|
23
|
+
*/
|
|
24
|
+
logitBias: z.record(z.string(), z.number()).optional(),
|
|
18
25
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
/**
|
|
27
|
+
* The suffix that comes after a completion of inserted text.
|
|
28
|
+
*/
|
|
29
|
+
suffix: z.string().optional(),
|
|
23
30
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
})
|
|
31
|
+
/**
|
|
32
|
+
* A unique identifier representing your end-user, which can help providers to
|
|
33
|
+
* monitor and detect abuse.
|
|
34
|
+
*/
|
|
35
|
+
user: z.string().optional(),
|
|
36
|
+
}),
|
|
37
|
+
),
|
|
38
|
+
);
|
|
30
39
|
|
|
31
|
-
export type OpenAICompatibleLanguageModelCompletionOptions =
|
|
40
|
+
export type OpenAICompatibleLanguageModelCompletionOptions = InferSchema<
|
|
32
41
|
typeof openaiCompatibleLanguageModelCompletionOptions
|
|
33
42
|
>;
|
|
@@ -10,6 +10,8 @@ import type {
|
|
|
10
10
|
SharedV4Warning,
|
|
11
11
|
} from '@ai-sdk/provider';
|
|
12
12
|
import {
|
|
13
|
+
lazySchema,
|
|
14
|
+
zodSchema,
|
|
13
15
|
combineHeaders,
|
|
14
16
|
createEventSourceResponseHandler,
|
|
15
17
|
createJsonErrorResponseHandler,
|
|
@@ -380,26 +382,31 @@ export class OpenAICompatibleCompletionLanguageModel implements LanguageModelV4
|
|
|
380
382
|
}
|
|
381
383
|
|
|
382
384
|
// Loose: the parsed value is returned as `usage.raw`.
|
|
383
|
-
const usageSchema =
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
385
|
+
const usageSchema = () =>
|
|
386
|
+
z.looseObject({
|
|
387
|
+
prompt_tokens: z.number(),
|
|
388
|
+
completion_tokens: z.number(),
|
|
389
|
+
total_tokens: z.number(),
|
|
390
|
+
});
|
|
388
391
|
|
|
389
392
|
// limited version of the schema, focussed on what is needed for the implementation
|
|
390
393
|
// this approach limits breakages when the API changes and increases efficiency
|
|
391
|
-
const openaiCompatibleCompletionResponseSchema =
|
|
392
|
-
|
|
393
|
-
created: z.number().nullish(),
|
|
394
|
-
model: z.string().nullish(),
|
|
395
|
-
choices: z.array(
|
|
394
|
+
const openaiCompatibleCompletionResponseSchema = lazySchema(() =>
|
|
395
|
+
zodSchema(
|
|
396
396
|
z.object({
|
|
397
|
-
|
|
398
|
-
|
|
397
|
+
id: z.string().nullish(),
|
|
398
|
+
created: z.number().nullish(),
|
|
399
|
+
model: z.string().nullish(),
|
|
400
|
+
choices: z.array(
|
|
401
|
+
z.object({
|
|
402
|
+
text: z.string(),
|
|
403
|
+
finish_reason: z.string(),
|
|
404
|
+
}),
|
|
405
|
+
),
|
|
406
|
+
usage: usageSchema().nullish(),
|
|
399
407
|
}),
|
|
400
408
|
),
|
|
401
|
-
|
|
402
|
-
});
|
|
409
|
+
);
|
|
403
410
|
|
|
404
411
|
// limited version of the schema, focussed on what is needed for the implementation
|
|
405
412
|
// this approach limits breakages when the API changes and increases efficiency
|
|
@@ -420,7 +427,7 @@ const createOpenAICompatibleCompletionChunkSchema = <
|
|
|
420
427
|
index: z.number(),
|
|
421
428
|
}),
|
|
422
429
|
),
|
|
423
|
-
usage: usageSchema.nullish(),
|
|
430
|
+
usage: usageSchema().nullish(),
|
|
424
431
|
}),
|
|
425
432
|
errorSchema,
|
|
426
433
|
]);
|
|
@@ -1,21 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
lazySchema,
|
|
3
|
+
zodSchema,
|
|
4
|
+
type InferSchema,
|
|
5
|
+
} from '@ai-sdk/provider-utils';
|
|
1
6
|
import { z } from 'zod/v4';
|
|
2
7
|
|
|
3
8
|
export type OpenAICompatibleEmbeddingModelId = string;
|
|
4
9
|
|
|
5
|
-
export const openaiCompatibleEmbeddingModelOptions =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
export const openaiCompatibleEmbeddingModelOptions = lazySchema(() =>
|
|
11
|
+
zodSchema(
|
|
12
|
+
z.object({
|
|
13
|
+
/**
|
|
14
|
+
* The number of dimensions the resulting output embeddings should have.
|
|
15
|
+
* Only supported in text-embedding-3 and later models.
|
|
16
|
+
*/
|
|
17
|
+
dimensions: z.number().optional(),
|
|
11
18
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
})
|
|
19
|
+
/**
|
|
20
|
+
* A unique identifier representing your end-user, which can help providers to
|
|
21
|
+
* monitor and detect abuse.
|
|
22
|
+
*/
|
|
23
|
+
user: z.string().optional(),
|
|
24
|
+
}),
|
|
25
|
+
),
|
|
26
|
+
);
|
|
18
27
|
|
|
19
|
-
export type OpenAICompatibleEmbeddingModelOptions =
|
|
28
|
+
export type OpenAICompatibleEmbeddingModelOptions = InferSchema<
|
|
20
29
|
typeof openaiCompatibleEmbeddingModelOptions
|
|
21
30
|
>;
|
|
@@ -4,6 +4,8 @@ import {
|
|
|
4
4
|
type SharedV4Warning,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import {
|
|
7
|
+
lazySchema,
|
|
8
|
+
zodSchema,
|
|
7
9
|
combineHeaders,
|
|
8
10
|
createJsonErrorResponseHandler,
|
|
9
11
|
createJsonResponseHandler,
|
|
@@ -184,10 +186,14 @@ export class OpenAICompatibleEmbeddingModel implements EmbeddingModelV4 {
|
|
|
184
186
|
|
|
185
187
|
// minimal version of the schema, focussed on what is needed for the implementation
|
|
186
188
|
// this approach limits breakages when the API changes and increases efficiency
|
|
187
|
-
const openaiTextEmbeddingResponseSchema =
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
189
|
+
const openaiTextEmbeddingResponseSchema = lazySchema(() =>
|
|
190
|
+
zodSchema(
|
|
191
|
+
z.object({
|
|
192
|
+
data: z.array(z.object({ embedding: z.array(z.number()) })),
|
|
193
|
+
usage: z.object({ prompt_tokens: z.number() }).nullish(),
|
|
194
|
+
providerMetadata: z
|
|
195
|
+
.record(z.string(), z.record(z.string(), z.any()))
|
|
196
|
+
.optional(),
|
|
197
|
+
}),
|
|
198
|
+
),
|
|
199
|
+
);
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
lazySchema,
|
|
3
|
+
zodSchema,
|
|
4
|
+
type InferSchema,
|
|
5
|
+
} from '@ai-sdk/provider-utils';
|
|
1
6
|
import { z } from 'zod/v4';
|
|
2
7
|
|
|
3
8
|
/**
|
|
@@ -5,41 +10,45 @@ import { z } from 'zod/v4';
|
|
|
5
10
|
*
|
|
6
11
|
* Additional provider-specific options are passed through to the API.
|
|
7
12
|
*/
|
|
8
|
-
export const openaiCompatibleImageModelOptions =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
export const openaiCompatibleImageModelOptions = lazySchema(() =>
|
|
14
|
+
zodSchema(
|
|
15
|
+
z.looseObject({
|
|
16
|
+
/**
|
|
17
|
+
* Dimensions of the generated image.
|
|
18
|
+
*
|
|
19
|
+
* Supported values depend on the provider and model.
|
|
20
|
+
*/
|
|
21
|
+
size: z.string().optional(),
|
|
15
22
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Quality of the generated image.
|
|
25
|
+
*
|
|
26
|
+
* Supported values depend on the provider and model.
|
|
27
|
+
*/
|
|
28
|
+
quality: z.string().optional(),
|
|
22
29
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
/**
|
|
31
|
+
* File format of the generated image.
|
|
32
|
+
*
|
|
33
|
+
* Supported values depend on the provider and model.
|
|
34
|
+
*/
|
|
35
|
+
output_format: z.string().optional(),
|
|
29
36
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Compression level for JPEG and WebP images.
|
|
39
|
+
*/
|
|
40
|
+
output_compression: z.number().min(0).max(100).optional(),
|
|
34
41
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
})
|
|
42
|
+
/**
|
|
43
|
+
* Background behavior for the generated image.
|
|
44
|
+
*
|
|
45
|
+
* Supported values depend on the provider and model.
|
|
46
|
+
*/
|
|
47
|
+
background: z.string().optional(),
|
|
48
|
+
}),
|
|
49
|
+
),
|
|
50
|
+
);
|
|
42
51
|
|
|
43
|
-
export type OpenAICompatibleImageModelOptions =
|
|
52
|
+
export type OpenAICompatibleImageModelOptions = InferSchema<
|
|
44
53
|
typeof openaiCompatibleImageModelOptions
|
|
45
54
|
>;
|