Date: Mon, 29 Jul 2024 15:19:23 +0000
Subject: [PATCH 4/5] feat: Workflows
---
src/ui/src/core/templateMap.ts | 4 ++
.../workflow_components/CoreCreateFile.vue | 61 +++++++++++++++++
.../workflow_components/CoreWriterKGAdd.vue | 68 +++++++++++++++++++
3 files changed, 133 insertions(+)
create mode 100644 src/ui/src/workflow_components/CoreCreateFile.vue
create mode 100644 src/ui/src/workflow_components/CoreWriterKGAdd.vue
diff --git a/src/ui/src/core/templateMap.ts b/src/ui/src/core/templateMap.ts
index 0c27530a1..8f0f9ed8c 100644
--- a/src/ui/src/core/templateMap.ts
+++ b/src/ui/src/core/templateMap.ts
@@ -65,6 +65,8 @@ import CoreHTTPCall from "../workflow_components/CoreHTTPCall.vue";
import CoreSetState from "../workflow_components/CoreSetState.vue";
import CoreWriterCompletion from "../workflow_components/CoreWriterCompletion.vue";
import CoreTwitterPost from "../workflow_components/CoreTwitterPost.vue";
+import CoreCreateFile from "../workflow_components/CoreCreateFile.vue";
+import CoreWriterKGAdd from "../workflow_components/CoreWriterKGAdd.vue";
import { WriterComponentDefinition } from "../writerTypes";
import { h } from "vue";
@@ -128,6 +130,8 @@ const templateMap = {
setstate: CoreSetState,
writercompletion: CoreWriterCompletion,
twitterpost: CoreTwitterPost,
+ createfile: CoreCreateFile,
+ writerkgadd: CoreWriterKGAdd,
};
if (WRITER_LIVE_CCT === "yes") {
diff --git a/src/ui/src/workflow_components/CoreCreateFile.vue b/src/ui/src/workflow_components/CoreCreateFile.vue
new file mode 100644
index 000000000..a225e9f36
--- /dev/null
+++ b/src/ui/src/workflow_components/CoreCreateFile.vue
@@ -0,0 +1,61 @@
+
+
+ I'm used to create files from content
+
+
+
+
+
+
+
diff --git a/src/ui/src/workflow_components/CoreWriterKGAdd.vue b/src/ui/src/workflow_components/CoreWriterKGAdd.vue
new file mode 100644
index 000000000..60eb8acdc
--- /dev/null
+++ b/src/ui/src/workflow_components/CoreWriterKGAdd.vue
@@ -0,0 +1,68 @@
+
+
+ I'm a Writer KG node
+
+
+
+
+
+
+
From 650b63b6de12d96a449873bb4bb1d03166a8e5ce Mon Sep 17 00:00:00 2001
From: Ramiro Medina <64783088+ramedina86@users.noreply.github.com>
Date: Thu, 15 Aug 2024 17:49:10 +0000
Subject: [PATCH 5/5] feat: Workflows
---
src/ui/src/core/templateMap.ts | 2 +
.../workflow_components/CoreCreateFile.vue | 10 ++-
.../src/workflow_components/CoreHTTPCall.vue | 21 +++--
.../CorePythonFunction.vue | 6 +-
.../src/workflow_components/CoreSetState.vue | 18 +++-
.../workflow_components/CoreTwitterPost.vue | 6 +-
.../CoreWriterCompletion.vue | 17 +++-
.../workflow_components/CoreWriterKGAdd.vue | 38 +++++----
.../src/workflow_components/CoreWriterSQL.vue | 82 +++++++++++++++++++
.../workflow_components/WorkflowsNodeBox.vue | 48 +++++++++--
src/writer/core.py | 42 ++++++----
11 files changed, 234 insertions(+), 56 deletions(-)
create mode 100644 src/ui/src/workflow_components/CoreWriterSQL.vue
diff --git a/src/ui/src/core/templateMap.ts b/src/ui/src/core/templateMap.ts
index b30f28e51..3a896b5ac 100644
--- a/src/ui/src/core/templateMap.ts
+++ b/src/ui/src/core/templateMap.ts
@@ -69,6 +69,7 @@ import CoreWriterCompletion from "../workflow_components/CoreWriterCompletion.vu
import CoreTwitterPost from "../workflow_components/CoreTwitterPost.vue";
import CoreCreateFile from "../workflow_components/CoreCreateFile.vue";
import CoreWriterKGAdd from "../workflow_components/CoreWriterKGAdd.vue";
+import CoreWriterSQL from "../workflow_components/CoreWriterSQL.vue";
import { WriterComponentDefinition } from "../writerTypes";
import { h } from "vue";
@@ -136,6 +137,7 @@ const templateMap = {
createfile: CoreCreateFile,
writerkgadd: CoreWriterKGAdd,
jsonviewer: CoreJsonViewer,
+ writersql: CoreWriterSQL,
};
if (WRITER_LIVE_CCT === "yes") {
diff --git a/src/ui/src/workflow_components/CoreCreateFile.vue b/src/ui/src/workflow_components/CoreCreateFile.vue
index a225e9f36..6ab1da4bb 100644
--- a/src/ui/src/workflow_components/CoreCreateFile.vue
+++ b/src/ui/src/workflow_components/CoreCreateFile.vue
@@ -1,5 +1,9 @@
-
+
I'm used to create files from content
@@ -19,8 +23,8 @@ export default {
name: "File name",
type: FieldType.Text,
},
- content: {
- name: "Content",
+ data: {
+ name: "Data",
type: FieldType.Text,
},
fileType: {
diff --git a/src/ui/src/workflow_components/CoreHTTPCall.vue b/src/ui/src/workflow_components/CoreHTTPCall.vue
index 0e81d842a..b36fe128d 100644
--- a/src/ui/src/workflow_components/CoreHTTPCall.vue
+++ b/src/ui/src/workflow_components/CoreHTTPCall.vue
@@ -1,12 +1,16 @@
-
+
-
+
{{ fields.method.value?.toUpperCase() }}
-
-
+
+
{{ fields.url.value }}
-
+
@@ -76,14 +80,15 @@ const component = computed(() => wf.getComponentById(componentId));
}
.content {
- gap: 4px;
+ display: block;
}
.method {
- background-color: #b5eeee;
+ background-color: #f0f0f0;
padding: 2px 4px 2px 4px;
+ margin: 2px 0 2px 0;
border-radius: 4px;
- display: inline;
+ display: inline-block;
}
.url {
diff --git a/src/ui/src/workflow_components/CorePythonFunction.vue b/src/ui/src/workflow_components/CorePythonFunction.vue
index 6fe2d1a41..f5e83ec0f 100644
--- a/src/ui/src/workflow_components/CorePythonFunction.vue
+++ b/src/ui/src/workflow_components/CorePythonFunction.vue
@@ -1,5 +1,9 @@
-
+
I'm a Python function
diff --git a/src/ui/src/workflow_components/CoreSetState.vue b/src/ui/src/workflow_components/CoreSetState.vue
index a560b0dc5..c52fc0b48 100644
--- a/src/ui/src/workflow_components/CoreSetState.vue
+++ b/src/ui/src/workflow_components/CoreSetState.vue
@@ -1,6 +1,11 @@
-
- I'm used to set state
+
+ Set {{ fields.element.value }} to
+ {{ fields.value.value }}
@@ -45,6 +50,7 @@ import injectionKeys from "../injectionKeys";
const wf = inject(injectionKeys.core);
const componentId = inject(injectionKeys.componentId);
+const fields = inject(injectionKeys.evaluatedFields);
const component = computed(() => wf.getComponentById(componentId));
@@ -54,4 +60,12 @@ const component = computed(() => wf.getComponentById(componentId));
.CoreSetState {
}
+
+.highlight {
+ background-color: #f0f0f0;
+ padding: 2px 4px 2px 4px;
+ margin: 2px 0 2px 0;
+ border-radius: 4px;
+ display: inline-block;
+}
diff --git a/src/ui/src/workflow_components/CoreTwitterPost.vue b/src/ui/src/workflow_components/CoreTwitterPost.vue
index 936075e2d..cc5d560b7 100644
--- a/src/ui/src/workflow_components/CoreTwitterPost.vue
+++ b/src/ui/src/workflow_components/CoreTwitterPost.vue
@@ -1,5 +1,9 @@
-
diff --git a/src/ui/src/workflow_components/CoreWriterCompletion.vue b/src/ui/src/workflow_components/CoreWriterCompletion.vue
index a1070982b..c6c2b5206 100644
--- a/src/ui/src/workflow_components/CoreWriterCompletion.vue
+++ b/src/ui/src/workflow_components/CoreWriterCompletion.vue
@@ -1,6 +1,10 @@
-
- I'm a Writer completion
+
+ Complete text {{ fields.text.value }}
@@ -57,6 +61,7 @@ import injectionKeys from "../injectionKeys";
const wf = inject(injectionKeys.core);
const componentId = inject(injectionKeys.componentId);
+const fields = inject(injectionKeys.evaluatedFields);
const component = computed(() => wf.getComponentById(componentId));
@@ -66,4 +71,12 @@ const component = computed(() => wf.getComponentById(componentId));
.CoreWriterCompletion {
}
+
+.highlight {
+ background-color: #f0f0f0;
+ padding: 2px 4px 2px 4px;
+ margin: 2px 0 2px 0;
+ border-radius: 4px;
+ display: inline-block;
+}
diff --git a/src/ui/src/workflow_components/CoreWriterKGAdd.vue b/src/ui/src/workflow_components/CoreWriterKGAdd.vue
index 60eb8acdc..20c32388f 100644
--- a/src/ui/src/workflow_components/CoreWriterKGAdd.vue
+++ b/src/ui/src/workflow_components/CoreWriterKGAdd.vue
@@ -1,5 +1,9 @@
-
+
I'm a Writer KG node
@@ -15,25 +19,24 @@ export default {
category: "Content",
allowedParentTypes: ["workflow"],
fields: {
- text: {
- name: "Text",
+ data: {
+ name: "Data",
type: FieldType.Text,
control: FieldControl.Textarea,
- desc: "The text to complete.",
},
- modelId: {
- name: "Model",
+ type: {
+ name: "Type",
+ type: FieldType.Text,
+ init: "text/plain",
+ },
+ name: {
+ name: "Name",
+ type: FieldType.Text,
+ init: "myfile.txt",
+ },
+ graphId: {
+ name: "Graph id",
type: FieldType.Text,
- options: {
- "palmyra-x-003-instruct": "palmyra-x-003-instruct",
- "palmyra-x-002-instruct": "palmyra-x-002-instruct",
- "palmyra-x-32k-instruct": "palmyra-x-32k-instruct",
- "palmyra-x-002-32k": "palmyra-x-002-32k",
- "palmyra-med-32k": "palmyra-med-32k",
- "palmyra-med": "palmyra-med",
- "palmyra-fin-32k": "palmyra-fin-32k",
- },
- init: "palmyra-x-002-instruct",
},
},
outs: {
@@ -64,5 +67,6 @@ const component = computed(() => wf.getComponentById(componentId));
diff --git a/src/ui/src/workflow_components/CoreWriterSQL.vue b/src/ui/src/workflow_components/CoreWriterSQL.vue
new file mode 100644
index 000000000..6fc0879f0
--- /dev/null
+++ b/src/ui/src/workflow_components/CoreWriterSQL.vue
@@ -0,0 +1,82 @@
+
+
+ Complete text {{ fields.text.value }}
+
+
+
+
+
+
+
diff --git a/src/ui/src/workflow_components/WorkflowsNodeBox.vue b/src/ui/src/workflow_components/WorkflowsNodeBox.vue
index 385016aad..c99f629e2 100644
--- a/src/ui/src/workflow_components/WorkflowsNodeBox.vue
+++ b/src/ui/src/workflow_components/WorkflowsNodeBox.vue
@@ -1,8 +1,19 @@
-
-
{{ def.name }}
+
+
+
settings
+
+ {{ def.name }}
+
@@ -30,6 +41,7 @@ const wf = inject(injectionKeys.core);
const props = defineProps<{
component: Component;
+ variant?: string;
}>();
const def = computed(() => {
@@ -56,16 +68,42 @@ function handleOutClick(ev: DragEvent, outId: string) {
}
.title {
- background: #ede2ff;
- padding: 12px 16px 12px 16px;
+ display: flex;
+ gap: 12px;
+ padding: 14px 16px 14px 16px;
border-radius: 12px 12px 0 0;
border-top: 1px solid var(--builderSeparatorColor);
border-left: 1px solid var(--builderSeparatorColor);
border-right: 1px solid var(--builderSeparatorColor);
+ align-items: center;
+ font-size: 12px;
+ font-style: normal;
+ font-weight: 500;
+ line-height: 12px;
+ letter-spacing: 1.3px;
+ text-transform: uppercase;
+}
+
+.title img {
+ width: 18px;
+}
+
+.title i {
+ font-size: 16px;
+}
+
+.WorkflowsNodeBox.writer .title {
+ color: #4f4f4f;
+ background: linear-gradient(264deg, #f6effd 0.71%, #e4e9ff 100%);
+}
+
+.WorkflowsNodeBox.tool .title {
+ background: #4f4f4f;
+ color: #ffffff;
}
.main {
- font-size: 12.5px;
+ font-size: 14px;
padding: 12px 16px 12px 16px;
border-left: 1px solid var(--builderSeparatorColor);
border-right: 1px solid var(--builderSeparatorColor);
diff --git a/src/writer/core.py b/src/writer/core.py
index 0d6e5e63a..80b218032 100644
--- a/src/writer/core.py
+++ b/src/writer/core.py
@@ -1099,26 +1099,33 @@ def replacer(matched):
expr = matched.group(1).strip()
expr_value = self.evaluate_expression(expr, instance_path, base_context)
- serialised_value = None
try:
- serialised_value = state_serialiser.serialise(expr_value)
+ if as_json:
+ serialised_value = state_serialiser.serialise(expr_value)
+ return json.dumps(serialised_value)
+ return expr_value
except BaseException:
raise ValueError(
f"""Couldn't serialise value of type "{ type(expr_value) }" when evaluating field "{ field_key }".""")
- if as_json:
- return json.dumps(serialised_value)
- return str(serialised_value)
-
component_id = instance_path[-1]["componentId"]
component = self.ct.get_component(component_id)
if component:
field_value = component.content.get(field_key) or default_field_value
- replaced = self.template_regex.sub(replacer, field_value)
+ replaced = None
+ full_match = self.template_regex.fullmatch(field_value)
+
+ if full_match is None:
+ print(f"Did not obtain full match for {field_key}")
+ replaced = self.template_regex.sub(lambda m: str(replacer(m)), field_value)
+ else:
+ print(f"Obtained full match for {field_key}")
+ replaced = replacer(full_match)
if as_json:
return json.loads(replaced)
else:
+ print(f"Returning {field_key} as {type(replaced)}")
return replaced
else:
raise ValueError(f"Couldn't acquire a component by ID '{component_id}'")
@@ -1212,27 +1219,28 @@ def parse_expression(self, expr: str, instance_path: Optional[InstancePath] = No
def evaluate_expression(self, expr: str, instance_path: Optional[InstancePath] = None, base_context = {}) -> Any:
- context_data = None
+ context_data = base_context
+ result = None
if instance_path:
context_data = self.get_context_data(instance_path, base_context)
context_ref: Any = context_data
state_ref: Any = self.wf.user_state.state
accessors: List[str] = self.parse_expression(expr, instance_path)
+
for accessor in accessors:
- if isinstance(state_ref, (StateProxy, dict)):
+ if isinstance(state_ref, (StateProxy, dict)) and state_ref.get(accessor):
state_ref = state_ref.get(accessor)
-
- if context_ref and isinstance(context_ref, dict):
+ result = state_ref
+ elif isinstance(state_ref, (list)) and state_ref[int(accessor)] is not None:
+ state_ref = state_ref[int(accessor)]
+ result = state_ref
+ elif isinstance(context_ref, dict) and context_ref.get(accessor):
context_ref = context_ref.get(accessor)
-
- result = None
- if context_ref:
- result = context_ref
- elif state_ref:
- result = state_ref
+ result = context_ref
if isinstance(result, StateProxy):
return result.to_dict()
+
return result