Skip to content

Commit

Permalink
check instructor instal
Browse files Browse the repository at this point in the history
  • Loading branch information
tcapelle committed Oct 12, 2024
1 parent 7359469 commit 831db85
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions weave/flow/scorer/llm_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import TYPE_CHECKING, List, Optional, Union

import instructor

from weave.trace.autopatch import autopatch

autopatch() # fix instrucor tracing
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 831db85

Please sign in to comment.