Skip to content

Commit 535db1c

Browse files
authored
Merge pull request #5 from trustyai-explainability/get-token
feat: Add Kubernetes dependency and refactor token retrieval in RagasEvaluatorRemote.
2 parents a44623e + 865d846 commit 535db1c

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dependencies = [
1313
]
1414

1515
[project.optional-dependencies]
16-
remote = ["kfp>=2.5.0", "kfp-kubernetes>=2.0.0", "s3fs>=2024.12.0"]
16+
remote = ["kfp>=2.5.0", "kfp-kubernetes>=2.0.0", "s3fs>=2024.12.0", "kubernetes>=30.0.0"]
1717
distro = ["opentelemetry-api", "opentelemetry-exporter-otlp", "aiosqlite", "ollama", "uvicorn"]
1818
dev = [
1919
"llama-stack-provider-ragas[distro]",

src/llama_stack_provider_ragas/eval_remote.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# TODO: decide how to treat these imports & possibly an extras_require
21
import logging
3-
import subprocess
42
import uuid
53
from typing import Any
64

@@ -38,14 +36,7 @@ def __init__(
3836
try:
3937
import kfp
4038

41-
result = subprocess.run(
42-
["oc", "whoami", "-t"],
43-
capture_output=True,
44-
text=True,
45-
check=True,
46-
timeout=5,
47-
)
48-
token = result.stdout.strip()
39+
token = self._get_token()
4940
if not token:
5041
raise RagasEvaluationError(
5142
"No token found. Please run `oc login` and try again."
@@ -70,10 +61,6 @@ def __init__(
7061
raise RagasEvaluationError(
7162
"Kubeflow Pipelines SDK not available. Install with: pip install .[remote]"
7263
) from e
73-
except subprocess.CalledProcessError as e:
74-
raise RagasEvaluationError(
75-
f"Failed to get OpenShift token. Command failed with exit code {e.returncode}: {e.stderr.strip()}"
76-
) from e
7764
except requests.exceptions.RequestException as e:
7865
raise RagasEvaluationError(
7966
f"Failed to connect to Kubeflow Pipelines server at {self.config.kubeflow_config.pipelines_endpoint}, "
@@ -84,6 +71,25 @@ def __init__(
8471
"Failed to initialize Kubeflow Pipelines client."
8572
) from e
8673

74+
def _get_token(self) -> str:
75+
try:
76+
from kubernetes.client.configuration import Configuration
77+
from kubernetes.config.kube_config import load_kube_config
78+
79+
config = Configuration()
80+
load_kube_config(client_configuration=config)
81+
token = str(config.api_key["authorization"].split(" ")[-1])
82+
except ImportError as e:
83+
raise RagasEvaluationError(
84+
"Kubernetes client is not installed. Install with: pip install .[remote]"
85+
) from e
86+
except Exception as e:
87+
raise RagasEvaluationError(
88+
"Failed to get OpenShift token. Please run `oc login` and try again."
89+
) from e
90+
91+
return token
92+
8793
async def run_eval(
8894
self,
8995
benchmark_id: str,

uv.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)