Skip to content

Commit

Permalink
Hotfix for tools and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ogabrielluiz authored Apr 6, 2023
2 parents 5a1f137 + 291269f commit 174e75d
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 13 deletions.
57 changes: 52 additions & 5 deletions poetry.lock

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

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "langflow"
version = "0.0.53"
version = "0.0.54"
description = "A Python package with a built-in web application"
authors = ["Logspace <contact@logspace.ai>"]
maintainers = [
Expand Down Expand Up @@ -34,14 +34,15 @@ openai = "^0.27.2"
types-pyyaml = "^6.0.12.8"
dill = "^0.3.6"
pandas = "^1.5.3"
huggingface-hub = "^0.13.3"
rich = "^13.3.3"

[tool.poetry.group.dev.dependencies]
black = "^23.1.0"
ipykernel = "^6.21.2"
mypy = "^1.1.1"
ruff = "^0.0.254"
httpx = "^0.23.3"
rich = "^13.3.3"
pytest = "^7.2.2"
types-requests = "^2.28.11"
requests = "^2.28.0"
Expand Down
48 changes: 45 additions & 3 deletions src/backend/langflow/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,52 @@ class PromptValidationResponse(BaseModel):
input_variables: list


INVALID_CHARACTERS = {
" ",
",",
".",
":",
";",
"!",
"?",
"/",
"\\",
"(",
")",
"[",
"]",
"{",
"}",
}


def validate_prompt(template: str):
input_variables = extract_input_variables_from_prompt(template)
if invalid := [variable for variable in input_variables if " " in variable]:

# Check if there are invalid characters in the input_variables
input_variables = check_input_variables(input_variables)

return PromptValidationResponse(input_variables=input_variables)


def check_input_variables(input_variables: list):
invalid_chars = []
fixed_variables = []
for variable in input_variables:
new_var = variable
for char in INVALID_CHARACTERS:
if char in variable:
invalid_chars.append(char)
new_var = new_var.replace(char, "")
fixed_variables.append(new_var)
if new_var != variable:
input_variables.remove(variable)
input_variables.append(new_var)
# If any of the input_variables is not in the fixed_variables, then it means that
# there are invalid characters in the input_variables
if any(var not in fixed_variables for var in input_variables):
raise ValueError(
f"Invalid input variables: {invalid}. Please remove spaces from input variables"
f"Invalid input variables: {input_variables}. Please, use something like {fixed_variables} instead."
)
return PromptValidationResponse(input_variables=input_variables)

return input_variables
5 changes: 3 additions & 2 deletions src/backend/langflow/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ llms:
- OpenAI
- AzureOpenAI
- ChatOpenAI
- HuggingFaceHub

tools:
- Search
# - Search
- PAL-MATH
- Calculator
- Serper Search
# - Serper Search
- Tool
- PythonFunction
- JsonSpec
Expand Down
3 changes: 2 additions & 1 deletion src/backend/langflow/template/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ def format_field(field: TemplateField, name: Optional[str] = None) -> None:
field.show = bool(
(field.required and key not in ["input_variables"])
or key in FORCE_SHOW_FIELDS
or "api_key" in key
or "api" in key
or "key" in key
)

# Add password field
Expand Down

0 comments on commit 174e75d

Please sign in to comment.