@llumiverse/drivers 0.20.0 → 0.22.0-dev.1
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/cjs/adobe/firefly.js +6 -5
- package/lib/cjs/adobe/firefly.js.map +1 -1
- package/lib/cjs/azure/azure_foundry.js +388 -0
- package/lib/cjs/azure/azure_foundry.js.map +1 -0
- package/lib/cjs/bedrock/index.js +62 -39
- package/lib/cjs/bedrock/index.js.map +1 -1
- package/lib/cjs/groq/index.js +178 -22
- package/lib/cjs/groq/index.js.map +1 -1
- package/lib/cjs/huggingface_ie.js +5 -4
- package/lib/cjs/huggingface_ie.js.map +1 -1
- package/lib/cjs/index.js +3 -2
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/mistral/index.js +5 -3
- package/lib/cjs/mistral/index.js.map +1 -1
- package/lib/cjs/openai/azure_openai.js +72 -0
- package/lib/cjs/openai/azure_openai.js.map +1 -0
- package/lib/cjs/openai/index.js +13 -16
- package/lib/cjs/openai/index.js.map +1 -1
- package/lib/cjs/openai/openai.js +2 -2
- package/lib/cjs/openai/openai.js.map +1 -1
- package/lib/cjs/openai/openai_format.js +138 -0
- package/lib/cjs/openai/openai_format.js.map +1 -0
- package/lib/cjs/replicate.js +3 -3
- 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 +2 -2
- 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 +90 -28
- package/lib/cjs/vertexai/index.js.map +1 -1
- package/lib/cjs/vertexai/models/claude.js +14 -12
- package/lib/cjs/vertexai/models/claude.js.map +1 -1
- package/lib/cjs/vertexai/models/gemini.js +158 -52
- package/lib/cjs/vertexai/models/gemini.js.map +1 -1
- package/lib/cjs/vertexai/models/imagen.js +11 -22
- 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/watsonx/index.js +3 -3
- package/lib/cjs/watsonx/index.js.map +1 -1
- package/lib/cjs/xai/index.js +4 -4
- package/lib/cjs/xai/index.js.map +1 -1
- package/lib/esm/adobe/firefly.js +6 -5
- package/lib/esm/adobe/firefly.js.map +1 -1
- package/lib/esm/azure/azure_foundry.js +382 -0
- package/lib/esm/azure/azure_foundry.js.map +1 -0
- package/lib/esm/bedrock/index.js +62 -39
- package/lib/esm/bedrock/index.js.map +1 -1
- package/lib/esm/groq/index.js +178 -22
- package/lib/esm/groq/index.js.map +1 -1
- package/lib/esm/huggingface_ie.js +6 -5
- package/lib/esm/huggingface_ie.js.map +1 -1
- package/lib/esm/index.js +3 -2
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/mistral/index.js +5 -3
- package/lib/esm/mistral/index.js.map +1 -1
- package/lib/esm/openai/azure_openai.js +68 -0
- package/lib/esm/openai/azure_openai.js.map +1 -0
- package/lib/esm/openai/index.js +12 -15
- package/lib/esm/openai/index.js.map +1 -1
- package/lib/esm/openai/openai.js +2 -2
- package/lib/esm/openai/openai.js.map +1 -1
- package/lib/esm/openai/openai_format.js +134 -0
- package/lib/esm/openai/openai_format.js.map +1 -0
- package/lib/esm/replicate.js +3 -3
- 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 +819 -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/groq/index.js +286 -0
- package/lib/esm/src/groq/index.js.map +1 -0
- package/lib/esm/src/huggingface_ie.js +196 -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 +460 -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/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 +332 -0
- package/lib/esm/src/vertexai/index.js.map +1 -0
- package/lib/esm/src/vertexai/models/claude.js +372 -0
- package/lib/esm/src/vertexai/models/claude.js.map +1 -0
- package/lib/esm/src/vertexai/models/gemini.js +806 -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 +21 -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 +2 -2
- 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 +91 -29
- package/lib/esm/vertexai/index.js.map +1 -1
- package/lib/esm/vertexai/models/claude.js +14 -12
- package/lib/esm/vertexai/models/claude.js.map +1 -1
- package/lib/esm/vertexai/models/gemini.js +159 -53
- package/lib/esm/vertexai/models/gemini.js.map +1 -1
- package/lib/esm/vertexai/models/imagen.js +8 -16
- 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.map +1 -1
- package/lib/esm/watsonx/index.js +3 -3
- package/lib/esm/watsonx/index.js.map +1 -1
- package/lib/esm/xai/index.js +3 -3
- 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 +50 -0
- package/lib/types/azure/azure_foundry.d.ts.map +1 -0
- package/lib/types/bedrock/index.d.ts +4 -4
- package/lib/types/bedrock/index.d.ts.map +1 -1
- package/lib/types/groq/index.d.ts +8 -5
- 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 +3 -2
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/mistral/index.d.ts +4 -4
- package/lib/types/mistral/index.d.ts.map +1 -1
- package/lib/types/openai/azure_openai.d.ts +25 -0
- package/lib/types/openai/azure_openai.d.ts.map +1 -0
- package/lib/types/openai/index.d.ts +6 -7
- package/lib/types/openai/index.d.ts.map +1 -1
- package/lib/types/openai/openai.d.ts +2 -2
- package/lib/types/openai/openai.d.ts.map +1 -1
- package/lib/types/openai/openai_format.d.ts +19 -0
- package/lib/types/openai/openai_format.d.ts.map +1 -0
- 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 +57 -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/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/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 +17 -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 +10 -7
- package/lib/types/vertexai/index.d.ts.map +1 -1
- package/lib/types/vertexai/models/claude.d.ts.map +1 -1
- package/lib/types/vertexai/models/gemini.d.ts +3 -2
- 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/lib/types/xai/index.d.ts.map +1 -1
- package/package.json +29 -25
- package/src/adobe/firefly.ts +12 -20
- package/src/azure/azure_foundry.ts +458 -0
- package/src/bedrock/index.ts +65 -43
- package/src/groq/index.ts +219 -32
- package/src/huggingface_ie.ts +13 -14
- package/src/index.ts +3 -2
- package/src/mistral/index.ts +11 -9
- package/src/openai/azure_openai.ts +92 -0
- package/src/openai/index.ts +27 -28
- package/src/openai/openai.ts +2 -5
- package/src/openai/openai_format.ts +165 -0
- package/src/replicate.ts +12 -12
- 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 +104 -38
- package/src/vertexai/models/claude.ts +18 -16
- package/src/vertexai/models/gemini.ts +195 -67
- package/src/vertexai/models/imagen.ts +15 -26
- package/src/vertexai/models/llama.ts +6 -5
- package/src/vertexai/models.ts +4 -4
- package/src/watsonx/index.ts +10 -10
- package/src/xai/index.ts +13 -15
- package/lib/cjs/openai/azure.js +0 -31
- package/lib/cjs/openai/azure.js.map +0 -1
- package/lib/esm/openai/azure.js +0 -27
- package/lib/esm/openai/azure.js.map +0 -1
- package/lib/types/openai/azure.d.ts +0 -20
- package/lib/types/openai/azure.d.ts.map +0 -1
- package/src/openai/azure.ts +0 -54
- /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/replicate.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
AIModel,
|
|
3
3
|
AbstractDriver,
|
|
4
4
|
Completion,
|
|
5
|
-
|
|
5
|
+
CompletionChunkObject,
|
|
6
6
|
DataSource,
|
|
7
7
|
DriverOptions,
|
|
8
8
|
EmbeddingsResult,
|
|
@@ -64,12 +64,12 @@ export class ReplicateDriver extends AbstractDriver<DriverOptions, string> {
|
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
async requestTextCompletionStream(prompt: string, options: ExecutionOptions): Promise<AsyncIterable<
|
|
67
|
+
async requestTextCompletionStream(prompt: string, options: ExecutionOptions): Promise<AsyncIterable<CompletionChunkObject>> {
|
|
68
68
|
if (options.model_options?._option_id !== "text-fallback") {
|
|
69
|
-
this.logger.warn("Invalid model options", {options: options.model_options });
|
|
69
|
+
this.logger.warn("Invalid model options", { options: options.model_options });
|
|
70
70
|
}
|
|
71
71
|
options.model_options = options.model_options as TextFallbackOptions;
|
|
72
|
-
|
|
72
|
+
|
|
73
73
|
const model = ReplicateDriver.parseModelId(options.model);
|
|
74
74
|
const predictionData = {
|
|
75
75
|
input: {
|
|
@@ -84,11 +84,11 @@ export class ReplicateDriver extends AbstractDriver<DriverOptions, string> {
|
|
|
84
84
|
const prediction =
|
|
85
85
|
await this.service.predictions.create(predictionData);
|
|
86
86
|
|
|
87
|
-
const stream = new EventStream<
|
|
87
|
+
const stream = new EventStream<CompletionChunkObject>();
|
|
88
88
|
|
|
89
89
|
const source = new EventSource(prediction.urls.stream!);
|
|
90
90
|
source.addEventListener("output", (e: any) => {
|
|
91
|
-
stream.push(e.data);
|
|
91
|
+
stream.push({result: [{ type: "text", value: e.data }] });
|
|
92
92
|
});
|
|
93
93
|
source.addEventListener("error", (e: any) => {
|
|
94
94
|
let error: any;
|
|
@@ -97,7 +97,7 @@ export class ReplicateDriver extends AbstractDriver<DriverOptions, string> {
|
|
|
97
97
|
} catch (error) {
|
|
98
98
|
error = JSON.stringify(e);
|
|
99
99
|
}
|
|
100
|
-
this.logger?.error("Error in SSE stream", {e, error});
|
|
100
|
+
this.logger?.error("Error in SSE stream", { e, error });
|
|
101
101
|
});
|
|
102
102
|
source.addEventListener("done", () => {
|
|
103
103
|
try {
|
|
@@ -111,7 +111,7 @@ export class ReplicateDriver extends AbstractDriver<DriverOptions, string> {
|
|
|
111
111
|
|
|
112
112
|
async requestTextCompletion(prompt: string, options: ExecutionOptions) {
|
|
113
113
|
if (options.model_options?._option_id !== "text-fallback") {
|
|
114
|
-
this.logger.warn("Invalid model options", {options: options.model_options });
|
|
114
|
+
this.logger.warn("Invalid model options", { options: options.model_options });
|
|
115
115
|
}
|
|
116
116
|
options.model_options = options.model_options as TextFallbackOptions;
|
|
117
117
|
const model = ReplicateDriver.parseModelId(options.model);
|
|
@@ -136,9 +136,9 @@ export class ReplicateDriver extends AbstractDriver<DriverOptions, string> {
|
|
|
136
136
|
//not streaming, wait for the result
|
|
137
137
|
const res = await this.service.wait(prediction, {});
|
|
138
138
|
|
|
139
|
-
const text = res.output.join("");
|
|
139
|
+
const text: string = res.output.join("");
|
|
140
140
|
return {
|
|
141
|
-
result: text,
|
|
141
|
+
result: [{ type: "text" as const, value: text }],
|
|
142
142
|
original_response: options.include_original_response ? res : undefined,
|
|
143
143
|
};
|
|
144
144
|
}
|
|
@@ -236,7 +236,7 @@ export class ReplicateDriver extends AbstractDriver<DriverOptions, string> {
|
|
|
236
236
|
this.service.models.versions.list(owner, model),
|
|
237
237
|
]);
|
|
238
238
|
|
|
239
|
-
if (!rModel || !versions || versions.length === 0) {
|
|
239
|
+
if (!rModel || !versions || (versions as any).results?.length === 0) {
|
|
240
240
|
throw new Error("Model not found or no versions available");
|
|
241
241
|
}
|
|
242
242
|
|
|
@@ -298,7 +298,7 @@ function jobInfo(job: Prediction, modelName?: string): TrainingJob {
|
|
|
298
298
|
status = TrainingJobStatus.succeeded;
|
|
299
299
|
} else if (jobStatus === 'failed') {
|
|
300
300
|
status = TrainingJobStatus.failed;
|
|
301
|
-
const error = job.error as any;
|
|
301
|
+
const error = job.error as any;
|
|
302
302
|
if (typeof error === 'string') {
|
|
303
303
|
details = error;
|
|
304
304
|
} else {
|
|
@@ -8,7 +8,7 @@ export function throwError(message: string, prompt: PromptSegment[]): never {
|
|
|
8
8
|
|
|
9
9
|
export function createValidationErrorCompletion(segments: PromptSegment[]) {
|
|
10
10
|
return {
|
|
11
|
-
result: "An invalid result",
|
|
11
|
+
result: [{ type: "text", value: "An invalid result" }],
|
|
12
12
|
prompt: segments,
|
|
13
13
|
execution_time: 3000,
|
|
14
14
|
error: {
|
package/src/togetherai/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AIModel, AbstractDriver, Completion,
|
|
1
|
+
import { AIModel, AbstractDriver, Completion, CompletionChunkObject, DriverOptions, EmbeddingsResult, ExecutionOptions, TextFallbackOptions } from "@llumiverse/core";
|
|
2
2
|
import { transformSSEStream } from "@llumiverse/core/async";
|
|
3
3
|
import { FetchClient } from "@vertesia/api-fetch-client";
|
|
4
4
|
import { TextCompletion, TogetherModelInfo } from "./interfaces.js";
|
|
@@ -29,9 +29,9 @@ export class TogetherAIDriver extends AbstractDriver<TogetherAIDriverOptions, st
|
|
|
29
29
|
} : undefined;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
async requestTextCompletion(prompt: string, options: ExecutionOptions): Promise<Completion
|
|
32
|
+
async requestTextCompletion(prompt: string, options: ExecutionOptions): Promise<Completion> {
|
|
33
33
|
if (options.model_options?._option_id !== "text-fallback") {
|
|
34
|
-
this.logger.warn("Invalid model options", {options: options.model_options });
|
|
34
|
+
this.logger.warn("Invalid model options", { options: options.model_options });
|
|
35
35
|
}
|
|
36
36
|
options.model_options = options.model_options as TextFallbackOptions;
|
|
37
37
|
|
|
@@ -60,7 +60,7 @@ export class TogetherAIDriver extends AbstractDriver<TogetherAIDriverOptions, st
|
|
|
60
60
|
const text = choice.text ?? '';
|
|
61
61
|
const usage = res.usage || {};
|
|
62
62
|
return {
|
|
63
|
-
result: text,
|
|
63
|
+
result: [{ type: "text", value: text }],
|
|
64
64
|
token_usage: {
|
|
65
65
|
prompt: usage.prompt_tokens,
|
|
66
66
|
result: usage.completion_tokens,
|
|
@@ -71,9 +71,9 @@ export class TogetherAIDriver extends AbstractDriver<TogetherAIDriverOptions, st
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
async requestTextCompletionStream(prompt: string, options: ExecutionOptions): Promise<AsyncIterable<
|
|
74
|
+
async requestTextCompletionStream(prompt: string, options: ExecutionOptions): Promise<AsyncIterable<CompletionChunkObject>> {
|
|
75
75
|
if (options.model_options?._option_id !== "text-fallback") {
|
|
76
|
-
this.logger.warn("Invalid model options", {options: options.model_options });
|
|
76
|
+
this.logger.warn("Invalid model options", { options: options.model_options });
|
|
77
77
|
}
|
|
78
78
|
options.model_options = options.model_options as TextFallbackOptions;
|
|
79
79
|
|
|
@@ -103,7 +103,7 @@ export class TogetherAIDriver extends AbstractDriver<TogetherAIDriverOptions, st
|
|
|
103
103
|
return transformSSEStream(stream, (data: string) => {
|
|
104
104
|
const json = JSON.parse(data);
|
|
105
105
|
return {
|
|
106
|
-
result: json.choices[0]?.text ?? '',
|
|
106
|
+
result: [{ type: "text", value: json.choices[0]?.text ?? '' }],
|
|
107
107
|
finish_reason: json.choices[0]?.finish_reason, //Uses expected "stop" , "length" format
|
|
108
108
|
token_usage: {
|
|
109
109
|
prompt: json.usage?.prompt_tokens,
|
|
@@ -36,9 +36,9 @@ export async function getEmbeddingsForText(driver: VertexAIDriver, options: Text
|
|
|
36
36
|
title: options.title,
|
|
37
37
|
content: options.content
|
|
38
38
|
}]
|
|
39
|
-
}
|
|
39
|
+
} satisfies EmbeddingsForTextPrompt;
|
|
40
40
|
|
|
41
|
-
const model = options.model || "
|
|
41
|
+
const model = options.model || "gemini-embedding-001";
|
|
42
42
|
|
|
43
43
|
const client = driver.getFetchClient();
|
|
44
44
|
|
package/src/vertexai/index.ts
CHANGED
|
@@ -2,11 +2,10 @@ import {
|
|
|
2
2
|
AIModel,
|
|
3
3
|
AbstractDriver,
|
|
4
4
|
Completion,
|
|
5
|
-
|
|
5
|
+
CompletionChunkObject,
|
|
6
6
|
DriverOptions,
|
|
7
7
|
EmbeddingsResult,
|
|
8
8
|
ExecutionOptions,
|
|
9
|
-
ImageGeneration,
|
|
10
9
|
Modalities,
|
|
11
10
|
ModelSearchPayload,
|
|
12
11
|
PromptSegment,
|
|
@@ -20,10 +19,10 @@ import { TextEmbeddingsOptions, getEmbeddingsForText } from "./embeddings/embedd
|
|
|
20
19
|
import { getModelDefinition } from "./models.js";
|
|
21
20
|
import { EmbeddingsOptions } from "@llumiverse/core";
|
|
22
21
|
import { getEmbeddingsForImages } from "./embeddings/embeddings-image.js";
|
|
23
|
-
import { v1beta1 } from "@google-cloud/aiplatform";
|
|
22
|
+
import { PredictionServiceClient, v1beta1 } from "@google-cloud/aiplatform";
|
|
24
23
|
import { AnthropicVertex } from "@anthropic-ai/vertex-sdk";
|
|
25
24
|
import { ImagenModelDefinition, ImagenPrompt } from "./models/imagen.js";
|
|
26
|
-
import { GoogleGenAI, Content } from "@google/genai";
|
|
25
|
+
import { GoogleGenAI, Content, Model } from "@google/genai";
|
|
27
26
|
|
|
28
27
|
export interface VertexAIDriverOptions extends DriverOptions {
|
|
29
28
|
project: string;
|
|
@@ -54,6 +53,7 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
54
53
|
googleGenAI: GoogleGenAI | undefined;
|
|
55
54
|
llamaClient: FetchClient & { region?: string } | undefined;
|
|
56
55
|
modelGarden: v1beta1.ModelGardenServiceClient | undefined;
|
|
56
|
+
imagenClient: PredictionServiceClient | undefined;
|
|
57
57
|
|
|
58
58
|
authClient: JSONClient | GoogleAuth<JSONClient>;
|
|
59
59
|
|
|
@@ -66,16 +66,28 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
66
66
|
this.googleGenAI = undefined;
|
|
67
67
|
this.modelGarden = undefined;
|
|
68
68
|
this.llamaClient = undefined;
|
|
69
|
+
this.imagenClient = undefined;
|
|
69
70
|
|
|
70
71
|
this.authClient = options.googleAuthOptions?.authClient ?? new GoogleAuth(options.googleAuthOptions);
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
public getGoogleGenAIClient(): GoogleGenAI {
|
|
74
|
-
//Lazy
|
|
74
|
+
public getGoogleGenAIClient(region: string = this.options.region): GoogleGenAI {
|
|
75
|
+
//Lazy initialization
|
|
76
|
+
if (region !== this.options.region) {
|
|
77
|
+
//Get one off client for different region
|
|
78
|
+
return new GoogleGenAI({
|
|
79
|
+
project: this.options.project,
|
|
80
|
+
location: region,
|
|
81
|
+
vertexai: true,
|
|
82
|
+
googleAuthOptions: {
|
|
83
|
+
authClient: this.authClient as JSONClient,
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
75
87
|
if (!this.googleGenAI) {
|
|
76
88
|
this.googleGenAI = new GoogleGenAI({
|
|
77
89
|
project: this.options.project,
|
|
78
|
-
location:
|
|
90
|
+
location: region,
|
|
79
91
|
vertexai: true,
|
|
80
92
|
googleAuthOptions: {
|
|
81
93
|
authClient: this.authClient as JSONClient,
|
|
@@ -86,7 +98,7 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
86
98
|
}
|
|
87
99
|
|
|
88
100
|
public getFetchClient(): FetchClient {
|
|
89
|
-
//Lazy
|
|
101
|
+
//Lazy initialization
|
|
90
102
|
if (!this.fetchClient) {
|
|
91
103
|
this.fetchClient = createFetchClient({
|
|
92
104
|
region: this.options.region,
|
|
@@ -101,7 +113,7 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
101
113
|
}
|
|
102
114
|
|
|
103
115
|
public getLLamaClient(region: string = "us-central1"): FetchClient {
|
|
104
|
-
//Lazy
|
|
116
|
+
//Lazy initialization
|
|
105
117
|
if (!this.llamaClient || this.llamaClient["region"] !== region) {
|
|
106
118
|
this.llamaClient = createFetchClient({
|
|
107
119
|
region: region,
|
|
@@ -119,19 +131,24 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
119
131
|
}
|
|
120
132
|
|
|
121
133
|
public getAnthropicClient(): AnthropicVertex {
|
|
122
|
-
//Lazy
|
|
134
|
+
//Lazy initialization
|
|
123
135
|
if (!this.anthropicClient) {
|
|
124
136
|
this.anthropicClient = new AnthropicVertex({
|
|
125
137
|
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
|
|
126
138
|
region: "us-east5",
|
|
127
|
-
projectId:
|
|
139
|
+
projectId: this.options.project,
|
|
140
|
+
googleAuth: new GoogleAuth({
|
|
141
|
+
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
|
|
142
|
+
authClient: this.authClient as JSONClient,
|
|
143
|
+
projectId: this.options.project,
|
|
144
|
+
}),
|
|
128
145
|
});
|
|
129
146
|
}
|
|
130
147
|
return this.anthropicClient;
|
|
131
148
|
}
|
|
132
149
|
|
|
133
150
|
public getAIPlatformClient(): v1beta1.ModelServiceClient {
|
|
134
|
-
//Lazy
|
|
151
|
+
//Lazy initialization
|
|
135
152
|
if (!this.aiplatform) {
|
|
136
153
|
this.aiplatform = new v1beta1.ModelServiceClient({
|
|
137
154
|
projectId: this.options.project,
|
|
@@ -143,7 +160,7 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
143
160
|
}
|
|
144
161
|
|
|
145
162
|
public getModelGardenClient(): v1beta1.ModelGardenServiceClient {
|
|
146
|
-
//Lazy
|
|
163
|
+
//Lazy initialization
|
|
147
164
|
if (!this.modelGarden) {
|
|
148
165
|
this.modelGarden = new v1beta1.ModelGardenServiceClient({
|
|
149
166
|
projectId: this.options.project,
|
|
@@ -154,6 +171,19 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
154
171
|
return this.modelGarden;
|
|
155
172
|
}
|
|
156
173
|
|
|
174
|
+
public getImagenClient(): PredictionServiceClient {
|
|
175
|
+
//Lazy initialization
|
|
176
|
+
if (!this.imagenClient) {
|
|
177
|
+
// TODO: make location configurable, fixed to us-central1 for now
|
|
178
|
+
this.imagenClient = new PredictionServiceClient({
|
|
179
|
+
projectId: this.options.project,
|
|
180
|
+
apiEndpoint: `us-central1-${API_BASE_PATH}`,
|
|
181
|
+
authClient: this.authClient as JSONClient,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return this.imagenClient;
|
|
185
|
+
}
|
|
186
|
+
|
|
157
187
|
validateResult(result: Completion, options: ExecutionOptions) {
|
|
158
188
|
// Optionally preprocess the result before validation
|
|
159
189
|
const modelDef = getModelDefinition(options.model);
|
|
@@ -180,44 +210,42 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
180
210
|
return getModelDefinition(options.model).createPrompt(this, segments, options);
|
|
181
211
|
}
|
|
182
212
|
|
|
183
|
-
async requestTextCompletion(prompt: VertexAIPrompt, options: ExecutionOptions): Promise<Completion
|
|
213
|
+
async requestTextCompletion(prompt: VertexAIPrompt, options: ExecutionOptions): Promise<Completion> {
|
|
184
214
|
return getModelDefinition(options.model).requestTextCompletion(this, prompt, options);
|
|
185
215
|
}
|
|
186
216
|
async requestTextCompletionStream(
|
|
187
217
|
prompt: VertexAIPrompt,
|
|
188
218
|
options: ExecutionOptions,
|
|
189
|
-
): Promise<AsyncIterable<
|
|
219
|
+
): Promise<AsyncIterable<CompletionChunkObject>> {
|
|
190
220
|
return getModelDefinition(options.model).requestTextCompletionStream(this, prompt, options);
|
|
191
221
|
}
|
|
192
222
|
|
|
193
223
|
async requestImageGeneration(
|
|
194
224
|
_prompt: ImagenPrompt,
|
|
195
225
|
_options: ExecutionOptions,
|
|
196
|
-
): Promise<Completion
|
|
226
|
+
): Promise<Completion> {
|
|
197
227
|
const splits = _options.model.split("/");
|
|
198
228
|
const modelName = trimModelName(splits[splits.length - 1]);
|
|
199
229
|
return new ImagenModelDefinition(modelName).requestImageGeneration(this, _prompt, _options);
|
|
200
230
|
}
|
|
201
231
|
|
|
232
|
+
async getGenAIModelsArray(client: GoogleGenAI): Promise<Model[]> {
|
|
233
|
+
const models: Model[] = [];
|
|
234
|
+
const pager = await client.models.list();
|
|
235
|
+
for await (const item of pager) {
|
|
236
|
+
models.push(item);
|
|
237
|
+
}
|
|
238
|
+
return models;
|
|
239
|
+
}
|
|
240
|
+
|
|
202
241
|
async listModels(_params?: ModelSearchPayload): Promise<AIModel<string>[]> {
|
|
203
242
|
// Get clients
|
|
204
243
|
const modelGarden = this.getModelGardenClient();
|
|
205
244
|
const aiplatform = this.getAIPlatformClient();
|
|
245
|
+
const globalGenAiClient = this.getGoogleGenAIClient("global");
|
|
206
246
|
|
|
207
247
|
let models: AIModel<string>[] = [];
|
|
208
248
|
|
|
209
|
-
//Project specific deployed models
|
|
210
|
-
const [response] = await aiplatform.listModels({
|
|
211
|
-
parent: `projects/${this.options.project}/locations/${this.options.region}`,
|
|
212
|
-
});
|
|
213
|
-
models = models.concat(
|
|
214
|
-
response.map((model) => ({
|
|
215
|
-
id: model.name?.split("/").pop() ?? "",
|
|
216
|
-
name: model.displayName ?? "",
|
|
217
|
-
provider: "vertexai"
|
|
218
|
-
})),
|
|
219
|
-
);
|
|
220
|
-
|
|
221
249
|
//Model Garden Publisher models - Pretrained models
|
|
222
250
|
const publishers = ["google", "anthropic", "meta"];
|
|
223
251
|
// Meta "maas" models are LLama Models-As-A-Service. Non-maas models are not pre-deployed.
|
|
@@ -225,7 +253,9 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
225
253
|
// Additional models not in the listings, but we want to include
|
|
226
254
|
// TODO: Remove once the models are available in the listing API, or no longer needed
|
|
227
255
|
const additionalModels = {
|
|
228
|
-
google: [
|
|
256
|
+
google: [
|
|
257
|
+
"imagen-3.0-fast-generate-001",
|
|
258
|
+
],
|
|
229
259
|
anthropic: [],
|
|
230
260
|
meta: [
|
|
231
261
|
"llama-4-maverick-17b-128e-instruct-maas",
|
|
@@ -241,25 +271,61 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
241
271
|
//Used to exclude retired models that are still in the listing API but not available for use.
|
|
242
272
|
//Or models we do not support yet
|
|
243
273
|
const unsupportedModelsByPublisher = {
|
|
244
|
-
google: ["gemini-pro", "gemini-ultra"],
|
|
274
|
+
google: ["gemini-pro", "gemini-ultra", "imagen-product-recontext-preview", "embedding"],
|
|
245
275
|
anthropic: [],
|
|
246
276
|
meta: [],
|
|
247
277
|
};
|
|
248
278
|
|
|
249
|
-
|
|
250
|
-
|
|
279
|
+
// Start all network requests in parallel
|
|
280
|
+
const aiplatformPromise = aiplatform.listModels({
|
|
281
|
+
parent: `projects/${this.options.project}/locations/${this.options.region}`,
|
|
282
|
+
});
|
|
283
|
+
const publisherPromises = publishers.map(async (publisher) => {
|
|
284
|
+
const [response] = await modelGarden.listPublisherModels({
|
|
251
285
|
parent: `publishers/${publisher}`,
|
|
252
286
|
orderBy: "name",
|
|
253
287
|
listAllVersions: true,
|
|
254
288
|
});
|
|
289
|
+
return { publisher, response };
|
|
290
|
+
});
|
|
255
291
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
292
|
+
const globalGooglePromise = this.getGenAIModelsArray(globalGenAiClient);
|
|
293
|
+
// Await all network requests
|
|
294
|
+
const [aiplatformResult, globalGoogleResult, ...publisherResults] = await Promise.all([
|
|
295
|
+
aiplatformPromise,
|
|
296
|
+
globalGooglePromise,
|
|
297
|
+
...publisherPromises,
|
|
298
|
+
]);
|
|
299
|
+
|
|
300
|
+
// Process aiplatform models, project specific models
|
|
301
|
+
const [response] = aiplatformResult;
|
|
302
|
+
models = models.concat(
|
|
303
|
+
response.map((model) => ({
|
|
304
|
+
id: model.name?.split("/").pop() ?? "",
|
|
305
|
+
name: model.displayName ?? "",
|
|
306
|
+
provider: "vertexai"
|
|
307
|
+
}))
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
// Process global google models from GenAI
|
|
311
|
+
models = models.concat(
|
|
312
|
+
globalGoogleResult.map((model) => {
|
|
313
|
+
const modelCapability = getModelCapabilities(model.name ?? '', "vertexai");
|
|
314
|
+
return {
|
|
315
|
+
id: "locations/global/" + model.name,
|
|
316
|
+
name: "Global " + model.name?.split('/').pop(),
|
|
317
|
+
provider: "vertexai",
|
|
318
|
+
owner: "google",
|
|
319
|
+
input_modalities: modelModalitiesToArray(modelCapability.input),
|
|
320
|
+
output_modalities: modelModalitiesToArray(modelCapability.output),
|
|
321
|
+
tool_support: modelCapability.tool_support,
|
|
322
|
+
};
|
|
323
|
+
})
|
|
324
|
+
);
|
|
262
325
|
|
|
326
|
+
// Process publisher models
|
|
327
|
+
for (const result of publisherResults) {
|
|
328
|
+
const { publisher, response } = result;
|
|
263
329
|
const modelFamily = supportedModels[publisher as keyof typeof supportedModels];
|
|
264
330
|
const retiredModels = unsupportedModelsByPublisher[publisher as keyof typeof unsupportedModelsByPublisher];
|
|
265
331
|
|
|
@@ -72,11 +72,13 @@ function maxToken(option: StatelessExecutionOptions): number {
|
|
|
72
72
|
if (modelOptions && typeof modelOptions.max_tokens === "number") {
|
|
73
73
|
return modelOptions.max_tokens;
|
|
74
74
|
} else {
|
|
75
|
+
const thinking_budget = modelOptions?.thinking_budget_tokens ?? 0;
|
|
76
|
+
let maxSupportedTokens = getMaxTokensLimitVertexAi(option.model);
|
|
75
77
|
// Fallback to the default max tokens limit for the model
|
|
76
|
-
if (option.model.includes('claude-3-7-sonnet') && (modelOptions?.thinking_budget_tokens ?? 0) <
|
|
77
|
-
|
|
78
|
+
if (option.model.includes('claude-3-7-sonnet') && (modelOptions?.thinking_budget_tokens ?? 0) < 48000) {
|
|
79
|
+
maxSupportedTokens = 64000; // Claude 3.7 can go up to 128k with a beta header, but when no max tokens is specified, we default to 64k.
|
|
78
80
|
}
|
|
79
|
-
return
|
|
81
|
+
return Math.min(16000 + thinking_budget, maxSupportedTokens); // Cap to 16k, to avoid taking up too much context window and quota.
|
|
80
82
|
}
|
|
81
83
|
}
|
|
82
84
|
|
|
@@ -85,7 +87,7 @@ async function collectFileBlocks(segment: PromptSegment, restrictedTypes: true):
|
|
|
85
87
|
async function collectFileBlocks(segment: PromptSegment, restrictedTypes?: false): Promise<ContentBlockParam[]>;
|
|
86
88
|
async function collectFileBlocks(segment: PromptSegment, restrictedTypes: boolean = false): Promise<ContentBlockParam[]> {
|
|
87
89
|
const contentBlocks: ContentBlockParam[] = [];
|
|
88
|
-
|
|
90
|
+
|
|
89
91
|
for (const file of segment.files || []) {
|
|
90
92
|
if (file.mime_type?.startsWith("image/")) {
|
|
91
93
|
const allowedTypes = ["image/png", "image/jpeg", "image/gif", "image/webp"];
|
|
@@ -126,7 +128,7 @@ async function collectFileBlocks(segment: PromptSegment, restrictedTypes: boolea
|
|
|
126
128
|
}
|
|
127
129
|
}
|
|
128
130
|
}
|
|
129
|
-
|
|
131
|
+
|
|
130
132
|
return contentBlocks;
|
|
131
133
|
}
|
|
132
134
|
|
|
@@ -189,7 +191,7 @@ export class ClaudeModelDefinition implements ModelDefinition<ClaudePrompt> {
|
|
|
189
191
|
text: segment.content
|
|
190
192
|
} satisfies TextBlockParam);
|
|
191
193
|
}
|
|
192
|
-
|
|
194
|
+
|
|
193
195
|
// Collect file blocks with type safety
|
|
194
196
|
const fileBlocks = await collectFileBlocks(segment, true);
|
|
195
197
|
contentBlocks.push(...fileBlocks);
|
|
@@ -206,7 +208,7 @@ export class ClaudeModelDefinition implements ModelDefinition<ClaudePrompt> {
|
|
|
206
208
|
} else {
|
|
207
209
|
// Build content blocks for regular messages (all types allowed)
|
|
208
210
|
const contentBlocks: ContentBlockParam[] = [];
|
|
209
|
-
|
|
211
|
+
|
|
210
212
|
if (segment.content) {
|
|
211
213
|
contentBlocks.push({
|
|
212
214
|
type: 'text',
|
|
@@ -271,7 +273,7 @@ export class ClaudeModelDefinition implements ModelDefinition<ClaudePrompt> {
|
|
|
271
273
|
conversation = updateConversation(conversation, createPromptFromResponse(result));
|
|
272
274
|
|
|
273
275
|
return {
|
|
274
|
-
result: text
|
|
276
|
+
result: text ? [{ type: "text", value: text }] : [{ type: "text", value: '' }],
|
|
275
277
|
tool_use,
|
|
276
278
|
token_usage: {
|
|
277
279
|
prompt: result.usage.input_tokens,
|
|
@@ -301,7 +303,7 @@ export class ClaudeModelDefinition implements ModelDefinition<ClaudePrompt> {
|
|
|
301
303
|
switch (streamEvent.type) {
|
|
302
304
|
case "message_start":
|
|
303
305
|
return {
|
|
304
|
-
result: '',
|
|
306
|
+
result: [{ type: "text", value: '' }],
|
|
305
307
|
token_usage: {
|
|
306
308
|
prompt: streamEvent.message.usage.input_tokens,
|
|
307
309
|
result: streamEvent.message.usage.output_tokens
|
|
@@ -309,7 +311,7 @@ export class ClaudeModelDefinition implements ModelDefinition<ClaudePrompt> {
|
|
|
309
311
|
} satisfies CompletionChunkObject;
|
|
310
312
|
case "message_delta":
|
|
311
313
|
return {
|
|
312
|
-
result: '',
|
|
314
|
+
result: [{ type: "text", value: '' }],
|
|
313
315
|
token_usage: {
|
|
314
316
|
result: streamEvent.usage.output_tokens
|
|
315
317
|
},
|
|
@@ -319,7 +321,7 @@ export class ClaudeModelDefinition implements ModelDefinition<ClaudePrompt> {
|
|
|
319
321
|
// Handle redacted thinking blocks
|
|
320
322
|
if (streamEvent.content_block.type === "redacted_thinking" && model_options?.include_thoughts) {
|
|
321
323
|
return {
|
|
322
|
-
result: `[Redacted thinking: ${streamEvent.content_block.data}]`
|
|
324
|
+
result: [{ type: "text", value: `[Redacted thinking: ${streamEvent.content_block.data}]` }]
|
|
323
325
|
} satisfies CompletionChunkObject;
|
|
324
326
|
}
|
|
325
327
|
break;
|
|
@@ -328,12 +330,12 @@ export class ClaudeModelDefinition implements ModelDefinition<ClaudePrompt> {
|
|
|
328
330
|
switch (streamEvent.delta.type) {
|
|
329
331
|
case "text_delta":
|
|
330
332
|
return {
|
|
331
|
-
result: streamEvent.delta.text
|
|
333
|
+
result: streamEvent.delta.text ? [{ type: "text", value: streamEvent.delta.text }] : []
|
|
332
334
|
} satisfies CompletionChunkObject;
|
|
333
335
|
case "thinking_delta":
|
|
334
336
|
if (model_options?.include_thoughts) {
|
|
335
337
|
return {
|
|
336
|
-
result: streamEvent.delta.thinking
|
|
338
|
+
result: streamEvent.delta.thinking ? [{ type: "text", value: streamEvent.delta.thinking }] : [],
|
|
337
339
|
} satisfies CompletionChunkObject;
|
|
338
340
|
}
|
|
339
341
|
break;
|
|
@@ -341,7 +343,7 @@ export class ClaudeModelDefinition implements ModelDefinition<ClaudePrompt> {
|
|
|
341
343
|
// Signature deltas, signify the end of the thoughts.
|
|
342
344
|
if (model_options?.include_thoughts) {
|
|
343
345
|
return {
|
|
344
|
-
result: '\n\n', // Double newline for more spacing
|
|
346
|
+
result: [{ type: "text", value: '\n\n' }], // Double newline for more spacing
|
|
345
347
|
} satisfies CompletionChunkObject;
|
|
346
348
|
}
|
|
347
349
|
break;
|
|
@@ -351,7 +353,7 @@ export class ClaudeModelDefinition implements ModelDefinition<ClaudePrompt> {
|
|
|
351
353
|
// Handle the end of content blocks, for redacted thinking blocks
|
|
352
354
|
if (model_options?.include_thoughts) {
|
|
353
355
|
return {
|
|
354
|
-
result: '\n\n' // Add double newline for spacing
|
|
356
|
+
result: [{ type: "text", value: '\n\n' }] // Add double newline for spacing
|
|
355
357
|
} satisfies CompletionChunkObject;
|
|
356
358
|
}
|
|
357
359
|
break;
|
|
@@ -359,7 +361,7 @@ export class ClaudeModelDefinition implements ModelDefinition<ClaudePrompt> {
|
|
|
359
361
|
|
|
360
362
|
// Default case for all other event types
|
|
361
363
|
return {
|
|
362
|
-
result:
|
|
364
|
+
result: []
|
|
363
365
|
} satisfies CompletionChunkObject;
|
|
364
366
|
});
|
|
365
367
|
|