fiddler-evals 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. fiddler_evals/VERSION +1 -0
  2. fiddler_evals/__init__.py +71 -0
  3. fiddler_evals/configs.py +14 -0
  4. fiddler_evals/conftest.py +28 -0
  5. fiddler_evals/connection.py +451 -0
  6. fiddler_evals/constants.py +9 -0
  7. fiddler_evals/decorators.py +189 -0
  8. fiddler_evals/entities/__init__.py +0 -0
  9. fiddler_evals/entities/application.py +398 -0
  10. fiddler_evals/entities/base.py +58 -0
  11. fiddler_evals/entities/dataset.py +1230 -0
  12. fiddler_evals/entities/experiment.py +934 -0
  13. fiddler_evals/entities/project.py +362 -0
  14. fiddler_evals/entities/tests/__init__.py +0 -0
  15. fiddler_evals/entities/tests/test_application.py +340 -0
  16. fiddler_evals/entities/tests/test_dataset.py +602 -0
  17. fiddler_evals/entities/tests/test_dataset_items.py +492 -0
  18. fiddler_evals/entities/tests/test_experiment.py +719 -0
  19. fiddler_evals/entities/tests/test_experiment_items.py +495 -0
  20. fiddler_evals/entities/tests/test_experiment_results.py +330 -0
  21. fiddler_evals/entities/tests/test_project.py +270 -0
  22. fiddler_evals/evaluators/__init__.py +24 -0
  23. fiddler_evals/evaluators/answer_relevance.py +92 -0
  24. fiddler_evals/evaluators/base.py +141 -0
  25. fiddler_evals/evaluators/coherence.py +111 -0
  26. fiddler_evals/evaluators/conciseness.py +84 -0
  27. fiddler_evals/evaluators/eval_fn.py +214 -0
  28. fiddler_evals/evaluators/ftl_prompt_safety.py +113 -0
  29. fiddler_evals/evaluators/ftl_response_faithfulness.py +115 -0
  30. fiddler_evals/evaluators/regex.py +99 -0
  31. fiddler_evals/evaluators/sentiment.py +112 -0
  32. fiddler_evals/evaluators/tests/__init__.py +0 -0
  33. fiddler_evals/evaluators/tests/test_answer_relevance.py +237 -0
  34. fiddler_evals/evaluators/tests/test_coherence.py +369 -0
  35. fiddler_evals/evaluators/tests/test_conciseness.py +225 -0
  36. fiddler_evals/evaluators/tests/test_eval_fn.py +359 -0
  37. fiddler_evals/evaluators/tests/test_ftl_prompt_safety.py +222 -0
  38. fiddler_evals/evaluators/tests/test_ftl_response_faithfulness.py +205 -0
  39. fiddler_evals/evaluators/tests/test_regex.py +116 -0
  40. fiddler_evals/evaluators/tests/test_sentiment.py +224 -0
  41. fiddler_evals/evaluators/tests/test_topic_classification.py +249 -0
  42. fiddler_evals/evaluators/tests/test_toxicity.py +201 -0
  43. fiddler_evals/evaluators/topic.py +127 -0
  44. fiddler_evals/evaluators/toxicity.py +101 -0
  45. fiddler_evals/exceptions.py +221 -0
  46. fiddler_evals/libs/__init__.py +0 -0
  47. fiddler_evals/libs/http_client.py +483 -0
  48. fiddler_evals/libs/json_encoder.py +25 -0
  49. fiddler_evals/libs/semver.py +614 -0
  50. fiddler_evals/libs/tests/__init__.py +0 -0
  51. fiddler_evals/libs/tests/test_json_encoder.py +27 -0
  52. fiddler_evals/libs/tests/test_request_client.py +715 -0
  53. fiddler_evals/pydantic_models/__init__.py +4 -0
  54. fiddler_evals/pydantic_models/application.py +24 -0
  55. fiddler_evals/pydantic_models/base.py +9 -0
  56. fiddler_evals/pydantic_models/compact.py +41 -0
  57. fiddler_evals/pydantic_models/dataset.py +58 -0
  58. fiddler_evals/pydantic_models/error.py +22 -0
  59. fiddler_evals/pydantic_models/evaluator.py +18 -0
  60. fiddler_evals/pydantic_models/experiment.py +89 -0
  61. fiddler_evals/pydantic_models/filter_query.py +54 -0
  62. fiddler_evals/pydantic_models/project.py +17 -0
  63. fiddler_evals/pydantic_models/response.py +51 -0
  64. fiddler_evals/pydantic_models/score.py +26 -0
  65. fiddler_evals/pydantic_models/server_info.py +20 -0
  66. fiddler_evals/runner/__init__.py +0 -0
  67. fiddler_evals/runner/evaluation.py +178 -0
  68. fiddler_evals/runner/executor.py +102 -0
  69. fiddler_evals/runner/experiment_result_publisher.py +97 -0
  70. fiddler_evals/runner/experiment_runner.py +640 -0
  71. fiddler_evals/runner/tests/__init__.py +0 -0
  72. fiddler_evals/runner/tests/test_evaluate.py +692 -0
  73. fiddler_evals/runner/tests/test_experiment_result_publisher.py +264 -0
  74. fiddler_evals/tests/__init__.py +0 -0
  75. fiddler_evals/tests/constants.py +40 -0
  76. fiddler_evals/tests/test_connection.py +224 -0
  77. fiddler_evals/tests/test_decorators.py +346 -0
  78. fiddler_evals/utils/__init__.py +0 -0
  79. fiddler_evals/utils/environment.py +46 -0
  80. fiddler_evals/utils/pd.py +9 -0
  81. fiddler_evals/utils/tests/__init__.py +0 -0
  82. fiddler_evals/utils/tests/test_environment.py +146 -0
  83. fiddler_evals/utils/tqdm.py +23 -0
  84. fiddler_evals/version.py +4 -0
  85. fiddler_evals-0.1.0.dist-info/METADATA +341 -0
  86. fiddler_evals-0.1.0.dist-info/RECORD +88 -0
  87. fiddler_evals-0.1.0.dist-info/WHEEL +5 -0
  88. fiddler_evals-0.1.0.dist-info/top_level.txt +1 -0
