Skip to content

Commit 3c5f286

Browse files
committed
feat: enhance evaluate() with environment variable support
- Make api_key parameter optional (reads from HONEYHIVE_API_KEY or HH_API_KEY) - Add server_url parameter with env var support (HONEYHIVE_SERVER_URL, HH_SERVER_URL, HH_API_URL) - Support both HONEYHIVE_* and HH_* prefix variations for better UX - Update run_experiment() to accept optional api_key - Add comprehensive unit tests for environment variable fallback - Improve documentation with environment variable usage
1 parent 5698a0f commit 3c5f286

5 files changed

Lines changed: 354 additions & 11 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
- Updated documentation: tutorials, how-to guides, and API reference with new interfaces and examples
1313

1414
### Changed
15+
- **🔧 API: Enhanced evaluate() Function Environment Variable Support**
16+
- Made api_key parameter optional (reads from HONEYHIVE_API_KEY or HH_API_KEY env vars)
17+
- Added server_url parameter with environment variable support (HONEYHIVE_SERVER_URL, HH_SERVER_URL, or HH_API_URL)
18+
- Improved UX by supporting both HONEYHIVE_* and HH_* prefix variations
19+
- Updated run_experiment() to accept optional api_key
1520
- **🔄 Examples: Updated Google ADK Integration with Async Support**
1621
- Migrated from GOOGLE_ADK_API_KEY to GOOGLE_API_KEY environment variable
1722
- Added async/await support to all test functions

‎docs/changelog.rst‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ Current Version Highlights
8181
* **Resource Information**: Captures resource attributes and instrumentation info for complete observability
8282
* **JSON Formatting**: Outputs pretty-printed JSON for easy debugging and troubleshooting
8383

84+
**🔧 CHANGED: Enhanced evaluate() Environment Variable Support**
85+
86+
* **Optional API Key**: api_key parameter now optional, reads from environment variables
87+
* **Server URL Support**: Added server_url parameter with env var support
88+
* **Dual Prefix Support**: Accepts both HONEYHIVE_* and HH_* environment variable prefixes
89+
* **Better UX**: More flexible configuration without hardcoding credentials
90+
8491
**🔄 CHANGED: Updated Google ADK Integration with Async Support**
8592

8693
* **Modern API**: Updated to newer Google ADK API with LlmAgent, Runner, and InMemorySessionService

‎docs/reference/index.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Core Capabilities
3737
**Evaluation Framework**:
3838

3939
- **@evaluate Decorator**: Automatic evaluation of function outputs with built-in and custom evaluators
40+
- **Environment Variable Support**: Optional ``api_key`` and ``server_url`` parameters with automatic fallback to environment variables (``HONEYHIVE_API_KEY``/``HH_API_KEY`` and ``HONEYHIVE_SERVER_URL``/``HH_SERVER_URL``/``HH_API_URL``)
4041
- **Batch Evaluation**: Evaluate multiple outputs simultaneously with threading support
4142
- **Async Evaluations**: Full async support for evaluation workflows
4243
- **Built-in Evaluators**: Accuracy, F1-score, length, quality score, and custom evaluators

‎src/honeyhive/experiments/core.py‎

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88

99
import asyncio
10+
import os
1011
import uuid
1112
from concurrent.futures import ThreadPoolExecutor, as_completed
1213
from typing import Any, Callable, Dict, List, Optional
@@ -124,7 +125,7 @@ def run_experiment(
124125
datapoint_ids: List[str],
125126
*,
126127
experiment_context: ExperimentContext,
127-
api_key: str,
128+
api_key: Optional[str] = None,
128129
max_workers: int = 10,
129130
verbose: bool = False,
130131
) -> List[Dict[str, Any]]:
@@ -148,7 +149,7 @@ def run_experiment(
148149
dataset: List of datapoint dictionaries
149150
datapoint_ids: List of datapoint IDs (parallel to dataset)
150151
experiment_context: ExperimentContext with run metadata
151-
api_key: HoneyHive API key for tracer
152+
api_key: HoneyHive API key for tracer (or set HONEYHIVE_API_KEY env var)
152153
max_workers: ThreadPool size (default: 10)
153154
verbose: Enable verbose logging
154155
@@ -578,6 +579,7 @@ def evaluate( # pylint: disable=too-many-locals,too-many-branches
578579
dataset_id: Optional[str] = None,
579580
evaluators: Optional[List[Callable]] = None,
580581
api_key: Optional[str] = None,
582+
server_url: Optional[str] = None,
581583
project: str = "default",
582584
name: Optional[str] = None,
583585
max_workers: int = 10,
@@ -599,7 +601,8 @@ def evaluate( # pylint: disable=too-many-locals,too-many-branches
599601
dataset: External dataset (list of dicts with 'inputs' and 'ground_truth')
600602
dataset_id: HoneyHive dataset ID (alternative to external dataset)
601603
evaluators: List of evaluator functions (optional)
602-
api_key: HoneyHive API key (or set HONEYHIVE_API_KEY env var)
604+
api_key: HoneyHive API key (or set HONEYHIVE_API_KEY/HH_API_KEY env var)
605+
server_url: HoneyHive server URL (or set HONEYHIVE_SERVER_URL/HH_SERVER_URL/HH_API_URL env var)
603606
project: HoneyHive project (or set HONEYHIVE_PROJECT env var)
604607
name: Experiment run name (auto-generated if not provided)
605608
max_workers: ThreadPool size for concurrent execution (default: 10)
@@ -653,13 +656,27 @@ def evaluate( # pylint: disable=too-many-locals,too-many-branches
653656
raise ValueError("Must provide either 'dataset' or 'dataset_id'")
654657
if dataset is not None and dataset_id is not None:
655658
raise ValueError("Cannot provide both 'dataset' and 'dataset_id'")
656-
if api_key is None:
657-
raise ValueError("Must provide 'api_key' or set HONEYHIVE_API_KEY env var")
658659
if project is None:
659660
raise ValueError("Must provide 'project' or set HONEYHIVE_PROJECT env var")
660661

661-
# Initialize client
662-
client = HoneyHive(api_key=api_key, verbose=verbose)
662+
# Load from environment variables if not provided
663+
# Support both HONEYHIVE_* and HH_* prefixes for convenience
664+
# Note: HoneyHive client's config only reads HH_* prefix, so we check
665+
# HONEYHIVE_* first for better UX, then pass explicitly to client
666+
if api_key is None:
667+
api_key = os.getenv("HONEYHIVE_API_KEY") or os.getenv("HH_API_KEY")
668+
669+
if server_url is None:
670+
# Check multiple variations for maximum compatibility
671+
server_url = (
672+
os.getenv("HONEYHIVE_SERVER_URL") # Most intuitive
673+
or os.getenv("HH_SERVER_URL") # Alternative shorthand
674+
or os.getenv("HH_API_URL") # Client config uses this
675+
)
676+
677+
# Initialize client - passing explicit values ensures both HONEYHIVE_* and HH_*
678+
# environment variables work (client's config only checks HH_* prefix)
679+
client = HoneyHive(api_key=api_key, server_url=server_url, verbose=verbose)
663680

664681
# Step 1: Prepare dataset
665682
if dataset is not None:

0 commit comments

Comments
 (0)