Merge branch 'form_io' of github.com:logspace-ai/langflow into form_io
This commit is contained in:
commit
46e59a31d8
6 changed files with 61 additions and 46 deletions
|
|
@ -126,7 +126,7 @@ async def stream_build(flow_id: str):
|
||||||
params = vertex._built_object_repr()
|
params = vertex._built_object_repr()
|
||||||
valid = True
|
valid = True
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"Building node {params[:50]}{'...' if len(params) > 50 else ''}"
|
f"Building node {str(params)[:50]}{'...' if len(str(params)) > 50 else ''}"
|
||||||
)
|
)
|
||||||
if vertex.artifacts:
|
if vertex.artifacts:
|
||||||
# The artifacts will be prompt variables
|
# The artifacts will be prompt variables
|
||||||
|
|
|
||||||
|
|
@ -213,23 +213,27 @@ class PromptVertex(Vertex):
|
||||||
|
|
||||||
def _built_object_repr(self):
|
def _built_object_repr(self):
|
||||||
if (
|
if (
|
||||||
self.artifacts
|
not self.artifacts
|
||||||
and self._built_object is not None
|
or self._built_object is None
|
||||||
and hasattr(self._built_object, "format")
|
or not hasattr(self._built_object, "format")
|
||||||
):
|
):
|
||||||
# We'll build the prompt with the artifacts
|
|
||||||
# to show the user what the prompt looks like
|
|
||||||
# with the variables filled in
|
|
||||||
artifacts = self.artifacts.copy()
|
|
||||||
# Remove the handle_keys from the artifacts
|
|
||||||
# so the prompt format doesn't break
|
|
||||||
artifacts.pop("handle_keys", None)
|
|
||||||
try:
|
|
||||||
return self._built_object.format(**artifacts)
|
|
||||||
except KeyError:
|
|
||||||
return super()._built_object_repr()
|
|
||||||
else:
|
|
||||||
return super()._built_object_repr()
|
return super()._built_object_repr()
|
||||||
|
# We'll build the prompt with the artifacts
|
||||||
|
# to show the user what the prompt looks like
|
||||||
|
# with the variables filled in
|
||||||
|
artifacts = self.artifacts.copy()
|
||||||
|
# Remove the handle_keys from the artifacts
|
||||||
|
# so the prompt format doesn't break
|
||||||
|
artifacts.pop("handle_keys", None)
|
||||||
|
try:
|
||||||
|
template = self._built_object.format(**artifacts)
|
||||||
|
return (
|
||||||
|
template
|
||||||
|
if isinstance(template, str)
|
||||||
|
else f"{self.vertex_type}({template})"
|
||||||
|
)
|
||||||
|
except KeyError:
|
||||||
|
return str(self._built_object)
|
||||||
|
|
||||||
|
|
||||||
class OutputParserVertex(Vertex):
|
class OutputParserVertex(Vertex):
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import contextlib
|
||||||
import json
|
import json
|
||||||
from typing import Any, Callable, Dict, List, Sequence, Type
|
from typing import Any, Callable, Dict, List, Sequence, Type
|
||||||
|
|
||||||
|
|
@ -196,7 +197,7 @@ def instantiate_prompt(node_type, class_object, params: Dict):
|
||||||
if "tools" not in params:
|
if "tools" not in params:
|
||||||
params["tools"] = []
|
params["tools"] = []
|
||||||
return ZeroShotAgent.create_prompt(**params)
|
return ZeroShotAgent.create_prompt(**params)
|
||||||
if "MessagePromptTemplate" in node_type:
|
elif "MessagePromptTemplate" in node_type:
|
||||||
# Then we only need the template
|
# Then we only need the template
|
||||||
from_template_params = {
|
from_template_params = {
|
||||||
"template": params.pop("prompt", params.pop("template", ""))
|
"template": params.pop("prompt", params.pop("template", ""))
|
||||||
|
|
@ -204,12 +205,12 @@ def instantiate_prompt(node_type, class_object, params: Dict):
|
||||||
|
|
||||||
if not from_template_params.get("template"):
|
if not from_template_params.get("template"):
|
||||||
raise ValueError("Prompt template is required")
|
raise ValueError("Prompt template is required")
|
||||||
return class_object.from_template(**from_template_params)
|
prompt = class_object.from_template(**from_template_params)
|
||||||
|
|
||||||
if node_type == "ChatPromptTemplate":
|
elif node_type == "ChatPromptTemplate":
|
||||||
return class_object.from_messages(**params)
|
prompt = class_object.from_messages(**params)
|
||||||
|
else:
|
||||||
prompt = class_object(**params)
|
prompt = class_object(**params)
|
||||||
|
|
||||||
format_kwargs: Dict[str, Any] = {}
|
format_kwargs: Dict[str, Any] = {}
|
||||||
for input_variable in prompt.input_variables:
|
for input_variable in prompt.input_variables:
|
||||||
|
|
@ -221,18 +222,23 @@ def instantiate_prompt(node_type, class_object, params: Dict):
|
||||||
variable, "get_format_instructions"
|
variable, "get_format_instructions"
|
||||||
):
|
):
|
||||||
format_kwargs[input_variable] = variable.get_format_instructions()
|
format_kwargs[input_variable] = variable.get_format_instructions()
|
||||||
# check if is a list of Document
|
|
||||||
elif isinstance(variable, List) and all(
|
elif isinstance(variable, List) and all(
|
||||||
isinstance(item, Document) for item in variable
|
isinstance(item, Document) for item in variable
|
||||||
):
|
):
|
||||||
# Format document to contain page_content and metadata
|
# Format document to contain page_content and metadata
|
||||||
# as one string separated by a newline
|
# as one string separated by a newline
|
||||||
format_kwargs[input_variable] = "\n".join(
|
if len(variable) > 1:
|
||||||
[
|
content = "\n".join(
|
||||||
f"Document:{item.page_content}\nMetadata:{item.metadata}"
|
[item.page_content for item in variable if item.page_content]
|
||||||
for item in variable
|
)
|
||||||
]
|
else:
|
||||||
)
|
content = variable[0].page_content
|
||||||
|
# content could be a json list of strings
|
||||||
|
with contextlib.suppress(json.JSONDecodeError):
|
||||||
|
content = json.loads(content)
|
||||||
|
if isinstance(content, list):
|
||||||
|
content = ",".join([str(item) for item in content])
|
||||||
|
format_kwargs[input_variable] = content
|
||||||
# handle_keys will be a list but it does not exist yet
|
# handle_keys will be a list but it does not exist yet
|
||||||
# so we need to create it
|
# so we need to create it
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ class PythonFunctionToolNode(FrontendNode):
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
description: str = "Python function to be executed."
|
description: str = "Python function to be executed."
|
||||||
base_classes: list[str] = ["Tool"]
|
base_classes: list[str] = ["BaseTool", "Tool"]
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
return super().to_dict()
|
return super().to_dict()
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
@layer base {
|
@layer base {
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
--background: 0 0% 100%; /* hsl(0 0% 100%) */
|
--background: 0 0% 100%; /* hsl(0 0% 100%) */
|
||||||
--foreground: 222.2 47.4% 11.2%; /* hsl(222 47% 11%) */
|
--foreground: 222.2 47.4% 11.2%; /* hsl(222 47% 11%) */
|
||||||
--muted: 210 40% 98%; /* hsl(210 40% 98%) */
|
--muted: 210 40% 98%; /* hsl(210 40% 98%) */
|
||||||
|
|
@ -43,6 +43,9 @@
|
||||||
--high-indigo: #4338ca;
|
--high-indigo: #4338ca;
|
||||||
--medium-indigo: #6366f1;
|
--medium-indigo: #6366f1;
|
||||||
|
|
||||||
|
--chat-bot-icon: #afe6ef;
|
||||||
|
--chat-user-icon: #aface9;
|
||||||
|
|
||||||
/* Colors that are shared in dark and light mode */
|
/* Colors that are shared in dark and light mode */
|
||||||
--blur-shared: #151923de;
|
--blur-shared: #151923de;
|
||||||
--build-trigger: #dc735b;
|
--build-trigger: #dc735b;
|
||||||
|
|
@ -915,16 +918,16 @@ The cursor: default; property value restores the browser's default cursor style
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-modal-lock-true {
|
.form-modal-lock-true {
|
||||||
@apply bg-input text-black dark:bg-gray-700 dark:text-gray-300
|
@apply bg-input text-black
|
||||||
}
|
}
|
||||||
.form-modal-no-input {
|
.form-modal-no-input {
|
||||||
@apply bg-input text-center text-black dark:bg-gray-700 dark:text-gray-300
|
@apply bg-input text-center text-black dark:bg-gray-700 dark:text-gray-300
|
||||||
}
|
}
|
||||||
.form-modal-lock-false {
|
.form-modal-lock-false {
|
||||||
@apply bg-white text-black dark:bg-gray-900 dark:text-gray-300
|
@apply bg-white text-black
|
||||||
}
|
}
|
||||||
.form-modal-lockchat {
|
.form-modal-lockchat {
|
||||||
@apply form-input focus:ring-ring focus:border-ring block w-full rounded-md border-gray-300 p-4 pr-16 custom-scroll dark:border-gray-600 sm:text-sm
|
@apply form-input focus:ring-ring focus:border-ring block w-full rounded-md border-border p-4 pr-16 custom-scroll sm:text-sm
|
||||||
}
|
}
|
||||||
.form-modal-send-icon-position {
|
.form-modal-send-icon-position {
|
||||||
@apply absolute bottom-2 right-4
|
@apply absolute bottom-2 right-4
|
||||||
|
|
@ -954,10 +957,10 @@ The cursor: default; property value restores the browser's default cursor style
|
||||||
@apply relative flex h-8 w-8 items-center justify-center overflow-hidden rounded-md p-5 text-2xl
|
@apply relative flex h-8 w-8 items-center justify-center overflow-hidden rounded-md p-5 text-2xl
|
||||||
}
|
}
|
||||||
.form-modal-chat-bot-icon {
|
.form-modal-chat-bot-icon {
|
||||||
@apply form-modal-chat-img-box bg-[#afe6ef]
|
@apply form-modal-chat-img-box bg-chat-bot-icon
|
||||||
}
|
}
|
||||||
.form-modal-chat-user-icon {
|
.form-modal-chat-user-icon {
|
||||||
@apply form-modal-chat-img-box bg-[#aface9]
|
@apply form-modal-chat-img-box bg-chat-user-icon
|
||||||
}
|
}
|
||||||
.form-modal-chat-icon-img {
|
.form-modal-chat-icon-img {
|
||||||
@apply absolute scale-[60%]
|
@apply absolute scale-[60%]
|
||||||
|
|
@ -972,7 +975,7 @@ The cursor: default; property value restores the browser's default cursor style
|
||||||
@apply absolute -left-6 -top-3 cursor-pointer
|
@apply absolute -left-6 -top-3 cursor-pointer
|
||||||
}
|
}
|
||||||
.form-modal-chat-icon {
|
.form-modal-chat-icon {
|
||||||
@apply h-4 w-4 animate-bounce dark:text-white
|
@apply h-4 w-4 animate-bounce
|
||||||
}
|
}
|
||||||
.form-modal-chat-thought-border {
|
.form-modal-chat-thought-border {
|
||||||
@apply rounded-md border border-ring/60
|
@apply rounded-md border border-ring/60
|
||||||
|
|
@ -1041,13 +1044,13 @@ The cursor: default; property value restores the browser's default cursor style
|
||||||
@apply flex-max-width h-full flex-col items-center justify-center text-center align-middle
|
@apply flex-max-width h-full flex-col items-center justify-center text-center align-middle
|
||||||
}
|
}
|
||||||
.langflow-chat-span {
|
.langflow-chat-span {
|
||||||
@apply text-lg text-gray-600 dark:text-gray-300
|
@apply text-lg text-foreground
|
||||||
}
|
}
|
||||||
.langflow-chat-desc {
|
.langflow-chat-desc {
|
||||||
@apply w-2/4 rounded-md border border-gray-200 bg-muted px-6 py-8 dark:border-gray-700 dark:bg-gray-900
|
@apply w-2/4 rounded-md border border-border bg-muted px-6 py-8
|
||||||
}
|
}
|
||||||
.langflow-chat-desc-span {
|
.langflow-chat-desc-span {
|
||||||
@apply text-base text-gray-500
|
@apply text-base text-muted-foreground
|
||||||
}
|
}
|
||||||
.langflow-chat-input-div {
|
.langflow-chat-input-div {
|
||||||
@apply flex-max-width flex-col items-center justify-between px-8 pb-6
|
@apply flex-max-width flex-col items-center justify-between px-8 pb-6
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,8 @@ module.exports = {
|
||||||
"status-yellow": "var(--status-yellow)",
|
"status-yellow": "var(--status-yellow)",
|
||||||
"success-background": "var(--success-background)",
|
"success-background": "var(--success-background)",
|
||||||
"success-foreground": "var(--success-foreground)",
|
"success-foreground": "var(--success-foreground)",
|
||||||
|
"chat-bot-icon": "var(--chat-bot-icon)",
|
||||||
|
"chat-user-icon": "var(--chat-user-icon)",
|
||||||
|
|
||||||
white: "var(--white)",
|
white: "var(--white)",
|
||||||
border: "hsl(var(--border))",
|
border: "hsl(var(--border))",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue