Skip to content

Commit

Permalink
fix: General Fixes and Improvements from v1.0.19.2 Fixes Branch (#4411)
Browse files Browse the repository at this point in the history
* fix: update assistants client import (#4150)

* remove unnecessary patch

* remove unnecessary patch

* compatible release operator

* chore: add opensearch-py dependency (#4134)

Add opensearch-py dependency to pyproject.toml

* patch version

* lock

* lock some packages to speed up pip install

* langflow-base version

* fix: fix retrieverTool component (#4201)

♻️ (RetrieverTool.py): refactor build method signature to accept additional keyword arguments for future extensibility

* Fixed save modal not exiting

* fix: object has no attribute 'set_event_manager' (#4200)

* 🐛 (base.py): fix AttributeError by checking if custom_component has set_event_manager method before calling it

* 📝 (base.py): Import Component from langflow.custom to improve code readability and maintainability
♻️ (base.py): Refactor code to use isinstance() method for checking if custom_component is an instance of Component

* Refactor: Eliminate Global Variables for Improved Code Maintainability_fix_release (#4208)

Refactor: Eliminate Global Variables for Improved Code Maintainability

- Replaced global variables with local variables or class attributes.
- Enhanced code readability and reduced potential side effects.

* fix: Update example (#4204)

update example

* fix: avoids error NameError: name 'MAX_NUMBER_OF_FIELDS' is not defin… (#4203)

fix: avoids error NameError: name 'MAX_NUMBER_OF_FIELDS' is not defined and fixes build method

Co-authored-by: Edwin Jose <[email protected]>

* fix: unexpected keyword argument 'code' -> SQLExecutor and SQLDatabase (#4230)

🔧 (SQLDatabase.py): update build method signature to accept additional keyword arguments for future extensibility
🔧 (SQLExecutor.py): update method signature to accept additional keyword arguments for future extensibility

* lock httptools to 0.6.4

* Move ChatInput import to within flow_component fixture in conftest.py

* Simplify error message formatting in test cases for data components

* Add readme to dockerfile

* build: dockerfile with entrypoint (#4062)

Adds a dockerfile with an entrypoint for use with Datastax Langflow

* fixes the leading v for checking out commits correctly

* fixes on more version checkout for docker build

* ✨ (authContext.tsx): Add functionality to fetch global variables on authentication
🔧 (api.tsx): Replace universal-cookie import with react-cookie for consistency
🔧 (authStore.ts): Replace universal-cookie import with react-cookie for consistency
🔧 (use-get-global-variables.ts): Add check to only fetch global variables if user is authenticated
✨ (use-get-mutation-global-variables.ts): Add mutation function to fetch and update global variables
🔧 (authStore.ts): Replace universal-cookie import with react-cookie for consistency

* [autofix.ci] apply automated fixes

* revert changes to workflows

* upgrade lockfile

* update pyproject versions

* update lockfile again

* ⬆️ (pyproject.toml): upgrade langflow-base dependency to version 0.0.99

* ⬆️ (pyproject.toml): downgrade version from 0.0.99 to 0.0.97 to align with project requirements and dependencies.

* ⬆️ (pyproject.toml): downgrade langflow-base dependency version from 0.0.99 to 0.0.97 to resolve compatibility issues

* ⬆️ (uv.lock): downgrade langchain-core package version from 0.3.15 to 0.3.12 to resolve compatibility issues with dependencies

* ⬆️ (pyproject.toml): upgrade langflow-base dependency to version 0.0.99 to utilize the latest features and improvements

---------

Co-authored-by: Sebastián Estévez <[email protected]>
Co-authored-by: Gabriel Luiz Freitas Almeida <[email protected]>
Co-authored-by: Lucas Oliveira <[email protected]>
Co-authored-by: Edwin Jose <[email protected]>
Co-authored-by: anovazzi1 <[email protected]>
Co-authored-by: João <[email protected]>
Co-authored-by: Jordan Frazier <[email protected]>
Co-authored-by: Jordan Frazier <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
10 people committed Nov 7, 2024
1 parent 722ef29 commit 8ed26c2
Show file tree
Hide file tree
Showing 13 changed files with 1,259 additions and 1,590 deletions.
9 changes: 7 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ packages = ["src/backend/langflow"]

[project]
name = "langflow"
version = "1.0.19"
version = "1.0.19.post2"
description = "A Python package with a built-in web application"
requires-python = ">=3.10,<3.13"
license = "MIT"
Expand All @@ -31,7 +31,7 @@ maintainers = [

# Define your main dependencies here
dependencies = [
"langflow-base==0.0.97",
"langflow-base==0.0.99",
"beautifulsoup4>=4.12.2",
"google-search-results>=2.4.1",
"google-api-python-client>=2.130.0",
Expand Down Expand Up @@ -68,13 +68,17 @@ dependencies = [
"litellm>=1.44.0",
"chromadb>=0.4",
"zep-python>=2.0.0",
"langchain-groq>=0.1.9",
"langchain-pinecone>=0.1.3",
"youtube-transcript-api>=0.6.2",
"markdown>=3.7",
"upstash-vector>=0.5.0",
"gitpython>=3.1.43",
"kubernetes>=30.1.0",
"firecrawl-py>=0.0.16",
"json-repair>=0.25.2",
"langchain-google-calendar-tools>=0.0.1",
"langchain-milvus>=0.1.1",
"langwatch==0.1.16",
"langsmith~=0.1.136",
"yfinance>=0.2.40",
Expand Down Expand Up @@ -107,6 +111,7 @@ dependencies = [
"langchain-milvus>=0.1.1",
"langchain-google-community~=2.0.1",
"langchain-elasticsearch>=0.2.0",
"opensearch-py>=2.7.1",
"langchain-ollama>=0.2.0",
"pymupdf~=1.24.13",
"sqlalchemy[aiosqlite,postgresql_psycopg2binary,postgresql_psycopgbinary]>=2.0.36"
Expand Down
4 changes: 0 additions & 4 deletions src/backend/base/langflow/components/astra_assistants/run.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import Any

from astra_assistants import patch
from openai import OpenAI
from openai.lib.streaming import AssistantEventHandler

from langflow.base.astra_assistants.util import get_patched_openai_client
Expand Down Expand Up @@ -63,8 +61,6 @@ def update_build_config(
outputs = [Output(display_name="Assistant Response", name="assistant_response", method="process_inputs")]

def process_inputs(self) -> Message:
patch(OpenAI())

text = ""

if self.thread_id is None:
Expand Down
12 changes: 6 additions & 6 deletions src/backend/base/langflow/components/prototypes/create_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
from langflow.schema import Data
from langflow.schema.dotdict import dotdict

MAX_NUMBER_OF_FIELDS = 15


class CreateDataComponent(Component):
display_name: str = "Create Data"
description: str = "Dynamically create a Data with a specified number of fields."
name: str = "CreateData"
MAX_FIELDS = 15 # Define a constant for maximum number of fields

inputs = [
IntInput(
Expand All @@ -22,7 +21,7 @@ class CreateDataComponent(Component):
info="Number of fields to be added to the record.",
real_time_refresh=True,
value=1,
range_spec=RangeSpec(min=1, max=15, step=1, step_type="int"),
range_spec=RangeSpec(min=1, max=MAX_FIELDS, step=1, step_type="int"),
),
MessageTextInput(
name="text_key",
Expand Down Expand Up @@ -50,10 +49,11 @@ def update_build_config(self, build_config: dotdict, field_value: Any, field_nam
except ValueError:
return build_config
existing_fields = {}
if field_value_int > MAX_NUMBER_OF_FIELDS:
build_config["number_of_fields"]["value"] = MAX_NUMBER_OF_FIELDS
if field_value_int > self.MAX_FIELDS:
build_config["number_of_fields"]["value"] = self.MAX_FIELDS
msg = (
f"Number of fields cannot exceed {MAX_NUMBER_OF_FIELDS}. Try using a Component to combine two Data."
f"Number of fields cannot exceed {self.MAX_FIELDS}. "
"Please adjust the number of fields to be within the allowed limit."
)
raise ValueError(msg)
if len(build_config) > len(default_keys):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def build(
include_columns: bool = False,
passthrough: bool = False,
add_error: bool = False,
**kwargs,
) -> Text:
_ = kwargs
error = None
try:
database = SQLDatabase.from_uri(database_url)
Expand Down
109 changes: 76 additions & 33 deletions src/backend/base/langflow/components/prototypes/update_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,38 @@

from langflow.custom import Component
from langflow.field_typing.range_spec import RangeSpec
from langflow.inputs.inputs import BoolInput, DataInput, DictInput, IntInput, MessageTextInput
from langflow.inputs.inputs import (
BoolInput,
DataInput,
DictInput,
IntInput,
MessageTextInput,
)
from langflow.io import Output
from langflow.schema import Data
from langflow.schema.dotdict import dotdict

MAX_NUMBER_OF_FIELDS = 15


class UpdateDataComponent(Component):
display_name: str = "Update data"
description: str = "Dynamically update or append data with the specified fields."
name: str = "UpdateData"
MAX_FIELDS = 15 # Define a constant for maximum number of fields

inputs = [
DataInput(
name="old_data",
display_name="Data",
info="The record to update.",
is_list=False,
is_list=True, # Changed to True to handle list of Data objects
),
IntInput(
name="number_of_fields",
display_name="Number of Fields",
info="Number of fields to be added to the record.",
real_time_refresh=True,
value=0,
range_spec=RangeSpec(min=1, max=15, step=1, step_type="int"),
range_spec=RangeSpec(min=1, max=MAX_FIELDS, step=1, step_type="int"),
),
MessageTextInput(
name="text_key",
Expand All @@ -49,24 +54,37 @@ class UpdateDataComponent(Component):
]

def update_build_config(self, build_config: dotdict, field_value: Any, field_name: str | None = None):
"""Update the build configuration when the number of fields changes.
Args:
build_config (dotdict): The current build configuration.
field_value (Any): The new value for the field.
field_name (Optional[str]): The name of the field being updated.
"""
if field_name == "number_of_fields":
default_keys = ["code", "_type", "number_of_fields", "text_key", "old_data", "text_key_validator"]
default_keys = {
"code",
"_type",
"number_of_fields",
"text_key",
"old_data",
"text_key_validator",
}
try:
field_value_int = int(field_value)
except ValueError:
return build_config
existing_fields = {}
if field_value_int > MAX_NUMBER_OF_FIELDS:
build_config["number_of_fields"]["value"] = MAX_NUMBER_OF_FIELDS
msg = (
f"Number of fields cannot exceed {MAX_NUMBER_OF_FIELDS}. Try using a Component to combine two Data."
)

if field_value_int > self.MAX_FIELDS:
build_config["number_of_fields"]["value"] = self.MAX_FIELDS
msg = f"Number of fields cannot exceed {self.MAX_FIELDS}. " "Try using a Component to combine two Data."
raise ValueError(msg)
if len(build_config) > len(default_keys):
# back up the existing template fields
for key in build_config.copy():
if key not in default_keys:
existing_fields[key] = build_config.pop(key)

existing_fields = {}
# Back up the existing template fields
for key in list(build_config.keys()):
if key not in default_keys:
existing_fields[key] = build_config.pop(key)

for i in range(1, field_value_int + 1):
key = f"field_{i}_key"
Expand All @@ -85,30 +103,55 @@ def update_build_config(self, build_config: dotdict, field_value: Any, field_nam
build_config["number_of_fields"]["value"] = field_value_int
return build_config

async def build_data(self) -> Data:
async def build_data(self) -> Data | list[Data]:
"""Build the updated data by combining the old data with new fields."""
new_data = self.get_data()
self.old_data.data.update(new_data)
if self.text_key:
self.old_data.text_key = self.text_key
self.status = self.old_data
self.validate_text_key(self.old_data)
return self.old_data
if isinstance(self.old_data, list):
for data_item in self.old_data:
if not isinstance(data_item, Data):
continue # Skip invalid items
data_item.data.update(new_data)
if self.text_key:
data_item.text_key = self.text_key
self.validate_text_key(data_item)
self.status = self.old_data
return self.old_data # Returns List[Data]
if isinstance(self.old_data, Data):
self.old_data.data.update(new_data)
if self.text_key:
self.old_data.text_key = self.text_key
self.status = self.old_data
self.validate_text_key(self.old_data)
return self.old_data # Returns Data
msg = "old_data is not a Data object or list of Data objects."
raise ValueError(msg)

def get_data(self):
"""Function to get the Data from the attributes."""
data = {}
for value_dict in self._attributes.values():
if isinstance(value_dict, dict):
# Check if the value of the value_dict is a Data
_value_dict = {
key: value.get_text() if isinstance(value, Data) else value for key, value in value_dict.items()
}
data.update(_value_dict)
default_keys = {
"code",
"_type",
"number_of_fields",
"text_key",
"old_data",
"text_key_validator",
}
for attr_name, attr_value in self._attributes.items():
if attr_name in default_keys:
continue # Skip default attributes
if isinstance(attr_value, dict):
for key, value in attr_value.items():
data[key] = value.get_text() if isinstance(value, Data) else value
elif isinstance(attr_value, Data):
data[attr_name] = attr_value.get_text()
else:
data[attr_name] = attr_value
return data

def validate_text_key(self, data: Data) -> None:
"""This function validates that the Text Key is one of the keys in the Data."""
data_keys = data.data.keys()
if self.text_key not in data_keys and self.text_key != "":
msg = f"Text Key: {self.text_key} not found in the Data keys: {','.join(data_keys)}"
if self.text_key and self.text_key not in data_keys:
msg = f"Text Key: '{self.text_key}' not found in the Data keys: " f"{', '.join(data_keys)}"
raise ValueError(msg)
8 changes: 2 additions & 6 deletions src/backend/base/langflow/components/tools/retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ def build_config(self):
"description": {"display_name": "Description", "info": "Description of the tool"},
}

def build(
self,
retriever: BaseRetriever,
name: str,
description: str,
) -> Tool:
def build(self, retriever: BaseRetriever, name: str, description: str, **kwargs) -> Tool:
_ = kwargs
return create_retriever_tool(
retriever=retriever,
name=name,
Expand Down
Loading

0 comments on commit 8ed26c2

Please sign in to comment.