ai 6.0.0-beta.78 → 6.0.0-beta.80
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 +16 -0
- package/dist/index.d.mts +144 -4
- package/dist/index.d.ts +144 -4
- package/dist/index.js +164 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +163 -4
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/dist/test/index.d.mts +17 -3
- package/dist/test/index.d.ts +17 -3
- package/dist/test/index.js +24 -1
- package/dist/test/index.js.map +1 -1
- package/dist/test/index.mjs +23 -1
- package/dist/test/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -775,7 +775,7 @@ import {
|
|
|
775
775
|
} from "@ai-sdk/provider-utils";
|
|
776
776
|
|
|
777
777
|
// src/version.ts
|
|
778
|
-
var VERSION = true ? "6.0.0-beta.
|
|
778
|
+
var VERSION = true ? "6.0.0-beta.80" : "0.0.0-test";
|
|
779
779
|
|
|
780
780
|
// src/util/download/download.ts
|
|
781
781
|
var download = async ({ url }) => {
|
|
@@ -9865,7 +9865,9 @@ function asProviderV3(provider) {
|
|
|
9865
9865
|
textEmbeddingModel: (modelId) => asEmbeddingModelV3(provider.textEmbeddingModel(modelId)),
|
|
9866
9866
|
imageModel: (modelId) => asImageModelV3(provider.imageModel(modelId)),
|
|
9867
9867
|
transcriptionModel: provider.transcriptionModel ? (modelId) => asTranscriptionModelV3(provider.transcriptionModel(modelId)) : void 0,
|
|
9868
|
-
speechModel: provider.speechModel ? (modelId) => asSpeechModelV3(provider.speechModel(modelId)) : void 0
|
|
9868
|
+
speechModel: provider.speechModel ? (modelId) => asSpeechModelV3(provider.speechModel(modelId)) : void 0,
|
|
9869
|
+
rerankingModel: void 0
|
|
9870
|
+
// v2 providers don't have reranking models
|
|
9869
9871
|
};
|
|
9870
9872
|
}
|
|
9871
9873
|
|
|
@@ -9884,7 +9886,8 @@ function wrapProvider({
|
|
|
9884
9886
|
textEmbeddingModel: providerV3.textEmbeddingModel,
|
|
9885
9887
|
imageModel: providerV3.imageModel,
|
|
9886
9888
|
transcriptionModel: providerV3.transcriptionModel,
|
|
9887
|
-
speechModel: providerV3.speechModel
|
|
9889
|
+
speechModel: providerV3.speechModel,
|
|
9890
|
+
rerankingModel: providerV3.rerankingModel
|
|
9888
9891
|
};
|
|
9889
9892
|
}
|
|
9890
9893
|
|
|
@@ -9898,8 +9901,10 @@ function customProvider({
|
|
|
9898
9901
|
imageModels,
|
|
9899
9902
|
transcriptionModels,
|
|
9900
9903
|
speechModels,
|
|
9901
|
-
|
|
9904
|
+
rerankingModels,
|
|
9905
|
+
fallbackProvider: fallbackProviderArg
|
|
9902
9906
|
}) {
|
|
9907
|
+
const fallbackProvider = fallbackProviderArg ? asProviderV3(fallbackProviderArg) : void 0;
|
|
9903
9908
|
return {
|
|
9904
9909
|
specificationVersion: "v3",
|
|
9905
9910
|
languageModel(modelId) {
|
|
@@ -9946,6 +9951,15 @@ function customProvider({
|
|
|
9946
9951
|
return fallbackProvider.speechModel(modelId);
|
|
9947
9952
|
}
|
|
9948
9953
|
throw new NoSuchModelError2({ modelId, modelType: "speechModel" });
|
|
9954
|
+
},
|
|
9955
|
+
rerankingModel(modelId) {
|
|
9956
|
+
if (rerankingModels != null && modelId in rerankingModels) {
|
|
9957
|
+
return rerankingModels[modelId];
|
|
9958
|
+
}
|
|
9959
|
+
if (fallbackProvider == null ? void 0 : fallbackProvider.rerankingModel) {
|
|
9960
|
+
return fallbackProvider.rerankingModel(modelId);
|
|
9961
|
+
}
|
|
9962
|
+
throw new NoSuchModelError2({ modelId, modelType: "rerankingModel" });
|
|
9949
9963
|
}
|
|
9950
9964
|
};
|
|
9951
9965
|
}
|
|
@@ -10096,6 +10110,150 @@ var DefaultProviderRegistry = class {
|
|
|
10096
10110
|
}
|
|
10097
10111
|
return model;
|
|
10098
10112
|
}
|
|
10113
|
+
rerankingModel(id) {
|
|
10114
|
+
var _a16;
|
|
10115
|
+
const [providerId, modelId] = this.splitId(id, "rerankingModel");
|
|
10116
|
+
const provider = this.getProvider(providerId, "rerankingModel");
|
|
10117
|
+
const model = (_a16 = provider.rerankingModel) == null ? void 0 : _a16.call(provider, modelId);
|
|
10118
|
+
if (model == null) {
|
|
10119
|
+
throw new NoSuchModelError4({ modelId: id, modelType: "rerankingModel" });
|
|
10120
|
+
}
|
|
10121
|
+
return model;
|
|
10122
|
+
}
|
|
10123
|
+
};
|
|
10124
|
+
|
|
10125
|
+
// src/rerank/rerank.ts
|
|
10126
|
+
async function rerank({
|
|
10127
|
+
model,
|
|
10128
|
+
documents,
|
|
10129
|
+
query,
|
|
10130
|
+
topN,
|
|
10131
|
+
maxRetries: maxRetriesArg,
|
|
10132
|
+
abortSignal,
|
|
10133
|
+
headers,
|
|
10134
|
+
providerOptions,
|
|
10135
|
+
experimental_telemetry: telemetry
|
|
10136
|
+
}) {
|
|
10137
|
+
if (documents.length === 0) {
|
|
10138
|
+
return new DefaultRerankResult({
|
|
10139
|
+
originalDocuments: [],
|
|
10140
|
+
ranking: [],
|
|
10141
|
+
providerMetadata: void 0,
|
|
10142
|
+
response: {
|
|
10143
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
10144
|
+
modelId: model.modelId
|
|
10145
|
+
}
|
|
10146
|
+
});
|
|
10147
|
+
}
|
|
10148
|
+
const { maxRetries, retry } = prepareRetries({
|
|
10149
|
+
maxRetries: maxRetriesArg,
|
|
10150
|
+
abortSignal
|
|
10151
|
+
});
|
|
10152
|
+
const documentsToSend = typeof documents[0] === "string" ? { type: "text", values: documents } : { type: "object", values: documents };
|
|
10153
|
+
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
|
10154
|
+
model,
|
|
10155
|
+
telemetry,
|
|
10156
|
+
headers,
|
|
10157
|
+
settings: { maxRetries }
|
|
10158
|
+
});
|
|
10159
|
+
const tracer = getTracer(telemetry);
|
|
10160
|
+
return recordSpan({
|
|
10161
|
+
name: "ai.rerank",
|
|
10162
|
+
attributes: selectTelemetryAttributes({
|
|
10163
|
+
telemetry,
|
|
10164
|
+
attributes: {
|
|
10165
|
+
...assembleOperationName({ operationId: "ai.rerank", telemetry }),
|
|
10166
|
+
...baseTelemetryAttributes,
|
|
10167
|
+
"ai.documents": {
|
|
10168
|
+
input: () => documents.map((document) => JSON.stringify(document))
|
|
10169
|
+
}
|
|
10170
|
+
}
|
|
10171
|
+
}),
|
|
10172
|
+
tracer,
|
|
10173
|
+
fn: async () => {
|
|
10174
|
+
var _a16, _b;
|
|
10175
|
+
const { ranking, response, providerMetadata, warnings } = await retry(
|
|
10176
|
+
() => recordSpan({
|
|
10177
|
+
name: "ai.rerank.doRerank",
|
|
10178
|
+
attributes: selectTelemetryAttributes({
|
|
10179
|
+
telemetry,
|
|
10180
|
+
attributes: {
|
|
10181
|
+
...assembleOperationName({
|
|
10182
|
+
operationId: "ai.rerank.doRerank",
|
|
10183
|
+
telemetry
|
|
10184
|
+
}),
|
|
10185
|
+
...baseTelemetryAttributes,
|
|
10186
|
+
// specific settings that only make sense on the outer level:
|
|
10187
|
+
"ai.documents": {
|
|
10188
|
+
input: () => documents.map((document) => JSON.stringify(document))
|
|
10189
|
+
}
|
|
10190
|
+
}
|
|
10191
|
+
}),
|
|
10192
|
+
tracer,
|
|
10193
|
+
fn: async (doRerankSpan) => {
|
|
10194
|
+
const modelResponse = await model.doRerank({
|
|
10195
|
+
documents: documentsToSend,
|
|
10196
|
+
query,
|
|
10197
|
+
topN,
|
|
10198
|
+
providerOptions,
|
|
10199
|
+
abortSignal,
|
|
10200
|
+
headers
|
|
10201
|
+
});
|
|
10202
|
+
const ranking2 = modelResponse.ranking;
|
|
10203
|
+
doRerankSpan.setAttributes(
|
|
10204
|
+
await selectTelemetryAttributes({
|
|
10205
|
+
telemetry,
|
|
10206
|
+
attributes: {
|
|
10207
|
+
"ai.ranking.type": documentsToSend.type,
|
|
10208
|
+
"ai.ranking": {
|
|
10209
|
+
output: () => ranking2.map((ranking3) => JSON.stringify(ranking3))
|
|
10210
|
+
}
|
|
10211
|
+
}
|
|
10212
|
+
})
|
|
10213
|
+
);
|
|
10214
|
+
return {
|
|
10215
|
+
ranking: ranking2,
|
|
10216
|
+
providerMetadata: modelResponse.providerMetadata,
|
|
10217
|
+
response: modelResponse.response,
|
|
10218
|
+
warnings: modelResponse.warnings
|
|
10219
|
+
};
|
|
10220
|
+
}
|
|
10221
|
+
})
|
|
10222
|
+
);
|
|
10223
|
+
logWarnings({
|
|
10224
|
+
warnings: warnings != null ? warnings : [],
|
|
10225
|
+
provider: model.provider,
|
|
10226
|
+
model: model.modelId
|
|
10227
|
+
});
|
|
10228
|
+
return new DefaultRerankResult({
|
|
10229
|
+
originalDocuments: documents,
|
|
10230
|
+
ranking: ranking.map((ranking2) => ({
|
|
10231
|
+
originalIndex: ranking2.index,
|
|
10232
|
+
score: ranking2.relevanceScore,
|
|
10233
|
+
document: documents[ranking2.index]
|
|
10234
|
+
})),
|
|
10235
|
+
providerMetadata,
|
|
10236
|
+
response: {
|
|
10237
|
+
id: response == null ? void 0 : response.id,
|
|
10238
|
+
timestamp: (_a16 = response == null ? void 0 : response.timestamp) != null ? _a16 : /* @__PURE__ */ new Date(),
|
|
10239
|
+
modelId: (_b = response == null ? void 0 : response.modelId) != null ? _b : model.modelId,
|
|
10240
|
+
headers: response == null ? void 0 : response.headers,
|
|
10241
|
+
body: response == null ? void 0 : response.body
|
|
10242
|
+
}
|
|
10243
|
+
});
|
|
10244
|
+
}
|
|
10245
|
+
});
|
|
10246
|
+
}
|
|
10247
|
+
var DefaultRerankResult = class {
|
|
10248
|
+
constructor(options) {
|
|
10249
|
+
this.originalDocuments = options.originalDocuments;
|
|
10250
|
+
this.ranking = options.ranking;
|
|
10251
|
+
this.response = options.response;
|
|
10252
|
+
this.providerMetadata = options.providerMetadata;
|
|
10253
|
+
}
|
|
10254
|
+
get rerankedDocuments() {
|
|
10255
|
+
return this.ranking.map((ranking) => ranking.document);
|
|
10256
|
+
}
|
|
10099
10257
|
};
|
|
10100
10258
|
|
|
10101
10259
|
// src/transcribe/transcribe.ts
|
|
@@ -11036,6 +11194,7 @@ export {
|
|
|
11036
11194
|
pipeUIMessageStreamToResponse,
|
|
11037
11195
|
pruneMessages,
|
|
11038
11196
|
readUIMessageStream,
|
|
11197
|
+
rerank,
|
|
11039
11198
|
safeValidateUIMessages,
|
|
11040
11199
|
simulateReadableStream,
|
|
11041
11200
|
simulateStreamingMiddleware,
|