🔨 refactor(vector_store.py): refactor initialize_supabase function to improve readability and remove redundant code
The function now checks if "texts" is in the params dictionary and renames it to "documents" for consistency. The "supabase_url" and "supabase_service_key" are now removed from the params dictionary and passed directly to the create_client function. The function also removes the "documents" and "texts" keys from the params dictionary if there are no documents in the params. This improves the readability of the code and removes redundant code.
This commit is contained in:
parent
c8a5edb9ab
commit
7da5197f35
1 changed files with 6 additions and 4 deletions
|
|
@ -24,18 +24,20 @@ def initialize_supabase(class_object: Type[SupabaseVectorStore], params: dict):
|
|||
|
||||
if "supabase_url" not in params or "supabase_service_key" not in params:
|
||||
raise ValueError("Supabase url and service key must be provided in the params")
|
||||
if "texts" in params:
|
||||
params["documents"] = params.pop("texts")
|
||||
|
||||
client_kwargs = {
|
||||
"supabase_url": params["supabase_url"],
|
||||
"supabase_key": params["supabase_service_key"],
|
||||
"supabase_url": params.pop("supabase_url"),
|
||||
"supabase_key": params.pop("supabase_service_key"),
|
||||
}
|
||||
|
||||
supabase: Client = create_client(**client_kwargs)
|
||||
if not docs_in_params(params):
|
||||
params.pop("documents", None)
|
||||
params.pop("texts", None)
|
||||
return class_object(client=supabase, **params)
|
||||
# If there are docs in the params, create a new index
|
||||
if "texts" in params:
|
||||
params["documents"] = params.pop("texts")
|
||||
|
||||
return class_object.from_documents(client=supabase, **params)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue