@llumiverse/drivers 1.3.0 → 1.4.0
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
package/src/vertexai/index.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { AnthropicVertex } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { AnthropicVertex } from '@anthropic-ai/vertex-sdk';
|
|
2
|
+
import { type Content, GoogleGenAI, type Model } from '@google/genai';
|
|
3
|
+
import { PredictionServiceClient, v1beta1 } from '@google-cloud/aiplatform';
|
|
4
4
|
import {
|
|
5
5
|
type AIModel,
|
|
6
|
-
AbstractDriver,
|
|
7
6
|
type Completion,
|
|
8
7
|
type CompletionChunkObject,
|
|
9
8
|
type CompletionResult,
|
|
@@ -11,25 +10,31 @@ import {
|
|
|
11
10
|
type EmbeddingsOptions,
|
|
12
11
|
type EmbeddingsResult,
|
|
13
12
|
type ExecutionOptions,
|
|
14
|
-
type LlumiverseError,
|
|
15
|
-
type LlumiverseErrorContext,
|
|
16
|
-
type ModelSearchPayload,
|
|
17
|
-
type PromptSegment,
|
|
18
13
|
getConversationMeta,
|
|
19
14
|
getModelCapabilities,
|
|
15
|
+
type HttpTimeoutOptions,
|
|
20
16
|
incrementConversationTurn,
|
|
17
|
+
type LlumiverseError,
|
|
18
|
+
type LlumiverseErrorContext,
|
|
19
|
+
type ModelSearchPayload,
|
|
21
20
|
modelModalitiesToArray,
|
|
21
|
+
type PromptSegment,
|
|
22
22
|
stripBase64ImagesFromConversation,
|
|
23
23
|
stripHeartbeatsFromConversation,
|
|
24
|
+
type ToolUse,
|
|
24
25
|
truncateLargeTextInConversation,
|
|
25
|
-
} from
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import { type
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
26
|
+
} from '@llumiverse/core';
|
|
27
|
+
import { AbstractDriver } from '@llumiverse/core/driver';
|
|
28
|
+
import { mergeDriverHttpTimeoutOptions, resolveDriverHttpTimeouts } from '@llumiverse/core/http-agent';
|
|
29
|
+
import { type FETCH_FN, FetchClient } from '@vertesia/api-fetch-client';
|
|
30
|
+
import { type AuthClient, GoogleAuth, type GoogleAuthOptions } from 'google-auth-library';
|
|
31
|
+
import { type ClaudePrompt, formatClaudeDebugPrompt } from '../shared/claude-messages.js';
|
|
32
|
+
import { generateVertexAiEmbeddings } from './embeddings/embed.js';
|
|
33
|
+
import { ANTHROPIC_REGIONS, NON_GLOBAL_ANTHROPIC_MODELS } from './models/claude.js';
|
|
34
|
+
import { formatGeminiDebugPrompt } from './models/gemini.js';
|
|
35
|
+
import { formatImagenDebugPrompt, ImagenModelDefinition, type ImagenPrompt } from './models/imagen.js';
|
|
36
|
+
import type { LLamaPrompt } from './models/llama.js';
|
|
37
|
+
import { getModelDefinition, trimModelName } from './models.js';
|
|
33
38
|
|
|
34
39
|
export interface VertexAIDriverOptions extends DriverOptions {
|
|
35
40
|
project: string;
|
|
@@ -41,17 +46,32 @@ export interface GenerateContentPrompt {
|
|
|
41
46
|
contents: Content[];
|
|
42
47
|
system?: Content;
|
|
43
48
|
}
|
|
49
|
+
type ClaudeStreamingPrompt = { messages: unknown[]; system?: unknown[] };
|
|
50
|
+
type ConversationWrapper = { messages?: unknown[]; system?: unknown[] };
|
|
51
|
+
|
|
52
|
+
function isClaudePrompt(prompt: VertexAIPrompt): prompt is ClaudePrompt {
|
|
53
|
+
return (
|
|
54
|
+
'messages' in prompt &&
|
|
55
|
+
('system' in prompt || prompt.messages.some((message) => Array.isArray(message.content)))
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function isClaudeStreamingPrompt(prompt: unknown): prompt is ClaudeStreamingPrompt {
|
|
60
|
+
return (
|
|
61
|
+
prompt !== null &&
|
|
62
|
+
typeof prompt === 'object' &&
|
|
63
|
+
'messages' in prompt &&
|
|
64
|
+
Array.isArray((prompt as ConversationWrapper).messages)
|
|
65
|
+
);
|
|
66
|
+
}
|
|
44
67
|
|
|
45
68
|
//General Prompt type for VertexAI
|
|
46
|
-
export type VertexAIPrompt = ImagenPrompt | GenerateContentPrompt;
|
|
69
|
+
export type VertexAIPrompt = ImagenPrompt | GenerateContentPrompt | ClaudePrompt | LLamaPrompt;
|
|
47
70
|
|
|
48
|
-
export
|
|
49
|
-
const i = model.lastIndexOf("@");
|
|
50
|
-
return i > -1 ? model.substring(0, i) : model;
|
|
51
|
-
}
|
|
71
|
+
export { trimModelName };
|
|
52
72
|
|
|
53
73
|
export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, VertexAIPrompt> {
|
|
54
|
-
static PROVIDER =
|
|
74
|
+
static PROVIDER = 'vertexai';
|
|
55
75
|
provider = VertexAIDriver.PROVIDER;
|
|
56
76
|
|
|
57
77
|
aiplatform: v1beta1.ModelServiceClient | undefined;
|
|
@@ -60,11 +80,12 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
60
80
|
googleGenAI: GoogleGenAI | undefined;
|
|
61
81
|
googleGenAIRegion: string | undefined;
|
|
62
82
|
googleGenAIFlex: boolean | undefined;
|
|
63
|
-
llamaClient: FetchClient & { region?: string } | undefined;
|
|
83
|
+
llamaClient: (FetchClient & { region?: string }) | undefined;
|
|
64
84
|
modelGarden: v1beta1.ModelGardenServiceClient | undefined;
|
|
65
85
|
imagenClient: PredictionServiceClient | undefined;
|
|
86
|
+
predictionClient: PredictionServiceClient | undefined;
|
|
66
87
|
|
|
67
|
-
googleAuth: GoogleAuth<
|
|
88
|
+
googleAuth: GoogleAuth<AuthClient>;
|
|
68
89
|
private authClientPromise: Promise<AuthClient> | undefined;
|
|
69
90
|
|
|
70
91
|
constructor(options: VertexAIDriverOptions) {
|
|
@@ -72,18 +93,32 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
72
93
|
|
|
73
94
|
this.aiplatform = undefined;
|
|
74
95
|
this.anthropicClient = undefined;
|
|
75
|
-
this.fetchClient = undefined
|
|
96
|
+
this.fetchClient = undefined;
|
|
76
97
|
this.googleGenAI = undefined;
|
|
77
98
|
this.googleGenAIRegion = undefined;
|
|
78
99
|
this.googleGenAIFlex = undefined;
|
|
79
100
|
this.modelGarden = undefined;
|
|
80
101
|
this.llamaClient = undefined;
|
|
81
102
|
this.imagenClient = undefined;
|
|
103
|
+
this.predictionClient = undefined;
|
|
82
104
|
|
|
83
|
-
this.googleAuth = new GoogleAuth(options.googleAuthOptions)
|
|
105
|
+
this.googleAuth = new GoogleAuth(options.googleAuthOptions);
|
|
84
106
|
this.authClientPromise = undefined;
|
|
85
107
|
}
|
|
86
108
|
|
|
109
|
+
/**
|
|
110
|
+
* Cleanup Google Cloud clients when the driver is evicted from the cache.
|
|
111
|
+
* `super.destroy()` releases the HTTP agent socket pool created by
|
|
112
|
+
* {@link AbstractDriver.getHttpAgent} / {@link AbstractDriver.getDriverFetch}.
|
|
113
|
+
*/
|
|
114
|
+
destroy(): void {
|
|
115
|
+
this.aiplatform?.close();
|
|
116
|
+
this.modelGarden?.close();
|
|
117
|
+
this.imagenClient?.close();
|
|
118
|
+
this.predictionClient?.close();
|
|
119
|
+
super.destroy();
|
|
120
|
+
}
|
|
121
|
+
|
|
87
122
|
private async getAuthClient(): Promise<AuthClient> {
|
|
88
123
|
if (!this.authClientPromise) {
|
|
89
124
|
this.authClientPromise = this.googleAuth.getClient();
|
|
@@ -91,10 +126,46 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
91
126
|
return this.authClientPromise;
|
|
92
127
|
}
|
|
93
128
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
this.
|
|
97
|
-
|
|
129
|
+
private getSdkRequestTimeoutMs(httpTimeout?: HttpTimeoutOptions): number {
|
|
130
|
+
const timeouts = resolveDriverHttpTimeouts(
|
|
131
|
+
mergeDriverHttpTimeoutOptions(this.options.httpTimeout, httpTimeout),
|
|
132
|
+
);
|
|
133
|
+
return Math.max(timeouts.headersTimeout, timeouts.bodyTimeout);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private getGoogleGenAIHttpOptions(flex: boolean, httpTimeout?: HttpTimeoutOptions) {
|
|
137
|
+
return {
|
|
138
|
+
timeout: this.getSdkRequestTimeoutMs(httpTimeout),
|
|
139
|
+
...(flex
|
|
140
|
+
? {
|
|
141
|
+
headers: {
|
|
142
|
+
'X-Vertex-AI-LLM-Request-Type': 'shared',
|
|
143
|
+
'X-Vertex-AI-LLM-Shared-Request-Type': 'flex',
|
|
144
|
+
},
|
|
145
|
+
}
|
|
146
|
+
: {}),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
private getAnthropicVertexClientOptions(region: string, authClient: AuthClient, httpTimeout?: HttpTimeoutOptions) {
|
|
151
|
+
return {
|
|
152
|
+
timeout: this.getSdkRequestTimeoutMs(httpTimeout),
|
|
153
|
+
region,
|
|
154
|
+
projectId: this.options.project,
|
|
155
|
+
authClient: authClient,
|
|
156
|
+
fetch: this.getDriverFetch(),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
public getGoogleGenAIClient(
|
|
161
|
+
region: string = this.options.region,
|
|
162
|
+
flex: boolean = false,
|
|
163
|
+
httpTimeout?: HttpTimeoutOptions,
|
|
164
|
+
): GoogleGenAI {
|
|
165
|
+
if (httpTimeout) {
|
|
166
|
+
return this.buildGoogleGenAIClient(region, flex, httpTimeout);
|
|
167
|
+
}
|
|
168
|
+
if (this.googleGenAI && this.googleGenAIRegion === region && this.googleGenAIFlex === flex) {
|
|
98
169
|
// Return existing client if region and flex settings match
|
|
99
170
|
return this.googleGenAI;
|
|
100
171
|
}
|
|
@@ -104,31 +175,25 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
104
175
|
return this.googleGenAI;
|
|
105
176
|
}
|
|
106
177
|
|
|
107
|
-
private buildGoogleGenAIClient(region: string, flex: boolean): GoogleGenAI {
|
|
178
|
+
private buildGoogleGenAIClient(region: string, flex: boolean, httpTimeout?: HttpTimeoutOptions): GoogleGenAI {
|
|
108
179
|
return new GoogleGenAI({
|
|
109
180
|
project: this.options.project,
|
|
110
181
|
location: region,
|
|
111
182
|
vertexai: true,
|
|
112
183
|
googleAuthOptions: this.options.googleAuthOptions || {
|
|
113
|
-
scopes: [
|
|
184
|
+
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
|
|
114
185
|
},
|
|
115
|
-
|
|
116
|
-
httpOptions: {
|
|
117
|
-
headers: {
|
|
118
|
-
"X-Vertex-AI-LLM-Request-Type": "shared",
|
|
119
|
-
"X-Vertex-AI-LLM-Shared-Request-Type": "flex",
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
} : {}),
|
|
186
|
+
httpOptions: this.getGoogleGenAIHttpOptions(flex, httpTimeout),
|
|
123
187
|
});
|
|
124
188
|
}
|
|
125
189
|
|
|
126
|
-
public getFetchClient(): FetchClient {
|
|
190
|
+
public getFetchClient(region: string = this.options.region): FetchClient {
|
|
127
191
|
//Lazy initialization
|
|
128
192
|
if (!this.fetchClient) {
|
|
129
193
|
this.fetchClient = createFetchClient({
|
|
130
|
-
region:
|
|
194
|
+
region: region,
|
|
131
195
|
project: this.options.project,
|
|
196
|
+
fetchImpl: this.getDriverFetch(),
|
|
132
197
|
}).withAuthCallback(async () => {
|
|
133
198
|
const token = await this.googleAuth.getAccessToken();
|
|
134
199
|
return `Bearer ${token}`;
|
|
@@ -137,24 +202,28 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
137
202
|
return this.fetchClient;
|
|
138
203
|
}
|
|
139
204
|
|
|
140
|
-
public getLLamaClient(region: string =
|
|
205
|
+
public getLLamaClient(region: string = 'us-central1'): FetchClient {
|
|
141
206
|
//Lazy initialization
|
|
142
|
-
if (!this.llamaClient || this.llamaClient
|
|
207
|
+
if (!this.llamaClient || this.llamaClient.region !== region) {
|
|
143
208
|
this.llamaClient = createFetchClient({
|
|
144
209
|
region: region,
|
|
145
210
|
project: this.options.project,
|
|
146
|
-
apiVersion:
|
|
211
|
+
apiVersion: 'v1beta1',
|
|
212
|
+
fetchImpl: this.getDriverFetch(),
|
|
147
213
|
}).withAuthCallback(async () => {
|
|
148
214
|
const token = await this.googleAuth.getAccessToken();
|
|
149
215
|
return `Bearer ${token}`;
|
|
150
216
|
});
|
|
151
217
|
// Store the region for potential client reuse
|
|
152
|
-
this.llamaClient
|
|
218
|
+
this.llamaClient.region = region;
|
|
153
219
|
}
|
|
154
220
|
return this.llamaClient;
|
|
155
221
|
}
|
|
156
222
|
|
|
157
|
-
public async getAnthropicClient(
|
|
223
|
+
public async getAnthropicClient(
|
|
224
|
+
region: string = this.options.region,
|
|
225
|
+
httpTimeout?: HttpTimeoutOptions,
|
|
226
|
+
): Promise<AnthropicVertex> {
|
|
158
227
|
// Extract region prefix and map if it exists in ANTHROPIC_REGIONS, otherwise use as-is
|
|
159
228
|
const getRegionPrefix = (r: string) => r.split('-')[0];
|
|
160
229
|
const regionPrefix = getRegionPrefix(region);
|
|
@@ -167,23 +236,13 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
167
236
|
const authClient = await this.getAuthClient();
|
|
168
237
|
|
|
169
238
|
// If mapped region is different from default mapped region, create one-off client
|
|
170
|
-
if (mappedRegion !== defaultMappedRegion) {
|
|
171
|
-
return new AnthropicVertex(
|
|
172
|
-
timeout: 20 * 60 * 10000, // Set to 20 minutes, 10 minute default, setting this disables long request error: https://github.com/anthropics/anthropic-sdk-typescript?#long-requests
|
|
173
|
-
region: mappedRegion,
|
|
174
|
-
projectId: this.options.project,
|
|
175
|
-
authClient: authClient,
|
|
176
|
-
});
|
|
239
|
+
if (httpTimeout || mappedRegion !== defaultMappedRegion) {
|
|
240
|
+
return new AnthropicVertex(this.getAnthropicVertexClientOptions(mappedRegion, authClient, httpTimeout));
|
|
177
241
|
}
|
|
178
242
|
|
|
179
243
|
//Lazy initialization for default region
|
|
180
244
|
if (!this.anthropicClient) {
|
|
181
|
-
this.anthropicClient = new AnthropicVertex(
|
|
182
|
-
timeout: 20 * 60 * 10000, // Set to 20 minutes, 10 minute default, setting this disables long request error: https://github.com/anthropics/anthropic-sdk-typescript?#long-requests
|
|
183
|
-
region: mappedRegion,
|
|
184
|
-
projectId: this.options.project,
|
|
185
|
-
authClient: authClient,
|
|
186
|
-
});
|
|
245
|
+
this.anthropicClient = new AnthropicVertex(this.getAnthropicVertexClientOptions(mappedRegion, authClient));
|
|
187
246
|
}
|
|
188
247
|
return this.anthropicClient;
|
|
189
248
|
}
|
|
@@ -228,10 +287,23 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
228
287
|
return this.imagenClient;
|
|
229
288
|
}
|
|
230
289
|
|
|
290
|
+
public async getPredictionServiceClient(): Promise<PredictionServiceClient> {
|
|
291
|
+
//Lazy initialization using the driver's configured region
|
|
292
|
+
if (!this.predictionClient) {
|
|
293
|
+
const authClient = await this.getAuthClient();
|
|
294
|
+
this.predictionClient = new PredictionServiceClient({
|
|
295
|
+
projectId: this.options.project,
|
|
296
|
+
apiEndpoint: `${this.options.region}-${API_BASE_PATH}`,
|
|
297
|
+
authClient,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
return this.predictionClient;
|
|
301
|
+
}
|
|
302
|
+
|
|
231
303
|
validateResult(result: Completion, options: ExecutionOptions) {
|
|
232
304
|
// Optionally preprocess the result before validation
|
|
233
305
|
const modelDef = getModelDefinition(options.model);
|
|
234
|
-
if (typeof modelDef.preValidationProcessing ===
|
|
306
|
+
if (typeof modelDef.preValidationProcessing === 'function') {
|
|
235
307
|
const processed = modelDef.preValidationProcessing(result, options);
|
|
236
308
|
result = processed.result;
|
|
237
309
|
options = processed.options;
|
|
@@ -248,7 +320,7 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
248
320
|
}
|
|
249
321
|
|
|
250
322
|
protected isImageModel(model: string): boolean {
|
|
251
|
-
return model.includes(
|
|
323
|
+
return model.includes('imagen');
|
|
252
324
|
}
|
|
253
325
|
|
|
254
326
|
public createPrompt(segments: PromptSegment[], options: ExecutionOptions): Promise<VertexAIPrompt> {
|
|
@@ -258,6 +330,19 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
258
330
|
return getModelDefinition(options.model).createPrompt(this, segments, options);
|
|
259
331
|
}
|
|
260
332
|
|
|
333
|
+
public formatDebugPrompt(prompt: VertexAIPrompt): VertexAIPrompt {
|
|
334
|
+
if (isClaudePrompt(prompt)) {
|
|
335
|
+
return formatClaudeDebugPrompt(prompt);
|
|
336
|
+
}
|
|
337
|
+
if ('contents' in prompt) {
|
|
338
|
+
return formatGeminiDebugPrompt(prompt);
|
|
339
|
+
}
|
|
340
|
+
if ('messages' in prompt) {
|
|
341
|
+
return prompt;
|
|
342
|
+
}
|
|
343
|
+
return formatImagenDebugPrompt(prompt);
|
|
344
|
+
}
|
|
345
|
+
|
|
261
346
|
async requestTextCompletion(prompt: VertexAIPrompt, options: ExecutionOptions): Promise<Completion> {
|
|
262
347
|
return getModelDefinition(options.model).requestTextCompletion(this, prompt, options);
|
|
263
348
|
}
|
|
@@ -277,11 +362,11 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
277
362
|
prompt: VertexAIPrompt,
|
|
278
363
|
result: unknown[],
|
|
279
364
|
toolUse: unknown[] | undefined,
|
|
280
|
-
options: ExecutionOptions
|
|
365
|
+
options: ExecutionOptions,
|
|
281
366
|
): Content[] | unknown | undefined {
|
|
282
367
|
// Handle Claude-style prompts (has 'messages' array)
|
|
283
|
-
if (
|
|
284
|
-
return this.buildClaudeStreamingConversation(prompt
|
|
368
|
+
if (isClaudeStreamingPrompt(prompt)) {
|
|
369
|
+
return this.buildClaudeStreamingConversation(prompt, result, toolUse, options);
|
|
285
370
|
}
|
|
286
371
|
|
|
287
372
|
// Only handle Gemini-style prompts with contents array
|
|
@@ -293,7 +378,7 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
293
378
|
|
|
294
379
|
// Convert accumulated results to text content for assistant message
|
|
295
380
|
const textContent = completionResults
|
|
296
|
-
.map(r => {
|
|
381
|
+
.map((r) => {
|
|
297
382
|
switch (r.type) {
|
|
298
383
|
case 'text':
|
|
299
384
|
return r.value;
|
|
@@ -302,25 +387,27 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
302
387
|
case 'image':
|
|
303
388
|
// Skip images in conversation - they're in the result
|
|
304
389
|
return '';
|
|
305
|
-
default:
|
|
306
|
-
|
|
390
|
+
default: {
|
|
391
|
+
const _exhaustive: never = r;
|
|
392
|
+
return String(_exhaustive);
|
|
393
|
+
}
|
|
307
394
|
}
|
|
308
395
|
})
|
|
309
396
|
.join('');
|
|
310
397
|
|
|
311
398
|
// Build parts array for assistant message
|
|
312
|
-
const parts:
|
|
399
|
+
const parts: unknown[] = [];
|
|
313
400
|
if (textContent) {
|
|
314
401
|
parts.push({ text: textContent });
|
|
315
402
|
}
|
|
316
403
|
// Add function calls if present (Gemini format)
|
|
317
404
|
if (toolUse && toolUse.length > 0) {
|
|
318
|
-
for (const tool of toolUse as
|
|
319
|
-
const functionCallPart:
|
|
405
|
+
for (const tool of toolUse as ToolUse<unknown>[]) {
|
|
406
|
+
const functionCallPart: Record<string, unknown> = {
|
|
320
407
|
functionCall: {
|
|
321
408
|
name: tool.tool_name,
|
|
322
409
|
args: tool.tool_input,
|
|
323
|
-
}
|
|
410
|
+
},
|
|
324
411
|
};
|
|
325
412
|
// Include thought_signature for Gemini thinking models (2.5+/3.0+)
|
|
326
413
|
// This must be preserved in the conversation for subsequent API calls
|
|
@@ -334,16 +421,14 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
334
421
|
// prompt.contents already includes the conversation history
|
|
335
422
|
// (merged in requestTextCompletionStream via updateConversation),
|
|
336
423
|
// so we use it directly — do NOT prepend options.conversation again.
|
|
337
|
-
let conversation: Content[] = [
|
|
338
|
-
...prompt.contents,
|
|
339
|
-
];
|
|
424
|
+
let conversation: Content[] = [...prompt.contents];
|
|
340
425
|
|
|
341
426
|
// Only add assistant message if there's actual content
|
|
342
427
|
// (Empty text parts can cause API errors)
|
|
343
428
|
if (parts.length > 0) {
|
|
344
429
|
conversation.push({
|
|
345
430
|
role: 'model',
|
|
346
|
-
parts: parts
|
|
431
|
+
parts: parts as Content['parts'],
|
|
347
432
|
});
|
|
348
433
|
}
|
|
349
434
|
|
|
@@ -355,7 +440,7 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
355
440
|
const stripOptions = {
|
|
356
441
|
keepForTurns: options.stripImagesAfterTurns ?? Infinity,
|
|
357
442
|
currentTurn,
|
|
358
|
-
textMaxTokens: options.stripTextMaxTokens
|
|
443
|
+
textMaxTokens: options.stripTextMaxTokens,
|
|
359
444
|
};
|
|
360
445
|
let processedConversation = stripBase64ImagesFromConversation(conversation, stripOptions);
|
|
361
446
|
processedConversation = truncateLargeTextInConversation(processedConversation, stripOptions);
|
|
@@ -370,7 +455,10 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
370
455
|
const geminiPrompt = prompt as GenerateContentPrompt;
|
|
371
456
|
if (geminiPrompt.system) {
|
|
372
457
|
if (typeof processedConversation === 'object' && processedConversation !== null) {
|
|
373
|
-
processedConversation = {
|
|
458
|
+
processedConversation = {
|
|
459
|
+
...(processedConversation as object),
|
|
460
|
+
_llumiverse_system: geminiPrompt.system,
|
|
461
|
+
};
|
|
374
462
|
}
|
|
375
463
|
}
|
|
376
464
|
|
|
@@ -385,13 +473,13 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
385
473
|
prompt: { messages: unknown[]; system?: unknown[] },
|
|
386
474
|
result: unknown[],
|
|
387
475
|
toolUse: unknown[] | undefined,
|
|
388
|
-
options: ExecutionOptions
|
|
476
|
+
options: ExecutionOptions,
|
|
389
477
|
): unknown {
|
|
390
478
|
const completionResults = result as CompletionResult[];
|
|
391
479
|
|
|
392
480
|
// Convert accumulated results to text content
|
|
393
481
|
const textContent = completionResults
|
|
394
|
-
.map(r => {
|
|
482
|
+
.map((r) => {
|
|
395
483
|
switch (r.type) {
|
|
396
484
|
case 'text':
|
|
397
485
|
return r.value;
|
|
@@ -399,8 +487,10 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
399
487
|
return typeof r.value === 'string' ? r.value : JSON.stringify(r.value);
|
|
400
488
|
case 'image':
|
|
401
489
|
return '';
|
|
402
|
-
default:
|
|
403
|
-
|
|
490
|
+
default: {
|
|
491
|
+
const _exhaustive: never = r;
|
|
492
|
+
return String(_exhaustive);
|
|
493
|
+
}
|
|
404
494
|
}
|
|
405
495
|
})
|
|
406
496
|
.join('');
|
|
@@ -412,46 +502,44 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
412
502
|
if (textContent) {
|
|
413
503
|
content.push({
|
|
414
504
|
type: 'text',
|
|
415
|
-
text: textContent
|
|
505
|
+
text: textContent,
|
|
416
506
|
});
|
|
417
507
|
}
|
|
418
508
|
|
|
419
509
|
// Add tool_use blocks in Claude format
|
|
420
510
|
if (toolUse && toolUse.length > 0) {
|
|
421
|
-
for (const tool of toolUse as
|
|
511
|
+
for (const tool of toolUse as ToolUse<unknown>[]) {
|
|
422
512
|
content.push({
|
|
423
513
|
type: 'tool_use',
|
|
424
514
|
id: tool.id,
|
|
425
515
|
name: tool.tool_name,
|
|
426
|
-
input: tool.tool_input ?? {}
|
|
516
|
+
input: tool.tool_input ?? {},
|
|
427
517
|
});
|
|
428
518
|
}
|
|
429
519
|
}
|
|
430
520
|
|
|
431
521
|
// Claude's requestTextCompletionStream does NOT mutate prompt.messages
|
|
432
522
|
// to include history, so we must prepend options.conversation here.
|
|
433
|
-
const
|
|
434
|
-
const
|
|
523
|
+
const existingConversation = options.conversation as ConversationWrapper | undefined;
|
|
524
|
+
const existingMessages = existingConversation?.messages ?? [];
|
|
525
|
+
const existingSystem = existingConversation?.system ?? prompt.system;
|
|
435
526
|
|
|
436
527
|
// Build the new messages array
|
|
437
|
-
const newMessages = [
|
|
438
|
-
...existingMessages,
|
|
439
|
-
...prompt.messages,
|
|
440
|
-
];
|
|
528
|
+
const newMessages = [...existingMessages, ...prompt.messages];
|
|
441
529
|
|
|
442
530
|
// Only add assistant message if there's actual content
|
|
443
531
|
// (Claude API rejects empty text content blocks)
|
|
444
532
|
if (content.length > 0) {
|
|
445
533
|
newMessages.push({
|
|
446
534
|
role: 'assistant',
|
|
447
|
-
content: content
|
|
535
|
+
content: content,
|
|
448
536
|
});
|
|
449
537
|
}
|
|
450
538
|
|
|
451
539
|
// Build the new conversation in ClaudePrompt format
|
|
452
540
|
const conversation = {
|
|
453
541
|
messages: newMessages,
|
|
454
|
-
system: existingSystem
|
|
542
|
+
system: existingSystem,
|
|
455
543
|
};
|
|
456
544
|
|
|
457
545
|
// Increment turn counter
|
|
@@ -462,7 +550,7 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
462
550
|
const stripOptions = {
|
|
463
551
|
keepForTurns: options.stripImagesAfterTurns ?? Infinity,
|
|
464
552
|
currentTurn,
|
|
465
|
-
textMaxTokens: options.stripTextMaxTokens
|
|
553
|
+
textMaxTokens: options.stripTextMaxTokens,
|
|
466
554
|
};
|
|
467
555
|
let processedConversation = stripBase64ImagesFromConversation(withTurn, stripOptions);
|
|
468
556
|
processedConversation = truncateLargeTextInConversation(processedConversation, stripOptions);
|
|
@@ -474,11 +562,8 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
474
562
|
return processedConversation;
|
|
475
563
|
}
|
|
476
564
|
|
|
477
|
-
async requestImageGeneration(
|
|
478
|
-
|
|
479
|
-
_options: ExecutionOptions,
|
|
480
|
-
): Promise<Completion> {
|
|
481
|
-
const splits = _options.model.split("/");
|
|
565
|
+
async requestImageGeneration(_prompt: ImagenPrompt, _options: ExecutionOptions): Promise<Completion> {
|
|
566
|
+
const splits = _options.model.split('/');
|
|
482
567
|
const modelName = trimModelName(splits[splits.length - 1]);
|
|
483
568
|
return new ImagenModelDefinition(modelName).requestImageGeneration(this, _prompt, _options);
|
|
484
569
|
}
|
|
@@ -496,36 +581,42 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
496
581
|
// Get clients
|
|
497
582
|
const modelGarden = await this.getModelGardenClient();
|
|
498
583
|
const aiplatform = await this.getAIPlatformClient();
|
|
499
|
-
const globalGenAiClient = this.getGoogleGenAIClient(
|
|
584
|
+
const globalGenAiClient = this.getGoogleGenAIClient('global');
|
|
500
585
|
|
|
501
586
|
let models: AIModel<string>[] = [];
|
|
502
587
|
|
|
503
588
|
//Model Garden Publisher models - Pretrained models
|
|
504
|
-
const publishers = [
|
|
589
|
+
const publishers = ['google', 'anthropic', 'meta'];
|
|
505
590
|
// Meta "maas" models are LLama Models-As-A-Service. Non-maas models are not pre-deployed.
|
|
506
|
-
const supportedModels = { google: [
|
|
591
|
+
const supportedModels = { google: ['gemini', 'imagen'], anthropic: ['claude'], meta: ['maas'] };
|
|
507
592
|
// Additional models not in the listings, but we want to include
|
|
508
593
|
// TODO: Remove once the models are available in the listing API, or no longer needed
|
|
509
594
|
const additionalModels = {
|
|
510
|
-
google: [
|
|
511
|
-
"imagen-3.0-fast-generate-001",
|
|
512
|
-
],
|
|
595
|
+
google: ['imagen-3.0-fast-generate-001'],
|
|
513
596
|
anthropic: [],
|
|
514
597
|
meta: [
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
598
|
+
'llama-4-maverick-17b-128e-instruct-maas',
|
|
599
|
+
'llama-4-scout-17b-16e-instruct-maas',
|
|
600
|
+
'llama-3.3-70b-instruct-maas',
|
|
601
|
+
'llama-3.2-90b-vision-instruct-maas',
|
|
602
|
+
'llama-3.1-405b-instruct-maas',
|
|
603
|
+
'llama-3.1-70b-instruct-maas',
|
|
604
|
+
'llama-3.1-8b-instruct-maas',
|
|
522
605
|
],
|
|
523
|
-
}
|
|
606
|
+
};
|
|
524
607
|
|
|
525
608
|
//Used to exclude retired models that are still in the listing API but not available for use.
|
|
526
609
|
//Or models we do not support yet
|
|
527
610
|
const unsupportedModelsByPublisher = {
|
|
528
|
-
google: [
|
|
611
|
+
google: [
|
|
612
|
+
'gemini-pro',
|
|
613
|
+
'gemini-ultra',
|
|
614
|
+
'imagen-product-recontext-preview',
|
|
615
|
+
'embedding',
|
|
616
|
+
'embed',
|
|
617
|
+
'gemini-live-2.5-flash-preview-native-audio',
|
|
618
|
+
'computer-use-preview',
|
|
619
|
+
],
|
|
529
620
|
anthropic: [],
|
|
530
621
|
meta: [],
|
|
531
622
|
};
|
|
@@ -537,7 +628,7 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
537
628
|
const publisherPromises = publishers.map(async (publisher) => {
|
|
538
629
|
const [response] = await modelGarden.listPublisherModels({
|
|
539
630
|
parent: `publishers/${publisher}`,
|
|
540
|
-
orderBy:
|
|
631
|
+
orderBy: 'name',
|
|
541
632
|
listAllVersions: true,
|
|
542
633
|
});
|
|
543
634
|
return { publisher, response };
|
|
@@ -555,124 +646,138 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
555
646
|
const [response] = aiplatformResult;
|
|
556
647
|
models = models.concat(
|
|
557
648
|
response.map((model) => ({
|
|
558
|
-
id: model.name?.split(
|
|
559
|
-
name: model.displayName ??
|
|
560
|
-
provider:
|
|
561
|
-
}))
|
|
649
|
+
id: model.name?.split('/').pop() ?? '',
|
|
650
|
+
name: model.displayName ?? '',
|
|
651
|
+
provider: 'vertexai',
|
|
652
|
+
})),
|
|
562
653
|
);
|
|
563
654
|
|
|
564
655
|
// Process global google models from GenAI
|
|
656
|
+
// Exclude embedding, retired and or unsupported models
|
|
657
|
+
const excludedModels = unsupportedModelsByPublisher.google;
|
|
565
658
|
models = models.concat(
|
|
566
|
-
globalGoogleResult
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
659
|
+
globalGoogleResult
|
|
660
|
+
.filter((model) => !excludedModels.includes(model.name ?? ''))
|
|
661
|
+
.map((model) => {
|
|
662
|
+
const modelCapability = getModelCapabilities(model.name ?? '', 'vertexai');
|
|
663
|
+
return {
|
|
664
|
+
id: `locations/global/${model.name}`,
|
|
665
|
+
name: `Global ${model.name?.split('/').pop()}`,
|
|
666
|
+
provider: 'vertexai',
|
|
667
|
+
owner: 'google',
|
|
668
|
+
input_modalities: modelModalitiesToArray(modelCapability.input),
|
|
669
|
+
output_modalities: modelModalitiesToArray(modelCapability.output),
|
|
670
|
+
tool_support: modelCapability.tool_support,
|
|
671
|
+
};
|
|
672
|
+
}),
|
|
578
673
|
);
|
|
579
674
|
|
|
580
675
|
// Process publisher models
|
|
581
676
|
for (const result of publisherResults) {
|
|
582
677
|
const { publisher, response } = result;
|
|
583
678
|
const modelFamily = supportedModels[publisher as keyof typeof supportedModels];
|
|
584
|
-
const
|
|
585
|
-
|
|
586
|
-
models = models.concat(
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
679
|
+
const excludedModels = unsupportedModelsByPublisher[publisher as keyof typeof unsupportedModelsByPublisher];
|
|
680
|
+
|
|
681
|
+
models = models.concat(
|
|
682
|
+
response
|
|
683
|
+
.filter((model) => {
|
|
684
|
+
const modelName = model.name ?? '';
|
|
685
|
+
// Exclude embedding, retired and or unsupported models
|
|
686
|
+
if (excludedModels.some((retiredModel) => modelName.includes(retiredModel))) {
|
|
687
|
+
return false;
|
|
688
|
+
}
|
|
689
|
+
// Check if the model belongs to the supported model families
|
|
690
|
+
if (modelFamily.some((family) => modelName.includes(family))) {
|
|
691
|
+
return true;
|
|
692
|
+
}
|
|
693
|
+
return false;
|
|
694
|
+
})
|
|
695
|
+
.map((model) => {
|
|
696
|
+
const modelCapability = getModelCapabilities(model.name ?? '', 'vertexai');
|
|
697
|
+
return {
|
|
698
|
+
id: model.name ?? '',
|
|
699
|
+
name: model.name?.split('/').pop() ?? '',
|
|
700
|
+
provider: 'vertexai',
|
|
701
|
+
owner: publisher,
|
|
702
|
+
input_modalities: modelModalitiesToArray(modelCapability.input),
|
|
703
|
+
output_modalities: modelModalitiesToArray(modelCapability.output),
|
|
704
|
+
tool_support: modelCapability.tool_support,
|
|
705
|
+
} satisfies AIModel<string>;
|
|
706
|
+
}),
|
|
707
|
+
);
|
|
609
708
|
|
|
610
709
|
// Create global google gemini models for Gemini 2.5 and later, if missing from GenAI listing
|
|
611
710
|
if (publisher === 'google') {
|
|
612
|
-
const globalGeminiModels = response
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
711
|
+
const globalGeminiModels = response
|
|
712
|
+
.filter((model) => {
|
|
713
|
+
const modelName = model.name ?? '';
|
|
714
|
+
if (excludedModels.some((retiredModel) => modelName.includes(retiredModel))) {
|
|
715
|
+
return false;
|
|
716
|
+
}
|
|
717
|
+
if (modelFamily.some((family) => modelName.includes(family))) {
|
|
718
|
+
const versionMatch = modelName.match(/gemini-(\d+(?:\.\d+)?)/);
|
|
719
|
+
if (versionMatch) {
|
|
720
|
+
const version = parseFloat(versionMatch[1]);
|
|
721
|
+
if (version >= 2.5) {
|
|
722
|
+
// Check if already present
|
|
723
|
+
const shortName = modelName.split('/').pop();
|
|
724
|
+
const globalName = `Global ${shortName}`;
|
|
725
|
+
if (models.some((m) => m.name === globalName)) {
|
|
726
|
+
return false;
|
|
727
|
+
}
|
|
728
|
+
return true;
|
|
627
729
|
}
|
|
628
|
-
return true;
|
|
629
730
|
}
|
|
731
|
+
return false;
|
|
630
732
|
}
|
|
631
733
|
return false;
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
}
|
|
645
|
-
});
|
|
734
|
+
})
|
|
735
|
+
.map((model) => {
|
|
736
|
+
const modelCapability = getModelCapabilities(model.name ?? '', 'vertexai');
|
|
737
|
+
return {
|
|
738
|
+
id: `locations/global/${model.name}`,
|
|
739
|
+
name: `Global ${model.name?.split('/').pop()}`,
|
|
740
|
+
provider: 'vertexai',
|
|
741
|
+
owner: publisher,
|
|
742
|
+
input_modalities: modelModalitiesToArray(modelCapability.input),
|
|
743
|
+
output_modalities: modelModalitiesToArray(modelCapability.output),
|
|
744
|
+
tool_support: modelCapability.tool_support,
|
|
745
|
+
} satisfies AIModel<string>;
|
|
746
|
+
});
|
|
646
747
|
|
|
647
748
|
models = models.concat(globalGeminiModels);
|
|
648
749
|
}
|
|
649
750
|
|
|
650
751
|
// Create global anthropic models for those not in NON_GLOBAL_ANTHROPIC_MODELS
|
|
651
752
|
if (publisher === 'anthropic') {
|
|
652
|
-
const globalAnthropicModels = response
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
if (modelFamily.some(family => modelName.includes(family))) {
|
|
658
|
-
if (modelName.includes("claude-3-7")) {
|
|
659
|
-
return true;
|
|
753
|
+
const globalAnthropicModels = response
|
|
754
|
+
.filter((model) => {
|
|
755
|
+
const modelName = model.name ?? '';
|
|
756
|
+
if (excludedModels.some((retiredModel) => modelName.includes(retiredModel))) {
|
|
757
|
+
return false;
|
|
660
758
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
759
|
+
if (modelFamily.some((family) => modelName.includes(family))) {
|
|
760
|
+
if (modelName.includes('claude-3-7')) {
|
|
761
|
+
return true;
|
|
762
|
+
}
|
|
763
|
+
return !NON_GLOBAL_ANTHROPIC_MODELS.some((nonGlobalModel) =>
|
|
764
|
+
modelName.includes(nonGlobalModel),
|
|
765
|
+
);
|
|
766
|
+
}
|
|
767
|
+
return false;
|
|
768
|
+
})
|
|
769
|
+
.map((model) => {
|
|
770
|
+
const modelCapability = getModelCapabilities(model.name ?? '', 'vertexai');
|
|
771
|
+
return {
|
|
772
|
+
id: `locations/global/${model.name}`,
|
|
773
|
+
name: `Global ${model.name?.split('/').pop()}`,
|
|
774
|
+
provider: 'vertexai',
|
|
775
|
+
owner: publisher,
|
|
776
|
+
input_modalities: modelModalitiesToArray(modelCapability.input),
|
|
777
|
+
output_modalities: modelModalitiesToArray(modelCapability.output),
|
|
778
|
+
tool_support: modelCapability.tool_support,
|
|
779
|
+
} satisfies AIModel<string>;
|
|
780
|
+
});
|
|
676
781
|
|
|
677
782
|
models = models.concat(globalAnthropicModels);
|
|
678
783
|
}
|
|
@@ -680,7 +785,7 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
680
785
|
// Add additional models that are not in the listing
|
|
681
786
|
for (const additionalModel of additionalModels[publisher as keyof typeof additionalModels]) {
|
|
682
787
|
const publisherModelName = `publishers/${publisher}/models/${additionalModel}`;
|
|
683
|
-
const modelCapability = getModelCapabilities(additionalModel,
|
|
788
|
+
const modelCapability = getModelCapabilities(additionalModel, 'vertexai');
|
|
684
789
|
models.push({
|
|
685
790
|
id: publisherModelName,
|
|
686
791
|
name: additionalModel,
|
|
@@ -694,54 +799,33 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
694
799
|
}
|
|
695
800
|
|
|
696
801
|
//Remove duplicates
|
|
697
|
-
const uniqueModels = Array.from(new Set(models.map(a => a.id)))
|
|
698
|
-
.map(id => {
|
|
699
|
-
return models.find(a => a.id === id) ?? {} as AIModel<string
|
|
700
|
-
})
|
|
802
|
+
const uniqueModels = Array.from(new Set(models.map((a) => a.id)))
|
|
803
|
+
.map((id) => {
|
|
804
|
+
return models.find((a) => a.id === id) ?? ({} as AIModel<string>);
|
|
805
|
+
})
|
|
806
|
+
.sort((a, b) => a.id.localeCompare(b.id));
|
|
701
807
|
|
|
702
808
|
return uniqueModels;
|
|
703
809
|
}
|
|
704
810
|
|
|
705
811
|
validateConnection(): Promise<boolean> {
|
|
706
|
-
throw new Error(
|
|
812
|
+
throw new Error('Method not implemented.');
|
|
707
813
|
}
|
|
708
814
|
|
|
709
815
|
async generateEmbeddings(options: EmbeddingsOptions): Promise<EmbeddingsResult> {
|
|
710
|
-
|
|
711
|
-
if (options.text && options.image) {
|
|
712
|
-
throw new Error("Text and Image simultaneous embedding not implemented. Submit separately");
|
|
713
|
-
}
|
|
714
|
-
return getEmbeddingsForImages(this, options);
|
|
715
|
-
}
|
|
716
|
-
const text_options: TextEmbeddingsOptions = {
|
|
717
|
-
content: options.text ?? "",
|
|
718
|
-
model: options.model,
|
|
719
|
-
};
|
|
720
|
-
return getEmbeddingsForText(this, text_options);
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
/**
|
|
724
|
-
* Cleanup Google Cloud clients when the driver is evicted from the cache.
|
|
725
|
-
*/
|
|
726
|
-
destroy(): void {
|
|
727
|
-
this.aiplatform?.close();
|
|
728
|
-
this.modelGarden?.close();
|
|
729
|
-
this.imagenClient?.close();
|
|
816
|
+
return generateVertexAiEmbeddings(this, options);
|
|
730
817
|
}
|
|
731
818
|
|
|
732
819
|
/**
|
|
733
820
|
* Format VertexAI errors by routing to model-specific error handlers.
|
|
734
821
|
* Each model definition (Gemini, Claude, Llama) can provide custom error parsing
|
|
735
822
|
* based on their specific SDK error structures.
|
|
736
|
-
*
|
|
823
|
+
*
|
|
737
824
|
* @param error - The error from the VertexAI/model SDK
|
|
738
825
|
* @param context - Context about where the error occurred
|
|
739
826
|
* @returns A standardized LlumiverseError
|
|
740
827
|
*/
|
|
741
|
-
public formatLlumiverseError(
|
|
742
|
-
error: unknown,
|
|
743
|
-
context: LlumiverseErrorContext
|
|
744
|
-
): LlumiverseError {
|
|
828
|
+
public formatLlumiverseError(error: unknown, context: LlumiverseErrorContext): LlumiverseError {
|
|
745
829
|
// Get the model definition for this request
|
|
746
830
|
const modelDef = getModelDefinition(context.model);
|
|
747
831
|
|
|
@@ -749,7 +833,7 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
749
833
|
if (modelDef.formatLlumiverseError) {
|
|
750
834
|
try {
|
|
751
835
|
return modelDef.formatLlumiverseError(this, error, context);
|
|
752
|
-
} catch
|
|
836
|
+
} catch {
|
|
753
837
|
// If model-specific handler throws, fall through to default handling
|
|
754
838
|
// This allows model handlers to explicitly opt out for certain errors
|
|
755
839
|
}
|
|
@@ -761,22 +845,25 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
761
845
|
}
|
|
762
846
|
|
|
763
847
|
//'us-central1-aiplatform.googleapis.com',
|
|
764
|
-
const API_BASE_PATH =
|
|
848
|
+
const API_BASE_PATH = 'aiplatform.googleapis.com';
|
|
765
849
|
function createFetchClient({
|
|
766
850
|
region,
|
|
767
851
|
project,
|
|
768
852
|
apiEndpoint,
|
|
769
|
-
apiVersion =
|
|
853
|
+
apiVersion = 'v1',
|
|
854
|
+
fetchImpl,
|
|
770
855
|
}: {
|
|
771
856
|
region: string;
|
|
772
857
|
project: string;
|
|
773
858
|
apiEndpoint?: string;
|
|
774
859
|
apiVersion?: string;
|
|
860
|
+
fetchImpl?: FETCH_FN;
|
|
775
861
|
}) {
|
|
776
862
|
const vertexBaseEndpoint = apiEndpoint ?? `${region}-${API_BASE_PATH}`;
|
|
777
863
|
return new FetchClient(
|
|
778
864
|
`https://${vertexBaseEndpoint}/${apiVersion}/projects/${project}/locations/${region}`,
|
|
865
|
+
fetchImpl,
|
|
779
866
|
).withHeaders({
|
|
780
|
-
|
|
867
|
+
'Content-Type': 'application/json',
|
|
781
868
|
});
|
|
782
869
|
}
|