From 7d006977c9e49fdc2906c0689217c068b09f0498 Mon Sep 17 00:00:00 2001 From: Bagatur Date: Thu, 7 Nov 2024 18:31:22 -0800 Subject: [PATCH] python: log experiment with html --- python/langsmith/evaluation/_runner.py | 27 ++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/python/langsmith/evaluation/_runner.py b/python/langsmith/evaluation/_runner.py index 111986b7..92cddc56 100644 --- a/python/langsmith/evaluation/_runner.py +++ b/python/langsmith/evaluation/_runner.py @@ -7,12 +7,14 @@ import concurrent.futures as cf import datetime import functools +import importlib import inspect import itertools import logging import pathlib import queue import random +import sys import textwrap import threading import uuid @@ -94,6 +96,9 @@ ], ] +_IS_INTERACTIVE_ENV = hasattr(sys, "ps2") +_IPYTHON_INSTALLED = importlib.util.find_spec("IPython") + def evaluate( target: TARGET_T, @@ -1113,15 +1118,25 @@ def _print_experiment_start( f"{base_url}/datasets/{dataset_id}/compare?" f"selectedSessions={project.id}" ) - print( # noqa: T201 - f"View the evaluation results for experiment: '{self.experiment_name}'" - f" at:\n{comparison_url}\n\n" - ) else: - # HACKHACK + comparison_url = None + + if _IS_INTERACTIVE_ENV and _IPYTHON_INSTALLED and comparison_url: + from IPython.display import HTML, display # type: ignore[import-not-found] + + display( + HTML( + f"RUNNING EXPERIMENT: " + f"{self.experiment_name}" + ) + ) + elif comparison_url: print( # noqa: T201 - "Starting evaluation of experiment: %s", self.experiment_name + f"RUNNING EXPERIMENT: {self.experiment_name}\nEXPERIMENT URL: " + f"{comparison_url}" ) + else: + print(f"RUNNING EXPERIMENT: {self.experiment_name}") # noqa: T201 class _ExperimentManager(_ExperimentManagerMixin):