|
9 | 9 | import random |
10 | 10 | import time |
11 | 11 | from datetime import datetime, timedelta |
12 | | -from typing import Any, Dict, List, Optional, Protocol |
| 12 | +from typing import Any, Callable, Dict, List, Optional, Protocol, cast |
13 | 13 |
|
14 | 14 | from eval_protocol.models import EvaluationRow, InputMetadata, Message |
15 | 15 | from .base import BaseAdapter |
@@ -44,14 +44,19 @@ def __call__( |
44 | 44 | ... |
45 | 45 |
|
46 | 46 |
|
| 47 | +LangfuseClient = Any |
| 48 | + |
| 49 | +_get_langfuse_client: Callable[[], Any] | None |
| 50 | + |
47 | 51 | try: |
48 | | - from langfuse import get_client # pyright: ignore[reportPrivateImportUsage] |
| 52 | + from langfuse import get_client as _get_langfuse_client # type: ignore[attr-defined, reportPrivateImportUsage] |
49 | 53 | from langfuse.api.resources.trace.types.traces import Traces |
50 | 54 | from langfuse.api.resources.commons.types.trace import Trace |
51 | 55 | from langfuse.api.resources.commons.types.trace_with_full_details import TraceWithFullDetails |
52 | 56 |
|
53 | 57 | LANGFUSE_AVAILABLE = True |
54 | | -except ImportError: |
| 58 | +except ImportError: # pragma: no cover - optional dependency |
| 59 | + _get_langfuse_client = None |
55 | 60 | LANGFUSE_AVAILABLE = False |
56 | 61 |
|
57 | 62 |
|
@@ -219,7 +224,11 @@ def __init__(self): |
219 | 224 | if not LANGFUSE_AVAILABLE: |
220 | 225 | raise ImportError("Langfuse not installed. Install with: pip install 'eval-protocol[langfuse]'") |
221 | 226 |
|
222 | | - self.client = get_client() |
| 227 | + if _get_langfuse_client is None: |
| 228 | + raise ImportError("Langfuse not installed. Install with: pip install 'eval-protocol[langfuse]'") |
| 229 | + |
| 230 | + client_factory = cast(Callable[[], LangfuseClient], _get_langfuse_client) |
| 231 | + self.client: LangfuseClient = client_factory() |
223 | 232 |
|
224 | 233 | def get_evaluation_rows( |
225 | 234 | self, |
|
0 commit comments