Skip to content

Commit

Permalink
Update extraction interface to require an Object node (#90)
Browse files Browse the repository at this point in the history
The schema should always be defined with respect to an Object rather
than other
types of nodes, otherwise there is some ambiguity about when
interpreting how to
encode the object (at least when using CSV encoding).
  • Loading branch information
eyurtsev authored Mar 25, 2023
1 parent f06ff7c commit ce4ed32
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions kor/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from langchain.schema import BaseLanguageModel

from kor.encoders import Encoder, initialize_encoder
from kor.nodes import AbstractSchemaNode
from kor.nodes import Object
from kor.prompts import create_langchain_prompt
from kor.type_descriptors import TypeDescriptor, initialize_type_descriptors
from kor.validators import Validator
Expand All @@ -14,7 +14,7 @@

def create_extraction_chain(
llm: BaseLanguageModel,
node: AbstractSchemaNode,
node: Object,
*,
encoder_or_encoder_class: Union[Type[Encoder], Encoder, str] = "csv",
type_descriptor: Union[TypeDescriptor, str] = "typescript",
Expand All @@ -36,6 +36,8 @@ def create_extraction_chain(
Returns:
A langchain chain
"""
if not isinstance(node, Object):
raise ValueError(f"node must be an Object got {type(node)}")
encoder = initialize_encoder(encoder_or_encoder_class, node, **encoder_kwargs)
type_descriptor_to_use = initialize_type_descriptors(type_descriptor)
return LLMChain(
Expand Down

0 comments on commit ce4ed32

Please sign in to comment.