From 831db8539328fa1c8890c23edb325a619d404f76 Mon Sep 17 00:00:00 2001 From: Thomas Capelle Date: Sat, 12 Oct 2024 13:01:48 +0200 Subject: [PATCH] check instructor instal --- weave/flow/scorer/llm_utils.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/weave/flow/scorer/llm_utils.py b/weave/flow/scorer/llm_utils.py index 069134d1452..c2c1875b6d4 100644 --- a/weave/flow/scorer/llm_utils.py +++ b/weave/flow/scorer/llm_utils.py @@ -1,7 +1,5 @@ from typing import TYPE_CHECKING, List, Optional, Union -import instructor - from weave.trace.autopatch import autopatch autopatch() # fix instrucor tracing @@ -19,6 +17,7 @@ DEFAULT_MAX_TOKENS = 4096 if TYPE_CHECKING: + import instructor from anthropic import Anthropic, AsyncAnthropic from mistralai import Mistral from openai import AsyncOpenAI, OpenAI @@ -28,7 +27,12 @@ _LLM_CLIENTS = object -def instructor_client(client: _LLM_CLIENTS) -> instructor.client: # type: ignore +def instructor_client(client: _LLM_CLIENTS) -> "instructor.client": # type: ignore + try: + import instructor + except ImportError: + raise ImportError("We need instructor to use this the LLM-powered scorers") + client_type = type(client).__name__.lower() if "mistral" in client_type: return instructor.from_mistral(client)