modelfusion 0.0.44
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/LICENSE +21 -0
- package/README.md +429 -0
- package/composed-function/index.cjs +22 -0
- package/composed-function/index.d.ts +6 -0
- package/composed-function/index.js +6 -0
- package/composed-function/summarize/SummarizationFunction.cjs +2 -0
- package/composed-function/summarize/SummarizationFunction.d.ts +4 -0
- package/composed-function/summarize/SummarizationFunction.js +1 -0
- package/composed-function/summarize/summarizeRecursively.cjs +19 -0
- package/composed-function/summarize/summarizeRecursively.d.ts +11 -0
- package/composed-function/summarize/summarizeRecursively.js +15 -0
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.cjs +29 -0
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.d.ts +24 -0
- package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.js +25 -0
- package/composed-function/use-tool/NoSuchToolError.cjs +17 -0
- package/composed-function/use-tool/NoSuchToolError.d.ts +4 -0
- package/composed-function/use-tool/NoSuchToolError.js +13 -0
- package/composed-function/use-tool/Tool.cjs +43 -0
- package/composed-function/use-tool/Tool.d.ts +15 -0
- package/composed-function/use-tool/Tool.js +39 -0
- package/composed-function/use-tool/useTool.cjs +59 -0
- package/composed-function/use-tool/useTool.d.ts +36 -0
- package/composed-function/use-tool/useTool.js +54 -0
- package/cost/Cost.cjs +38 -0
- package/cost/Cost.d.ts +16 -0
- package/cost/Cost.js +34 -0
- package/cost/CostCalculator.cjs +2 -0
- package/cost/CostCalculator.d.ts +8 -0
- package/cost/CostCalculator.js +1 -0
- package/cost/calculateCost.cjs +28 -0
- package/cost/calculateCost.d.ts +7 -0
- package/cost/calculateCost.js +24 -0
- package/cost/index.cjs +19 -0
- package/cost/index.d.ts +3 -0
- package/cost/index.js +3 -0
- package/index.cjs +25 -0
- package/index.d.ts +9 -0
- package/index.js +9 -0
- package/model-function/AbstractModel.cjs +22 -0
- package/model-function/AbstractModel.d.ts +12 -0
- package/model-function/AbstractModel.js +18 -0
- package/model-function/FunctionOptions.cjs +2 -0
- package/model-function/FunctionOptions.d.ts +6 -0
- package/model-function/FunctionOptions.js +1 -0
- package/model-function/Model.cjs +2 -0
- package/model-function/Model.d.ts +23 -0
- package/model-function/Model.js +1 -0
- package/model-function/ModelCallEvent.cjs +2 -0
- package/model-function/ModelCallEvent.d.ts +18 -0
- package/model-function/ModelCallEvent.js +1 -0
- package/model-function/ModelCallEventSource.cjs +42 -0
- package/model-function/ModelCallEventSource.d.ts +13 -0
- package/model-function/ModelCallEventSource.js +38 -0
- package/model-function/ModelCallObserver.cjs +2 -0
- package/model-function/ModelCallObserver.d.ts +5 -0
- package/model-function/ModelCallObserver.js +1 -0
- package/model-function/ModelInformation.cjs +2 -0
- package/model-function/ModelInformation.d.ts +4 -0
- package/model-function/ModelInformation.js +1 -0
- package/model-function/SuccessfulModelCall.cjs +22 -0
- package/model-function/SuccessfulModelCall.d.ts +9 -0
- package/model-function/SuccessfulModelCall.js +18 -0
- package/model-function/embed-text/TextEmbeddingEvent.cjs +2 -0
- package/model-function/embed-text/TextEmbeddingEvent.d.ts +23 -0
- package/model-function/embed-text/TextEmbeddingEvent.js +1 -0
- package/model-function/embed-text/TextEmbeddingModel.cjs +2 -0
- package/model-function/embed-text/TextEmbeddingModel.d.ts +18 -0
- package/model-function/embed-text/TextEmbeddingModel.js +1 -0
- package/model-function/embed-text/embedText.cjs +90 -0
- package/model-function/embed-text/embedText.d.ts +33 -0
- package/model-function/embed-text/embedText.js +85 -0
- package/model-function/executeCall.cjs +60 -0
- package/model-function/executeCall.d.ts +27 -0
- package/model-function/executeCall.js +56 -0
- package/model-function/generate-image/ImageGenerationEvent.cjs +2 -0
- package/model-function/generate-image/ImageGenerationEvent.d.ts +22 -0
- package/model-function/generate-image/ImageGenerationEvent.js +1 -0
- package/model-function/generate-image/ImageGenerationModel.cjs +2 -0
- package/model-function/generate-image/ImageGenerationModel.d.ts +8 -0
- package/model-function/generate-image/ImageGenerationModel.js +1 -0
- package/model-function/generate-image/generateImage.cjs +63 -0
- package/model-function/generate-image/generateImage.d.ts +23 -0
- package/model-function/generate-image/generateImage.js +59 -0
- package/model-function/generate-json/GenerateJsonModel.cjs +2 -0
- package/model-function/generate-json/GenerateJsonModel.d.ts +10 -0
- package/model-function/generate-json/GenerateJsonModel.js +1 -0
- package/model-function/generate-json/GenerateJsonOrTextModel.cjs +2 -0
- package/model-function/generate-json/GenerateJsonOrTextModel.d.ts +18 -0
- package/model-function/generate-json/GenerateJsonOrTextModel.js +1 -0
- package/model-function/generate-json/JsonGenerationEvent.cjs +2 -0
- package/model-function/generate-json/JsonGenerationEvent.d.ts +22 -0
- package/model-function/generate-json/JsonGenerationEvent.js +1 -0
- package/model-function/generate-json/NoSuchSchemaError.cjs +17 -0
- package/model-function/generate-json/NoSuchSchemaError.d.ts +4 -0
- package/model-function/generate-json/NoSuchSchemaError.js +13 -0
- package/model-function/generate-json/SchemaDefinition.cjs +2 -0
- package/model-function/generate-json/SchemaDefinition.d.ts +6 -0
- package/model-function/generate-json/SchemaDefinition.js +1 -0
- package/model-function/generate-json/SchemaValidationError.cjs +36 -0
- package/model-function/generate-json/SchemaValidationError.d.ts +11 -0
- package/model-function/generate-json/SchemaValidationError.js +32 -0
- package/model-function/generate-json/generateJson.cjs +61 -0
- package/model-function/generate-json/generateJson.d.ts +9 -0
- package/model-function/generate-json/generateJson.js +57 -0
- package/model-function/generate-json/generateJsonOrText.cjs +74 -0
- package/model-function/generate-json/generateJsonOrText.d.ts +25 -0
- package/model-function/generate-json/generateJsonOrText.js +70 -0
- package/model-function/generate-text/AsyncQueue.cjs +66 -0
- package/model-function/generate-text/AsyncQueue.d.ts +17 -0
- package/model-function/generate-text/AsyncQueue.js +62 -0
- package/model-function/generate-text/DeltaEvent.cjs +2 -0
- package/model-function/generate-text/DeltaEvent.d.ts +7 -0
- package/model-function/generate-text/DeltaEvent.js +1 -0
- package/model-function/generate-text/TextDeltaEventSource.cjs +54 -0
- package/model-function/generate-text/TextDeltaEventSource.d.ts +5 -0
- package/model-function/generate-text/TextDeltaEventSource.js +46 -0
- package/model-function/generate-text/TextGenerationEvent.cjs +2 -0
- package/model-function/generate-text/TextGenerationEvent.d.ts +22 -0
- package/model-function/generate-text/TextGenerationEvent.js +1 -0
- package/model-function/generate-text/TextGenerationModel.cjs +2 -0
- package/model-function/generate-text/TextGenerationModel.d.ts +42 -0
- package/model-function/generate-text/TextGenerationModel.js +1 -0
- package/model-function/generate-text/TextStreamingEvent.cjs +2 -0
- package/model-function/generate-text/TextStreamingEvent.d.ts +22 -0
- package/model-function/generate-text/TextStreamingEvent.js +1 -0
- package/model-function/generate-text/extractTextDeltas.cjs +23 -0
- package/model-function/generate-text/extractTextDeltas.d.ts +7 -0
- package/model-function/generate-text/extractTextDeltas.js +19 -0
- package/model-function/generate-text/generateText.cjs +67 -0
- package/model-function/generate-text/generateText.d.ts +20 -0
- package/model-function/generate-text/generateText.js +63 -0
- package/model-function/generate-text/parseEventSourceReadableStream.cjs +30 -0
- package/model-function/generate-text/parseEventSourceReadableStream.d.ts +8 -0
- package/model-function/generate-text/parseEventSourceReadableStream.js +26 -0
- package/model-function/generate-text/streamText.cjs +115 -0
- package/model-function/generate-text/streamText.d.ts +11 -0
- package/model-function/generate-text/streamText.js +111 -0
- package/model-function/index.cjs +47 -0
- package/model-function/index.d.ts +31 -0
- package/model-function/index.js +31 -0
- package/model-function/tokenize-text/Tokenizer.cjs +2 -0
- package/model-function/tokenize-text/Tokenizer.d.ts +19 -0
- package/model-function/tokenize-text/Tokenizer.js +1 -0
- package/model-function/tokenize-text/countTokens.cjs +10 -0
- package/model-function/tokenize-text/countTokens.d.ts +5 -0
- package/model-function/tokenize-text/countTokens.js +6 -0
- package/model-function/transcribe-audio/TranscriptionEvent.cjs +2 -0
- package/model-function/transcribe-audio/TranscriptionEvent.d.ts +22 -0
- package/model-function/transcribe-audio/TranscriptionEvent.js +1 -0
- package/model-function/transcribe-audio/TranscriptionModel.cjs +2 -0
- package/model-function/transcribe-audio/TranscriptionModel.d.ts +8 -0
- package/model-function/transcribe-audio/TranscriptionModel.js +1 -0
- package/model-function/transcribe-audio/transcribe.cjs +62 -0
- package/model-function/transcribe-audio/transcribe.d.ts +22 -0
- package/model-function/transcribe-audio/transcribe.js +58 -0
- package/model-provider/automatic1111/Automatic1111Error.cjs +39 -0
- package/model-provider/automatic1111/Automatic1111Error.d.ts +31 -0
- package/model-provider/automatic1111/Automatic1111Error.js +31 -0
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.cjs +76 -0
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.d.ts +54 -0
- package/model-provider/automatic1111/Automatic1111ImageGenerationModel.js +72 -0
- package/model-provider/automatic1111/index.cjs +20 -0
- package/model-provider/automatic1111/index.d.ts +2 -0
- package/model-provider/automatic1111/index.js +2 -0
- package/model-provider/cohere/CohereError.cjs +36 -0
- package/model-provider/cohere/CohereError.d.ts +22 -0
- package/model-provider/cohere/CohereError.js +28 -0
- package/model-provider/cohere/CohereTextEmbeddingModel.cjs +172 -0
- package/model-provider/cohere/CohereTextEmbeddingModel.d.ts +119 -0
- package/model-provider/cohere/CohereTextEmbeddingModel.js +165 -0
- package/model-provider/cohere/CohereTextGenerationModel.cjs +283 -0
- package/model-provider/cohere/CohereTextGenerationModel.d.ts +203 -0
- package/model-provider/cohere/CohereTextGenerationModel.js +276 -0
- package/model-provider/cohere/CohereTokenizer.cjs +136 -0
- package/model-provider/cohere/CohereTokenizer.d.ts +118 -0
- package/model-provider/cohere/CohereTokenizer.js +129 -0
- package/model-provider/cohere/index.cjs +22 -0
- package/model-provider/cohere/index.d.ts +4 -0
- package/model-provider/cohere/index.js +4 -0
- package/model-provider/huggingface/HuggingFaceError.cjs +52 -0
- package/model-provider/huggingface/HuggingFaceError.d.ts +22 -0
- package/model-provider/huggingface/HuggingFaceError.js +44 -0
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.cjs +174 -0
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.d.ts +75 -0
- package/model-provider/huggingface/HuggingFaceTextGenerationModel.js +167 -0
- package/model-provider/huggingface/index.cjs +20 -0
- package/model-provider/huggingface/index.d.ts +2 -0
- package/model-provider/huggingface/index.js +2 -0
- package/model-provider/index.cjs +22 -0
- package/model-provider/index.d.ts +6 -0
- package/model-provider/index.js +6 -0
- package/model-provider/llamacpp/LlamaCppError.cjs +52 -0
- package/model-provider/llamacpp/LlamaCppError.d.ts +22 -0
- package/model-provider/llamacpp/LlamaCppError.js +44 -0
- package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.cjs +96 -0
- package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.d.ts +40 -0
- package/model-provider/llamacpp/LlamaCppTextEmbeddingModel.js +89 -0
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.cjs +245 -0
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +399 -0
- package/model-provider/llamacpp/LlamaCppTextGenerationModel.js +238 -0
- package/model-provider/llamacpp/LlamaCppTokenizer.cjs +64 -0
- package/model-provider/llamacpp/LlamaCppTokenizer.d.ts +38 -0
- package/model-provider/llamacpp/LlamaCppTokenizer.js +57 -0
- package/model-provider/llamacpp/index.cjs +22 -0
- package/model-provider/llamacpp/index.d.ts +4 -0
- package/model-provider/llamacpp/index.js +4 -0
- package/model-provider/openai/OpenAICostCalculator.cjs +71 -0
- package/model-provider/openai/OpenAICostCalculator.d.ts +6 -0
- package/model-provider/openai/OpenAICostCalculator.js +67 -0
- package/model-provider/openai/OpenAIError.cjs +50 -0
- package/model-provider/openai/OpenAIError.d.ts +47 -0
- package/model-provider/openai/OpenAIError.js +42 -0
- package/model-provider/openai/OpenAIImageGenerationModel.cjs +124 -0
- package/model-provider/openai/OpenAIImageGenerationModel.d.ts +113 -0
- package/model-provider/openai/OpenAIImageGenerationModel.js +119 -0
- package/model-provider/openai/OpenAIModelSettings.cjs +2 -0
- package/model-provider/openai/OpenAIModelSettings.d.ts +8 -0
- package/model-provider/openai/OpenAIModelSettings.js +1 -0
- package/model-provider/openai/OpenAITextEmbeddingModel.cjs +171 -0
- package/model-provider/openai/OpenAITextEmbeddingModel.d.ts +122 -0
- package/model-provider/openai/OpenAITextEmbeddingModel.js +162 -0
- package/model-provider/openai/OpenAITextGenerationModel.cjs +326 -0
- package/model-provider/openai/OpenAITextGenerationModel.d.ts +254 -0
- package/model-provider/openai/OpenAITextGenerationModel.js +317 -0
- package/model-provider/openai/OpenAITranscriptionModel.cjs +195 -0
- package/model-provider/openai/OpenAITranscriptionModel.d.ts +196 -0
- package/model-provider/openai/OpenAITranscriptionModel.js +187 -0
- package/model-provider/openai/TikTokenTokenizer.cjs +86 -0
- package/model-provider/openai/TikTokenTokenizer.d.ts +35 -0
- package/model-provider/openai/TikTokenTokenizer.js +82 -0
- package/model-provider/openai/chat/OpenAIChatMessage.cjs +24 -0
- package/model-provider/openai/chat/OpenAIChatMessage.d.ts +26 -0
- package/model-provider/openai/chat/OpenAIChatMessage.js +21 -0
- package/model-provider/openai/chat/OpenAIChatModel.cjs +288 -0
- package/model-provider/openai/chat/OpenAIChatModel.d.ts +344 -0
- package/model-provider/openai/chat/OpenAIChatModel.js +279 -0
- package/model-provider/openai/chat/OpenAIChatPrompt.cjs +143 -0
- package/model-provider/openai/chat/OpenAIChatPrompt.d.ts +108 -0
- package/model-provider/openai/chat/OpenAIChatPrompt.js +135 -0
- package/model-provider/openai/chat/OpenAIChatStreamIterable.cjs +112 -0
- package/model-provider/openai/chat/OpenAIChatStreamIterable.d.ts +19 -0
- package/model-provider/openai/chat/OpenAIChatStreamIterable.js +105 -0
- package/model-provider/openai/chat/countOpenAIChatMessageTokens.cjs +28 -0
- package/model-provider/openai/chat/countOpenAIChatMessageTokens.d.ts +20 -0
- package/model-provider/openai/chat/countOpenAIChatMessageTokens.js +23 -0
- package/model-provider/openai/index.cjs +31 -0
- package/model-provider/openai/index.d.ts +13 -0
- package/model-provider/openai/index.js +12 -0
- package/model-provider/stability/StabilityError.cjs +36 -0
- package/model-provider/stability/StabilityError.d.ts +22 -0
- package/model-provider/stability/StabilityError.js +28 -0
- package/model-provider/stability/StabilityImageGenerationModel.cjs +133 -0
- package/model-provider/stability/StabilityImageGenerationModel.d.ts +95 -0
- package/model-provider/stability/StabilityImageGenerationModel.js +129 -0
- package/model-provider/stability/index.cjs +20 -0
- package/model-provider/stability/index.d.ts +2 -0
- package/model-provider/stability/index.js +2 -0
- package/package.json +87 -0
- package/prompt/InstructionPrompt.cjs +2 -0
- package/prompt/InstructionPrompt.d.ts +7 -0
- package/prompt/InstructionPrompt.js +1 -0
- package/prompt/Llama2PromptMapping.cjs +56 -0
- package/prompt/Llama2PromptMapping.d.ts +10 -0
- package/prompt/Llama2PromptMapping.js +51 -0
- package/prompt/OpenAIChatPromptMapping.cjs +62 -0
- package/prompt/OpenAIChatPromptMapping.d.ts +6 -0
- package/prompt/OpenAIChatPromptMapping.js +57 -0
- package/prompt/PromptMapping.cjs +2 -0
- package/prompt/PromptMapping.d.ts +7 -0
- package/prompt/PromptMapping.js +1 -0
- package/prompt/PromptMappingTextGenerationModel.cjs +88 -0
- package/prompt/PromptMappingTextGenerationModel.d.ts +26 -0
- package/prompt/PromptMappingTextGenerationModel.js +84 -0
- package/prompt/TextPromptMapping.cjs +50 -0
- package/prompt/TextPromptMapping.d.ts +14 -0
- package/prompt/TextPromptMapping.js +45 -0
- package/prompt/chat/ChatPrompt.cjs +2 -0
- package/prompt/chat/ChatPrompt.d.ts +33 -0
- package/prompt/chat/ChatPrompt.js +1 -0
- package/prompt/chat/trimChatPrompt.cjs +50 -0
- package/prompt/chat/trimChatPrompt.d.ts +19 -0
- package/prompt/chat/trimChatPrompt.js +46 -0
- package/prompt/chat/validateChatPrompt.cjs +36 -0
- package/prompt/chat/validateChatPrompt.d.ts +8 -0
- package/prompt/chat/validateChatPrompt.js +31 -0
- package/prompt/index.cjs +25 -0
- package/prompt/index.d.ts +9 -0
- package/prompt/index.js +9 -0
- package/run/ConsoleLogger.cjs +12 -0
- package/run/ConsoleLogger.d.ts +6 -0
- package/run/ConsoleLogger.js +8 -0
- package/run/DefaultRun.cjs +78 -0
- package/run/DefaultRun.d.ts +24 -0
- package/run/DefaultRun.js +74 -0
- package/run/IdMetadata.cjs +2 -0
- package/run/IdMetadata.d.ts +7 -0
- package/run/IdMetadata.js +1 -0
- package/run/Run.cjs +2 -0
- package/run/Run.d.ts +27 -0
- package/run/Run.js +1 -0
- package/run/RunFunction.cjs +2 -0
- package/run/RunFunction.d.ts +13 -0
- package/run/RunFunction.js +1 -0
- package/run/Vector.cjs +2 -0
- package/run/Vector.d.ts +5 -0
- package/run/Vector.js +1 -0
- package/run/index.cjs +22 -0
- package/run/index.d.ts +6 -0
- package/run/index.js +6 -0
- package/text-chunk/TextChunk.cjs +2 -0
- package/text-chunk/TextChunk.d.ts +3 -0
- package/text-chunk/TextChunk.js +1 -0
- package/text-chunk/index.cjs +22 -0
- package/text-chunk/index.d.ts +6 -0
- package/text-chunk/index.js +6 -0
- package/text-chunk/retrieve-text-chunks/TextChunkRetriever.cjs +2 -0
- package/text-chunk/retrieve-text-chunks/TextChunkRetriever.d.ts +8 -0
- package/text-chunk/retrieve-text-chunks/TextChunkRetriever.js +1 -0
- package/text-chunk/retrieve-text-chunks/retrieveTextChunks.cjs +10 -0
- package/text-chunk/retrieve-text-chunks/retrieveTextChunks.d.ts +6 -0
- package/text-chunk/retrieve-text-chunks/retrieveTextChunks.js +6 -0
- package/text-chunk/split/SplitFunction.cjs +2 -0
- package/text-chunk/split/SplitFunction.d.ts +4 -0
- package/text-chunk/split/SplitFunction.js +1 -0
- package/text-chunk/split/splitOnSeparator.cjs +12 -0
- package/text-chunk/split/splitOnSeparator.d.ts +8 -0
- package/text-chunk/split/splitOnSeparator.js +7 -0
- package/text-chunk/split/splitRecursively.cjs +41 -0
- package/text-chunk/split/splitRecursively.d.ts +22 -0
- package/text-chunk/split/splitRecursively.js +33 -0
- package/util/DurationMeasurement.cjs +42 -0
- package/util/DurationMeasurement.d.ts +5 -0
- package/util/DurationMeasurement.js +38 -0
- package/util/ErrorHandler.cjs +2 -0
- package/util/ErrorHandler.d.ts +1 -0
- package/util/ErrorHandler.js +1 -0
- package/util/SafeResult.cjs +2 -0
- package/util/SafeResult.d.ts +8 -0
- package/util/SafeResult.js +1 -0
- package/util/api/AbortError.cjs +9 -0
- package/util/api/AbortError.d.ts +3 -0
- package/util/api/AbortError.js +5 -0
- package/util/api/ApiCallError.cjs +45 -0
- package/util/api/ApiCallError.d.ts +15 -0
- package/util/api/ApiCallError.js +41 -0
- package/util/api/RetryError.cjs +24 -0
- package/util/api/RetryError.d.ts +10 -0
- package/util/api/RetryError.js +20 -0
- package/util/api/RetryFunction.cjs +2 -0
- package/util/api/RetryFunction.d.ts +1 -0
- package/util/api/RetryFunction.js +1 -0
- package/util/api/ThrottleFunction.cjs +2 -0
- package/util/api/ThrottleFunction.d.ts +1 -0
- package/util/api/ThrottleFunction.js +1 -0
- package/util/api/callWithRetryAndThrottle.cjs +7 -0
- package/util/api/callWithRetryAndThrottle.d.ts +7 -0
- package/util/api/callWithRetryAndThrottle.js +3 -0
- package/util/api/postToApi.cjs +103 -0
- package/util/api/postToApi.d.ts +29 -0
- package/util/api/postToApi.js +96 -0
- package/util/api/retryNever.cjs +8 -0
- package/util/api/retryNever.d.ts +4 -0
- package/util/api/retryNever.js +4 -0
- package/util/api/retryWithExponentialBackoff.cjs +48 -0
- package/util/api/retryWithExponentialBackoff.d.ts +10 -0
- package/util/api/retryWithExponentialBackoff.js +44 -0
- package/util/api/throttleMaxConcurrency.cjs +65 -0
- package/util/api/throttleMaxConcurrency.d.ts +7 -0
- package/util/api/throttleMaxConcurrency.js +61 -0
- package/util/api/throttleUnlimitedConcurrency.cjs +8 -0
- package/util/api/throttleUnlimitedConcurrency.d.ts +5 -0
- package/util/api/throttleUnlimitedConcurrency.js +4 -0
- package/util/cosineSimilarity.cjs +26 -0
- package/util/cosineSimilarity.d.ts +11 -0
- package/util/cosineSimilarity.js +22 -0
- package/util/index.cjs +26 -0
- package/util/index.d.ts +10 -0
- package/util/index.js +10 -0
- package/util/never.cjs +6 -0
- package/util/never.d.ts +1 -0
- package/util/never.js +2 -0
- package/util/runSafe.cjs +15 -0
- package/util/runSafe.d.ts +2 -0
- package/util/runSafe.js +11 -0
- package/vector-index/VectorIndex.cjs +2 -0
- package/vector-index/VectorIndex.d.ts +18 -0
- package/vector-index/VectorIndex.js +1 -0
- package/vector-index/VectorIndexSimilarTextChunkRetriever.cjs +57 -0
- package/vector-index/VectorIndexSimilarTextChunkRetriever.d.ts +20 -0
- package/vector-index/VectorIndexSimilarTextChunkRetriever.js +53 -0
- package/vector-index/VectorIndexTextChunkStore.cjs +77 -0
- package/vector-index/VectorIndexTextChunkStore.d.ts +35 -0
- package/vector-index/VectorIndexTextChunkStore.js +73 -0
- package/vector-index/index.cjs +22 -0
- package/vector-index/index.d.ts +6 -0
- package/vector-index/index.js +6 -0
- package/vector-index/memory/MemoryVectorIndex.cjs +63 -0
- package/vector-index/memory/MemoryVectorIndex.d.ts +31 -0
- package/vector-index/memory/MemoryVectorIndex.js +56 -0
- package/vector-index/pinecone/PineconeVectorIndex.cjs +66 -0
- package/vector-index/pinecone/PineconeVectorIndex.d.ts +29 -0
- package/vector-index/pinecone/PineconeVectorIndex.js +62 -0
- package/vector-index/upsertTextChunks.cjs +15 -0
- package/vector-index/upsertTextChunks.d.ts +11 -0
- package/vector-index/upsertTextChunks.js +11 -0
@@ -0,0 +1,63 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.generateImage = void 0;
|
4
|
+
const executeCall_js_1 = require("../executeCall.cjs");
|
5
|
+
/**
|
6
|
+
* Generates a base64-encoded image using a prompt.
|
7
|
+
* The prompt format depends on the model.
|
8
|
+
* For example, OpenAI image models expect a string prompt,
|
9
|
+
* and Stability AI models expect an array of text prompts with optional weights.
|
10
|
+
*
|
11
|
+
* @example
|
12
|
+
* const { image } = await generateImage(
|
13
|
+
* new StabilityImageGenerationModel(...),
|
14
|
+
* [
|
15
|
+
* { text: "the wicked witch of the west" },
|
16
|
+
* { text: "style of early 19th century painting", weight: 0.5 },
|
17
|
+
* ]
|
18
|
+
* );
|
19
|
+
*/
|
20
|
+
async function generateImage(model, prompt, options) {
|
21
|
+
const result = await (0, executeCall_js_1.executeCall)({
|
22
|
+
model,
|
23
|
+
options,
|
24
|
+
generateResponse: (options) => model.generateImageResponse(prompt, options),
|
25
|
+
extractOutputValue: model.extractBase64Image,
|
26
|
+
getStartEvent: (metadata, settings) => ({
|
27
|
+
type: "image-generation-started",
|
28
|
+
metadata,
|
29
|
+
settings,
|
30
|
+
prompt,
|
31
|
+
}),
|
32
|
+
getAbortEvent: (metadata, settings) => ({
|
33
|
+
type: "image-generation-finished",
|
34
|
+
status: "abort",
|
35
|
+
metadata,
|
36
|
+
settings,
|
37
|
+
prompt,
|
38
|
+
}),
|
39
|
+
getFailureEvent: (metadata, settings, error) => ({
|
40
|
+
type: "image-generation-finished",
|
41
|
+
status: "failure",
|
42
|
+
metadata,
|
43
|
+
settings,
|
44
|
+
prompt,
|
45
|
+
error,
|
46
|
+
}),
|
47
|
+
getSuccessEvent: (metadata, settings, response, output) => ({
|
48
|
+
type: "image-generation-finished",
|
49
|
+
status: "success",
|
50
|
+
metadata,
|
51
|
+
settings,
|
52
|
+
prompt,
|
53
|
+
response,
|
54
|
+
generatedImage: output,
|
55
|
+
}),
|
56
|
+
});
|
57
|
+
return {
|
58
|
+
image: result.output,
|
59
|
+
response: result.response,
|
60
|
+
metadata: result.metadata,
|
61
|
+
};
|
62
|
+
}
|
63
|
+
exports.generateImage = generateImage;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { FunctionOptions } from "../FunctionOptions.js";
|
2
|
+
import { CallMetadata } from "../executeCall.js";
|
3
|
+
import { ImageGenerationModel, ImageGenerationModelSettings } from "./ImageGenerationModel.js";
|
4
|
+
/**
|
5
|
+
* Generates a base64-encoded image using a prompt.
|
6
|
+
* The prompt format depends on the model.
|
7
|
+
* For example, OpenAI image models expect a string prompt,
|
8
|
+
* and Stability AI models expect an array of text prompts with optional weights.
|
9
|
+
*
|
10
|
+
* @example
|
11
|
+
* const { image } = await generateImage(
|
12
|
+
* new StabilityImageGenerationModel(...),
|
13
|
+
* [
|
14
|
+
* { text: "the wicked witch of the west" },
|
15
|
+
* { text: "style of early 19th century painting", weight: 0.5 },
|
16
|
+
* ]
|
17
|
+
* );
|
18
|
+
*/
|
19
|
+
export declare function generateImage<PROMPT, RESPONSE, SETTINGS extends ImageGenerationModelSettings>(model: ImageGenerationModel<PROMPT, RESPONSE, SETTINGS>, prompt: PROMPT, options?: FunctionOptions<SETTINGS>): Promise<{
|
20
|
+
image: string;
|
21
|
+
response: RESPONSE;
|
22
|
+
metadata: CallMetadata<ImageGenerationModel<PROMPT, RESPONSE, SETTINGS>>;
|
23
|
+
}>;
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import { executeCall } from "../executeCall.js";
|
2
|
+
/**
|
3
|
+
* Generates a base64-encoded image using a prompt.
|
4
|
+
* The prompt format depends on the model.
|
5
|
+
* For example, OpenAI image models expect a string prompt,
|
6
|
+
* and Stability AI models expect an array of text prompts with optional weights.
|
7
|
+
*
|
8
|
+
* @example
|
9
|
+
* const { image } = await generateImage(
|
10
|
+
* new StabilityImageGenerationModel(...),
|
11
|
+
* [
|
12
|
+
* { text: "the wicked witch of the west" },
|
13
|
+
* { text: "style of early 19th century painting", weight: 0.5 },
|
14
|
+
* ]
|
15
|
+
* );
|
16
|
+
*/
|
17
|
+
export async function generateImage(model, prompt, options) {
|
18
|
+
const result = await executeCall({
|
19
|
+
model,
|
20
|
+
options,
|
21
|
+
generateResponse: (options) => model.generateImageResponse(prompt, options),
|
22
|
+
extractOutputValue: model.extractBase64Image,
|
23
|
+
getStartEvent: (metadata, settings) => ({
|
24
|
+
type: "image-generation-started",
|
25
|
+
metadata,
|
26
|
+
settings,
|
27
|
+
prompt,
|
28
|
+
}),
|
29
|
+
getAbortEvent: (metadata, settings) => ({
|
30
|
+
type: "image-generation-finished",
|
31
|
+
status: "abort",
|
32
|
+
metadata,
|
33
|
+
settings,
|
34
|
+
prompt,
|
35
|
+
}),
|
36
|
+
getFailureEvent: (metadata, settings, error) => ({
|
37
|
+
type: "image-generation-finished",
|
38
|
+
status: "failure",
|
39
|
+
metadata,
|
40
|
+
settings,
|
41
|
+
prompt,
|
42
|
+
error,
|
43
|
+
}),
|
44
|
+
getSuccessEvent: (metadata, settings, response, output) => ({
|
45
|
+
type: "image-generation-finished",
|
46
|
+
status: "success",
|
47
|
+
metadata,
|
48
|
+
settings,
|
49
|
+
prompt,
|
50
|
+
response,
|
51
|
+
generatedImage: output,
|
52
|
+
}),
|
53
|
+
});
|
54
|
+
return {
|
55
|
+
image: result.output,
|
56
|
+
response: result.response,
|
57
|
+
metadata: result.metadata,
|
58
|
+
};
|
59
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { FunctionOptions } from "../FunctionOptions.js";
|
2
|
+
import { Model, ModelSettings } from "../Model.js";
|
3
|
+
export interface GenerateJsonModelSettings extends ModelSettings {
|
4
|
+
}
|
5
|
+
export interface GenerateJsonPrompt<RESPONSE> {
|
6
|
+
extractJson(response: RESPONSE): unknown;
|
7
|
+
}
|
8
|
+
export interface GenerateJsonModel<PROMPT, RESPONSE, SETTINGS extends GenerateJsonModelSettings> extends Model<SETTINGS> {
|
9
|
+
generateJsonResponse(prompt: PROMPT & GenerateJsonPrompt<RESPONSE>, options?: FunctionOptions<SETTINGS>): PromiseLike<RESPONSE>;
|
10
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { FunctionOptions } from "../FunctionOptions.js";
|
2
|
+
import { Model, ModelSettings } from "../Model.js";
|
3
|
+
export interface GenerateJsonOrTextModelSettings extends ModelSettings {
|
4
|
+
}
|
5
|
+
export interface GenerateJsonOrTextPrompt<RESPONSE> {
|
6
|
+
extractJsonAndText(response: RESPONSE): {
|
7
|
+
schema: null;
|
8
|
+
value: null;
|
9
|
+
text: string;
|
10
|
+
} | {
|
11
|
+
schema: string;
|
12
|
+
value: unknown;
|
13
|
+
text: string | null;
|
14
|
+
};
|
15
|
+
}
|
16
|
+
export interface GenerateJsonOrTextModel<PROMPT, RESPONSE, SETTINGS extends GenerateJsonOrTextModelSettings> extends Model<SETTINGS> {
|
17
|
+
generateJsonResponse(prompt: PROMPT & GenerateJsonOrTextPrompt<RESPONSE>, options?: FunctionOptions<SETTINGS>): PromiseLike<RESPONSE>;
|
18
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import { ModelCallFinishedEventMetadata, ModelCallStartedEventMetadata } from "../ModelCallEvent.js";
|
2
|
+
export type JsonGenerationStartedEvent = {
|
3
|
+
type: "json-generation-started";
|
4
|
+
metadata: ModelCallStartedEventMetadata;
|
5
|
+
settings: unknown;
|
6
|
+
prompt: unknown;
|
7
|
+
};
|
8
|
+
export type JsonGenerationFinishedEvent = {
|
9
|
+
type: "json-generation-finished";
|
10
|
+
metadata: ModelCallFinishedEventMetadata;
|
11
|
+
settings: unknown;
|
12
|
+
prompt: unknown;
|
13
|
+
} & ({
|
14
|
+
status: "success";
|
15
|
+
response: unknown;
|
16
|
+
generatedJson: unknown;
|
17
|
+
} | {
|
18
|
+
status: "failure";
|
19
|
+
error: unknown;
|
20
|
+
} | {
|
21
|
+
status: "abort";
|
22
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.NoSuchSchemaError = void 0;
|
4
|
+
class NoSuchSchemaError extends Error {
|
5
|
+
constructor(schemaName) {
|
6
|
+
super(`No such schema: ${schemaName}`);
|
7
|
+
Object.defineProperty(this, "schemaName", {
|
8
|
+
enumerable: true,
|
9
|
+
configurable: true,
|
10
|
+
writable: true,
|
11
|
+
value: void 0
|
12
|
+
});
|
13
|
+
this.name = "NoSuchSchemaError";
|
14
|
+
this.schemaName = schemaName;
|
15
|
+
}
|
16
|
+
}
|
17
|
+
exports.NoSuchSchemaError = NoSuchSchemaError;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
export class NoSuchSchemaError extends Error {
|
2
|
+
constructor(schemaName) {
|
3
|
+
super(`No such schema: ${schemaName}`);
|
4
|
+
Object.defineProperty(this, "schemaName", {
|
5
|
+
enumerable: true,
|
6
|
+
configurable: true,
|
7
|
+
writable: true,
|
8
|
+
value: void 0
|
9
|
+
});
|
10
|
+
this.name = "NoSuchSchemaError";
|
11
|
+
this.schemaName = schemaName;
|
12
|
+
}
|
13
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,36 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.SchemaValidationError = void 0;
|
4
|
+
class SchemaValidationError extends Error {
|
5
|
+
constructor({ schemaName, value, errors, }) {
|
6
|
+
super(`Schema validation error for '${schemaName}'. ` +
|
7
|
+
`Value: ${JSON.stringify(value)}.\n` +
|
8
|
+
`Error details: ${errors.message}\n` +
|
9
|
+
`Error field(s): ${errors.errors
|
10
|
+
.map((err) => err.path.join("."))
|
11
|
+
.join(", ")}`);
|
12
|
+
Object.defineProperty(this, "schemaName", {
|
13
|
+
enumerable: true,
|
14
|
+
configurable: true,
|
15
|
+
writable: true,
|
16
|
+
value: void 0
|
17
|
+
});
|
18
|
+
Object.defineProperty(this, "errors", {
|
19
|
+
enumerable: true,
|
20
|
+
configurable: true,
|
21
|
+
writable: true,
|
22
|
+
value: void 0
|
23
|
+
});
|
24
|
+
Object.defineProperty(this, "value", {
|
25
|
+
enumerable: true,
|
26
|
+
configurable: true,
|
27
|
+
writable: true,
|
28
|
+
value: void 0
|
29
|
+
});
|
30
|
+
this.name = "SchemaValidationError";
|
31
|
+
this.schemaName = schemaName;
|
32
|
+
this.errors = errors;
|
33
|
+
this.value = value;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
exports.SchemaValidationError = SchemaValidationError;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { z } from "zod";
|
2
|
+
export declare class SchemaValidationError extends Error {
|
3
|
+
readonly schemaName: string;
|
4
|
+
readonly errors: z.ZodError;
|
5
|
+
readonly value: unknown;
|
6
|
+
constructor({ schemaName, value, errors, }: {
|
7
|
+
schemaName: string;
|
8
|
+
value: unknown;
|
9
|
+
errors: z.ZodError;
|
10
|
+
});
|
11
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
export class SchemaValidationError extends Error {
|
2
|
+
constructor({ schemaName, value, errors, }) {
|
3
|
+
super(`Schema validation error for '${schemaName}'. ` +
|
4
|
+
`Value: ${JSON.stringify(value)}.\n` +
|
5
|
+
`Error details: ${errors.message}\n` +
|
6
|
+
`Error field(s): ${errors.errors
|
7
|
+
.map((err) => err.path.join("."))
|
8
|
+
.join(", ")}`);
|
9
|
+
Object.defineProperty(this, "schemaName", {
|
10
|
+
enumerable: true,
|
11
|
+
configurable: true,
|
12
|
+
writable: true,
|
13
|
+
value: void 0
|
14
|
+
});
|
15
|
+
Object.defineProperty(this, "errors", {
|
16
|
+
enumerable: true,
|
17
|
+
configurable: true,
|
18
|
+
writable: true,
|
19
|
+
value: void 0
|
20
|
+
});
|
21
|
+
Object.defineProperty(this, "value", {
|
22
|
+
enumerable: true,
|
23
|
+
configurable: true,
|
24
|
+
writable: true,
|
25
|
+
value: void 0
|
26
|
+
});
|
27
|
+
this.name = "SchemaValidationError";
|
28
|
+
this.schemaName = schemaName;
|
29
|
+
this.errors = errors;
|
30
|
+
this.value = value;
|
31
|
+
}
|
32
|
+
}
|
@@ -0,0 +1,61 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.generateJson = void 0;
|
4
|
+
const executeCall_js_1 = require("../executeCall.cjs");
|
5
|
+
const SchemaValidationError_js_1 = require("./SchemaValidationError.cjs");
|
6
|
+
async function generateJson(model, schemaDefinition, prompt, options) {
|
7
|
+
const expandedPrompt = prompt(schemaDefinition);
|
8
|
+
const result = await (0, executeCall_js_1.executeCall)({
|
9
|
+
model,
|
10
|
+
options,
|
11
|
+
generateResponse: (options) => model.generateJsonResponse(expandedPrompt, options),
|
12
|
+
extractOutputValue: (response) => {
|
13
|
+
const json = expandedPrompt.extractJson(response);
|
14
|
+
const parseResult = schemaDefinition.schema.safeParse(json);
|
15
|
+
if (!parseResult.success) {
|
16
|
+
throw new SchemaValidationError_js_1.SchemaValidationError({
|
17
|
+
schemaName: schemaDefinition.name,
|
18
|
+
value: json,
|
19
|
+
errors: parseResult.error,
|
20
|
+
});
|
21
|
+
}
|
22
|
+
return parseResult.data;
|
23
|
+
},
|
24
|
+
getStartEvent: (metadata, settings) => ({
|
25
|
+
type: "json-generation-started",
|
26
|
+
metadata,
|
27
|
+
settings,
|
28
|
+
prompt,
|
29
|
+
}),
|
30
|
+
getAbortEvent: (metadata, settings) => ({
|
31
|
+
type: "json-generation-finished",
|
32
|
+
status: "abort",
|
33
|
+
metadata,
|
34
|
+
settings,
|
35
|
+
prompt,
|
36
|
+
}),
|
37
|
+
getFailureEvent: (metadata, settings, error) => ({
|
38
|
+
type: "json-generation-finished",
|
39
|
+
status: "failure",
|
40
|
+
metadata,
|
41
|
+
settings,
|
42
|
+
prompt,
|
43
|
+
error,
|
44
|
+
}),
|
45
|
+
getSuccessEvent: (metadata, settings, response, output) => ({
|
46
|
+
type: "json-generation-finished",
|
47
|
+
status: "success",
|
48
|
+
metadata,
|
49
|
+
settings,
|
50
|
+
prompt,
|
51
|
+
response,
|
52
|
+
generatedJson: output,
|
53
|
+
}),
|
54
|
+
});
|
55
|
+
return {
|
56
|
+
value: result.output,
|
57
|
+
response: result.response,
|
58
|
+
metadata: result.metadata,
|
59
|
+
};
|
60
|
+
}
|
61
|
+
exports.generateJson = generateJson;
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { FunctionOptions } from "../FunctionOptions.js";
|
2
|
+
import { CallMetadata } from "../executeCall.js";
|
3
|
+
import { GenerateJsonModel, GenerateJsonModelSettings, GenerateJsonPrompt } from "./GenerateJsonModel.js";
|
4
|
+
import { SchemaDefinition } from "./SchemaDefinition.js";
|
5
|
+
export declare function generateJson<STRUCTURE, PROMPT, RESPONSE, NAME extends string, SETTINGS extends GenerateJsonModelSettings>(model: GenerateJsonModel<PROMPT, RESPONSE, SETTINGS>, schemaDefinition: SchemaDefinition<NAME, STRUCTURE>, prompt: (schemaDefinition: SchemaDefinition<NAME, STRUCTURE>) => PROMPT & GenerateJsonPrompt<RESPONSE>, options?: FunctionOptions<SETTINGS>): Promise<{
|
6
|
+
value: STRUCTURE;
|
7
|
+
response: RESPONSE;
|
8
|
+
metadata: CallMetadata<GenerateJsonModel<PROMPT, RESPONSE, SETTINGS>>;
|
9
|
+
}>;
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import { executeCall } from "../executeCall.js";
|
2
|
+
import { SchemaValidationError } from "./SchemaValidationError.js";
|
3
|
+
export async function generateJson(model, schemaDefinition, prompt, options) {
|
4
|
+
const expandedPrompt = prompt(schemaDefinition);
|
5
|
+
const result = await executeCall({
|
6
|
+
model,
|
7
|
+
options,
|
8
|
+
generateResponse: (options) => model.generateJsonResponse(expandedPrompt, options),
|
9
|
+
extractOutputValue: (response) => {
|
10
|
+
const json = expandedPrompt.extractJson(response);
|
11
|
+
const parseResult = schemaDefinition.schema.safeParse(json);
|
12
|
+
if (!parseResult.success) {
|
13
|
+
throw new SchemaValidationError({
|
14
|
+
schemaName: schemaDefinition.name,
|
15
|
+
value: json,
|
16
|
+
errors: parseResult.error,
|
17
|
+
});
|
18
|
+
}
|
19
|
+
return parseResult.data;
|
20
|
+
},
|
21
|
+
getStartEvent: (metadata, settings) => ({
|
22
|
+
type: "json-generation-started",
|
23
|
+
metadata,
|
24
|
+
settings,
|
25
|
+
prompt,
|
26
|
+
}),
|
27
|
+
getAbortEvent: (metadata, settings) => ({
|
28
|
+
type: "json-generation-finished",
|
29
|
+
status: "abort",
|
30
|
+
metadata,
|
31
|
+
settings,
|
32
|
+
prompt,
|
33
|
+
}),
|
34
|
+
getFailureEvent: (metadata, settings, error) => ({
|
35
|
+
type: "json-generation-finished",
|
36
|
+
status: "failure",
|
37
|
+
metadata,
|
38
|
+
settings,
|
39
|
+
prompt,
|
40
|
+
error,
|
41
|
+
}),
|
42
|
+
getSuccessEvent: (metadata, settings, response, output) => ({
|
43
|
+
type: "json-generation-finished",
|
44
|
+
status: "success",
|
45
|
+
metadata,
|
46
|
+
settings,
|
47
|
+
prompt,
|
48
|
+
response,
|
49
|
+
generatedJson: output,
|
50
|
+
}),
|
51
|
+
});
|
52
|
+
return {
|
53
|
+
value: result.output,
|
54
|
+
response: result.response,
|
55
|
+
metadata: result.metadata,
|
56
|
+
};
|
57
|
+
}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.generateJsonOrText = void 0;
|
4
|
+
const executeCall_js_1 = require("../executeCall.cjs");
|
5
|
+
const NoSuchSchemaError_js_1 = require("./NoSuchSchemaError.cjs");
|
6
|
+
const SchemaValidationError_js_1 = require("./SchemaValidationError.cjs");
|
7
|
+
async function generateJsonOrText(model, schemaDefinitions, prompt, options) {
|
8
|
+
const expandedPrompt = prompt(schemaDefinitions);
|
9
|
+
const result = await (0, executeCall_js_1.executeCall)({
|
10
|
+
model,
|
11
|
+
options,
|
12
|
+
generateResponse: (options) => model.generateJsonResponse(expandedPrompt, options),
|
13
|
+
extractOutputValue: (response) => {
|
14
|
+
const { schema, value, text } = expandedPrompt.extractJsonAndText(response);
|
15
|
+
// text generation:
|
16
|
+
if (schema == null) {
|
17
|
+
return { schema, value, text };
|
18
|
+
}
|
19
|
+
const definition = schemaDefinitions.find((d) => d.name === schema);
|
20
|
+
if (definition == undefined) {
|
21
|
+
throw new NoSuchSchemaError_js_1.NoSuchSchemaError(schema);
|
22
|
+
}
|
23
|
+
const parseResult = definition.schema.safeParse(value);
|
24
|
+
if (!parseResult.success) {
|
25
|
+
throw new SchemaValidationError_js_1.SchemaValidationError({
|
26
|
+
schemaName: schema,
|
27
|
+
value,
|
28
|
+
errors: parseResult.error,
|
29
|
+
});
|
30
|
+
}
|
31
|
+
return {
|
32
|
+
schema: schema,
|
33
|
+
value: parseResult.data,
|
34
|
+
text: text, // text is string | null, which is part of the response for schema values
|
35
|
+
};
|
36
|
+
},
|
37
|
+
getStartEvent: (metadata, settings) => ({
|
38
|
+
type: "json-generation-started",
|
39
|
+
metadata,
|
40
|
+
settings,
|
41
|
+
prompt,
|
42
|
+
}),
|
43
|
+
getAbortEvent: (metadata, settings) => ({
|
44
|
+
type: "json-generation-finished",
|
45
|
+
status: "abort",
|
46
|
+
metadata,
|
47
|
+
settings,
|
48
|
+
prompt,
|
49
|
+
}),
|
50
|
+
getFailureEvent: (metadata, settings, error) => ({
|
51
|
+
type: "json-generation-finished",
|
52
|
+
status: "failure",
|
53
|
+
metadata,
|
54
|
+
settings,
|
55
|
+
prompt,
|
56
|
+
error,
|
57
|
+
}),
|
58
|
+
getSuccessEvent: (metadata, settings, response, output) => ({
|
59
|
+
type: "json-generation-finished",
|
60
|
+
status: "success",
|
61
|
+
metadata,
|
62
|
+
settings,
|
63
|
+
prompt,
|
64
|
+
response,
|
65
|
+
generatedJson: output,
|
66
|
+
}),
|
67
|
+
});
|
68
|
+
return {
|
69
|
+
...result.output,
|
70
|
+
response: result.response,
|
71
|
+
metadata: result.metadata,
|
72
|
+
};
|
73
|
+
}
|
74
|
+
exports.generateJsonOrText = generateJsonOrText;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { FunctionOptions } from "../FunctionOptions.js";
|
2
|
+
import { CallMetadata } from "../executeCall.js";
|
3
|
+
import { GenerateJsonOrTextModel, GenerateJsonOrTextModelSettings, GenerateJsonOrTextPrompt } from "./GenerateJsonOrTextModel.js";
|
4
|
+
import { SchemaDefinition } from "./SchemaDefinition.js";
|
5
|
+
type SchemaDefinitionArray<T extends SchemaDefinition<any, any>[]> = T;
|
6
|
+
type ToSchemaDefinitionsMap<T extends SchemaDefinitionArray<SchemaDefinition<any, any>[]>> = {
|
7
|
+
[K in T[number]["name"]]: Extract<T[number], SchemaDefinition<K, any>>;
|
8
|
+
};
|
9
|
+
type ToSchemaUnion<T> = {
|
10
|
+
[KEY in keyof T]: T[KEY] extends SchemaDefinition<any, infer SCHEMA> ? {
|
11
|
+
schema: KEY;
|
12
|
+
value: SCHEMA;
|
13
|
+
text: string | null;
|
14
|
+
} : never;
|
15
|
+
}[keyof T];
|
16
|
+
type ToOutputValue<SCHEMAS extends SchemaDefinitionArray<SchemaDefinition<any, any>[]>> = ToSchemaUnion<ToSchemaDefinitionsMap<SCHEMAS>>;
|
17
|
+
export declare function generateJsonOrText<SCHEMAS extends SchemaDefinition<any, any>[], PROMPT, RESPONSE, SETTINGS extends GenerateJsonOrTextModelSettings>(model: GenerateJsonOrTextModel<PROMPT, RESPONSE, SETTINGS>, schemaDefinitions: SCHEMAS, prompt: (schemaDefinitions: SCHEMAS) => PROMPT & GenerateJsonOrTextPrompt<RESPONSE>, options?: FunctionOptions<SETTINGS>): Promise<({
|
18
|
+
schema: null;
|
19
|
+
value: null;
|
20
|
+
text: string;
|
21
|
+
} | ToOutputValue<SCHEMAS>) & {
|
22
|
+
response: RESPONSE;
|
23
|
+
metadata: CallMetadata<GenerateJsonOrTextModel<PROMPT, RESPONSE, SETTINGS>>;
|
24
|
+
}>;
|
25
|
+
export {};
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import { executeCall } from "../executeCall.js";
|
2
|
+
import { NoSuchSchemaError } from "./NoSuchSchemaError.js";
|
3
|
+
import { SchemaValidationError } from "./SchemaValidationError.js";
|
4
|
+
export async function generateJsonOrText(model, schemaDefinitions, prompt, options) {
|
5
|
+
const expandedPrompt = prompt(schemaDefinitions);
|
6
|
+
const result = await executeCall({
|
7
|
+
model,
|
8
|
+
options,
|
9
|
+
generateResponse: (options) => model.generateJsonResponse(expandedPrompt, options),
|
10
|
+
extractOutputValue: (response) => {
|
11
|
+
const { schema, value, text } = expandedPrompt.extractJsonAndText(response);
|
12
|
+
// text generation:
|
13
|
+
if (schema == null) {
|
14
|
+
return { schema, value, text };
|
15
|
+
}
|
16
|
+
const definition = schemaDefinitions.find((d) => d.name === schema);
|
17
|
+
if (definition == undefined) {
|
18
|
+
throw new NoSuchSchemaError(schema);
|
19
|
+
}
|
20
|
+
const parseResult = definition.schema.safeParse(value);
|
21
|
+
if (!parseResult.success) {
|
22
|
+
throw new SchemaValidationError({
|
23
|
+
schemaName: schema,
|
24
|
+
value,
|
25
|
+
errors: parseResult.error,
|
26
|
+
});
|
27
|
+
}
|
28
|
+
return {
|
29
|
+
schema: schema,
|
30
|
+
value: parseResult.data,
|
31
|
+
text: text, // text is string | null, which is part of the response for schema values
|
32
|
+
};
|
33
|
+
},
|
34
|
+
getStartEvent: (metadata, settings) => ({
|
35
|
+
type: "json-generation-started",
|
36
|
+
metadata,
|
37
|
+
settings,
|
38
|
+
prompt,
|
39
|
+
}),
|
40
|
+
getAbortEvent: (metadata, settings) => ({
|
41
|
+
type: "json-generation-finished",
|
42
|
+
status: "abort",
|
43
|
+
metadata,
|
44
|
+
settings,
|
45
|
+
prompt,
|
46
|
+
}),
|
47
|
+
getFailureEvent: (metadata, settings, error) => ({
|
48
|
+
type: "json-generation-finished",
|
49
|
+
status: "failure",
|
50
|
+
metadata,
|
51
|
+
settings,
|
52
|
+
prompt,
|
53
|
+
error,
|
54
|
+
}),
|
55
|
+
getSuccessEvent: (metadata, settings, response, output) => ({
|
56
|
+
type: "json-generation-finished",
|
57
|
+
status: "success",
|
58
|
+
metadata,
|
59
|
+
settings,
|
60
|
+
prompt,
|
61
|
+
response,
|
62
|
+
generatedJson: output,
|
63
|
+
}),
|
64
|
+
});
|
65
|
+
return {
|
66
|
+
...result.output,
|
67
|
+
response: result.response,
|
68
|
+
metadata: result.metadata,
|
69
|
+
};
|
70
|
+
}
|