Skip to content

Commit

Permalink
Release 0.0.53
Browse files Browse the repository at this point in the history
added colors to toolkits and wrappers
  • Loading branch information
anovazzi1 authored Apr 6, 2023
2 parents d88c2ae + 8890c84 commit 5a1f137
Show file tree
Hide file tree
Showing 13 changed files with 263 additions and 39 deletions.
55 changes: 28 additions & 27 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "langflow"
version = "0.0.52"
version = "0.0.53"
description = "A Python package with a built-in web application"
authors = ["Logspace <contact@logspace.ai>"]
maintainers = [
Expand Down
10 changes: 10 additions & 0 deletions src/backend/langflow/api/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from langflow.graph.utils import extract_input_variables_from_prompt
from pydantic import BaseModel, validator


Expand Down Expand Up @@ -25,3 +26,12 @@ def validate_function(cls, v):

class PromptValidationResponse(BaseModel):
input_variables: list


def validate_prompt(template: str):
input_variables = extract_input_variables_from_prompt(template)
if invalid := [variable for variable in input_variables if " " in variable]:
raise ValueError(
f"Invalid input variables: {invalid}. Please remove spaces from input variables"
)
return PromptValidationResponse(input_variables=input_variables)
6 changes: 3 additions & 3 deletions src/backend/langflow/api/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
CodeValidationResponse,
Prompt,
PromptValidationResponse,
validate_prompt,
)
from langflow.graph.utils import extract_input_variables_from_prompt
from langflow.utils.logger import logger
Expand All @@ -29,8 +30,7 @@ def post_validate_code(code: Code):
@router.post("/prompt", status_code=200, response_model=PromptValidationResponse)
def post_validate_prompt(prompt: Prompt):
try:
input_variables = extract_input_variables_from_prompt(prompt.template)
return PromptValidationResponse(input_variables=input_variables)
return validate_prompt(prompt.template)
except Exception as e:
logger.exception(e)
return HTTPException(status_code=500, detail=str(e))
raise HTTPException(status_code=500, detail=str(e)) from e
11 changes: 10 additions & 1 deletion src/backend/langflow/template/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,22 @@ class PromptFrontendNode(FrontendNode):
def format_field(field: TemplateField, name: Optional[str] = None) -> None:
# if field.field_type == "StringPromptTemplate"
# change it to str
PROMPT_FIELDS = [
"template",
"suffix",
"prefix",
"examples",
]
if field.field_type == "StringPromptTemplate" and "Message" in str(name):
field.field_type = "str"
field.field_type = "prompt"
field.multiline = True
field.value = HUMAN_PROMPT if "Human" in field.name else SYSTEM_PROMPT
if field.name == "template" and field.value == "":
field.value = DEFAULT_PROMPT

if field.name in PROMPT_FIELDS:
field.field_type = "prompt"

if (
"Union" in field.field_type
and "BaseMessagePromptTemplate" in field.field_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import CodeAreaComponent from "../../../../components/codeAreaComponent";
import InputFileComponent from "../../../../components/inputFileComponent";
import { TabsContext } from "../../../../contexts/tabsContext";
import IntComponent from "../../../../components/intComponent";
import PromptAreaComponent from "../../../../components/promptComponent";

export default function ParameterComponent({
left,
Expand Down Expand Up @@ -63,6 +64,7 @@ export default function ParameterComponent({
type === "bool" ||
type === "float" ||
type === "code" ||
type === "prompt" ||
type === "file" ||
type === "int") ? (
<></>
Expand Down Expand Up @@ -187,9 +189,16 @@ export default function ParameterComponent({
save();
}}
/>
) : (
<></>
)}
) : left === true && type === "prompt" ? (
<PromptAreaComponent
disabled={disabled}
value={data.node.template[name].value ?? ""}
onChange={(t: string) => {
data.node.template[name].value = t;
save();
}}
/>
):(<></>)}
</>
</div>
);
Expand Down
35 changes: 35 additions & 0 deletions src/frontend/src/components/promptComponent/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ArrowTopRightOnSquareIcon } from "@heroicons/react/24/outline";
import { useContext, useEffect, useState } from "react";
import { PopUpContext } from "../../contexts/popUpContext";
import CodeAreaModal from "../../modals/codeAreaModal";
import TextAreaModal from "../../modals/textAreaModal";
import { TextAreaComponentType } from "../../types/components";
import PromptAreaModal from "../../modals/promptModal";

export default function PromptAreaComponent({ value, onChange, disabled }:TextAreaComponentType) {
const [myValue, setMyValue] = useState(value);
const { openPopUp } = useContext(PopUpContext);
useEffect(() => {
if (disabled) {
setMyValue("");
onChange("");
}
}, [disabled, onChange]);
return (
<div className={disabled ? "pointer-events-none cursor-not-allowed w-full" : " w-full"}>
<div className="w-full flex items-center gap-3">
<span
className={
"truncate block w-full text-gray-500 px-3 py-2 rounded-md border border-gray-300 dark:border-gray-700 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm" +
(disabled ? " bg-gray-200" : "")
}
>
{myValue !== "" ? myValue : 'Text empty'}
</span>
<button onClick={()=>{openPopUp(<PromptAreaModal value={myValue} setValue={(t:string) => {setMyValue(t); onChange(t);}}/>)}}>
<ArrowTopRightOnSquareIcon className="w-6 h-6 hover:text-blue-600" />
</button>
</div>
</div>
);
}
7 changes: 6 additions & 1 deletion src/frontend/src/controllers/API/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { errorsTypeAPI } from './../../types/api/index';
import { PromptTypeAPI, errorsTypeAPI } from './../../types/api/index';
import { APIObjectType, sendAllProps } from '../../types/api/index';
import axios, { AxiosResponse } from "axios";

Expand All @@ -13,4 +13,9 @@ export async function sendAll(data:sendAllProps) {
export async function checkCode(code:string):Promise<AxiosResponse<errorsTypeAPI>>{

return await axios.post('/validate/code',{code})
}

export async function checkPrompt(template:string):Promise<AxiosResponse<PromptTypeAPI>>{

return await axios.post('/validate/prompt',{template})
}
1 change: 0 additions & 1 deletion src/frontend/src/modals/codeAreaModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ export default function CodeAreaModal({
<div className="h-full w-full bg-gray-200 overflow-auto dark:bg-gray-900 p-4 gap-4 flex flex-row justify-center items-center">
<div className="flex h-full w-full">
<div className="overflow-hidden px-4 py-5 sm:p-6 w-full h-full rounded-lg bg-white dark:bg-gray-800 shadow">
{/* need to insert code editor */}
<AceEditor
value={code}
mode="python"
Expand Down
Loading

0 comments on commit 5a1f137

Please sign in to comment.