@vertesia/workflow 0.55.0 → 0.56.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.
Files changed (36) hide show
  1. package/lib/cjs/activities/executeInteraction.js +5 -0
  2. package/lib/cjs/activities/executeInteraction.js.map +1 -1
  3. package/lib/cjs/activities/generateDocumentProperties.js +1 -0
  4. package/lib/cjs/activities/generateDocumentProperties.js.map +1 -1
  5. package/lib/cjs/activities/generateEmbeddings.js +1 -1
  6. package/lib/cjs/activities/generateEmbeddings.js.map +1 -1
  7. package/lib/cjs/dsl/dsl-workflow.js +1 -0
  8. package/lib/cjs/dsl/dsl-workflow.js.map +1 -1
  9. package/lib/cjs/utils/blobs.js +5 -13
  10. package/lib/cjs/utils/blobs.js.map +1 -1
  11. package/lib/esm/activities/executeInteraction.js +5 -0
  12. package/lib/esm/activities/executeInteraction.js.map +1 -1
  13. package/lib/esm/activities/generateDocumentProperties.js +1 -0
  14. package/lib/esm/activities/generateDocumentProperties.js.map +1 -1
  15. package/lib/esm/activities/generateEmbeddings.js +1 -1
  16. package/lib/esm/activities/generateEmbeddings.js.map +1 -1
  17. package/lib/esm/dsl/dsl-workflow.js +2 -1
  18. package/lib/esm/dsl/dsl-workflow.js.map +1 -1
  19. package/lib/esm/utils/blobs.js +6 -13
  20. package/lib/esm/utils/blobs.js.map +1 -1
  21. package/lib/types/activities/executeInteraction.d.ts +4 -2
  22. package/lib/types/activities/executeInteraction.d.ts.map +1 -1
  23. package/lib/types/activities/generateDocumentProperties.d.ts.map +1 -1
  24. package/lib/types/dsl/dsl-workflow.d.ts.map +1 -1
  25. package/lib/types/iterative-generation/utils.d.ts +1 -1
  26. package/lib/types/iterative-generation/utils.d.ts.map +1 -1
  27. package/lib/types/utils/blobs.d.ts +0 -1
  28. package/lib/types/utils/blobs.d.ts.map +1 -1
  29. package/lib/workflows-bundle.js +265 -9893
  30. package/package.json +4 -4
  31. package/src/activities/executeInteraction.ts +9 -2
  32. package/src/activities/generateDocumentProperties.ts +1 -0
  33. package/src/activities/generateEmbeddings.ts +2 -2
  34. package/src/dsl/dsl-workflow.ts +2 -1
  35. package/src/iterative-generation/utils.ts +1 -1
  36. package/src/utils/blobs.ts +8 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vertesia/workflow",
3
- "version": "0.55.0",
3
+ "version": "0.56.0",
4
4
  "type": "module",
5
5
  "description": "Composable prompts workflow dsl",
6
6
  "main": "./lib/esm/index.js",
@@ -51,9 +51,9 @@
51
51
  "tmp": "^0.2.3",
52
52
  "tmp-promise": "^3.0.3",
53
53
  "yaml": "^2.6.0",
54
- "@llumiverse/core": "0.17.0",
55
- "@vertesia/common": "0.55.0",
56
- "@vertesia/client": "0.55.0"
54
+ "@vertesia/common": "0.56.0",
55
+ "@llumiverse/common": "0.18.0",
56
+ "@vertesia/client": "0.56.0"
57
57
  },
