@llumiverse/drivers 1.3.0 → 1.4.0-dev.20260629.090753Z
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/lib/{types/adobe → adobe}/firefly.d.ts +2 -1
- package/lib/adobe/firefly.d.ts.map +1 -0
- package/lib/adobe/firefly.js +120 -0
- package/lib/adobe/firefly.js.map +1 -0
- package/lib/{types/anthropic → anthropic}/index.d.ts +4 -2
- package/lib/anthropic/index.d.ts.map +1 -0
- package/lib/{esm/anthropic → anthropic}/index.js +19 -8
- package/lib/anthropic/index.js.map +1 -0
- package/lib/{types/azure → azure}/azure_foundry.d.ts +9 -7
- package/lib/azure/azure_foundry.d.ts.map +1 -0
- package/lib/{esm/azure → azure}/azure_foundry.js +138 -124
- package/lib/azure/azure_foundry.js.map +1 -0
- package/lib/{types/bedrock → bedrock}/converse.d.ts +2 -2
- package/lib/bedrock/converse.d.ts.map +1 -0
- package/lib/{esm/bedrock → bedrock}/converse.js +86 -79
- package/lib/bedrock/converse.js.map +1 -0
- package/lib/bedrock/embeddings.d.ts +4 -0
- package/lib/bedrock/embeddings.d.ts.map +1 -0
- package/lib/bedrock/embeddings.js +359 -0
- package/lib/bedrock/embeddings.js.map +1 -0
- package/lib/{types/bedrock → bedrock}/index.d.ts +33 -9
- package/lib/bedrock/index.d.ts.map +1 -0
- package/lib/{esm/bedrock → bedrock}/index.js +599 -324
- package/lib/bedrock/index.js.map +1 -0
- package/lib/{types/bedrock → bedrock}/nova-image-payload.d.ts +5 -5
- package/lib/bedrock/nova-image-payload.d.ts.map +1 -0
- package/lib/{esm/bedrock → bedrock}/nova-image-payload.js +31 -36
- package/lib/bedrock/nova-image-payload.js.map +1 -0
- package/lib/{types/bedrock → bedrock}/payloads.d.ts +1 -1
- package/lib/bedrock/payloads.d.ts.map +1 -0
- package/lib/{cjs/bedrock → bedrock}/payloads.js.map +1 -1
- package/lib/{types/bedrock → bedrock}/s3.d.ts +3 -2
- package/lib/bedrock/s3.d.ts.map +1 -0
- package/lib/{esm/bedrock → bedrock}/s3.js +27 -23
- package/lib/bedrock/s3.js.map +1 -0
- package/lib/{types/bedrock → bedrock}/twelvelabs.d.ts +8 -9
- package/lib/bedrock/twelvelabs.d.ts.map +1 -0
- package/lib/{esm/bedrock → bedrock}/twelvelabs.js +17 -21
- package/lib/bedrock/twelvelabs.js.map +1 -0
- package/lib/{types/groq → groq}/index.d.ts +6 -4
- package/lib/groq/index.d.ts.map +1 -0
- package/lib/{esm/groq → groq}/index.js +72 -39
- package/lib/groq/index.js.map +1 -0
- package/lib/{types/huggingface_ie.d.ts → huggingface_ie.d.ts} +4 -3
- package/lib/huggingface_ie.d.ts.map +1 -0
- package/lib/{esm/huggingface_ie.js → huggingface_ie.js} +32 -31
- package/lib/huggingface_ie.js.map +1 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +16 -0
- package/lib/index.js.map +1 -0
- package/lib/{types/mistral → mistral}/index.d.ts +6 -5
- package/lib/mistral/index.d.ts.map +1 -0
- package/lib/{esm/mistral → mistral}/index.js +66 -38
- package/lib/mistral/index.js.map +1 -0
- package/lib/{types/mistral → mistral}/types.d.ts +1 -0
- package/lib/mistral/types.d.ts.map +1 -0
- package/lib/mistral/types.js.map +1 -0
- package/lib/{types/openai → openai}/azure_openai.d.ts +5 -4
- package/lib/openai/azure_openai.d.ts.map +1 -0
- package/lib/{esm/openai → openai}/azure_openai.js +17 -14
- package/lib/openai/azure_openai.js.map +1 -0
- package/lib/openai/drivers.d.ts +4 -0
- package/lib/openai/drivers.d.ts.map +1 -0
- package/lib/openai/drivers.js +9 -0
- package/lib/openai/drivers.js.map +1 -0
- package/lib/{types/openai → openai}/index.d.ts +16 -5
- package/lib/openai/index.d.ts.map +1 -0
- package/lib/{esm/openai → openai}/index.js +242 -141
- package/lib/openai/index.js.map +1 -0
- package/lib/{types/openai → openai}/openai.d.ts +3 -3
- package/lib/openai/openai.d.ts.map +1 -0
- package/lib/openai/openai.js +15 -0
- package/lib/openai/openai.js.map +1 -0
- package/lib/{types/openai → openai}/openai_compatible.d.ts +3 -3
- package/lib/openai/openai_compatible.d.ts.map +1 -0
- package/lib/{esm/openai → openai}/openai_compatible.js +14 -11
- package/lib/openai/openai_compatible.js.map +1 -0
- package/lib/{types/openai → openai}/openai_format.d.ts +3 -2
- package/lib/openai/openai_format.d.ts.map +1 -0
- package/lib/{esm/openai → openai}/openai_format.js +66 -24
- package/lib/openai/openai_format.js.map +1 -0
- package/lib/{types/replicate.d.ts → replicate.d.ts} +3 -2
- package/lib/replicate.d.ts.map +1 -0
- package/lib/{esm/replicate.js → replicate.js} +59 -49
- package/lib/replicate.js.map +1 -0
- package/lib/{types/shared → shared}/claude-messages.d.ts +25 -1
- package/lib/shared/claude-messages.d.ts.map +1 -0
- package/lib/{esm/shared → shared}/claude-messages.js +212 -59
- package/lib/shared/claude-messages.js.map +1 -0
- package/lib/{types/shared → shared}/claude-thinking.d.ts +1 -1
- package/lib/shared/claude-thinking.d.ts.map +1 -0
- package/lib/{esm/shared → shared}/claude-thinking.js +5 -7
- package/lib/shared/claude-thinking.js.map +1 -0
- package/lib/shared/debug-prompt.d.ts +5 -0
- package/lib/shared/debug-prompt.d.ts.map +1 -0
- package/lib/shared/debug-prompt.js +25 -0
- package/lib/shared/debug-prompt.js.map +1 -0
- package/lib/{types/test-driver → test-driver}/TestErrorCompletionStream.d.ts +1 -1
- package/lib/test-driver/TestErrorCompletionStream.d.ts.map +1 -0
- package/lib/test-driver/TestErrorCompletionStream.js +16 -0
- package/lib/test-driver/TestErrorCompletionStream.js.map +1 -0
- package/lib/{types/test-driver → test-driver}/TestValidationErrorCompletionStream.d.ts +1 -1
- package/lib/test-driver/TestValidationErrorCompletionStream.d.ts.map +1 -0
- package/lib/{esm/test-driver → test-driver}/TestValidationErrorCompletionStream.js +4 -4
- package/lib/test-driver/TestValidationErrorCompletionStream.js.map +1 -0
- package/lib/{types/test-driver → test-driver}/index.d.ts +3 -3
- package/lib/test-driver/index.d.ts.map +1 -0
- package/lib/{esm/test-driver → test-driver}/index.js +20 -20
- package/lib/test-driver/index.js.map +1 -0
- package/lib/{types/test-driver → test-driver}/utils.d.ts +1 -1
- package/lib/test-driver/utils.d.ts.map +1 -0
- package/lib/{esm/test-driver → test-driver}/utils.js +4 -4
- package/lib/test-driver/utils.js.map +1 -0
- package/lib/togetherai/index.d.ts +15 -0
- package/lib/togetherai/index.d.ts.map +1 -0
- package/lib/togetherai/index.js +54 -0
- package/lib/togetherai/index.js.map +1 -0
- package/lib/{types/togetherai → togetherai}/interfaces.d.ts +1 -1
- package/lib/togetherai/interfaces.d.ts.map +1 -0
- package/lib/{cjs/watsonx → togetherai}/interfaces.js.map +1 -1
- package/lib/vertexai/debug.d.ts +2 -0
- package/lib/vertexai/debug.d.ts.map +1 -0
- package/lib/{esm/vertexai → vertexai}/debug.js +1 -1
- package/lib/vertexai/debug.js.map +1 -0
- package/lib/vertexai/embeddings/embed-legacy-multimodal.d.ts +9 -0
- package/lib/vertexai/embeddings/embed-legacy-multimodal.d.ts.map +1 -0
- package/lib/vertexai/embeddings/embed-legacy-multimodal.js +141 -0
- package/lib/vertexai/embeddings/embed-legacy-multimodal.js.map +1 -0
- package/lib/vertexai/embeddings/embed.d.ts +13 -0
- package/lib/vertexai/embeddings/embed.d.ts.map +1 -0
- package/lib/vertexai/embeddings/embed.js +162 -0
- package/lib/vertexai/embeddings/embed.js.map +1 -0
- package/lib/vertexai/embeddings/source-utils.d.ts +9 -0
- package/lib/vertexai/embeddings/source-utils.d.ts.map +1 -0
- package/lib/vertexai/embeddings/source-utils.js +18 -0
- package/lib/vertexai/embeddings/source-utils.js.map +1 -0
- package/lib/{types/vertexai → vertexai}/index.d.ts +31 -19
- package/lib/vertexai/index.d.ts.map +1 -0
- package/lib/{esm/vertexai → vertexai}/index.js +221 -159
- package/lib/vertexai/index.js.map +1 -0
- package/lib/{types/vertexai → vertexai}/models/claude.d.ts +4 -4
- package/lib/vertexai/models/claude.d.ts.map +1 -0
- package/lib/{esm/vertexai → vertexai}/models/claude.js +17 -20
- package/lib/vertexai/models/claude.js.map +1 -0
- package/lib/{types/vertexai → vertexai}/models/gemini.d.ts +28 -4
- package/lib/vertexai/models/gemini.d.ts.map +1 -0
- package/lib/{esm/vertexai → vertexai}/models/gemini.js +238 -116
- package/lib/vertexai/models/gemini.js.map +1 -0
- package/lib/{types/vertexai → vertexai}/models/imagen.d.ts +12 -11
- package/lib/vertexai/models/imagen.d.ts.map +1 -0
- package/lib/{esm/vertexai → vertexai}/models/imagen.js +74 -47
- package/lib/vertexai/models/imagen.js.map +1 -0
- package/lib/{types/vertexai → vertexai}/models/llama.d.ts +4 -4
- package/lib/vertexai/models/llama.d.ts.map +1 -0
- package/lib/{esm/vertexai → vertexai}/models/llama.js +37 -33
- package/lib/vertexai/models/llama.js.map +1 -0
- package/lib/vertexai/models.d.ts +21 -0
- package/lib/vertexai/models.d.ts.map +1 -0
- package/lib/{esm/vertexai → vertexai}/models.js +12 -9
- package/lib/vertexai/models.js.map +1 -0
- package/lib/{types/watsonx → watsonx}/index.d.ts +4 -3
- package/lib/watsonx/index.d.ts.map +1 -0
- package/lib/{esm/watsonx → watsonx}/index.js +69 -41
- package/lib/watsonx/index.js.map +1 -0
- package/lib/watsonx/interfaces.d.ts.map +1 -0
- package/lib/{esm/watsonx → watsonx}/interfaces.js.map +1 -1
- package/lib/{types/xai → xai}/index.d.ts +4 -4
- package/lib/xai/index.d.ts.map +1 -0
- package/lib/{esm/xai → xai}/index.js +22 -18
- package/lib/xai/index.js.map +1 -0
- package/package.json +87 -36
- package/src/adobe/firefly.ts +60 -43
- package/src/anthropic/index.ts +37 -20
- package/src/azure/azure_foundry.ts +210 -165
- package/src/bedrock/converse.ts +124 -101
- package/src/bedrock/embeddings.test.ts +508 -0
- package/src/bedrock/embeddings.ts +517 -0
- package/src/bedrock/error-handling.test.ts +62 -14
- package/src/bedrock/index.ts +832 -466
- package/src/bedrock/nova-image-payload.ts +98 -91
- package/src/bedrock/payloads.ts +9 -9
- package/src/bedrock/s3.test.ts +39 -0
- package/src/bedrock/s3.ts +57 -38
- package/src/bedrock/streaming-tool-use.test.ts +86 -69
- package/src/bedrock/twelvelabs.ts +35 -32
- package/src/groq/index.ts +143 -60
- package/src/http-timeout-wiring.test.ts +263 -0
- package/src/huggingface_ie.ts +45 -61
- package/src/index.ts +15 -16
- package/src/mistral/index.ts +97 -48
- package/src/mistral/types.ts +13 -12
- package/src/openai/azure_openai.ts +35 -27
- package/src/openai/drivers.ts +9 -0
- package/src/openai/error-handling.test.ts +308 -113
- package/src/openai/index.ts +378 -248
- package/src/openai/openai.ts +6 -13
- package/src/openai/openai_compatible.ts +35 -25
- package/src/openai/openai_format.ts +90 -40
- package/src/replicate.ts +108 -86
- package/src/shared/claude-messages.test.ts +37 -0
- package/src/shared/claude-messages.ts +303 -97
- package/src/shared/claude-thinking.ts +6 -12
- package/src/shared/debug-prompt.ts +28 -0
- package/src/test-driver/TestErrorCompletionStream.ts +9 -10
- package/src/test-driver/TestValidationErrorCompletionStream.ts +9 -10
- package/src/test-driver/index.ts +43 -27
- package/src/test-driver/utils.ts +8 -8
- package/src/togetherai/index.test.ts +32 -0
- package/src/togetherai/index.ts +64 -128
- package/src/togetherai/interfaces.ts +5 -5
- package/src/vertexai/debug.ts +3 -3
- package/src/vertexai/embeddings/embed-legacy-multimodal.ts +211 -0
- package/src/vertexai/embeddings/embed.ts +206 -0
- package/src/vertexai/embeddings/embeddings.test.ts +497 -0
- package/src/vertexai/embeddings/source-utils.test.ts +54 -0
- package/src/vertexai/embeddings/source-utils.ts +29 -0
- package/src/vertexai/index.ts +331 -244
- package/src/vertexai/models/claude-error-handling.test.ts +83 -36
- package/src/vertexai/models/claude-streaming-spacing.test.ts +82 -75
- package/src/vertexai/models/claude.ts +55 -40
- package/src/vertexai/models/gemini-conversation-mutation.test.ts +65 -23
- package/src/vertexai/models/gemini-error-handling.test.ts +126 -10
- package/src/vertexai/models/gemini-orphaned-tool-result.test.ts +118 -0
- package/src/vertexai/models/gemini.ts +349 -172
- package/src/vertexai/models/imagen.ts +164 -100
- package/src/vertexai/models/llama.ts +70 -48
- package/src/vertexai/models.ts +36 -16
- package/src/watsonx/index.ts +101 -65
- package/src/watsonx/interfaces.ts +10 -15
- package/src/xai/index.ts +30 -30
- package/lib/cjs/adobe/firefly.js +0 -120
- package/lib/cjs/adobe/firefly.js.map +0 -1
- package/lib/cjs/anthropic/index.js +0 -64
- package/lib/cjs/anthropic/index.js.map +0 -1
- package/lib/cjs/azure/azure_foundry.js +0 -432
- package/lib/cjs/azure/azure_foundry.js.map +0 -1
- package/lib/cjs/bedrock/converse.js +0 -359
- package/lib/cjs/bedrock/converse.js.map +0 -1
- package/lib/cjs/bedrock/index.js +0 -1508
- package/lib/cjs/bedrock/index.js.map +0 -1
- package/lib/cjs/bedrock/nova-image-payload.js +0 -207
- package/lib/cjs/bedrock/nova-image-payload.js.map +0 -1
- package/lib/cjs/bedrock/payloads.js +0 -3
- package/lib/cjs/bedrock/s3.js +0 -107
- package/lib/cjs/bedrock/s3.js.map +0 -1
- package/lib/cjs/bedrock/twelvelabs.js +0 -87
- package/lib/cjs/bedrock/twelvelabs.js.map +0 -1
- package/lib/cjs/groq/index.js +0 -328
- package/lib/cjs/groq/index.js.map +0 -1
- package/lib/cjs/huggingface_ie.js +0 -201
- package/lib/cjs/huggingface_ie.js.map +0 -1
- package/lib/cjs/index.js +0 -32
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/mistral/index.js +0 -176
- package/lib/cjs/mistral/index.js.map +0 -1
- package/lib/cjs/mistral/types.js +0 -83
- package/lib/cjs/mistral/types.js.map +0 -1
- package/lib/cjs/openai/azure_openai.js +0 -72
- package/lib/cjs/openai/azure_openai.js.map +0 -1
- package/lib/cjs/openai/index.js +0 -1135
- package/lib/cjs/openai/index.js.map +0 -1
- package/lib/cjs/openai/openai.js +0 -21
- package/lib/cjs/openai/openai.js.map +0 -1
- package/lib/cjs/openai/openai_compatible.js +0 -63
- package/lib/cjs/openai/openai_compatible.js.map +0 -1
- package/lib/cjs/openai/openai_format.js +0 -131
- package/lib/cjs/openai/openai_format.js.map +0 -1
- package/lib/cjs/package.json +0 -3
- package/lib/cjs/replicate.js +0 -275
- package/lib/cjs/replicate.js.map +0 -1
- package/lib/cjs/shared/claude-messages.js +0 -737
- package/lib/cjs/shared/claude-messages.js.map +0 -1
- package/lib/cjs/shared/claude-thinking.js +0 -60
- package/lib/cjs/shared/claude-thinking.js.map +0 -1
- package/lib/cjs/test-driver/TestErrorCompletionStream.js +0 -20
- package/lib/cjs/test-driver/TestErrorCompletionStream.js.map +0 -1
- package/lib/cjs/test-driver/TestValidationErrorCompletionStream.js +0 -24
- package/lib/cjs/test-driver/TestValidationErrorCompletionStream.js.map +0 -1
- package/lib/cjs/test-driver/index.js +0 -109
- package/lib/cjs/test-driver/index.js.map +0 -1
- package/lib/cjs/test-driver/utils.js +0 -30
- package/lib/cjs/test-driver/utils.js.map +0 -1
- package/lib/cjs/togetherai/index.js +0 -126
- package/lib/cjs/togetherai/index.js.map +0 -1
- package/lib/cjs/togetherai/interfaces.js +0 -3
- package/lib/cjs/togetherai/interfaces.js.map +0 -1
- package/lib/cjs/vertexai/debug.js +0 -12
- package/lib/cjs/vertexai/debug.js.map +0 -1
- package/lib/cjs/vertexai/embeddings/embeddings-image.js +0 -27
- package/lib/cjs/vertexai/embeddings/embeddings-image.js.map +0 -1
- package/lib/cjs/vertexai/embeddings/embeddings-text.js +0 -23
- package/lib/cjs/vertexai/embeddings/embeddings-text.js.map +0 -1
- package/lib/cjs/vertexai/index.js +0 -644
- package/lib/cjs/vertexai/index.js.map +0 -1
- package/lib/cjs/vertexai/models/claude.js +0 -72
- package/lib/cjs/vertexai/models/claude.js.map +0 -1
- package/lib/cjs/vertexai/models/gemini.js +0 -864
- package/lib/cjs/vertexai/models/gemini.js.map +0 -1
- package/lib/cjs/vertexai/models/imagen.js +0 -303
- package/lib/cjs/vertexai/models/imagen.js.map +0 -1
- package/lib/cjs/vertexai/models/llama.js +0 -183
- package/lib/cjs/vertexai/models/llama.js.map +0 -1
- package/lib/cjs/vertexai/models.js +0 -35
- package/lib/cjs/vertexai/models.js.map +0 -1
- package/lib/cjs/watsonx/index.js +0 -161
- package/lib/cjs/watsonx/index.js.map +0 -1
- package/lib/cjs/watsonx/interfaces.js +0 -3
- package/lib/cjs/xai/index.js +0 -65
- package/lib/cjs/xai/index.js.map +0 -1
- package/lib/esm/adobe/firefly.js +0 -116
- package/lib/esm/adobe/firefly.js.map +0 -1
- package/lib/esm/anthropic/index.js.map +0 -1
- package/lib/esm/azure/azure_foundry.js.map +0 -1
- package/lib/esm/bedrock/converse.js.map +0 -1
- package/lib/esm/bedrock/index.js.map +0 -1
- package/lib/esm/bedrock/nova-image-payload.js.map +0 -1
- package/lib/esm/bedrock/payloads.js.map +0 -1
- package/lib/esm/bedrock/s3.js.map +0 -1
- package/lib/esm/bedrock/twelvelabs.js.map +0 -1
- package/lib/esm/groq/index.js.map +0 -1
- package/lib/esm/huggingface_ie.js.map +0 -1
- package/lib/esm/index.js +0 -16
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/mistral/index.js.map +0 -1
- package/lib/esm/mistral/types.js.map +0 -1
- package/lib/esm/openai/azure_openai.js.map +0 -1
- package/lib/esm/openai/index.js.map +0 -1
- package/lib/esm/openai/openai.js +0 -14
- package/lib/esm/openai/openai.js.map +0 -1
- package/lib/esm/openai/openai_compatible.js.map +0 -1
- package/lib/esm/openai/openai_format.js.map +0 -1
- package/lib/esm/replicate.js.map +0 -1
- package/lib/esm/shared/claude-messages.js.map +0 -1
- package/lib/esm/shared/claude-thinking.js.map +0 -1
- package/lib/esm/test-driver/TestErrorCompletionStream.js +0 -16
- package/lib/esm/test-driver/TestErrorCompletionStream.js.map +0 -1
- package/lib/esm/test-driver/TestValidationErrorCompletionStream.js.map +0 -1
- package/lib/esm/test-driver/index.js.map +0 -1
- package/lib/esm/test-driver/utils.js.map +0 -1
- package/lib/esm/togetherai/index.js +0 -122
- package/lib/esm/togetherai/index.js.map +0 -1
- package/lib/esm/togetherai/interfaces.js.map +0 -1
- package/lib/esm/vertexai/debug.js.map +0 -1
- package/lib/esm/vertexai/embeddings/embeddings-image.js +0 -24
- package/lib/esm/vertexai/embeddings/embeddings-image.js.map +0 -1
- package/lib/esm/vertexai/embeddings/embeddings-text.js +0 -20
- package/lib/esm/vertexai/embeddings/embeddings-text.js.map +0 -1
- package/lib/esm/vertexai/index.js.map +0 -1
- package/lib/esm/vertexai/models/claude.js.map +0 -1
- package/lib/esm/vertexai/models/gemini.js.map +0 -1
- package/lib/esm/vertexai/models/imagen.js.map +0 -1
- package/lib/esm/vertexai/models/llama.js.map +0 -1
- package/lib/esm/vertexai/models.js.map +0 -1
- package/lib/esm/watsonx/index.js.map +0 -1
- package/lib/esm/xai/index.js.map +0 -1
- package/lib/types/adobe/firefly.d.ts.map +0 -1
- package/lib/types/anthropic/index.d.ts.map +0 -1
- package/lib/types/azure/azure_foundry.d.ts.map +0 -1
- package/lib/types/bedrock/converse.d.ts.map +0 -1
- package/lib/types/bedrock/index.d.ts.map +0 -1
- package/lib/types/bedrock/nova-image-payload.d.ts.map +0 -1
- package/lib/types/bedrock/payloads.d.ts.map +0 -1
- package/lib/types/bedrock/s3.d.ts.map +0 -1
- package/lib/types/bedrock/twelvelabs.d.ts.map +0 -1
- package/lib/types/groq/index.d.ts.map +0 -1
- package/lib/types/huggingface_ie.d.ts.map +0 -1
- package/lib/types/index.d.ts +0 -16
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/mistral/index.d.ts.map +0 -1
- package/lib/types/mistral/types.d.ts.map +0 -1
- package/lib/types/openai/azure_openai.d.ts.map +0 -1
- package/lib/types/openai/index.d.ts.map +0 -1
- package/lib/types/openai/openai.d.ts.map +0 -1
- package/lib/types/openai/openai_compatible.d.ts.map +0 -1
- package/lib/types/openai/openai_format.d.ts.map +0 -1
- package/lib/types/replicate.d.ts.map +0 -1
- package/lib/types/shared/claude-messages.d.ts.map +0 -1
- package/lib/types/shared/claude-thinking.d.ts.map +0 -1
- package/lib/types/test-driver/TestErrorCompletionStream.d.ts.map +0 -1
- package/lib/types/test-driver/TestValidationErrorCompletionStream.d.ts.map +0 -1
- package/lib/types/test-driver/index.d.ts.map +0 -1
- package/lib/types/test-driver/utils.d.ts.map +0 -1
- package/lib/types/togetherai/index.d.ts +0 -23
- package/lib/types/togetherai/index.d.ts.map +0 -1
- package/lib/types/togetherai/interfaces.d.ts.map +0 -1
- package/lib/types/vertexai/debug.d.ts +0 -2
- package/lib/types/vertexai/debug.d.ts.map +0 -1
- package/lib/types/vertexai/embeddings/embeddings-image.d.ts +0 -11
- package/lib/types/vertexai/embeddings/embeddings-image.d.ts.map +0 -1
- package/lib/types/vertexai/embeddings/embeddings-text.d.ts +0 -10
- package/lib/types/vertexai/embeddings/embeddings-text.d.ts.map +0 -1
- package/lib/types/vertexai/index.d.ts.map +0 -1
- package/lib/types/vertexai/models/claude.d.ts.map +0 -1
- package/lib/types/vertexai/models/gemini.d.ts.map +0 -1
- package/lib/types/vertexai/models/imagen.d.ts.map +0 -1
- package/lib/types/vertexai/models/llama.d.ts.map +0 -1
- package/lib/types/vertexai/models.d.ts +0 -20
- package/lib/types/vertexai/models.d.ts.map +0 -1
- package/lib/types/watsonx/index.d.ts.map +0 -1
- package/lib/types/watsonx/interfaces.d.ts.map +0 -1
- package/lib/types/xai/index.d.ts.map +0 -1
- package/src/vertexai/embeddings/embeddings-image.ts +0 -52
- package/src/vertexai/embeddings/embeddings-text.ts +0 -54
- /package/lib/{esm/bedrock → bedrock}/payloads.js +0 -0
- /package/lib/{esm/mistral → mistral}/types.js +0 -0
- /package/lib/{esm/togetherai → togetherai}/interfaces.js +0 -0
- /package/lib/{types/watsonx → watsonx}/interfaces.d.ts +0 -0
- /package/lib/{esm/watsonx → watsonx}/interfaces.js +0 -0
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
|
-
AIModel,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
type AIModel,
|
|
3
|
+
type Completion,
|
|
4
|
+
type CompletionChunkObject,
|
|
5
|
+
type ExecutionOptions,
|
|
6
|
+
ModelType,
|
|
7
|
+
type PromptOptions,
|
|
8
|
+
PromptRole,
|
|
9
|
+
type PromptSegment,
|
|
10
|
+
type TextFallbackOptions,
|
|
11
|
+
} from '@llumiverse/core';
|
|
12
|
+
import { transformSSEStream } from '@llumiverse/core/async';
|
|
13
|
+
import type { ServerSentEvent } from '@vertesia/api-fetch-client';
|
|
14
|
+
import type { VertexAIDriver } from '../index.js';
|
|
15
|
+
import type { ModelDefinition } from '../models.js';
|
|
9
16
|
|
|
10
17
|
interface LLamaMessage {
|
|
11
18
|
role: string;
|
|
12
19
|
content: string;
|
|
13
20
|
}
|
|
14
21
|
|
|
15
|
-
interface LLamaPrompt {
|
|
22
|
+
export interface LLamaPrompt {
|
|
16
23
|
messages: LLamaMessage[];
|
|
17
24
|
}
|
|
18
25
|
|
|
@@ -61,7 +68,7 @@ interface LLamaStreamResponse {
|
|
|
61
68
|
/**
|
|
62
69
|
* Convert a stream to a string
|
|
63
70
|
*/
|
|
64
|
-
async function streamToString(stream:
|
|
71
|
+
async function streamToString(stream: AsyncIterable<Uint8Array | Buffer | string>): Promise<string> {
|
|
65
72
|
const chunks: Buffer[] = [];
|
|
66
73
|
for await (const chunk of stream) {
|
|
67
74
|
chunks.push(Buffer.from(chunk));
|
|
@@ -84,8 +91,7 @@ function updateConversation(conversation: LLamaPrompt | undefined | null, prompt
|
|
|
84
91
|
}
|
|
85
92
|
|
|
86
93
|
export class LLamaModelDefinition implements ModelDefinition<LLamaPrompt> {
|
|
87
|
-
|
|
88
|
-
model: AIModel
|
|
94
|
+
model: AIModel;
|
|
89
95
|
|
|
90
96
|
constructor(modelId: string) {
|
|
91
97
|
this.model = {
|
|
@@ -107,7 +113,11 @@ export class LLamaModelDefinition implements ModelDefinition<LLamaPrompt> {
|
|
|
107
113
|
}
|
|
108
114
|
}
|
|
109
115
|
|
|
110
|
-
async createPrompt(
|
|
116
|
+
async createPrompt(
|
|
117
|
+
_driver: VertexAIDriver,
|
|
118
|
+
segments: PromptSegment[],
|
|
119
|
+
options: PromptOptions,
|
|
120
|
+
): Promise<LLamaPrompt> {
|
|
111
121
|
const messages: LLamaMessage[] = [];
|
|
112
122
|
|
|
113
123
|
// Process segments and convert them to the Llama MaaS format
|
|
@@ -120,7 +130,7 @@ export class LLamaModelDefinition implements ModelDefinition<LLamaPrompt> {
|
|
|
120
130
|
|
|
121
131
|
if (segment.files && segment.files.length > 0) {
|
|
122
132
|
for (const file of segment.files) {
|
|
123
|
-
if (file.mime_type?.startsWith(
|
|
133
|
+
if (file.mime_type?.startsWith('text/')) {
|
|
124
134
|
const fileStream = await file.getStream();
|
|
125
135
|
const fileContent = await streamToString(fileStream);
|
|
126
136
|
messageContent += `\n\nFile content:\n${fileContent}`;
|
|
@@ -130,14 +140,14 @@ export class LLamaModelDefinition implements ModelDefinition<LLamaPrompt> {
|
|
|
130
140
|
|
|
131
141
|
messages.push({
|
|
132
142
|
role: role,
|
|
133
|
-
content: messageContent
|
|
143
|
+
content: messageContent,
|
|
134
144
|
});
|
|
135
145
|
}
|
|
136
146
|
|
|
137
147
|
if (options.result_schema) {
|
|
138
148
|
messages.push({
|
|
139
149
|
role: 'user',
|
|
140
|
-
content:
|
|
150
|
+
content: `The answer must be a JSON object using the following JSON Schema:\n${JSON.stringify(options.result_schema)}`,
|
|
141
151
|
});
|
|
142
152
|
}
|
|
143
153
|
|
|
@@ -147,15 +157,19 @@ export class LLamaModelDefinition implements ModelDefinition<LLamaPrompt> {
|
|
|
147
157
|
};
|
|
148
158
|
}
|
|
149
159
|
|
|
150
|
-
async requestTextCompletion(
|
|
151
|
-
|
|
160
|
+
async requestTextCompletion(
|
|
161
|
+
driver: VertexAIDriver,
|
|
162
|
+
prompt: LLamaPrompt,
|
|
163
|
+
options: ExecutionOptions,
|
|
164
|
+
): Promise<Completion> {
|
|
165
|
+
const splits = options.model.split('/');
|
|
152
166
|
const modelName = splits[splits.length - 1];
|
|
153
167
|
|
|
154
168
|
let conversation = updateConversation(options.conversation as LLamaPrompt, prompt);
|
|
155
169
|
|
|
156
170
|
const modelOptions = options.model_options as TextFallbackOptions;
|
|
157
171
|
|
|
158
|
-
const payload: Record<string,
|
|
172
|
+
const payload: Record<string, unknown> = {
|
|
159
173
|
model: `meta/${modelName}`,
|
|
160
174
|
messages: conversation.messages,
|
|
161
175
|
stream: false,
|
|
@@ -168,19 +182,19 @@ export class LLamaModelDefinition implements ModelDefinition<LLamaPrompt> {
|
|
|
168
182
|
google: {
|
|
169
183
|
model_safety_settings: {
|
|
170
184
|
enabled: false,
|
|
171
|
-
llama_guard_settings: {}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
185
|
+
llama_guard_settings: {},
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
},
|
|
175
189
|
};
|
|
176
190
|
|
|
177
191
|
// Make POST request to the Llama MaaS API
|
|
178
192
|
const region = this.getLlamaModelRegion(modelName);
|
|
179
193
|
const client = driver.getLLamaClient(region);
|
|
180
194
|
const openaiEndpoint = `endpoints/openapi/chat/completions`;
|
|
181
|
-
const result = await client.post(openaiEndpoint, {
|
|
182
|
-
payload
|
|
183
|
-
}) as LLamaResponse;
|
|
195
|
+
const result = (await client.post(openaiEndpoint, {
|
|
196
|
+
payload,
|
|
197
|
+
})) as LLamaResponse;
|
|
184
198
|
|
|
185
199
|
// Extract response data
|
|
186
200
|
const assistantMessage = result?.choices[0]?.message;
|
|
@@ -188,33 +202,39 @@ export class LLamaModelDefinition implements ModelDefinition<LLamaPrompt> {
|
|
|
188
202
|
|
|
189
203
|
// Update conversation with the response
|
|
190
204
|
conversation = updateConversation(conversation, {
|
|
191
|
-
messages: [
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
205
|
+
messages: [
|
|
206
|
+
{
|
|
207
|
+
role: assistantMessage?.role,
|
|
208
|
+
content: text,
|
|
209
|
+
},
|
|
210
|
+
],
|
|
195
211
|
});
|
|
196
212
|
|
|
197
213
|
return {
|
|
198
|
-
result: [{ type:
|
|
214
|
+
result: [{ type: 'text', value: text }],
|
|
199
215
|
token_usage: {
|
|
200
216
|
prompt: result.usage.prompt_tokens,
|
|
201
217
|
result: result.usage.completion_tokens,
|
|
202
|
-
total: result.usage.total_tokens
|
|
218
|
+
total: result.usage.total_tokens,
|
|
203
219
|
},
|
|
204
220
|
finish_reason: result.choices[0].finish_reason,
|
|
205
|
-
conversation
|
|
221
|
+
conversation,
|
|
206
222
|
};
|
|
207
223
|
}
|
|
208
224
|
|
|
209
|
-
async requestTextCompletionStream(
|
|
210
|
-
|
|
225
|
+
async requestTextCompletionStream(
|
|
226
|
+
driver: VertexAIDriver,
|
|
227
|
+
prompt: LLamaPrompt,
|
|
228
|
+
options: ExecutionOptions,
|
|
229
|
+
): Promise<AsyncIterable<CompletionChunkObject>> {
|
|
230
|
+
const splits = options.model.split('/');
|
|
211
231
|
const modelName = splits[splits.length - 1];
|
|
212
232
|
|
|
213
233
|
const conversation = updateConversation(options.conversation as LLamaPrompt, prompt);
|
|
214
234
|
|
|
215
235
|
const modelOptions = options.model_options as TextFallbackOptions;
|
|
216
236
|
|
|
217
|
-
const payload: Record<string,
|
|
237
|
+
const payload: Record<string, unknown> = {
|
|
218
238
|
model: `meta/${modelName}`,
|
|
219
239
|
messages: conversation.messages,
|
|
220
240
|
stream: true,
|
|
@@ -227,10 +247,10 @@ export class LLamaModelDefinition implements ModelDefinition<LLamaPrompt> {
|
|
|
227
247
|
google: {
|
|
228
248
|
model_safety_settings: {
|
|
229
249
|
enabled: false,
|
|
230
|
-
llama_guard_settings: {}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
250
|
+
llama_guard_settings: {},
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
},
|
|
234
254
|
};
|
|
235
255
|
|
|
236
256
|
// Make POST request to the Llama MaaS API
|
|
@@ -239,23 +259,25 @@ export class LLamaModelDefinition implements ModelDefinition<LLamaPrompt> {
|
|
|
239
259
|
const region = this.getLlamaModelRegion(modelName);
|
|
240
260
|
const client = driver.getLLamaClient(region);
|
|
241
261
|
const openaiEndpoint = `endpoints/openapi/chat/completions`;
|
|
242
|
-
const stream = await client.post(openaiEndpoint, {
|
|
262
|
+
const stream = (await client.post(openaiEndpoint, {
|
|
243
263
|
payload,
|
|
244
|
-
reader: 'sse'
|
|
245
|
-
})
|
|
264
|
+
reader: 'sse',
|
|
265
|
+
})) as ReadableStream<ServerSentEvent>;
|
|
246
266
|
|
|
247
267
|
return transformSSEStream(stream, (data: string): CompletionChunkObject => {
|
|
248
268
|
const json = JSON.parse(data) as LLamaStreamResponse;
|
|
249
269
|
const choice = json.choices?.[0];
|
|
250
270
|
const content = choice?.delta?.content ?? '';
|
|
251
271
|
return {
|
|
252
|
-
result: content ? [{ type:
|
|
272
|
+
result: content ? [{ type: 'text', value: content }] : [],
|
|
253
273
|
finish_reason: choice?.finish_reason,
|
|
254
|
-
token_usage: json.usage
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
274
|
+
token_usage: json.usage
|
|
275
|
+
? {
|
|
276
|
+
prompt: json.usage.prompt_tokens,
|
|
277
|
+
result: json.usage.completion_tokens,
|
|
278
|
+
total: json.usage.total_tokens,
|
|
279
|
+
}
|
|
280
|
+
: undefined,
|
|
259
281
|
};
|
|
260
282
|
});
|
|
261
283
|
}
|
package/src/vertexai/models.ts
CHANGED
|
@@ -1,16 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type {
|
|
2
|
+
AIModel,
|
|
3
|
+
Completion,
|
|
4
|
+
CompletionChunkObject,
|
|
5
|
+
ExecutionOptions,
|
|
6
|
+
LlumiverseError,
|
|
7
|
+
LlumiverseErrorContext,
|
|
8
|
+
PromptSegment,
|
|
9
|
+
} from '@llumiverse/core';
|
|
10
|
+
import type { VertexAIDriver, VertexAIPrompt } from './index.js';
|
|
11
|
+
import { ClaudeModelDefinition } from './models/claude.js';
|
|
12
|
+
import { GeminiModelDefinition } from './models/gemini.js';
|
|
13
|
+
import { LLamaModelDefinition } from './models/llama.js';
|
|
6
14
|
|
|
7
|
-
export
|
|
15
|
+
export function trimModelName(model: string): string {
|
|
16
|
+
const i = model.lastIndexOf('@');
|
|
17
|
+
return i > -1 ? model.substring(0, i) : model;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ModelDefinition<PromptT = VertexAIPrompt> {
|
|
8
21
|
model: AIModel;
|
|
9
22
|
versions?: string[]; // the versions of the model that are available. ex: ['001', '002']
|
|
10
|
-
createPrompt
|
|
11
|
-
requestTextCompletion
|
|
12
|
-
requestTextCompletionStream
|
|
13
|
-
|
|
23
|
+
createPrompt(driver: VertexAIDriver, segments: PromptSegment[], options: ExecutionOptions): Promise<PromptT>;
|
|
24
|
+
requestTextCompletion(driver: VertexAIDriver, prompt: PromptT, options: ExecutionOptions): Promise<Completion>;
|
|
25
|
+
requestTextCompletionStream(
|
|
26
|
+
driver: VertexAIDriver,
|
|
27
|
+
prompt: PromptT,
|
|
28
|
+
options: ExecutionOptions,
|
|
29
|
+
): Promise<AsyncIterable<CompletionChunkObject>>;
|
|
30
|
+
preValidationProcessing?(
|
|
31
|
+
result: Completion,
|
|
32
|
+
options: ExecutionOptions,
|
|
33
|
+
): { result: Completion; options: ExecutionOptions };
|
|
14
34
|
/**
|
|
15
35
|
* Format provider-specific errors into standardized LlumiverseError.
|
|
16
36
|
* Optional - if not provided, VertexAIDriver will use default error handling.
|
|
@@ -19,13 +39,13 @@ export interface ModelDefinition<PromptT = any> {
|
|
|
19
39
|
}
|
|
20
40
|
|
|
21
41
|
export function getModelDefinition(model: string): ModelDefinition {
|
|
22
|
-
const splits = model.split(
|
|
42
|
+
const splits = model.split('/');
|
|
23
43
|
|
|
24
44
|
// Handle both formats: "publishers/anthropic/models/..." and "locations/.../publishers/anthropic/models/..."
|
|
25
45
|
let publisher: string | undefined;
|
|
26
46
|
let modelName: string;
|
|
27
47
|
|
|
28
|
-
const publisherIndex = splits.indexOf(
|
|
48
|
+
const publisherIndex = splits.indexOf('publishers');
|
|
29
49
|
if (publisherIndex !== -1 && publisherIndex + 1 < splits.length) {
|
|
30
50
|
publisher = splits[publisherIndex + 1];
|
|
31
51
|
modelName = trimModelName(splits[splits.length - 1]);
|
|
@@ -35,14 +55,14 @@ export function getModelDefinition(model: string): ModelDefinition {
|
|
|
35
55
|
modelName = trimModelName(splits[splits.length - 1]);
|
|
36
56
|
}
|
|
37
57
|
|
|
38
|
-
if (publisher?.includes(
|
|
58
|
+
if (publisher?.includes('anthropic')) {
|
|
39
59
|
return new ClaudeModelDefinition(modelName);
|
|
40
|
-
} else if (publisher?.includes(
|
|
60
|
+
} else if (publisher?.includes('google')) {
|
|
41
61
|
return new GeminiModelDefinition(modelName);
|
|
42
|
-
} else if (publisher?.includes(
|
|
62
|
+
} else if (publisher?.includes('meta')) {
|
|
43
63
|
return new LLamaModelDefinition(modelName);
|
|
44
64
|
}
|
|
45
65
|
|
|
46
66
|
//Fallback, assume it is Gemini.
|
|
47
67
|
return new GeminiModelDefinition(modelName);
|
|
48
|
-
}
|
|
68
|
+
}
|
package/src/watsonx/index.ts
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {
|
|
2
|
+
type AIModel,
|
|
3
|
+
type Completion,
|
|
4
|
+
type CompletionChunkObject,
|
|
5
|
+
type DriverOptions,
|
|
6
|
+
type EmbeddingsOptions,
|
|
7
|
+
type EmbeddingsResult,
|
|
8
|
+
type ExecutionOptions,
|
|
9
|
+
LlumiverseError,
|
|
10
|
+
normalizeEmbeddingsOptions,
|
|
11
|
+
type TextFallbackOptions,
|
|
12
|
+
WATSONX_DEFAULT_EMBEDDING_MODEL,
|
|
13
|
+
} from '@llumiverse/core';
|
|
14
|
+
import { transformSSEStream } from '@llumiverse/core/async';
|
|
15
|
+
import { AbstractDriver } from '@llumiverse/core/driver';
|
|
16
|
+
import { FetchClient, type ServerSentEvent } from '@vertesia/api-fetch-client';
|
|
17
|
+
import type {
|
|
18
|
+
GenerateEmbeddingPayload,
|
|
19
|
+
GenerateEmbeddingResponse,
|
|
20
|
+
WatsonAuthToken,
|
|
21
|
+
WatsonxListModelResponse,
|
|
22
|
+
WatsonxModelSpec,
|
|
23
|
+
WatsonxTextGenerationPayload,
|
|
24
|
+
WatsonxTextGenerationResponse,
|
|
25
|
+
} from './interfaces.js';
|
|
5
26
|
|
|
6
27
|
interface WatsonxDriverOptions extends DriverOptions {
|
|
7
28
|
apiKey: string;
|
|
@@ -9,35 +30,37 @@ interface WatsonxDriverOptions extends DriverOptions {
|
|
|
9
30
|
endpointUrl: string;
|
|
10
31
|
}
|
|
11
32
|
|
|
12
|
-
const API_VERSION =
|
|
33
|
+
const API_VERSION = '2024-03-14';
|
|
13
34
|
|
|
14
35
|
export class WatsonxDriver extends AbstractDriver<WatsonxDriverOptions, string> {
|
|
15
|
-
static PROVIDER =
|
|
36
|
+
static PROVIDER = 'watsonx';
|
|
16
37
|
provider = WatsonxDriver.PROVIDER;
|
|
17
38
|
apiKey: string;
|
|
18
39
|
endpoint_url: string;
|
|
19
40
|
projectId: string;
|
|
20
41
|
authToken?: WatsonAuthToken;
|
|
21
42
|
fetcher?: FetchClient;
|
|
22
|
-
fetchClient: FetchClient
|
|
43
|
+
fetchClient: FetchClient;
|
|
23
44
|
|
|
24
45
|
constructor(options: WatsonxDriverOptions) {
|
|
25
46
|
super(options);
|
|
26
47
|
this.apiKey = options.apiKey;
|
|
27
48
|
this.projectId = options.projectId;
|
|
28
49
|
this.endpoint_url = options.endpointUrl;
|
|
29
|
-
this.fetchClient = new FetchClient(this.endpoint_url).withAuthCallback(async () =>
|
|
50
|
+
this.fetchClient = new FetchClient(this.endpoint_url, this.getDriverFetch()).withAuthCallback(async () =>
|
|
51
|
+
this.getAuthToken().then((token) => `Bearer ${token}`),
|
|
52
|
+
);
|
|
30
53
|
}
|
|
31
54
|
|
|
32
55
|
async requestTextCompletion(prompt: string, options: ExecutionOptions): Promise<Completion> {
|
|
33
|
-
if (options.model_options?._option_id !== undefined && options.model_options?._option_id !==
|
|
34
|
-
this.logger.debug({ options: options.model_options },
|
|
56
|
+
if (options.model_options?._option_id !== undefined && options.model_options?._option_id !== 'text-fallback') {
|
|
57
|
+
this.logger.debug({ options: options.model_options }, 'Unexpected option id');
|
|
35
58
|
}
|
|
36
59
|
options.model_options = options.model_options as TextFallbackOptions | undefined;
|
|
37
60
|
|
|
38
61
|
const payload: WatsonxTextGenerationPayload = {
|
|
39
62
|
model_id: options.model,
|
|
40
|
-
input: prompt
|
|
63
|
+
input: `${prompt}\n`,
|
|
41
64
|
parameters: {
|
|
42
65
|
max_new_tokens: options.model_options?.max_tokens,
|
|
43
66
|
temperature: options.model_options?.temperature,
|
|
@@ -46,14 +69,16 @@ export class WatsonxDriver extends AbstractDriver<WatsonxDriverOptions, string>
|
|
|
46
69
|
stop_sequences: options.model_options?.stop_sequence,
|
|
47
70
|
},
|
|
48
71
|
project_id: this.projectId,
|
|
49
|
-
}
|
|
72
|
+
};
|
|
50
73
|
|
|
51
|
-
const res = await this.fetchClient.post(`/ml/v1/text/generation?version=${API_VERSION}`, {
|
|
74
|
+
const res = (await this.fetchClient.post(`/ml/v1/text/generation?version=${API_VERSION}`, {
|
|
75
|
+
payload,
|
|
76
|
+
})) as WatsonxTextGenerationResponse;
|
|
52
77
|
|
|
53
78
|
const result = res.results[0];
|
|
54
79
|
|
|
55
80
|
return {
|
|
56
|
-
result: [{ type:
|
|
81
|
+
result: [{ type: 'text', value: result.generated_text }],
|
|
57
82
|
token_usage: {
|
|
58
83
|
prompt: result.input_token_count,
|
|
59
84
|
result: result.generated_token_count,
|
|
@@ -61,17 +86,20 @@ export class WatsonxDriver extends AbstractDriver<WatsonxDriverOptions, string>
|
|
|
61
86
|
},
|
|
62
87
|
finish_reason: watsonFinishReason(result.stop_reason),
|
|
63
88
|
original_response: options.include_original_response ? res : undefined,
|
|
64
|
-
}
|
|
89
|
+
};
|
|
65
90
|
}
|
|
66
91
|
|
|
67
|
-
async requestTextCompletionStream(
|
|
68
|
-
|
|
69
|
-
|
|
92
|
+
async requestTextCompletionStream(
|
|
93
|
+
prompt: string,
|
|
94
|
+
options: ExecutionOptions,
|
|
95
|
+
): Promise<AsyncIterable<CompletionChunkObject>> {
|
|
96
|
+
if (options.model_options?._option_id !== undefined && options.model_options?._option_id !== 'text-fallback') {
|
|
97
|
+
this.logger.debug({ options: options.model_options }, 'Unexpected option id');
|
|
70
98
|
}
|
|
71
99
|
options.model_options = options.model_options as TextFallbackOptions | undefined;
|
|
72
100
|
const payload: WatsonxTextGenerationPayload = {
|
|
73
101
|
model_id: options.model,
|
|
74
|
-
input: prompt
|
|
102
|
+
input: `${prompt}\n`,
|
|
75
103
|
parameters: {
|
|
76
104
|
max_new_tokens: options.model_options?.max_tokens,
|
|
77
105
|
temperature: options.model_options?.temperature,
|
|
@@ -80,17 +108,19 @@ export class WatsonxDriver extends AbstractDriver<WatsonxDriverOptions, string>
|
|
|
80
108
|
stop_sequences: options.model_options?.stop_sequence,
|
|
81
109
|
},
|
|
82
110
|
project_id: this.projectId,
|
|
83
|
-
}
|
|
111
|
+
};
|
|
84
112
|
|
|
85
|
-
const stream = await this.fetchClient.post(`/ml/v1/text/generation_stream?version=${API_VERSION}`, {
|
|
113
|
+
const stream = (await this.fetchClient.post(`/ml/v1/text/generation_stream?version=${API_VERSION}`, {
|
|
86
114
|
payload: payload,
|
|
87
|
-
reader: 'sse'
|
|
88
|
-
})
|
|
115
|
+
reader: 'sse',
|
|
116
|
+
})) as ReadableStream<ServerSentEvent>;
|
|
89
117
|
|
|
90
118
|
return transformSSEStream(stream, (data: string) => {
|
|
91
119
|
const json = JSON.parse(data) as WatsonxTextGenerationResponse;
|
|
92
120
|
return {
|
|
93
|
-
result: json.results[0]?.generated_text
|
|
121
|
+
result: json.results[0]?.generated_text
|
|
122
|
+
? [{ type: 'text', value: json.results[0].generated_text }]
|
|
123
|
+
: [],
|
|
94
124
|
finish_reason: watsonFinishReason(json.results[0]?.stop_reason),
|
|
95
125
|
token_usage: {
|
|
96
126
|
prompt: json.results[0].input_token_count,
|
|
@@ -99,17 +129,12 @@ export class WatsonxDriver extends AbstractDriver<WatsonxDriverOptions, string>
|
|
|
99
129
|
},
|
|
100
130
|
};
|
|
101
131
|
});
|
|
102
|
-
|
|
103
132
|
}
|
|
104
133
|
|
|
105
|
-
|
|
106
|
-
|
|
107
134
|
async listModels(): Promise<AIModel<string>[]> {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const res = await this.fetchClient.get(`/ml/v1/foundation_model_specs?version=${API_VERSION}`)
|
|
112
|
-
.catch(err => this.logger.warn("Can't list models on Watsonx: " + err)) as WatsonxListModelResponse;
|
|
135
|
+
const res = (await this.fetchClient
|
|
136
|
+
.get(`/ml/v1/foundation_model_specs?version=${API_VERSION}`)
|
|
137
|
+
.catch((err) => this.logger.warn(`Can't list models on Watsonx: ${err}`))) as WatsonxListModelResponse;
|
|
113
138
|
|
|
114
139
|
const aiModels = res.resources.map((m: WatsonxModelSpec) => {
|
|
115
140
|
return {
|
|
@@ -117,83 +142,94 @@ export class WatsonxDriver extends AbstractDriver<WatsonxDriverOptions, string>
|
|
|
117
142
|
name: m.label,
|
|
118
143
|
description: m.short_description,
|
|
119
144
|
provider: this.provider,
|
|
120
|
-
}
|
|
145
|
+
};
|
|
121
146
|
});
|
|
122
147
|
|
|
123
148
|
return aiModels;
|
|
124
|
-
|
|
125
149
|
}
|
|
126
150
|
|
|
127
151
|
async getAuthToken(): Promise<string> {
|
|
128
|
-
|
|
129
|
-
|
|
130
152
|
if (this.authToken) {
|
|
131
153
|
const now = Date.now() / 1000;
|
|
132
154
|
if (now < this.authToken.expiration) {
|
|
133
155
|
return this.authToken.access_token;
|
|
134
156
|
} else {
|
|
135
|
-
this.logger.debug(
|
|
157
|
+
this.logger.debug('Token expired, refetching');
|
|
136
158
|
}
|
|
137
159
|
}
|
|
138
|
-
const authToken = await
|
|
160
|
+
const authToken = (await this.getDriverFetch()('https://iam.cloud.ibm.com/identity/token', {
|
|
139
161
|
method: 'POST',
|
|
140
162
|
headers: {
|
|
141
163
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
142
164
|
},
|
|
143
165
|
body: `grant_type=urn:ibm:params:oauth:grant-type:apikey&apikey=${this.apiKey}`,
|
|
144
|
-
}).then(response => response.json()) as WatsonAuthToken;
|
|
166
|
+
}).then((response) => response.json())) as WatsonAuthToken;
|
|
145
167
|
|
|
146
168
|
this.authToken = authToken;
|
|
147
169
|
return this.authToken.access_token;
|
|
148
|
-
|
|
149
170
|
}
|
|
150
171
|
|
|
151
172
|
async validateConnection(): Promise<boolean> {
|
|
152
173
|
return this.listModels()
|
|
153
174
|
.then(() => true)
|
|
154
175
|
.catch((err) => {
|
|
155
|
-
this.logger.warn({ error: err },
|
|
156
|
-
return false
|
|
176
|
+
this.logger.warn({ error: err }, 'Failed to connect to WatsonX');
|
|
177
|
+
return false;
|
|
157
178
|
});
|
|
158
179
|
}
|
|
159
180
|
|
|
160
181
|
async generateEmbeddings(options: EmbeddingsOptions): Promise<EmbeddingsResult> {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
182
|
+
const normalized = normalizeEmbeddingsOptions(options);
|
|
183
|
+
const texts = normalized.inputs.map((input) => {
|
|
184
|
+
if (input.type !== 'text') {
|
|
185
|
+
throw new Error(
|
|
186
|
+
`Provider 'watsonx' does not support '${input.type}' embeddings; only 'text' is supported.`,
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
return input.text;
|
|
190
|
+
});
|
|
168
191
|
|
|
169
192
|
const payload: GenerateEmbeddingPayload = {
|
|
170
|
-
inputs:
|
|
171
|
-
model_id:
|
|
172
|
-
project_id: this.projectId
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const res = await this.fetchClient.post(`/ml/v1/text/embeddings?version=${API_VERSION}`, { payload }) as GenerateEmbeddingResponse;
|
|
193
|
+
inputs: texts,
|
|
194
|
+
model_id: normalized.model ?? WATSONX_DEFAULT_EMBEDDING_MODEL,
|
|
195
|
+
project_id: this.projectId,
|
|
196
|
+
};
|
|
176
197
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
198
|
+
const model = payload.model_id;
|
|
199
|
+
try {
|
|
200
|
+
const res = (await this.fetchClient.post(`/ml/v1/text/embeddings?version=${API_VERSION}`, {
|
|
201
|
+
payload,
|
|
202
|
+
})) as GenerateEmbeddingResponse;
|
|
203
|
+
return {
|
|
204
|
+
model: res.model_id,
|
|
205
|
+
results: res.results.map((entry) => ({
|
|
206
|
+
outputs: [{ values: entry.embedding, modality: 'text' }],
|
|
207
|
+
})),
|
|
208
|
+
};
|
|
209
|
+
} catch (error) {
|
|
210
|
+
if (LlumiverseError.isLlumiverseError(error)) throw error;
|
|
211
|
+
if (error instanceof Error && typeof (error as { status?: unknown }).status !== 'number') throw error;
|
|
212
|
+
throw this.formatLlumiverseError(error, {
|
|
213
|
+
provider: this.provider,
|
|
214
|
+
model,
|
|
215
|
+
operation: 'execute',
|
|
216
|
+
});
|
|
180
217
|
}
|
|
181
|
-
|
|
182
218
|
}
|
|
183
|
-
|
|
184
219
|
}
|
|
185
220
|
|
|
186
221
|
function watsonFinishReason(reason: string | undefined) {
|
|
187
222
|
if (!reason) return undefined;
|
|
188
223
|
switch (reason) {
|
|
189
|
-
case 'eos_token':
|
|
190
|
-
|
|
191
|
-
|
|
224
|
+
case 'eos_token':
|
|
225
|
+
return 'stop';
|
|
226
|
+
case 'max_tokens':
|
|
227
|
+
return 'length';
|
|
228
|
+
default:
|
|
229
|
+
return reason;
|
|
192
230
|
}
|
|
193
231
|
}
|
|
194
232
|
|
|
195
|
-
|
|
196
|
-
|
|
197
233
|
/*interface ListModelsParams extends ModelSearchPayload {
|
|
198
234
|
limit?: number;
|
|
199
235
|
}*/
|