From e6933b4977f8c0d38ab7aa64330a34fc213fd990 Mon Sep 17 00:00:00 2001 From: wenzhe <145375501+wenzhe-log10@users.noreply.github.com> Date: Thu, 11 Apr 2024 23:44:13 -0700 Subject: [PATCH] fix cli import issue when magentic is not installed (#140) --- log10/feedback/autofeedback.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/log10/feedback/autofeedback.py b/log10/feedback/autofeedback.py index fec0004e..c6d98a8b 100644 --- a/log10/feedback/autofeedback.py +++ b/log10/feedback/autofeedback.py @@ -8,11 +8,17 @@ from rich.console import Console from log10.completions.completions import _get_completion -from log10.feedback._summary_feedback_utils import flatten_messages, summary_feedback_llm_call from log10.feedback.feedback import _get_feedback_list from log10.load import log10, log10_session +try: + from log10.feedback._summary_feedback_utils import flatten_messages, summary_feedback_llm_call + + Magentic_imported = True +except ImportError: + Magentic_imported = False + log10(openai) logger = logging.getLogger("LOG10") @@ -28,6 +34,10 @@ class AutoFeedbackICL: _predict_func: FunctionType = None def __init__(self, task_id: str, num_samples: int = 5, predict_func: FunctionType = summary_feedback_llm_call): + if not Magentic_imported: + raise ImportError( + "Log10 feedback predict requires magentic package. Please install using 'pip install log10-io[autofeedback_icl]'" + ) self.num_samples = num_samples self.task_id = task_id self._predict_func = predict_func