@@ -31,6 +31,19 @@ class LlamaCloudConfig(BaseModel):
31
31
description = "The name of the LlamaCloud project" ,
32
32
)
33
33
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
+
34
47
# Validate and throw error if the env variables are not set before starting the app
35
48
@field_validator ("pipeline" , "project" , "api_key" , mode = "before" )
36
49
@classmethod
@@ -48,20 +61,10 @@ def to_client_kwargs(self) -> dict:
48
61
"base_url" : self .base_url ,
49
62
}
50
63
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
-
61
64
62
65
class IndexConfig (BaseModel ):
63
66
llama_cloud_pipeline_config : LlamaCloudConfig = Field (
64
- default_factory = LlamaCloudConfig . from_env ,
67
+ default_factory = lambda : LlamaCloudConfig () ,
65
68
alias = "llamaCloudPipeline" ,
66
69
)
67
70
callback_manager : Optional [CallbackManager ] = Field (
@@ -88,5 +91,5 @@ def get_index(config: IndexConfig = None):
88
91
89
92
90
93
def get_client ():
91
- config = LlamaCloudConfig . from_env ()
94
+ config = LlamaCloudConfig ()
92
95
return llama_cloud_get_client (** config .to_client_kwargs ())
0 commit comments