Skip to content

Commit 006830d

Browse files
committed
use env directly in constructor
1 parent a47d778 commit 006830d

File tree

1 file changed

+15
-12
lines changed
  • templates/components/vectordbs/python/llamacloud

1 file changed

+15
-12
lines changed

templates/components/vectordbs/python/llamacloud/index.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ class LlamaCloudConfig(BaseModel):
3131
description="The name of the LlamaCloud project",
3232
)
3333

34+
def __init__(self, **kwargs):
35+
if "api_key" not in kwargs:
36+
kwargs["api_key"] = os.getenv("LLAMA_CLOUD_API_KEY")
37+
if "base_url" not in kwargs:
38+
kwargs["base_url"] = os.getenv("LLAMA_CLOUD_BASE_URL")
39+
if "organization_id" not in kwargs:
40+
kwargs["organization_id"] = os.getenv("LLAMA_CLOUD_ORGANIZATION_ID")
41+
if "pipeline" not in kwargs:
42+
kwargs["pipeline"] = os.getenv("LLAMA_CLOUD_INDEX_NAME")
43+
if "project" not in kwargs:
44+
kwargs["project"] = os.getenv("LLAMA_CLOUD_PROJECT_NAME")
45+
super().__init__(**kwargs)
46+
3447
# Validate and throw error if the env variables are not set before starting the app
3548
@field_validator("pipeline", "project", "api_key", mode="before")
3649
@classmethod
@@ -48,20 +61,10 @@ def to_client_kwargs(self) -> dict:
4861
"base_url": self.base_url,
4962
}
5063

51-
@classmethod
52-
def from_env(cls):
53-
return LlamaCloudConfig(
54-
api_key=os.getenv("LLAMA_CLOUD_API_KEY"),
55-
base_url=os.getenv("LLAMA_CLOUD_BASE_URL"),
56-
organization_id=os.getenv("LLAMA_CLOUD_ORGANIZATION_ID"),
57-
pipeline=os.getenv("LLAMA_CLOUD_INDEX_NAME"),
58-
project=os.getenv("LLAMA_CLOUD_PROJECT_NAME"),
59-
)
60-
6164

6265
class IndexConfig(BaseModel):
6366
llama_cloud_pipeline_config: LlamaCloudConfig = Field(
64-
default_factory=LlamaCloudConfig.from_env,
67+
default_factory=lambda: LlamaCloudConfig(),
6568
alias="llamaCloudPipeline",
6669
)
6770
callback_manager: Optional[CallbackManager] = Field(
@@ -88,5 +91,5 @@ def get_index(config: IndexConfig = None):
8891

8992

9093
def get_client():
91-
config = LlamaCloudConfig.from_env()
94+
config = LlamaCloudConfig()
9295
return llama_cloud_get_client(**config.to_client_kwargs())

0 commit comments

Comments
 (0)