UNPKG

ai

Version:

AI SDK by Vercel - build apps like ChatGPT, Claude, Gemini, and more with a single interface for any model using the Vercel AI Gateway or go direct to OpenAI, Anthropic, Google, or any other model provider.

405 lines (404 loc) • 15.5 kB
import { EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL, delay } from "@ai-sdk/provider-utils"; import { convertArrayToAsyncIterable, convertArrayToReadableStream, convertReadableStreamToArray, mockId } from "@ai-sdk/provider-utils/test"; import { NoSuchModelError } from "@ai-sdk/provider"; //#region src/test/not-implemented.ts function notImplemented() { throw new Error("Not implemented"); } //#endregion //#region src/test/decision-mock-model-v4.ts var DecisionMockModelV4 = class { /** @deprecated Use `doDecide` instead. */ doEvaluate(options) { return this.doDecide(options); } constructor({ provider = "mock-provider", modelId = "mock-model-id", supportedQuestionTypes = [ "choice", "score", "boolean" ], doDecide, doEvaluate } = {}) { this.specificationVersion = "v4"; this.provider = provider; this.modelId = modelId; this.supportedQuestionTypes = supportedQuestionTypes; this.doDecide = doDecide ?? doEvaluate ?? notImplemented; } }; //#endregion //#region src/util/simulate-readable-stream.ts /** * Creates a ReadableStream that emits the provided values with an optional delay between each value. * * @param options - The configuration options * @param options.chunks - Array of values to be emitted by the stream * @param options.initialDelayInMs - Optional initial delay in milliseconds before emitting the first value (default: 0). Can be set to `null` to skip the initial delay. The difference between `initialDelayInMs: null` and `initialDelayInMs: 0` is that `initialDelayInMs: null` will emit the values without any delay, while `initialDelayInMs: 0` will emit the values with a delay of 0 milliseconds. * @param options.chunkDelayInMs - Optional delay in milliseconds between emitting each value (default: 0). Can be set to `null` to skip the delay. The difference between `chunkDelayInMs: null` and `chunkDelayInMs: 0` is that `chunkDelayInMs: null` will emit the values without any delay, while `chunkDelayInMs: 0` will emit the values with a delay of 0 milliseconds. * @returns A ReadableStream that emits the provided values */ function simulateReadableStream$1({ chunks, initialDelayInMs = 0, chunkDelayInMs = 0, _internal }) { const delay$1 = _internal?.delay ?? delay; let index = 0; return new ReadableStream({ async pull(controller) { if (index < chunks.length) { await delay$1(index === 0 ? initialDelayInMs : chunkDelayInMs); controller.enqueue(chunks[index++]); } else controller.close(); } }); } //#endregion //#region src/test/mock-embedding-model-v3.ts var MockEmbeddingModelV3 = class { constructor({ provider = "mock-provider", modelId = "mock-model-id", maxEmbeddingsPerCall = 1, supportsParallelCalls = false, doEmbed = notImplemented } = {}) { this.specificationVersion = "v3"; this.doEmbedCalls = []; this.provider = provider; this.modelId = modelId; this.maxEmbeddingsPerCall = maxEmbeddingsPerCall ?? void 0; this.supportsParallelCalls = supportsParallelCalls; this.doEmbed = async (options) => { this.doEmbedCalls.push(options); if (typeof doEmbed === "function") return doEmbed(options); else if (Array.isArray(doEmbed)) return doEmbed[this.doEmbedCalls.length - 1]; else return doEmbed; }; } }; //#endregion //#region src/test/mock-embedding-model-v4.ts var MockEmbeddingModelV4 = class { constructor({ provider = "mock-provider", modelId = "mock-model-id", maxEmbeddingsPerCall = 1, maxInputBytesPerCall, supportsParallelCalls = false, doEmbed = notImplemented } = {}) { this.specificationVersion = "v4"; this.doEmbedCalls = []; this.provider = provider; this.modelId = modelId; this.maxEmbeddingsPerCall = maxEmbeddingsPerCall ?? void 0; this[EXPERIMENTAL_EMBEDDING_MODEL_MAX_INPUT_BYTES_PER_CALL] = maxInputBytesPerCall; this.supportsParallelCalls = supportsParallelCalls; this.doEmbed = async (options) => { this.doEmbedCalls.push(options); if (typeof doEmbed === "function") return doEmbed(options); else if (Array.isArray(doEmbed)) return doEmbed[this.doEmbedCalls.length - 1]; else return doEmbed; }; } }; //#endregion //#region src/test/extraction-mock-model-v4.ts var ExtractionMockModelV4 = class { constructor({ provider = "mock-provider", modelId = "mock-model-id", supportedFieldTypes = [ "text", "number", "date", "time", "datetime", "duration", "list" ], doExtract = notImplemented } = {}) { this.specificationVersion = "v4"; this.provider = provider; this.modelId = modelId; this.supportedFieldTypes = supportedFieldTypes; this.doExtract = doExtract; } }; //#endregion //#region src/test/mock-image-model-v3.ts var MockImageModelV3 = class { constructor({ provider = "mock-provider", modelId = "mock-model-id", maxImagesPerCall = 1, doGenerate = notImplemented } = {}) { this.specificationVersion = "v3"; this.provider = provider; this.modelId = modelId; this.maxImagesPerCall = maxImagesPerCall; this.doGenerate = doGenerate; } }; //#endregion //#region src/test/mock-image-model-v4.ts var MockImageModelV4 = class { constructor({ provider = "mock-provider", modelId = "mock-model-id", maxImagesPerCall = 1, supportsFileInputs, supportsMaskInputs, doGenerate = notImplemented } = {}) { this.specificationVersion = "v4"; this.provider = provider; this.modelId = modelId; this.maxImagesPerCall = maxImagesPerCall; this.supportsFileInputs = supportsFileInputs; this.supportsMaskInputs = supportsMaskInputs; this.doGenerate = doGenerate; } }; //#endregion //#region src/test/mock-language-model-v3.ts var MockLanguageModelV3 = class { constructor({ provider = "mock-provider", modelId = "mock-model-id", supportedUrls = {}, doGenerate = notImplemented, doStream = notImplemented } = {}) { this.specificationVersion = "v3"; this.doGenerateCalls = []; this.doStreamCalls = []; this.provider = provider; this.modelId = modelId; this.doGenerate = async (options) => { this.doGenerateCalls.push(options); if (typeof doGenerate === "function") return await doGenerate(options); else if (Array.isArray(doGenerate)) return doGenerate[this.doGenerateCalls.length - 1]; else return doGenerate; }; this.doStream = async (options) => { this.doStreamCalls.push(options); if (typeof doStream === "function") return await doStream(options); else if (Array.isArray(doStream)) return doStream[this.doStreamCalls.length - 1]; else return doStream; }; this._supportedUrls = typeof supportedUrls === "function" ? supportedUrls : async () => await supportedUrls; } get supportedUrls() { return this._supportedUrls(); } }; //#endregion //#region src/test/mock-language-model-v4.ts var MockLanguageModelV4 = class { constructor({ provider = "mock-provider", modelId = "mock-model-id", supportedUrls = {}, doGenerate = notImplemented, doStream = notImplemented } = {}) { this.specificationVersion = "v4"; this.doGenerateCalls = []; this.doStreamCalls = []; this.provider = provider; this.modelId = modelId; this.doGenerate = async (options) => { this.doGenerateCalls.push(options); if (typeof doGenerate === "function") return await doGenerate(options); else if (Array.isArray(doGenerate)) return doGenerate[this.doGenerateCalls.length - 1]; else return doGenerate; }; this.doStream = async (options) => { this.doStreamCalls.push(options); if (typeof doStream === "function") return await doStream(options); else if (Array.isArray(doStream)) return doStream[this.doStreamCalls.length - 1]; else return doStream; }; this._supportedUrls = typeof supportedUrls === "function" ? supportedUrls : async () => await supportedUrls; } get supportedUrls() { return this._supportedUrls(); } }; //#endregion //#region src/test/mock-provider-v3.ts var MockProviderV3 = class { constructor({ languageModels, embeddingModels, imageModels, transcriptionModels, speechModels, rerankingModels } = {}) { this.specificationVersion = "v3"; this.languageModel = (modelId) => { if (!languageModels?.[modelId]) throw new NoSuchModelError({ modelId, modelType: "languageModel" }); return languageModels[modelId]; }; this.embeddingModel = (modelId) => { if (!embeddingModels?.[modelId]) throw new NoSuchModelError({ modelId, modelType: "embeddingModel" }); return embeddingModels[modelId]; }; this.imageModel = (modelId) => { if (!imageModels?.[modelId]) throw new NoSuchModelError({ modelId, modelType: "imageModel" }); return imageModels[modelId]; }; this.transcriptionModel = (modelId) => { if (!transcriptionModels?.[modelId]) throw new NoSuchModelError({ modelId, modelType: "transcriptionModel" }); return transcriptionModels[modelId]; }; this.speechModel = (modelId) => { if (!speechModels?.[modelId]) throw new NoSuchModelError({ modelId, modelType: "speechModel" }); return speechModels[modelId]; }; this.rerankingModel = (modelId) => { if (!rerankingModels?.[modelId]) throw new NoSuchModelError({ modelId, modelType: "rerankingModel" }); return rerankingModels[modelId]; }; } }; //#endregion //#region src/test/mock-provider-v4.ts var MockProviderV4 = class { constructor({ languageModels, embeddingModels, imageModels, transcriptionModels, speechModels, rerankingModels } = {}) { this.specificationVersion = "v4"; this.languageModel = (modelId) => { if (!languageModels?.[modelId]) throw new NoSuchModelError({ modelId, modelType: "languageModel" }); return languageModels[modelId]; }; this.embeddingModel = (modelId) => { if (!embeddingModels?.[modelId]) throw new NoSuchModelError({ modelId, modelType: "embeddingModel" }); return embeddingModels[modelId]; }; this.imageModel = (modelId) => { if (!imageModels?.[modelId]) throw new NoSuchModelError({ modelId, modelType: "imageModel" }); return imageModels[modelId]; }; this.transcriptionModel = (modelId) => { if (!transcriptionModels?.[modelId]) throw new NoSuchModelError({ modelId, modelType: "transcriptionModel" }); return transcriptionModels[modelId]; }; this.speechModel = (modelId) => { if (!speechModels?.[modelId]) throw new NoSuchModelError({ modelId, modelType: "speechModel" }); return speechModels[modelId]; }; this.rerankingModel = (modelId) => { if (!rerankingModels?.[modelId]) throw new NoSuchModelError({ modelId, modelType: "rerankingModel" }); return rerankingModels[modelId]; }; } }; //#endregion //#region src/test/mock-speech-model-v3.ts var MockSpeechModelV3 = class { constructor({ provider = "mock-provider", modelId = "mock-model-id", doGenerate = notImplemented } = {}) { this.specificationVersion = "v3"; this.provider = provider; this.modelId = modelId; this.doGenerate = doGenerate; } }; //#endregion //#region src/test/mock-speech-model-v4.ts var MockSpeechModelV4 = class { constructor({ provider = "mock-provider", modelId = "mock-model-id", doGenerate = notImplemented } = {}) { this.specificationVersion = "v4"; this.provider = provider; this.modelId = modelId; this.doGenerate = doGenerate; } }; //#endregion //#region src/test/mock-speech-translation-model-v4.ts var MockSpeechTranslationModelV4 = class { constructor({ provider = "mock-provider", modelId = "mock-model-id", doStream = notImplemented } = {}) { this.specificationVersion = "v4"; this.provider = provider; this.modelId = modelId; this.doStream = doStream; } }; //#endregion //#region src/test/mock-streaming-speech-model-v4.ts var MockStreamingSpeechModelV4 = class { constructor({ provider = "mock-provider", modelId = "mock-model-id", doGenerate = notImplemented, doStream = notImplemented } = {}) { this.specificationVersion = "v4"; this.provider = provider; this.modelId = modelId; this.doGenerate = doGenerate; this.doStream = doStream; } }; //#endregion //#region src/test/mock-transcription-model-v3.ts var MockTranscriptionModelV3 = class { constructor({ provider = "mock-provider", modelId = "mock-model-id", doGenerate = notImplemented } = {}) { this.specificationVersion = "v3"; this.provider = provider; this.modelId = modelId; this.doGenerate = doGenerate; } }; //#endregion //#region src/test/mock-transcription-model-v4.ts var MockTranscriptionModelV4 = class { constructor({ provider = "mock-provider", modelId = "mock-model-id", doGenerate = notImplemented, doStream, doGenerateFromUrl } = {}) { this.specificationVersion = "v4"; this.provider = provider; this.modelId = modelId; this.doGenerate = doGenerate; this.doStream = doStream; this.doGenerateFromUrl = doGenerateFromUrl; } }; //#endregion //#region src/test/mock-reranking-model-v3.ts var MockRerankingModelV3 = class { constructor({ provider = "mock-provider", modelId = "mock-model-id", doRerank = notImplemented } = {}) { this.specificationVersion = "v3"; this.provider = provider; this.modelId = modelId; this.doRerank = doRerank; } }; //#endregion //#region src/test/mock-reranking-model-v4.ts var MockRerankingModelV4 = class { constructor({ provider = "mock-provider", modelId = "mock-model-id", doRerank = notImplemented } = {}) { this.specificationVersion = "v4"; this.provider = provider; this.modelId = modelId; this.doRerank = doRerank; } }; //#endregion //#region src/test/mock-video-model-v3.ts var MockVideoModelV3 = class { constructor({ provider = "mock-provider", modelId = "mock-model-id", maxVideosPerCall = 1, doGenerate = notImplemented } = {}) { this.specificationVersion = "v3"; this.provider = provider; this.modelId = modelId; this.maxVideosPerCall = maxVideosPerCall; this.doGenerate = doGenerate; } }; //#endregion //#region src/test/mock-video-model-v4.ts var MockVideoModelV4 = class { constructor(options = {}) { this.specificationVersion = "v4"; this.provider = options.provider ?? "mock-provider"; this.modelId = options.modelId ?? "mock-model-id"; this.maxVideosPerCall = options.maxVideosPerCall ?? 1; this.doGenerate = "doGenerate" in options ? options.doGenerate : notImplemented; this.handleWebhookOption = options.handleWebhookOption; this.doStart = options.doStart; this.doStatus = options.doStatus; } }; //#endregion //#region src/test/mock-values.ts function mockValues(...values) { let counter = 0; return () => values[counter++] ?? values[values.length - 1]; } //#endregion //#region test/index.ts /** * @deprecated Use `simulateReadableStream` from `ai` instead. */ const simulateReadableStream = simulateReadableStream$1; /** @deprecated Use `Experimental_DecisionMockModelV4` instead. */ const Experimental_EvaluationMockModelV4 = DecisionMockModelV4; //#endregion export { DecisionMockModelV4 as Experimental_DecisionMockModelV4, Experimental_EvaluationMockModelV4, ExtractionMockModelV4 as Experimental_ExtractionMockModelV4, MockSpeechTranslationModelV4 as Experimental_MockSpeechTranslationModelV4, MockStreamingSpeechModelV4 as Experimental_MockStreamingSpeechModelV4, MockEmbeddingModelV3, MockEmbeddingModelV4, MockImageModelV3, MockImageModelV4, MockLanguageModelV3, MockLanguageModelV4, MockProviderV3, MockProviderV4, MockRerankingModelV3, MockRerankingModelV4, MockSpeechModelV3, MockSpeechModelV4, MockTranscriptionModelV3, MockTranscriptionModelV4, MockVideoModelV3, MockVideoModelV4, convertArrayToAsyncIterable, convertArrayToReadableStream, convertReadableStreamToArray, mockId, mockValues, simulateReadableStream }; //# sourceMappingURL=index.js.map