Skip to content

Commit

Permalink
fix: Correctly update reactive form on hosted instances (#6023)
Browse files Browse the repository at this point in the history
* fix: Update reactive form on hosted dslf

* [autofix.ci] apply automated fixes

* Update astradb.py

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
erichare and autofix-ci[bot] authored Jan 30, 2025
1 parent c007a5f commit 311b5b3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
45 changes: 24 additions & 21 deletions src/backend/base/langflow/components/vectorstores/astradb.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ def update_build_config(self, build_config: dict, field_value: str, field_name:

# Reload the list of collections and metadata associated
collection_options = self._initialize_collection_options(
api_endpoint=build_config["d_api_endpoint"]["value"]
api_endpoint=build_config["d_api_endpoint"]["value"] if not dslf else None
)

# If we have collections, show the dropdown
Expand All @@ -549,31 +549,34 @@ def update_build_config(self, build_config: dict, field_value: str, field_name:
# Hide embedding model option if opriona_metadata provider is not null
if field_name == "collection_name" and field_value:
# Set the options for collection name to be the field value if its a new collection
if not dslf and field_value not in build_config["collection_name"]["options"]:
# Add the new collection to the list of options
build_config["collection_name"]["options"].append(field_value)
build_config["collection_name"]["options_metadata"].append(
{"records": 0, "provider": None, "icon": "", "model": None}
)

# Ensure that autodetect collection is set to False
build_config["autodetect_collection"]["value"] = False
if field_value not in build_config["collection_name"]["options"]:
# If this is running in DSLF, we may need to initialize the options again
if dslf:
# Reload the list of collections and metadata associated
collection_options = self._initialize_collection_options(
api_endpoint=build_config["d_api_endpoint"]["value"] if not dslf else None
)

# If we have collections, show the dropdown
build_config["collection_name"]["options"] = [col["name"] for col in collection_options]
build_config["collection_name"]["options_metadata"] = [
{k: v for k, v in col.items() if k not in ["name"]} for col in collection_options
]
else:
# Add the new collection to the list of options
build_config["collection_name"]["options"].append(field_value)
build_config["collection_name"]["options_metadata"].append(
{"records": 0, "provider": None, "icon": "", "model": None}
)

# Ensure that autodetect collection is set to False, since its a new collection
build_config["autodetect_collection"]["value"] = False
else:
build_config["autodetect_collection"]["value"] = True

# Find location of the name in the options list
# Find the position of the selected collection to align with metadata
index_of_name = build_config["collection_name"]["options"].index(field_value)

# Return if not found
if index_of_name == -1:
return build_config

# Check if the number of records is 0
if build_config["collection_name"]["options_metadata"][index_of_name]["records"] == 0:
build_config["autodetect_collection"]["value"] = False
else:
build_config["autodetect_collection"]["value"] = True

# Get the provider value of the selected collection
value_of_provider = build_config["collection_name"]["options_metadata"][index_of_name]["provider"]

Expand Down
Loading

0 comments on commit 311b5b3

Please sign in to comment.