@llumiverse/drivers 0.22.0 → 0.23.0-dev-20251118
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/README.md +1 -1
- package/lib/cjs/adobe/firefly.js +8 -7
- package/lib/cjs/adobe/firefly.js.map +1 -1
- package/lib/cjs/azure/azure_foundry.js +12 -12
- package/lib/cjs/azure/azure_foundry.js.map +1 -1
- package/lib/cjs/bedrock/index.js +172 -22
- package/lib/cjs/bedrock/index.js.map +1 -1
- package/lib/cjs/bedrock/twelvelabs.js +87 -0
- package/lib/cjs/bedrock/twelvelabs.js.map +1 -0
- package/lib/cjs/groq/index.js +91 -16
- package/lib/cjs/groq/index.js.map +1 -1
- package/lib/cjs/huggingface_ie.js +7 -6
- package/lib/cjs/huggingface_ie.js.map +1 -1
- package/lib/cjs/index.js +2 -2
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/mistral/index.js +5 -4
- package/lib/cjs/mistral/index.js.map +1 -1
- package/lib/cjs/openai/azure_openai.js +1 -1
- package/lib/cjs/openai/azure_openai.js.map +1 -1
- package/lib/cjs/openai/index.js +16 -12
- package/lib/cjs/openai/index.js.map +1 -1
- package/lib/cjs/replicate.js +6 -6
- package/lib/cjs/replicate.js.map +1 -1
- package/lib/cjs/test/utils.js +1 -1
- package/lib/cjs/test/utils.js.map +1 -1
- package/lib/cjs/test-driver/TestErrorCompletionStream.js +20 -0
- package/lib/cjs/test-driver/TestErrorCompletionStream.js.map +1 -0
- package/lib/cjs/test-driver/TestValidationErrorCompletionStream.js +24 -0
- package/lib/cjs/test-driver/TestValidationErrorCompletionStream.js.map +1 -0
- package/lib/cjs/test-driver/index.js +109 -0
- package/lib/cjs/test-driver/index.js.map +1 -0
- package/lib/cjs/test-driver/utils.js +30 -0
- package/lib/cjs/test-driver/utils.js.map +1 -0
- package/lib/cjs/togetherai/index.js +4 -4
- package/lib/cjs/togetherai/index.js.map +1 -1
- package/lib/cjs/vertexai/embeddings/embeddings-text.js +1 -1
- package/lib/cjs/vertexai/embeddings/embeddings-text.js.map +1 -1
- package/lib/cjs/vertexai/index.js +136 -31
- package/lib/cjs/vertexai/index.js.map +1 -1
- package/lib/cjs/vertexai/models/claude.js +38 -16
- package/lib/cjs/vertexai/models/claude.js.map +1 -1
- package/lib/cjs/vertexai/models/gemini.js +131 -41
- package/lib/cjs/vertexai/models/gemini.js.map +1 -1
- package/lib/cjs/vertexai/models/imagen.js +12 -23
- package/lib/cjs/vertexai/models/imagen.js.map +1 -1
- package/lib/cjs/vertexai/models/llama.js +4 -3
- package/lib/cjs/vertexai/models/llama.js.map +1 -1
- package/lib/cjs/vertexai/models.js +13 -2
- package/lib/cjs/vertexai/models.js.map +1 -1
- package/lib/cjs/watsonx/index.js +5 -5
- package/lib/cjs/watsonx/index.js.map +1 -1
- package/lib/cjs/xai/index.js +1 -1
- package/lib/cjs/xai/index.js.map +1 -1
- package/lib/esm/adobe/firefly.js +8 -7
- package/lib/esm/adobe/firefly.js.map +1 -1
- package/lib/esm/azure/azure_foundry.js +12 -12
- package/lib/esm/azure/azure_foundry.js.map +1 -1
- package/lib/esm/bedrock/index.js +172 -22
- package/lib/esm/bedrock/index.js.map +1 -1
- package/lib/esm/bedrock/twelvelabs.js +84 -0
- package/lib/esm/bedrock/twelvelabs.js.map +1 -0
- package/lib/esm/groq/index.js +91 -16
- package/lib/esm/groq/index.js.map +1 -1
- package/lib/esm/huggingface_ie.js +8 -7
- package/lib/esm/huggingface_ie.js.map +1 -1
- package/lib/esm/index.js +2 -2
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/mistral/index.js +5 -4
- package/lib/esm/mistral/index.js.map +1 -1
- package/lib/esm/openai/azure_openai.js +1 -1
- package/lib/esm/openai/azure_openai.js.map +1 -1
- package/lib/esm/openai/index.js +16 -12
- package/lib/esm/openai/index.js.map +1 -1
- package/lib/esm/replicate.js +6 -6
- package/lib/esm/replicate.js.map +1 -1
- package/lib/esm/src/adobe/firefly.js +116 -0
- package/lib/esm/src/adobe/firefly.js.map +1 -0
- package/lib/esm/src/azure/azure_foundry.js +382 -0
- package/lib/esm/src/azure/azure_foundry.js.map +1 -0
- package/lib/esm/src/bedrock/converse.js +278 -0
- package/lib/esm/src/bedrock/converse.js.map +1 -0
- package/lib/esm/src/bedrock/index.js +962 -0
- package/lib/esm/src/bedrock/index.js.map +1 -0
- package/lib/esm/src/bedrock/nova-image-payload.js +203 -0
- package/lib/esm/src/bedrock/nova-image-payload.js.map +1 -0
- package/lib/esm/src/bedrock/payloads.js +2 -0
- package/lib/esm/src/bedrock/payloads.js.map +1 -0
- package/lib/esm/src/bedrock/s3.js +99 -0
- package/lib/esm/src/bedrock/s3.js.map +1 -0
- package/lib/esm/src/bedrock/twelvelabs.js +84 -0
- package/lib/esm/src/bedrock/twelvelabs.js.map +1 -0
- package/lib/esm/src/groq/index.js +286 -0
- package/lib/esm/src/groq/index.js.map +1 -0
- package/lib/esm/src/huggingface_ie.js +197 -0
- package/lib/esm/src/huggingface_ie.js.map +1 -0
- package/lib/esm/src/index.js +14 -0
- package/lib/esm/src/index.js.map +1 -0
- package/lib/esm/src/mistral/index.js +169 -0
- package/lib/esm/src/mistral/index.js.map +1 -0
- package/lib/esm/src/mistral/types.js +80 -0
- package/lib/esm/src/mistral/types.js.map +1 -0
- package/lib/esm/src/openai/azure_openai.js +68 -0
- package/lib/esm/src/openai/azure_openai.js.map +1 -0
- package/lib/esm/src/openai/index.js +464 -0
- package/lib/esm/src/openai/index.js.map +1 -0
- package/lib/esm/src/openai/openai.js +14 -0
- package/lib/esm/src/openai/openai.js.map +1 -0
- package/lib/esm/src/openai/openai_format.js +134 -0
- package/lib/esm/src/openai/openai_format.js.map +1 -0
- package/lib/esm/src/replicate.js +268 -0
- package/lib/esm/src/replicate.js.map +1 -0
- package/lib/esm/src/test/TestErrorCompletionStream.js +16 -0
- package/lib/esm/src/test/TestErrorCompletionStream.js.map +1 -0
- package/lib/esm/src/test/TestValidationErrorCompletionStream.js +20 -0
- package/lib/esm/src/test/TestValidationErrorCompletionStream.js.map +1 -0
- package/lib/esm/src/test/index.js +91 -0
- package/lib/esm/src/test/index.js.map +1 -0
- package/lib/esm/src/test/utils.js +25 -0
- package/lib/esm/src/test/utils.js.map +1 -0
- package/lib/esm/src/test-driver/TestErrorCompletionStream.js +16 -0
- package/lib/esm/src/test-driver/TestErrorCompletionStream.js.map +1 -0
- package/lib/esm/src/test-driver/TestValidationErrorCompletionStream.js +20 -0
- package/lib/esm/src/test-driver/TestValidationErrorCompletionStream.js.map +1 -0
- package/lib/esm/src/test-driver/index.js +91 -0
- package/lib/esm/src/test-driver/index.js.map +1 -0
- package/lib/esm/src/test-driver/utils.js +25 -0
- package/lib/esm/src/test-driver/utils.js.map +1 -0
- package/lib/esm/src/togetherai/index.js +122 -0
- package/lib/esm/src/togetherai/index.js.map +1 -0
- package/lib/esm/src/togetherai/interfaces.js +2 -0
- package/lib/esm/src/togetherai/interfaces.js.map +1 -0
- package/lib/esm/src/vertexai/debug.js +6 -0
- package/lib/esm/src/vertexai/debug.js.map +1 -0
- package/lib/esm/src/vertexai/embeddings/embeddings-image.js +24 -0
- package/lib/esm/src/vertexai/embeddings/embeddings-image.js.map +1 -0
- package/lib/esm/src/vertexai/embeddings/embeddings-text.js +20 -0
- package/lib/esm/src/vertexai/embeddings/embeddings-text.js.map +1 -0
- package/lib/esm/src/vertexai/index.js +383 -0
- package/lib/esm/src/vertexai/index.js.map +1 -0
- package/lib/esm/src/vertexai/models/claude.js +394 -0
- package/lib/esm/src/vertexai/models/claude.js.map +1 -0
- package/lib/esm/src/vertexai/models/gemini.js +817 -0
- package/lib/esm/src/vertexai/models/gemini.js.map +1 -0
- package/lib/esm/src/vertexai/models/imagen.js +302 -0
- package/lib/esm/src/vertexai/models/imagen.js.map +1 -0
- package/lib/esm/src/vertexai/models/llama.js +179 -0
- package/lib/esm/src/vertexai/models/llama.js.map +1 -0
- package/lib/esm/src/vertexai/models.js +32 -0
- package/lib/esm/src/vertexai/models.js.map +1 -0
- package/lib/esm/src/watsonx/index.js +157 -0
- package/lib/esm/src/watsonx/index.js.map +1 -0
- package/lib/esm/src/watsonx/interfaces.js +2 -0
- package/lib/esm/src/watsonx/interfaces.js.map +1 -0
- package/lib/esm/src/xai/index.js +64 -0
- package/lib/esm/src/xai/index.js.map +1 -0
- package/lib/esm/test/utils.js +1 -1
- package/lib/esm/test/utils.js.map +1 -1
- package/lib/esm/test-driver/TestErrorCompletionStream.js +16 -0
- package/lib/esm/test-driver/TestErrorCompletionStream.js.map +1 -0
- package/lib/esm/test-driver/TestValidationErrorCompletionStream.js +20 -0
- package/lib/esm/test-driver/TestValidationErrorCompletionStream.js.map +1 -0
- package/lib/esm/test-driver/index.js +91 -0
- package/lib/esm/test-driver/index.js.map +1 -0
- package/lib/esm/test-driver/utils.js +25 -0
- package/lib/esm/test-driver/utils.js.map +1 -0
- package/lib/esm/togetherai/index.js +4 -4
- package/lib/esm/togetherai/index.js.map +1 -1
- package/lib/esm/tsconfig.tsbuildinfo +1 -0
- package/lib/esm/vertexai/embeddings/embeddings-text.js +1 -1
- package/lib/esm/vertexai/embeddings/embeddings-text.js.map +1 -1
- package/lib/esm/vertexai/index.js +136 -31
- package/lib/esm/vertexai/index.js.map +1 -1
- package/lib/esm/vertexai/models/claude.js +37 -15
- package/lib/esm/vertexai/models/claude.js.map +1 -1
- package/lib/esm/vertexai/models/gemini.js +133 -43
- package/lib/esm/vertexai/models/gemini.js.map +1 -1
- package/lib/esm/vertexai/models/imagen.js +9 -17
- package/lib/esm/vertexai/models/imagen.js.map +1 -1
- package/lib/esm/vertexai/models/llama.js +4 -3
- package/lib/esm/vertexai/models/llama.js.map +1 -1
- package/lib/esm/vertexai/models.js +13 -2
- package/lib/esm/vertexai/models.js.map +1 -1
- package/lib/esm/watsonx/index.js +5 -5
- package/lib/esm/watsonx/index.js.map +1 -1
- package/lib/esm/xai/index.js +1 -1
- package/lib/esm/xai/index.js.map +1 -1
- package/lib/types/adobe/firefly.d.ts +3 -3
- package/lib/types/adobe/firefly.d.ts.map +1 -1
- package/lib/types/azure/azure_foundry.d.ts +2 -2
- package/lib/types/azure/azure_foundry.d.ts.map +1 -1
- package/lib/types/bedrock/index.d.ts +9 -5
- package/lib/types/bedrock/index.d.ts.map +1 -1
- package/lib/types/bedrock/twelvelabs.d.ts +50 -0
- package/lib/types/bedrock/twelvelabs.d.ts.map +1 -0
- package/lib/types/groq/index.d.ts +3 -0
- package/lib/types/groq/index.d.ts.map +1 -1
- package/lib/types/huggingface_ie.d.ts +8 -5
- package/lib/types/huggingface_ie.d.ts.map +1 -1
- package/lib/types/index.d.ts +2 -2
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/mistral/index.d.ts +2 -2
- package/lib/types/mistral/index.d.ts.map +1 -1
- package/lib/types/openai/index.d.ts +2 -2
- package/lib/types/openai/index.d.ts.map +1 -1
- package/lib/types/replicate.d.ts +6 -3
- package/lib/types/replicate.d.ts.map +1 -1
- package/lib/types/src/adobe/firefly.d.ts +29 -0
- package/lib/types/src/azure/azure_foundry.d.ts +49 -0
- package/lib/types/src/bedrock/converse.d.ts +8 -0
- package/lib/types/src/bedrock/index.d.ts +61 -0
- package/lib/types/src/bedrock/nova-image-payload.d.ts +73 -0
- package/lib/types/src/bedrock/payloads.d.ts +11 -0
- package/lib/types/src/bedrock/s3.d.ts +22 -0
- package/lib/types/src/bedrock/twelvelabs.d.ts +49 -0
- package/lib/types/src/groq/index.d.ts +26 -0
- package/lib/types/src/huggingface_ie.d.ts +34 -0
- package/lib/types/src/index.d.ts +13 -0
- package/lib/types/src/mistral/index.d.ts +24 -0
- package/lib/types/src/mistral/types.d.ts +131 -0
- package/lib/types/src/openai/azure_openai.d.ts +24 -0
- package/lib/types/src/openai/index.d.ts +24 -0
- package/lib/types/src/openai/openai.d.ts +14 -0
- package/lib/types/src/openai/openai_format.d.ts +18 -0
- package/lib/types/src/replicate.d.ts +47 -0
- package/lib/types/src/test/TestErrorCompletionStream.d.ts +8 -0
- package/lib/types/src/test/TestValidationErrorCompletionStream.d.ts +8 -0
- package/lib/types/src/test/index.d.ts +23 -0
- package/lib/types/src/test/utils.d.ts +4 -0
- package/lib/types/src/test-driver/TestErrorCompletionStream.d.ts +8 -0
- package/lib/types/src/test-driver/TestValidationErrorCompletionStream.d.ts +8 -0
- package/lib/types/src/test-driver/index.d.ts +23 -0
- package/lib/types/src/test-driver/utils.d.ts +4 -0
- package/lib/types/src/togetherai/index.d.ts +22 -0
- package/lib/types/src/togetherai/interfaces.d.ts +95 -0
- package/lib/types/src/vertexai/debug.d.ts +1 -0
- package/lib/types/src/vertexai/embeddings/embeddings-image.d.ts +10 -0
- package/lib/types/src/vertexai/embeddings/embeddings-text.d.ts +9 -0
- package/lib/types/src/vertexai/index.d.ts +52 -0
- package/lib/types/src/vertexai/models/claude.d.ts +19 -0
- package/lib/types/src/vertexai/models/gemini.d.ts +17 -0
- package/lib/types/src/vertexai/models/imagen.d.ts +74 -0
- package/lib/types/src/vertexai/models/llama.d.ts +19 -0
- package/lib/types/src/vertexai/models.d.ts +14 -0
- package/lib/types/src/watsonx/index.d.ts +26 -0
- package/lib/types/src/watsonx/interfaces.d.ts +64 -0
- package/lib/types/src/xai/index.d.ts +18 -0
- package/lib/types/test-driver/TestErrorCompletionStream.d.ts +9 -0
- package/lib/types/test-driver/TestErrorCompletionStream.d.ts.map +1 -0
- package/lib/types/test-driver/TestValidationErrorCompletionStream.d.ts +9 -0
- package/lib/types/test-driver/TestValidationErrorCompletionStream.d.ts.map +1 -0
- package/lib/types/test-driver/index.d.ts +24 -0
- package/lib/types/test-driver/index.d.ts.map +1 -0
- package/lib/types/test-driver/utils.d.ts +5 -0
- package/lib/types/test-driver/utils.d.ts.map +1 -0
- package/lib/types/togetherai/index.d.ts +3 -3
- package/lib/types/togetherai/index.d.ts.map +1 -1
- package/lib/types/vertexai/index.d.ts +17 -14
- package/lib/types/vertexai/index.d.ts.map +1 -1
- package/lib/types/vertexai/models/claude.d.ts +2 -0
- package/lib/types/vertexai/models/claude.d.ts.map +1 -1
- package/lib/types/vertexai/models/gemini.d.ts.map +1 -1
- package/lib/types/vertexai/models/imagen.d.ts +2 -2
- package/lib/types/vertexai/models/imagen.d.ts.map +1 -1
- package/lib/types/vertexai/models/llama.d.ts +2 -2
- package/lib/types/vertexai/models/llama.d.ts.map +1 -1
- package/lib/types/vertexai/models.d.ts +2 -2
- package/lib/types/vertexai/models.d.ts.map +1 -1
- package/lib/types/watsonx/index.d.ts +3 -3
- package/lib/types/watsonx/index.d.ts.map +1 -1
- package/package.json +90 -85
- package/src/adobe/firefly.ts +14 -22
- package/src/azure/azure_foundry.ts +16 -16
- package/src/bedrock/index.ts +207 -28
- package/src/bedrock/twelvelabs.ts +150 -0
- package/src/groq/index.ts +134 -37
- package/src/huggingface_ie.ts +13 -14
- package/src/index.ts +2 -2
- package/src/mistral/index.ts +8 -7
- package/src/openai/azure_openai.ts +5 -5
- package/src/openai/index.ts +19 -13
- package/src/replicate.ts +14 -14
- package/src/{test → test-driver}/utils.ts +1 -1
- package/src/togetherai/index.ts +7 -7
- package/src/vertexai/embeddings/embeddings-text.ts +2 -2
- package/src/vertexai/index.ts +156 -40
- package/src/vertexai/models/claude.ts +45 -19
- package/src/vertexai/models/gemini.ts +161 -60
- package/src/vertexai/models/imagen.ts +15 -26
- package/src/vertexai/models/llama.ts +6 -5
- package/src/vertexai/models.ts +18 -6
- package/src/watsonx/index.ts +8 -8
- package/src/xai/index.ts +11 -12
- /package/src/{test → test-driver}/TestErrorCompletionStream.ts +0 -0
- /package/src/{test → test-driver}/TestValidationErrorCompletionStream.ts +0 -0
- /package/src/{test → test-driver}/index.ts +0 -0
package/src/bedrock/index.ts
CHANGED
|
@@ -7,9 +7,9 @@ import { S3Client } from "@aws-sdk/client-s3";
|
|
|
7
7
|
import { AwsCredentialIdentity, Provider } from "@aws-sdk/types";
|
|
8
8
|
import {
|
|
9
9
|
AbstractDriver, AIModel, Completion, CompletionChunkObject, DataSource, DriverOptions, EmbeddingsOptions, EmbeddingsResult,
|
|
10
|
-
ExecutionOptions, ExecutionTokenUsage,
|
|
10
|
+
ExecutionOptions, ExecutionTokenUsage, Modalities, PromptSegment,
|
|
11
11
|
TextFallbackOptions, ToolDefinition, ToolUse, TrainingJob, TrainingJobStatus, TrainingOptions,
|
|
12
|
-
BedrockClaudeOptions, BedrockPalmyraOptions, getMaxTokensLimitBedrock, NovaCanvasOptions,
|
|
12
|
+
BedrockClaudeOptions, BedrockPalmyraOptions, BedrockGptOssOptions, getMaxTokensLimitBedrock, NovaCanvasOptions,
|
|
13
13
|
modelModalitiesToArray, getModelCapabilities,
|
|
14
14
|
StatelessExecutionOptions,
|
|
15
15
|
ModelOptions
|
|
@@ -20,6 +20,12 @@ import { LRUCache } from "mnemonist";
|
|
|
20
20
|
import { converseConcatMessages, converseJSONprefill, converseSystemToMessages, formatConversePrompt } from "./converse.js";
|
|
21
21
|
import { formatNovaImageGenerationPayload, NovaImageGenerationTaskType } from "./nova-image-payload.js";
|
|
22
22
|
import { forceUploadFile } from "./s3.js";
|
|
23
|
+
import {
|
|
24
|
+
formatTwelvelabsPegasusPrompt,
|
|
25
|
+
TwelvelabsPegasusRequest,
|
|
26
|
+
TwelvelabsMarengoRequest,
|
|
27
|
+
TwelvelabsMarengoResponse
|
|
28
|
+
} from "./twelvelabs.js";
|
|
23
29
|
|
|
24
30
|
const supportStreamingCache = new LRUCache<string, boolean>(4096);
|
|
25
31
|
|
|
@@ -84,7 +90,7 @@ function maxTokenFallbackClaude(option: StatelessExecutionOptions): number {
|
|
|
84
90
|
}
|
|
85
91
|
}
|
|
86
92
|
|
|
87
|
-
export type BedrockPrompt = NovaMessagesPrompt | ConverseRequest;
|
|
93
|
+
export type BedrockPrompt = NovaMessagesPrompt | ConverseRequest | TwelvelabsPegasusRequest;
|
|
88
94
|
|
|
89
95
|
export class BedrockDriver extends AbstractDriver<BedrockDriverOptions, BedrockPrompt> {
|
|
90
96
|
|
|
@@ -129,6 +135,9 @@ export class BedrockDriver extends AbstractDriver<BedrockDriverOptions, BedrockP
|
|
|
129
135
|
if (opts.model.includes("canvas")) {
|
|
130
136
|
return await formatNovaPrompt(segments, opts.result_schema);
|
|
131
137
|
}
|
|
138
|
+
if (opts.model.includes("twelvelabs.pegasus")) {
|
|
139
|
+
return await formatTwelvelabsPegasusPrompt(segments, opts);
|
|
140
|
+
}
|
|
132
141
|
return await formatConversePrompt(segments, opts);
|
|
133
142
|
}
|
|
134
143
|
|
|
@@ -160,7 +169,7 @@ export class BedrockDriver extends AbstractDriver<BedrockDriverOptions, BedrockP
|
|
|
160
169
|
const type = Object.keys(content).find(
|
|
161
170
|
key => key !== '$unknown' && content[key as keyof typeof content] !== undefined
|
|
162
171
|
);
|
|
163
|
-
this.logger.info("[Bedrock] Unsupported content response type:"
|
|
172
|
+
this.logger.info({ type }, "[Bedrock] Unsupported content response type:");
|
|
164
173
|
}
|
|
165
174
|
}
|
|
166
175
|
|
|
@@ -171,7 +180,7 @@ export class BedrockDriver extends AbstractDriver<BedrockDriverOptions, BedrockP
|
|
|
171
180
|
}
|
|
172
181
|
|
|
173
182
|
const completionResult: CompletionChunkObject = {
|
|
174
|
-
result: reasoning + resultText,
|
|
183
|
+
result: reasoning + resultText ? [{ type: "text", value: reasoning + resultText }] : [],
|
|
175
184
|
token_usage: {
|
|
176
185
|
prompt: result.usage?.inputTokens,
|
|
177
186
|
result: result.usage?.outputTokens,
|
|
@@ -226,7 +235,7 @@ export class BedrockDriver extends AbstractDriver<BedrockDriverOptions, BedrockP
|
|
|
226
235
|
const type = Object.keys(delta).find(
|
|
227
236
|
key => key !== '$unknown' && (delta as any)[key] !== undefined
|
|
228
237
|
);
|
|
229
|
-
this.logger.info("[Bedrock] Unsupported content response type:"
|
|
238
|
+
this.logger.info({ type }, "[Bedrock] Unsupported content response type:");
|
|
230
239
|
}
|
|
231
240
|
}
|
|
232
241
|
|
|
@@ -252,7 +261,7 @@ export class BedrockDriver extends AbstractDriver<BedrockDriverOptions, BedrockP
|
|
|
252
261
|
}
|
|
253
262
|
|
|
254
263
|
const completionResult: CompletionChunkObject = {
|
|
255
|
-
result: reasoning + output,
|
|
264
|
+
result: reasoning + output ? [{ type: "text", value: reasoning + output }] : [],
|
|
256
265
|
token_usage: token_usage,
|
|
257
266
|
finish_reason: converseFinishReason(stop_reason),
|
|
258
267
|
};
|
|
@@ -320,6 +329,11 @@ export class BedrockDriver extends AbstractDriver<BedrockDriverOptions, BedrockP
|
|
|
320
329
|
}
|
|
321
330
|
|
|
322
331
|
protected async canStream(options: ExecutionOptions): Promise<boolean> {
|
|
332
|
+
// // TwelveLabs Pegasus supports streaming according to the documentation
|
|
333
|
+
// if (options.model.includes("twelvelabs.pegasus")) {
|
|
334
|
+
// return true;
|
|
335
|
+
// }
|
|
336
|
+
|
|
323
337
|
let canStream = supportStreamingCache.get(options.model);
|
|
324
338
|
if (canStream == null) {
|
|
325
339
|
let type = BedrockModelType.Unknown;
|
|
@@ -336,8 +350,15 @@ export class BedrockDriver extends AbstractDriver<BedrockDriverOptions, BedrockP
|
|
|
336
350
|
return canStream;
|
|
337
351
|
}
|
|
338
352
|
|
|
339
|
-
async requestTextCompletion(prompt:
|
|
340
|
-
|
|
353
|
+
async requestTextCompletion(prompt: BedrockPrompt, options: ExecutionOptions): Promise<Completion> {
|
|
354
|
+
// Handle Twelvelabs Pegasus models
|
|
355
|
+
if (options.model.includes("twelvelabs.pegasus")) {
|
|
356
|
+
return this.requestTwelvelabsPegasusCompletion(prompt as TwelvelabsPegasusRequest, options);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// Handle other Bedrock models that use Converse API
|
|
360
|
+
const conversePrompt = prompt as ConverseRequest;
|
|
361
|
+
let conversation = updateConversation(options.conversation as ConverseRequest, conversePrompt);
|
|
341
362
|
|
|
342
363
|
const payload = this.preparePayload(conversation, options);
|
|
343
364
|
const executor = this.getExecutor();
|
|
@@ -348,7 +369,7 @@ export class BedrockDriver extends AbstractDriver<BedrockDriverOptions, BedrockP
|
|
|
348
369
|
|
|
349
370
|
conversation = updateConversation(conversation, {
|
|
350
371
|
messages: [res.output?.message ?? { content: [{ text: "" }], role: "assistant" }],
|
|
351
|
-
modelId:
|
|
372
|
+
modelId: conversePrompt.modelId,
|
|
352
373
|
});
|
|
353
374
|
|
|
354
375
|
let tool_use: ToolUse[] | undefined = undefined;
|
|
@@ -369,7 +390,7 @@ export class BedrockDriver extends AbstractDriver<BedrockDriverOptions, BedrockP
|
|
|
369
390
|
}
|
|
370
391
|
|
|
371
392
|
const completion = {
|
|
372
|
-
...this.getExtractedExecution(res,
|
|
393
|
+
...this.getExtractedExecution(res, conversePrompt, options),
|
|
373
394
|
original_response: options.include_original_response ? res : undefined,
|
|
374
395
|
conversation: conversation,
|
|
375
396
|
tool_use: tool_use,
|
|
@@ -378,8 +399,104 @@ export class BedrockDriver extends AbstractDriver<BedrockDriverOptions, BedrockP
|
|
|
378
399
|
return completion;
|
|
379
400
|
}
|
|
380
401
|
|
|
381
|
-
async
|
|
382
|
-
const
|
|
402
|
+
private async requestTwelvelabsPegasusCompletion(prompt: TwelvelabsPegasusRequest, options: ExecutionOptions): Promise<Completion> {
|
|
403
|
+
const executor = this.getExecutor();
|
|
404
|
+
|
|
405
|
+
const res = await executor.invokeModel({
|
|
406
|
+
modelId: options.model,
|
|
407
|
+
contentType: "application/json",
|
|
408
|
+
accept: "application/json",
|
|
409
|
+
body: JSON.stringify(prompt),
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
const decoder = new TextDecoder();
|
|
413
|
+
const body = decoder.decode(res.body);
|
|
414
|
+
const result = JSON.parse(body);
|
|
415
|
+
|
|
416
|
+
// Extract the response according to TwelveLabs Pegasus format
|
|
417
|
+
let finishReason: string | undefined;
|
|
418
|
+
switch (result.finishReason) {
|
|
419
|
+
case "stop":
|
|
420
|
+
finishReason = "stop";
|
|
421
|
+
break;
|
|
422
|
+
case "length":
|
|
423
|
+
finishReason = "length";
|
|
424
|
+
break;
|
|
425
|
+
default:
|
|
426
|
+
finishReason = result.finishReason;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
return {
|
|
430
|
+
result: result.message ? [{ type: "text" as const, value: result.message }] : [],
|
|
431
|
+
finish_reason: finishReason,
|
|
432
|
+
original_response: options.include_original_response ? result : undefined,
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
private async requestTwelvelabsPegasusCompletionStream(prompt: TwelvelabsPegasusRequest, options: ExecutionOptions): Promise<AsyncIterable<CompletionChunkObject>> {
|
|
437
|
+
const executor = this.getExecutor();
|
|
438
|
+
|
|
439
|
+
const res = await executor.invokeModelWithResponseStream({
|
|
440
|
+
modelId: options.model,
|
|
441
|
+
contentType: "application/json",
|
|
442
|
+
accept: "application/json",
|
|
443
|
+
body: JSON.stringify(prompt),
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
if (!res.body) {
|
|
447
|
+
throw new Error("[Bedrock] Stream not found in response");
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
return transformAsyncIterator(res.body, (chunk: any) => {
|
|
451
|
+
if (chunk.chunk?.bytes) {
|
|
452
|
+
const decoder = new TextDecoder();
|
|
453
|
+
const body = decoder.decode(chunk.chunk.bytes);
|
|
454
|
+
|
|
455
|
+
try {
|
|
456
|
+
const result = JSON.parse(body);
|
|
457
|
+
|
|
458
|
+
// Extract streaming response according to TwelveLabs Pegasus format
|
|
459
|
+
let finishReason: string | undefined;
|
|
460
|
+
if (result.finishReason) {
|
|
461
|
+
switch (result.finishReason) {
|
|
462
|
+
case "stop":
|
|
463
|
+
finishReason = "stop";
|
|
464
|
+
break;
|
|
465
|
+
case "length":
|
|
466
|
+
finishReason = "length";
|
|
467
|
+
break;
|
|
468
|
+
default:
|
|
469
|
+
finishReason = result.finishReason;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
return {
|
|
474
|
+
result: result.delta || result.message ? [{ type: "text" as const, value: result.delta || result.message || "" }] : [],
|
|
475
|
+
finish_reason: finishReason,
|
|
476
|
+
} satisfies CompletionChunkObject;
|
|
477
|
+
} catch (error) {
|
|
478
|
+
// If JSON parsing fails, return empty chunk
|
|
479
|
+
return {
|
|
480
|
+
result: [],
|
|
481
|
+
} satisfies CompletionChunkObject;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
return {
|
|
486
|
+
result: [],
|
|
487
|
+
} satisfies CompletionChunkObject;
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
async requestTextCompletionStream(prompt: BedrockPrompt, options: ExecutionOptions): Promise<AsyncIterable<CompletionChunkObject>> {
|
|
492
|
+
// Handle Twelvelabs Pegasus models
|
|
493
|
+
if (options.model.includes("twelvelabs.pegasus")) {
|
|
494
|
+
return this.requestTwelvelabsPegasusCompletionStream(prompt as TwelvelabsPegasusRequest, options);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// Handle other Bedrock models that use Converse API
|
|
498
|
+
const conversePrompt = prompt as ConverseRequest;
|
|
499
|
+
const payload = this.preparePayload(conversePrompt, options);
|
|
383
500
|
const executor = this.getExecutor();
|
|
384
501
|
return executor.converseStream({
|
|
385
502
|
...payload,
|
|
@@ -391,11 +508,11 @@ export class BedrockDriver extends AbstractDriver<BedrockDriverOptions, BedrockP
|
|
|
391
508
|
}
|
|
392
509
|
|
|
393
510
|
return transformAsyncIterator(stream, (streamSegment: ConverseStreamOutput) => {
|
|
394
|
-
return this.getExtractedStream(streamSegment,
|
|
511
|
+
return this.getExtractedStream(streamSegment, conversePrompt, options);
|
|
395
512
|
});
|
|
396
513
|
|
|
397
514
|
}).catch((err) => {
|
|
398
|
-
this.logger.error("[Bedrock] Failed to stream"
|
|
515
|
+
this.logger.error({ error: err }, "[Bedrock] Failed to stream");
|
|
399
516
|
throw err;
|
|
400
517
|
});
|
|
401
518
|
}
|
|
@@ -443,7 +560,6 @@ export class BedrockDriver extends AbstractDriver<BedrockDriverOptions, BedrockP
|
|
|
443
560
|
} else if (options.model.includes("mistral")) {
|
|
444
561
|
//7B instruct and 8x7B instruct
|
|
445
562
|
if (options.model.includes("7b")) {
|
|
446
|
-
supportsJSONPrefill = true;
|
|
447
563
|
additionalField = { top_k: model_options.top_k };
|
|
448
564
|
//Does not support system messages
|
|
449
565
|
if (prompt.system && prompt.system?.length != 0) {
|
|
@@ -499,12 +615,17 @@ export class BedrockDriver extends AbstractDriver<BedrockDriverOptions, BedrockP
|
|
|
499
615
|
}
|
|
500
616
|
} else if (options.model.includes("deepseek")) {
|
|
501
617
|
//DeepSeek models support no additional options
|
|
618
|
+
} else if (options.model.includes("gpt-oss")) {
|
|
619
|
+
const gptOssOptions = model_options as ModelOptions as BedrockGptOssOptions;
|
|
620
|
+
additionalField = {
|
|
621
|
+
reasoning_effort: gptOssOptions?.reasoning_effort,
|
|
622
|
+
};
|
|
502
623
|
}
|
|
503
624
|
|
|
504
625
|
//If last message is "```json", add corresponding ``` as a stop sequence.
|
|
505
626
|
if (prompt.messages && prompt.messages.length > 0) {
|
|
506
627
|
if (prompt.messages[prompt.messages.length - 1].content?.[0].text === "```json") {
|
|
507
|
-
|
|
628
|
+
const stopSeq = model_options.stop_sequence;
|
|
508
629
|
if (!stopSeq) {
|
|
509
630
|
model_options.stop_sequence = ["```"];
|
|
510
631
|
} else if (!stopSeq.includes("```")) {
|
|
@@ -536,8 +657,8 @@ export class BedrockDriver extends AbstractDriver<BedrockDriverOptions, BedrockP
|
|
|
536
657
|
}
|
|
537
658
|
};
|
|
538
659
|
|
|
539
|
-
//Only add tools if they are defined
|
|
540
|
-
if (tool_defs) {
|
|
660
|
+
//Only add tools if they are defined and not empty
|
|
661
|
+
if (tool_defs?.length) {
|
|
541
662
|
request.toolConfig = {
|
|
542
663
|
tools: tool_defs,
|
|
543
664
|
}
|
|
@@ -547,12 +668,12 @@ export class BedrockDriver extends AbstractDriver<BedrockDriverOptions, BedrockP
|
|
|
547
668
|
}
|
|
548
669
|
|
|
549
670
|
|
|
550
|
-
async requestImageGeneration(prompt: NovaMessagesPrompt, options: ExecutionOptions): Promise<Completion
|
|
671
|
+
async requestImageGeneration(prompt: NovaMessagesPrompt, options: ExecutionOptions): Promise<Completion> {
|
|
551
672
|
if (options.output_modality !== Modalities.image) {
|
|
552
673
|
throw new Error(`Image generation requires image output_modality`);
|
|
553
674
|
}
|
|
554
675
|
if (options.model_options?._option_id !== "bedrock-nova-canvas") {
|
|
555
|
-
this.logger.warn(
|
|
676
|
+
this.logger.warn({ options: options.model_options }, "Invalid model options");
|
|
556
677
|
}
|
|
557
678
|
const model_options = options.model_options as NovaCanvasOptions;
|
|
558
679
|
|
|
@@ -579,13 +700,14 @@ export class BedrockDriver extends AbstractDriver<BedrockDriverOptions, BedrockP
|
|
|
579
700
|
|
|
580
701
|
const decoder = new TextDecoder();
|
|
581
702
|
const body = decoder.decode(res.body);
|
|
582
|
-
const
|
|
703
|
+
const bedrockResult = JSON.parse(body);
|
|
583
704
|
|
|
584
705
|
return {
|
|
585
|
-
error:
|
|
586
|
-
result: {
|
|
587
|
-
|
|
588
|
-
|
|
706
|
+
error: bedrockResult.error,
|
|
707
|
+
result: bedrockResult.images.map((image: any) => ({
|
|
708
|
+
type: "image" as const,
|
|
709
|
+
value: image
|
|
710
|
+
}))
|
|
589
711
|
}
|
|
590
712
|
}
|
|
591
713
|
|
|
@@ -698,16 +820,21 @@ export class BedrockDriver extends AbstractDriver<BedrockDriverOptions, BedrockP
|
|
|
698
820
|
foundationModels = foundationModels.filter(foundationFilter);
|
|
699
821
|
}
|
|
700
822
|
|
|
701
|
-
const supportedPublishers = ["amazon", "anthropic", "cohere", "ai21",
|
|
823
|
+
const supportedPublishers = ["amazon", "anthropic", "cohere", "ai21",
|
|
824
|
+
"mistral", "meta", "deepseek", "writer",
|
|
825
|
+
"openai", "twelvelabs", "qwen"];
|
|
702
826
|
const unsupportedModelsByPublisher = {
|
|
703
827
|
amazon: ["titan-image-generator", "nova-reel", "nova-sonic", "rerank"],
|
|
704
828
|
anthropic: [],
|
|
705
|
-
cohere: ["rerank"],
|
|
829
|
+
cohere: ["rerank", "embed"],
|
|
706
830
|
ai21: [],
|
|
707
831
|
mistral: [],
|
|
708
832
|
meta: [],
|
|
709
833
|
deepseek: [],
|
|
710
834
|
writer: [],
|
|
835
|
+
openai: [],
|
|
836
|
+
twelvelabs: ["marengo"],
|
|
837
|
+
qwen: [],
|
|
711
838
|
};
|
|
712
839
|
|
|
713
840
|
// Helper function to check if model should be filtered out
|
|
@@ -833,6 +960,13 @@ export class BedrockDriver extends AbstractDriver<BedrockDriverOptions, BedrockP
|
|
|
833
960
|
async generateEmbeddings({ text, image, model }: EmbeddingsOptions): Promise<EmbeddingsResult> {
|
|
834
961
|
|
|
835
962
|
this.logger.info("[Bedrock] Generating embeddings with model " + model);
|
|
963
|
+
|
|
964
|
+
// Handle TwelveLabs Marengo models
|
|
965
|
+
if (model?.includes("twelvelabs.marengo")) {
|
|
966
|
+
return this.generateTwelvelabsMarengoEmbeddings({ text, image, model });
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
// Handle other Bedrock embedding models
|
|
836
970
|
const defaultModel = image ? "amazon.titan-embed-image-v1" : "amazon.titan-embed-text-v2:0";
|
|
837
971
|
const modelID = model ?? defaultModel;
|
|
838
972
|
|
|
@@ -865,6 +999,51 @@ export class BedrockDriver extends AbstractDriver<BedrockDriverOptions, BedrockP
|
|
|
865
999
|
token_count: result.inputTextTokenCount
|
|
866
1000
|
};
|
|
867
1001
|
}
|
|
1002
|
+
|
|
1003
|
+
private async generateTwelvelabsMarengoEmbeddings({ text, image, model }: EmbeddingsOptions): Promise<EmbeddingsResult> {
|
|
1004
|
+
const executor = this.getExecutor();
|
|
1005
|
+
|
|
1006
|
+
// Prepare the request payload for TwelveLabs Marengo
|
|
1007
|
+
let invokeBody: TwelvelabsMarengoRequest = {
|
|
1008
|
+
inputType: "text"
|
|
1009
|
+
};
|
|
1010
|
+
|
|
1011
|
+
if (text) {
|
|
1012
|
+
invokeBody.inputText = text;
|
|
1013
|
+
invokeBody.inputType = "text";
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
if (image) {
|
|
1017
|
+
// For the embeddings interface, image is expected to be base64
|
|
1018
|
+
invokeBody.mediaSource = {
|
|
1019
|
+
base64String: image
|
|
1020
|
+
};
|
|
1021
|
+
invokeBody.inputType = "image";
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
const res = await executor.invokeModel({
|
|
1025
|
+
modelId: model!,
|
|
1026
|
+
contentType: "application/json",
|
|
1027
|
+
accept: "application/json",
|
|
1028
|
+
body: JSON.stringify(invokeBody),
|
|
1029
|
+
});
|
|
1030
|
+
|
|
1031
|
+
const decoder = new TextDecoder();
|
|
1032
|
+
const body = decoder.decode(res.body);
|
|
1033
|
+
const result: TwelvelabsMarengoResponse = JSON.parse(body);
|
|
1034
|
+
|
|
1035
|
+
// TwelveLabs Marengo returns embedding data
|
|
1036
|
+
if (!result.embedding) {
|
|
1037
|
+
throw new Error("Embeddings not found in TwelveLabs Marengo response");
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
return {
|
|
1041
|
+
values: result.embedding,
|
|
1042
|
+
model: model!,
|
|
1043
|
+
// TwelveLabs Marengo doesn't return token count in the same way
|
|
1044
|
+
token_count: undefined
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
868
1047
|
}
|
|
869
1048
|
|
|
870
1049
|
function jobInfo(job: GetModelCustomizationJobCommandOutput, jobId: string): TrainingJob {
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { DataSource, ExecutionOptions, readStreamAsBase64 } from "@llumiverse/core";
|
|
2
|
+
import { PromptSegment, PromptRole } from "@llumiverse/core";
|
|
3
|
+
|
|
4
|
+
// TwelveLabs Pegasus Request/Response Types
|
|
5
|
+
export interface TwelvelabsPegasusRequest {
|
|
6
|
+
inputPrompt: string;
|
|
7
|
+
temperature?: number;
|
|
8
|
+
responseFormat?: {
|
|
9
|
+
type: "json_schema";
|
|
10
|
+
json_schema: {
|
|
11
|
+
name: string;
|
|
12
|
+
schema: any;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
mediaSource: {
|
|
16
|
+
base64String?: string;
|
|
17
|
+
s3Location?: {
|
|
18
|
+
uri: string;
|
|
19
|
+
bucketOwner?: string;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
maxOutputTokens?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface TwelvelabsPegasusResponse {
|
|
26
|
+
message: string;
|
|
27
|
+
finishReason: "stop" | "length";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// TwelveLabs Marengo Request/Response Types
|
|
31
|
+
export interface TwelvelabsMarengoRequest {
|
|
32
|
+
inputType: "text" | "image" | "video" | "audio";
|
|
33
|
+
inputText?: string;
|
|
34
|
+
textTruncate?: "start" | "end";
|
|
35
|
+
mediaSource?: {
|
|
36
|
+
base64String?: string;
|
|
37
|
+
s3Location?: {
|
|
38
|
+
uri: string;
|
|
39
|
+
bucketOwner?: string;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
embeddingOption?: "visual-text" | "visual-image" | "audio";
|
|
43
|
+
startSec?: number;
|
|
44
|
+
lengthSec?: number;
|
|
45
|
+
useFixedLengthSec?: boolean;
|
|
46
|
+
minClipSec?: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface TwelvelabsMarengoResponse {
|
|
50
|
+
embedding: number[];
|
|
51
|
+
embeddingOption: "visual-text" | "visual-image" | "audio";
|
|
52
|
+
startSec: number;
|
|
53
|
+
endSec: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Convert prompt segments to TwelveLabs Pegasus request
|
|
57
|
+
export async function formatTwelvelabsPegasusPrompt(
|
|
58
|
+
segments: PromptSegment[],
|
|
59
|
+
options: ExecutionOptions
|
|
60
|
+
): Promise<TwelvelabsPegasusRequest> {
|
|
61
|
+
let inputPrompt = "";
|
|
62
|
+
let videoFile: DataSource | undefined;
|
|
63
|
+
|
|
64
|
+
// Extract text content and video files from segments
|
|
65
|
+
for (const segment of segments) {
|
|
66
|
+
if (segment.role === PromptRole.system || segment.role === PromptRole.user) {
|
|
67
|
+
if (segment.content) {
|
|
68
|
+
inputPrompt += segment.content + "\n";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Look for video files
|
|
72
|
+
for (const file of segment.files ?? []) {
|
|
73
|
+
if (file.mime_type && file.mime_type.startsWith("video/")) {
|
|
74
|
+
videoFile = file;
|
|
75
|
+
break; // Use the first video file found
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (!videoFile) {
|
|
82
|
+
throw new Error("TwelveLabs Pegasus requires a video file input");
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Prepare media source
|
|
86
|
+
let mediaSource: TwelvelabsPegasusRequest["mediaSource"];
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
// Try to get S3 URL first
|
|
90
|
+
const url = await videoFile.getURL();
|
|
91
|
+
const parsedUrl = new URL(url);
|
|
92
|
+
|
|
93
|
+
if (parsedUrl.hostname.endsWith("amazonaws.com") &&
|
|
94
|
+
(parsedUrl.hostname.startsWith("s3.") || parsedUrl.hostname.includes(".s3."))) {
|
|
95
|
+
// Convert S3 URL to s3:// format
|
|
96
|
+
const bucketMatch = parsedUrl.hostname.match(/^(?:s3\.)?([^.]+)\.s3\./);
|
|
97
|
+
const bucket = bucketMatch ? bucketMatch[1] : parsedUrl.hostname.split('.')[0];
|
|
98
|
+
const key = parsedUrl.pathname.substring(1); // Remove leading slash
|
|
99
|
+
|
|
100
|
+
mediaSource = {
|
|
101
|
+
s3Location: {
|
|
102
|
+
uri: `s3://${bucket}/${key}`,
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
} else {
|
|
106
|
+
// Fall back to base64 encoding
|
|
107
|
+
const stream = await videoFile.getStream();
|
|
108
|
+
const base64String = await readStreamAsBase64(stream);
|
|
109
|
+
|
|
110
|
+
mediaSource = {
|
|
111
|
+
base64String
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
} catch (error) {
|
|
115
|
+
// If getting URL fails, use base64 encoding
|
|
116
|
+
const stream = await videoFile.getStream();
|
|
117
|
+
const base64String = await readStreamAsBase64(stream);
|
|
118
|
+
|
|
119
|
+
mediaSource = {
|
|
120
|
+
base64String
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const request: TwelvelabsPegasusRequest = {
|
|
125
|
+
inputPrompt: inputPrompt.trim(),
|
|
126
|
+
mediaSource
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
// Add optional parameters from model options
|
|
130
|
+
const modelOptions = options.model_options as any;
|
|
131
|
+
if (modelOptions?.temperature !== undefined) {
|
|
132
|
+
request.temperature = modelOptions.temperature;
|
|
133
|
+
}
|
|
134
|
+
if (modelOptions?.max_tokens !== undefined) {
|
|
135
|
+
request.maxOutputTokens = modelOptions.max_tokens;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Add response format if result schema is specified
|
|
139
|
+
if (options.result_schema) {
|
|
140
|
+
request.responseFormat = {
|
|
141
|
+
type: "json_schema",
|
|
142
|
+
json_schema: {
|
|
143
|
+
name: "response",
|
|
144
|
+
schema: options.result_schema
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return request;
|
|
150
|
+
}
|