58
58
  "ts_dual_module": {
59
59
  "outDir": "lib",
@@ -1,4 +1,4 @@
1
- import { ModelOptions } from "@llumiverse/core";
1
+ import { ModelOptions } from "@llumiverse/common";
2
2
  import { activityInfo, log } from "@temporalio/activity";
3
3
  import { VertesiaClient } from "@vertesia/client";
4
4
  import {
@@ -74,10 +74,13 @@ export interface InteractionExecutionParams {
74
74
  model?: string;
75
75
 
76
76
  /**
77
- * Force a JSON schema for the result
77
+ * Request a JSON schema for the result
78
78
  */
79
79
  result_schema?: any;
80
80
 
81
+ /** Wether to validate the result against the schema */
82
+ validate_result?: boolean;
83
+
81
84
  /**
82
85
  * Tags to add to the execution run
83
86
  */
@@ -154,6 +157,9 @@ export async function executeInteraction(payload: DSLActivityExecutionPayload<Ex
154
157
  if (error.message.includes("Failed to validate merged prompt schema")) {
155
158
  //issue with the input data, don't retry
156
159
  throw new ActivityParamInvalid("prompt_data", payload.activity, error.message);
160
+ } else if (error.message.includes("modelId: Path `modelId` is required")) {
161
+ //issue with the input data, don't retry
162
+ throw new ActivityParamInvalid("model", payload.activity, error.message);
157
163
  } else {
158
164
  throw error;
159
165
  }
@@ -203,6 +209,7 @@ export async function executeInteractionFromActivity(
203
209
  environment: params.environment,
204
210
  model: params.model,
205
211
  model_options: params.model_options,
212
+ do_validate: params.validate_result,
206
213
  };
207
214
  const data = {
208
215
  ...prompt_data,
@@ -73,6 +73,7 @@ export async function generateDocumentProperties(
73
73
  ...params,
74
74
  include_previous_error: true,
75
75
  result_schema: type.object_schema,
76
+ validate_result: type.strict_mode,
76
77
  },
77
78
  promptData,
78
79
  payload.debug_mode ?? false,
@@ -1,4 +1,4 @@
1
- import { EmbeddingsResult } from "@llumiverse/core";
1
+ import { EmbeddingsResult } from "@llumiverse/common";
2
2
  import { log } from "@temporalio/activity";
3
3
  import { VertesiaClient } from "@vertesia/client";
4
4
  import { ContentObject, DSLActivityExecutionPayload, DSLActivitySpec, ProjectConfigurationEmbeddings, SupportedEmbeddingTypes } from "@vertesia/common";
@@ -322,7 +322,7 @@ async function generateEmbeddingsFromStudio(text: string, env: string, client: V
322
322
  }
323
323
 
324
324
  //Simplified attention mechanism
325
- // This is a naive implementation and should be replaced with a more sophisticated
325
+ // This is a naive implementation and should be replaced with a more sophisticated
326
326
  // using tensorflow in a specific package
327
327
  function computeAttentionEmbedding(chunkEmbeddings: number[][]): number[] {
328
328
  if (chunkEmbeddings.length === 0) return [];
@@ -21,7 +21,7 @@ import {
21
21
  WorkflowExecutionPayload
22
22
  } from "@vertesia/common";
23
23
  import ms, { StringValue } from 'ms';
24
- import { ActivityParamNotFound, NoDocumentFound, WorkflowParamNotFound } from "../errors.js";
24
+ import { ActivityParamInvalid, ActivityParamNotFound, NoDocumentFound, WorkflowParamNotFound } from "../errors.js";
25
25
  import { Vars } from "./vars.js";
26
26
  import { HandleDslErrorParams } from "../activities/handleError.js";
27
27
  import * as activities from "../activities/index.js";
@@ -65,6 +65,7 @@ export async function dslWorkflow(payload: DSLWorkflowExecutionPayload) {
65
65
  NoDocumentFound.name,
66
66
  ActivityParamNotFound.name,
67
67
  WorkflowParamNotFound.name,
68
+ ActivityParamInvalid.name,
68
69
  ],
69
70
  },
70
71
  };
@@ -2,7 +2,7 @@ import { VertesiaClient } from "@vertesia/client";
2
2
  import { ExecutionRun } from "@vertesia/common";
3
3
  import { ApplicationFailure } from "@temporalio/workflow";
4
4
  import { OutputMemoryMeta, PartIndex, Toc, TocIndex, TocSection } from "./types.js";
5
- import { ModelOptions, TextFallbackOptions } from "@llumiverse/core";
5
+ import { ModelOptions, TextFallbackOptions } from "@llumiverse/common";
6
6
 
7
7
  //TODO: For whole file, support for options beyond max_tokens and temperature and multiple modalities.
8
8
  export interface ExecuteOptions {
@@ -3,6 +3,8 @@ import crypto from "crypto";
3
3
  import { createWriteStream } from "fs";
4
4
  import tmp from "tmp";
5
5
  import { NoDocumentFound } from "../errors.js";
6
+ import { Readable } from "stream";
7
+ import { pipeline } from "stream/promises";
6
8
 
7
9
  tmp.setGracefulCleanup();
8
10
 
@@ -32,32 +34,24 @@ export async function fetchBlobAsBase64(client: VertesiaClient, blobUri: string)
32
34
  return buffer.toString("base64");
33
35
  }
34
36
 
35
- export async function saveBlobToFile(client: VertesiaClient, blobUri: string, toFile: string): Promise<void> {
36
- let stream = await fetchBlobAsStream(client, blobUri);
37
+ async function saveBlobToFile(client: VertesiaClient, blobUri: string, toFile: string): Promise<void> {
38
+ const stream = await fetchBlobAsStream(client, blobUri);
39
+
40
+ const nodeReadable = Readable.from(stream);
37
41
  const out = createWriteStream(toFile);
38
- await writeChunksToStream(stream, out);
42
+
43
+ await pipeline(nodeReadable, out); // Ensures completion before continuing
39
44
  }
40
45
 
41
46
  export async function saveBlobToTempFile(client: VertesiaClient, blobUri: string, fileExt?: string): Promise<string> {
42
47
  const tmpFile = tmp.fileSync({
43
48
  prefix: "vertesia-activity-",
44
49
  postfix: fileExt ? "." + fileExt : "",
45
- discardDescriptor: true,
46
50
  });
47
51
  await saveBlobToFile(client, blobUri, tmpFile.name);
48
52
  return tmpFile.name;
49
53
  }
50
54
 
51
- async function writeChunksToStream(chunks: AsyncIterable<Uint8Array>, out: NodeJS.WritableStream) {
52
- for await (const chunk of chunks) {
53
- if (!out.write(chunk)) {
54
- // If the internal buffer is full, wait until it's drained
55
- await new Promise((resolve) => out.once("drain", resolve));
56
- }
57
- }
58
- out.end(); // Close the stream when done
59
- }
60
-
61
55
  export function md5(contents: string) {
62
56
  return crypto.createHash("md5").update(contents).digest("hex");
63
57
  }