mirror of
https://github.com/kennethreitz/instructor.git
synced 2026-06-05 22:50:18 +00:00
fix: clean up imports for anthropic (#517)
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
# type: ignore
|
||||
import re
|
||||
import xmltodict
|
||||
from pydantic import BaseModel
|
||||
import xml.etree.ElementTree as ET
|
||||
from typing import Type, Any, Dict, TypeVar
|
||||
|
||||
|
||||
try:
|
||||
import xmltodict
|
||||
import xml.etree.ElementTree as ET
|
||||
except ImportError:
|
||||
import warnings
|
||||
warnings.warn("xmltodict and xml.etree.ElementTree modules not found. Please install them to proceed. `pip install xmltodict`", ImportWarning)
|
||||
|
||||
|
||||
T = TypeVar("T", bound=BaseModel)
|
||||
|
||||
|
||||
|
||||
@@ -2,14 +2,12 @@ from typing import Any, Dict, Optional, Type, TypeVar
|
||||
from docstring_parser import parse
|
||||
from functools import wraps
|
||||
from pydantic import BaseModel, create_model
|
||||
from instructor.exceptions import IncompleteOutputException
|
||||
from openai.types.chat import ChatCompletion
|
||||
from instructor.exceptions import IncompleteOutputException
|
||||
from instructor.mode import Mode
|
||||
from instructor.utils import extract_json_from_codeblock
|
||||
import logging
|
||||
import importlib
|
||||
|
||||
from .anthropic_utils import json_to_xml, extract_xml, xml_to_model
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
@@ -63,6 +61,7 @@ class OpenAISchema(BaseModel): # type: ignore[misc]
|
||||
@classmethod
|
||||
@property
|
||||
def anthropic_schema(cls) -> str:
|
||||
from instructor.anthropic_utils import json_to_xml, extract_xml, xml_to_model
|
||||
return json_to_xml(cls)
|
||||
|
||||
@classmethod
|
||||
@@ -87,10 +86,7 @@ class OpenAISchema(BaseModel): # type: ignore[misc]
|
||||
"""
|
||||
if mode == Mode.ANTHROPIC_TOOLS:
|
||||
try:
|
||||
assert isinstance(
|
||||
completion,
|
||||
importlib.import_module("anthropic.types.message").Message,
|
||||
)
|
||||
from instructor.anthropic_utils import extract_xml, xml_to_model
|
||||
except ImportError as err:
|
||||
raise ImportError("Please 'pip install anthropic' package to proceed.") from err
|
||||
assert hasattr(completion, "content")
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "instructor"
|
||||
version = "0.6.5"
|
||||
version = "0.6.6"
|
||||
description = "structured outputs for llm"
|
||||
authors = ["Jason Liu <jason@jxnl.co>"]
|
||||
license = "MIT"
|
||||
|
||||
Reference in New Issue
Block a user