fiddler_evals/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0.dev1
@@ -0,0 +1,71 @@
1
+ from contextvars import ContextVar
2
+ from typing import TYPE_CHECKING
3
+
4
+ from fiddler_evals.connection import init
5
+ from fiddler_evals.entities.application import Application
6
+ from fiddler_evals.entities.dataset import Dataset
7
+ from fiddler_evals.entities.experiment import (
8
+ Experiment,
9
+ ExperimentItemStatus,
10
+ ExperimentStatus,
11
+ )
12
+ from fiddler_evals.entities.project import Project
13
+ from fiddler_evals.evaluators import (
14
+ AnswerRelevance,
15
+ Coherence,
16
+ Conciseness,
17
+ FTLPromptSafety,
18
+ FTLResponseFaithfulness,
19
+ RegexMatch,
20
+ RegexSearch,
21
+ Sentiment,
22
+ TopicClassification,
23
+ Toxicity,
24
+ )
25
+ from fiddler_evals.evaluators.base import Evaluator
26
+ from fiddler_evals.evaluators.eval_fn import EvalFn
27
+ from fiddler_evals.pydantic_models.dataset import DatasetItem, NewDatasetItem
28
+ from fiddler_evals.pydantic_models.score import Score, ScoreStatus
29
+ from fiddler_evals.runner.evaluation import evaluate
30
+ from fiddler_evals.version import __version__
31
+
32
+ if TYPE_CHECKING:
33
+ from fiddler_evals.connection import Connection
34
+
35
+ # ContextVar to store the connection object and reuse it while making API calls.
36
+ connection_context: ContextVar["Connection | None"] = ContextVar(
37
+ "connection", default=None
38
+ )
39
+
40
+ __all__ = [
41
+ "__version__",
42
+ "init",
43
+ # Entities
44
+ "Application",
45
+ "Project",
46
+ "Dataset",
47
+ "Experiment",
48
+ # Core data models
49
+ "NewDatasetItem",
50
+ "DatasetItem",
51
+ "Score",
52
+ # Evaluator system
53
+ "Evaluator",
54
+ "EvalFn",
55
+ "AnswerRelevance",
56
+ "Coherence",
57
+ "Conciseness",
58
+ "Toxicity",
59
+ "Sentiment",
60
+ "RegexSearch",
61
+ "RegexMatch",
62
+ "FTLPromptSafety",
63
+ "FTLResponseFaithfulness",
64
+ "TopicClassification",
65
+ # Top level methods
66
+ "evaluate",
67
+ # Status enums
68
+ "ExperimentStatus",
69
+ "ExperimentItemStatus",
70
+ "ScoreStatus",
71
+ ]
@@ -0,0 +1,14 @@
1
+ from decouple import config
2
+
3
+ REQUEST_CONN_TIMEOUT_SECONDS = config(
4
+ "FIDDLER_REQUEST_CONNECTION_TIMEOUT_SECONDS", cast=int, default=5
5
+ )
6
+ REQUEST_READ_TIMEOUT_SECONDS = config(
7
+ "FIDDLER_REQUEST_READ_TIMEOUT_SECONDS", cast=int, default=10
8
+ )
9
+
10
+ # requests lib format (conn. timeout, read timeout)
11
+ REQUEST_TIMEOUT_SECONDS = (REQUEST_CONN_TIMEOUT_SECONDS, REQUEST_READ_TIMEOUT_SECONDS)
12
+
13
+
14
+ REQUEST_PAGE_SIZE = config("FIDDLER_REQUEST_PAGE_SIZE", cast=int, default=50)
@@ -0,0 +1,28 @@
1
+ import pytest
2
+
3
+ from fiddler_evals.connection import Connection, set_connection
4
+ from fiddler_evals.pydantic_models.server_info import ServerInfo
5
+ from fiddler_evals.tests.constants import ORG_ID, ORG_NAME, SERVER_VERSION, TOKEN, URL
6
+
7
+
8
+ @pytest.fixture(autouse=True, scope="session")
9
+ def set_sdk_connection() -> Connection:
10
+ """Global connection instance for all tests."""
11
+ connection = Connection(
12
+ url=URL,
13
+ token=TOKEN,
14
+ validate=False,
15
+ )
16
+
17
+ connection.server_info = ServerInfo(
18
+ **{
19
+ "feature_flags": {},
20
+ "server_version": SERVER_VERSION,
21
+ "organization": {
22
+ "id": ORG_ID,
23
+ "name": ORG_NAME,
24
+ },
25
+ }
26
+ )
27
+ set_connection(connection)
28
+ yield connection
@@ -0,0 +1,451 @@
1
+ from __future__ import annotations
2
+
3
+ import logging
4
+ from functools import cached_property
5
+ from uuid import UUID
6
+
7
+ from fiddler_evals.constants import (
8
+ CLIENT_NAME,
9
+ FIDDLER_CLIENT_NAME_HEADER,
10
+ FIDDLER_CLIENT_VERSION_HEADER,
11
+ )
12
+ from fiddler_evals.decorators import handle_api_error
13
+ from fiddler_evals.libs.http_client import RequestClient
14
+ from fiddler_evals.libs.semver import VersionInfo
15
+ from fiddler_evals.pydantic_models.server_info import ServerInfo
16
+ from fiddler_evals.version import __version__
17
+
18
+ logger = logging.getLogger(__name__)
19
+
20
+
21
+ class Connection:
22
+ """Manages authenticated connections to the Fiddler platform.
23
+
24
+ The Connection class handles all aspects of connecting to and communicating
25
+ with the Fiddler platform, including authentication, HTTP client management,
26
+ server version compatibility checking, and organization context management.
27
+
28
+ This class provides the foundation for all API interactions with Fiddler,
29
+ managing connection parameters, authentication tokens, and ensuring proper
30
+ communication protocols are established.
31
+
32
+ Attributes
33
+ ----------
34
+ url : str
35
+ Base URL of the Fiddler platform instance
36
+ token : str
37
+ Authentication token for API access
38
+ proxies : dict, optional
39
+ Optional proxy configuration for HTTP requests
40
+ timeout : float or tuple, optional
41
+ HTTP request timeout settings
42
+ verify : bool
43
+ Whether to verify SSL/TLS certificates
44
+ request_headers : dict
45
+ HTTP headers including authentication and client info
46
+ client : RequestClient
47
+ Cached HTTP client instance for making requests
48
+ server_info : ServerInfo
49
+ Cached server information and metadata
50
+ server_version : VersionInfo
51
+ Version of the connected Fiddler server
52
+ organization_name : str
53
+ Name of the connected organization
54
+ organization_id : UUID
55
+ UUID of the connected organization
56
+
57
+ Examples
58
+ --------
59
+ Creating a basic connection:
60
+
61
+ .. code-block:: python
62
+
63
+ connection = Connection(
64
+ url="https://your-fiddler-instance.com",
65
+ token="your-auth-token"
66
+ )
67
+
68
+ Creating a connection with custom timeout and proxy:
69
+
70
+ .. code-block:: python
71
+
72
+ connection = Connection(
73
+ url="https://your-fiddler-instance.com",
74
+ token="your-auth-token",
75
+ timeout=(5.0, 30.0), # (connect_timeout, read_timeout)
76
+ proxies={"https": "https://proxy.company.com:8080"}
77
+ )
78
+
79
+ Creating a connection without SSL verification:
80
+
81
+ .. code-block:: python
82
+
83
+ connection = Connection(
84
+ url="https://your-fiddler-instance.com",
85
+ token="your-auth-token",
86
+ verify=False, # Not recommended for production
87
+ validate=False # Skip version compatibility check
88
+ )
89
+ """
90
+
91
+ def __init__( # pylint: disable=too-many-arguments
92
+ self,
93
+ url: str,
94
+ token: str,
95
+ proxies: dict | None = None,
96
+ timeout: float | tuple[float, float] | None = None,
97
+ verify: bool = True,
98
+ validate: bool = True,
99
+ ) -> None:
100
+ """Initialize a connection to the Fiddler platform.
101
+
102
+ Parameters
103
+ ----------
104
+ url : str
105
+ The base URL to your Fiddler platform instance
106
+ token : str
107
+ Authentication token obtained from the Fiddler UI
108
+ proxies : dict, optional
109
+ Dictionary mapping protocol to proxy URL for HTTP requests
110
+ timeout : float or tuple, optional
111
+ HTTP request timeout settings (float or tuple of connect/read timeouts)
112
+ verify : bool, default True
113
+ Whether to verify server's TLS certificate
114
+ validate : bool, default True
115
+ Whether to validate server/client version compatibility
116
+
117
+ Raises
118
+ ------
119
+ ValueError
120
+ If url or token parameters are empty
121
+ IncompatibleClient
122
+ If server version is incompatible with client version
123
+ """
124
+
125
+ self.url = url
126
+ self.token = token
127
+ self.proxies = proxies
128
+ self.timeout = timeout
129
+ self.verify = verify
130
+
131
+ if not url:
132
+ raise ValueError("`url` is empty")
133
+
134
+ if not token:
135
+ raise ValueError("`token` is empty")
136
+
137
+ self.request_headers = {
138
+ "Authorization": f"Bearer {token}",
139
+ FIDDLER_CLIENT_NAME_HEADER: CLIENT_NAME,
140
+ FIDDLER_CLIENT_VERSION_HEADER: __version__,
141
+ }
142
+
143
+ if validate:
144
+ self._check_server_version()
145
+ self._check_version_compatibility()
146
+
147
+ @cached_property
148
+ def client(self) -> RequestClient:
149
+ """Get the HTTP request client instance for API communication.
150
+
151
+ Returns:
152
+ RequestClient: Configured HTTP client with authentication headers,
153
+ proxy settings, and timeout configurations.
154
+ """
155
+ return RequestClient(
156
+ base_url=self.url,
157
+ headers=self.request_headers,
158
+ proxies=self.proxies,
159
+ verify=self.verify,
160
+ timeout=self.timeout,
161
+ )
162
+
163
+ @cached_property
164
+ def server_info(self) -> ServerInfo:
165
+ """Get server information and metadata from the Fiddler platform.
166
+
167
+ Returns:
168
+ ServerInfo: Server information including version, organization details,
169
+ and platform configuration.
170
+ """
171
+ return self._get_server_info()
172
+
173
+ @cached_property
174
+ def server_version(self) -> VersionInfo:
175
+ """Get the semantic version of the connected Fiddler server.
176
+
177
+ Returns:
178
+ VersionInfo: Semantic version object representing the server version.
179
+ """
180
+ return self.server_info.server_version
181
+
182
+ @cached_property
183
+ def organization_name(self) -> str:
184
+ """Get the name of the connected organization.
185
+
186
+ Returns:
187
+ str: Name of the organization associated with this connection.
188
+ """
189
+ return self.server_info.organization.name
190
+
191
+ @cached_property
192
+ def organization_id(self) -> UUID:
193
+ """Get the UUID of the connected organization.
194
+
195
+ Returns:
196
+ UUID: Unique identifier of the organization associated with this connection.
197
+ """
198
+ return self.server_info.organization.id
199
+
200
+ @handle_api_error
201
+ def _get_server_info(self) -> ServerInfo:
202
+ """Retrieve server information from the Fiddler platform.
203
+
204
+ Returns:
205
+ ServerInfo: Server information including version and organization details.
206
+
207
+ Raises:
208
+ ApiError: If the server info request fails.
209
+ """
210
+
211
+ response = self.client.get(url="/v3/server-info")
212
+
213
+ return ServerInfo(**response.json().get("data"))
214
+
215
+ @handle_api_error
216
+ def _check_version_compatibility(self) -> None:
217
+ """Check whether the SDK version is compatible with the Fiddler platform version.
218
+
219
+ Raises:
220
+ ApiError: If the version compatibility check fails.
221
+ IncompatibleClient: If the client version is not compatible with the server.
222
+ """
223
+ # @TODO https://github.com/fiddler-labs/fiddler/issues/14650
224
+
225
+ def _check_server_version(self) -> None:
226
+ """Check whether the Fiddler platform version is compatible with the client version.
227
+
228
+ Raises:
229
+ IncompatibleClient: If the server version is below the minimum required version.
230
+ """
231
+ # @TODO https://github.com/fiddler-labs/fiddler/issues/14650
232
+
233
+
234
+ class ConnectionMixin:
235
+ """Mixin class providing connection-related functionality to other classes.
236
+
237
+ ConnectionMixin provides a standardized way for other classes to access
238
+ the global Fiddler connection instance and its associated properties.
239
+ This mixin enables classes throughout the Fiddler client to access
240
+ connection details, HTTP client functionality, and organization context
241
+ without directly managing connection state.
242
+
243
+ This pattern ensures consistent access to connection resources across
244
+ all client components while maintaining a clean separation of concerns.
245
+
246
+ Methods:
247
+ _connection: Access to the global Connection instance
248
+ _client: Access to the HTTP client for API requests
249
+ organization_name: Property access to organization name
250
+ organization_id: Property access to organization UUID
251
+ get_organization_name: Class method to retrieve organization name
252
+ get_organization_id: Class method to retrieve organization UUID
253
+
254
+ Examples:
255
+ Using ConnectionMixin in a custom class:
256
+
257
+ class CustomModel(ConnectionMixin):
258
+ def fetch_data(self):
259
+ # Access HTTP client through mixin
260
+ response = self._client().get('/api/data')
261
+ return response.json()
262
+
263
+ def get_org_info(self):
264
+ # Access organization info through mixin
265
+ return {
266
+ 'name': self.organization_name,
267
+ 'id': str(self.organization_id)
268
+ }
269
+
270
+ Using class methods without instantiation:
271
+
272
+ org_name = SomeEntityClass.get_organization_name()
273
+ org_id = SomeEntityClass.get_organization_id()
274
+ """
275
+
276
+ @classmethod
277
+ def _connection(cls) -> Connection:
278
+ """Get the global Fiddler connection instance.
279
+
280
+ Returns:
281
+ Connection: The singleton Connection instance used throughout the client.
282
+
283
+ Raises:
284
+ RuntimeError: If no connection has been initialized via fiddler_evals.init().
285
+ """
286
+
287
+ return get_connection()
288
+
289
+ @classmethod
290
+ def _client(cls) -> RequestClient:
291
+ """Get the HTTP request client from the global connection.
292
+
293
+ Returns:
294
+ RequestClient: HTTP client instance for making API requests.
295
+ """
296
+ return cls._connection().client
297
+
298
+ @property
299
+ def organization_name(self) -> str:
300
+ """Get the organization name from the connection.
301
+
302
+ Returns:
303
+ str: Name of the organization associated with the current connection.
304
+ """
305
+ return self._connection().server_info.organization.name
306
+
307
+ @property
308
+ def organization_id(self) -> UUID:
309
+ """Get the organization UUID from the connection.
310
+
311
+ Returns:
312
+ UUID: Unique identifier of the organization associated with the current connection.
313
+ """
314
+ return self._connection().server_info.organization.id
315
+
316
+ @classmethod
317
+ def get_organization_name(cls) -> str:
318
+ """Get the organization name from the global connection.
319
+
320
+ Returns:
321
+ str: Name of the organization associated with the current connection.
322
+ """
323
+ return cls._connection().server_info.organization.name
324
+
325
+ @classmethod
326
+ def get_organization_id(cls) -> UUID:
327
+ """Get the organization UUID from the global connection.
328
+
329
+ Returns:
330
+ UUID: Unique identifier of the organization associated with the current connection.
331
+ """
332
+ return cls._connection().server_info.organization.id
333
+
334
+
335
+ def init( # pylint: disable=too-many-arguments
336
+ url: str,
337
+ token: str,
338
+ proxies: dict | None = None,
339
+ timeout: float | tuple[float, float] | None = None,
340
+ verify: bool = True,
341
+ validate: bool = True,
342
+ ) -> None:
343
+ """Initialize the Fiddler client with connection parameters and global configuration.
344
+
345
+ This function establishes a connection to the Fiddler platform and configures
346
+ the global client state. It handles authentication, server compatibility
347
+ validation, logging setup, and creates the singleton connection instance
348
+ used throughout the client library.
349
+
350
+ Args:
351
+ url: The base URL to your Fiddler platform instance
352
+ token: Authentication token obtained from the Fiddler UI Credentials tab
353
+ proxies: Dictionary mapping protocol to proxy URL for HTTP requests
354
+ timeout: HTTP request timeout settings (float or tuple of connect/read timeouts)
355
+ verify: Whether to verify server's TLS certificate (default: True)
356
+ validate: Whether to validate server/client version compatibility (default: True)
357
+
358
+ Raises:
359
+ ValueError: If url or token parameters are empty
360
+ IncompatibleClient: If server version is incompatible with client version
361
+ ConnectionError: If unable to connect to the Fiddler platform
362
+
363
+ Examples:
364
+ Basic initialization:
365
+
366
+ import fiddler as fdl
367
+
368
+ fdl.init(
369
+ url="https://your-fiddler-instance.com",
370
+ token="your-auth-token"
371
+ )
372
+
373
+ Initialization with custom timeout and proxy:
374
+
375
+ fdl.init(
376
+ url="https://your-fiddler-instance.com",
377
+ token="your-auth-token",
378
+ timeout=(10.0, 60.0), # 10s connect, 60s read timeout
379
+ proxies={"https": "https://proxy.company.com:8080"}
380
+ )
381
+
382
+ Initialization for development with relaxed settings:
383
+
384
+ fdl.init(
385
+ url="https://dev-fiddler-instance.com",
386
+ token="dev-token",
387
+ verify=False, # Skip SSL verification
388
+ validate=False, # Skip version compatibility check
389
+ )
390
+
391
+
392
+
393
+ Note:
394
+ The client implements automatic retry strategies for transient failures.
395
+ Configure retry duration via FIDDLER_CLIENT_RETRY_MAX_DURATION_SECONDS
396
+ environment variable (default: 300 seconds).
397
+
398
+ Logging is performed under the 'fiddler' namespace at INFO level.
399
+ If no root logger is configured, a stderr handler is automatically
400
+ attached unless auto_attach_log_handler=False.
401
+ """
402
+ logger.info("Initializing Fiddler Evals SDK with version %s", __version__)
403
+ # Singleton object in Python interpreter.
404
+ conn = Connection(
405
+ url=url,
406
+ token=token,
407
+ proxies=proxies,
408
+ timeout=timeout,
409
+ verify=verify,
410
+ validate=validate,
411
+ )
412
+ set_connection(conn)
413
+
414
+ logger.info(
415
+ "Connection established successfully with Fiddler Platform version %s",
416
+ conn.server_version,
417
+ )
418
+
419
+
420
+ def get_connection() -> Connection:
421
+ """Get the current global connection instance.
422
+
423
+ Returns:
424
+ Connection: The current connection instance.
425
+
426
+ Raises
427
+ AssertionError: If no connection has been initialized via fiddler_evals.init().
428
+ """
429
+ from fiddler_evals import (
430
+ connection_context, # pylint: disable=import-outside-toplevel
431
+ )
432
+
433
+ conn = connection_context.get()
434
+ if conn is None:
435
+ raise RuntimeError(
436
+ "No connection has been initialized. Call fiddler_evals.init() first."
437
+ )
438
+ return conn
439
+
440
+
441
+ def set_connection(conn: Connection) -> None:
442
+ """Set the current global connection instance.
443
+
444
+ Args:
445
+ conn: The connection instance to set.
446
+ """
447
+ from fiddler_evals import (
448
+ connection_context, # pylint: disable=import-outside-toplevel
449
+ )
450
+
451
+ connection_context.set(conn)
@@ -0,0 +1,9 @@
1
+ # Headers
2
+ CONTENT_TYPE_HEADER_KEY = "Content-Type"
3
+ JSON_CONTENT_TYPE = "application/json"
4
+ REQUEST_ID_HEADER_KEY = "X-Request-ID"
5
+ CORRELATION_ID_HEADER_KEY = "X-Correlation-ID"
6
+ FIDDLER_CLIENT_NAME_HEADER = "X-Fiddler-Client-Name"
7
+ FIDDLER_CLIENT_VERSION_HEADER = "X-Fiddler-Client-Version"
8
+
9
+ CLIENT_NAME = "evals-sdk-python"