Skip to content

Commit 80a3a67

Browse files
authored
Merge pull request #26 from dmaniloff/defer-kfp-init
refactor: lazy-initialize KFP client in RagasEvaluatorRemote.
2 parents c0789e0 + 13f4a71 commit 80a3a67

File tree

1 file changed

+41
-33
lines changed

1 file changed

+41
-33
lines changed

src/llama_stack_provider_ragas/remote/ragas_remote_eval.py

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -62,43 +62,51 @@ def __init__(
6262
self.config = config
6363
self.evaluation_jobs: dict[str, RagasEvaluationJob] = {}
6464
self.benchmarks: dict[str, Benchmark] = {}
65-
try:
66-
import kfp
65+
self._kfp_client = None
6766

68-
token = self._get_token()
69-
if not token:
70-
raise RagasEvaluationError(
71-
"No token found. Please run `oc login` and try again."
67+
@property
68+
def kfp_client(self):
69+
"""Lazy-initialized KFP client. Deferred to eval runtime."""
70+
if self._kfp_client is None:
71+
try:
72+
import kfp
73+
74+
token = self._get_token()
75+
if not token:
76+
raise RagasEvaluationError(
77+
"No token found. Please run `oc login` and try again."
78+
)
79+
80+
# the kfp.Client handles the healthz endpoint poorly, run a pre-flight check manually
81+
response = requests.get(
82+
f"{self.config.kubeflow_config.pipelines_endpoint}/apis/v2beta1/healthz",
83+
headers={
84+
"Accept": "application/json",
85+
"Authorization": f"Bearer {token}",
86+
},
87+
timeout=5,
7288
)
89+
response.raise_for_status()
7390

74-
# the kfp.Client handles the healthz endpoint poorly, run a pre-flight check manually
75-
response = requests.get(
76-
f"{self.config.kubeflow_config.pipelines_endpoint}/apis/v2beta1/healthz",
77-
headers={
78-
"Accept": "application/json",
79-
"Authorization": f"Bearer {token}",
80-
},
81-
timeout=5,
82-
)
83-
response.raise_for_status()
91+
self._kfp_client = kfp.Client(
92+
host=self.config.kubeflow_config.pipelines_endpoint,
93+
existing_token=token,
94+
)
95+
except ImportError as e:
96+
raise RagasEvaluationError(
97+
"Kubeflow Pipelines SDK not available. Install with: pip install .[remote]"
98+
) from e
99+
except requests.exceptions.RequestException as e:
100+
raise RagasEvaluationError(
101+
f"Failed to connect to Kubeflow Pipelines server at {self.config.kubeflow_config.pipelines_endpoint}, "
102+
"do you need a new token?"
103+
) from e
104+
except Exception as e:
105+
raise RagasEvaluationError(
106+
"Failed to initialize Kubeflow Pipelines client."
107+
) from e
84108

85-
self.kfp_client = kfp.Client(
86-
host=self.config.kubeflow_config.pipelines_endpoint,
87-
existing_token=token,
88-
)
89-
except ImportError as e:
90-
raise RagasEvaluationError(
91-
"Kubeflow Pipelines SDK not available. Install with: pip install .[remote]"
92-
) from e
93-
except requests.exceptions.RequestException as e:
94-
raise RagasEvaluationError(
95-
f"Failed to connect to Kubeflow Pipelines server at {self.config.kubeflow_config.pipelines_endpoint}, "
96-
"do you need a new token?"
97-
) from e
98-
except Exception as e:
99-
raise RagasEvaluationError(
100-
"Failed to initialize Kubeflow Pipelines client."
101-
) from e
109+
return self._kfp_client
102110

103111
def _get_token(self) -> str:
104112
try:

0 commit comments

Comments
 (0)