Replies: 2 comments 1 reply
-
Documentation is a bit hidden: https://eyurtsev.github.io/kor/validation.html#validating-collections There are recipes for extracting collections using a CSV encoder and also for using a JSON encoder. Feel free to drop an example of the schema / task you're trying to do as it would make it easier to suggest a solution. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Would this work? from kor.extraction import create_extraction_chain
from kor.nodes import Object, Text, Number
from langchain.chat_models import ChatOpenAI
schema = Object(
id="person",
description="Personal information",
examples=[
("Alice and Bob are friends", [{"first_name": "Alice"}, {"first_name": "Bob"}])
],
attributes=[
Text(
id="first_name",
description="The first name of a person.",
)
],
many=True,
)
llm = ChatOpenAI(
model_name="gpt-3.5-turbo",
temperature=0,
max_tokens=2000,
)
chain = create_extraction_chain(llm, schema)
text_with_names = llm.predict(text="Generate 10 baby names as a list.")
chain.run(text_with_names) {'data': {'person': [{'first_name': 'Olivia'},
{'first_name': 'Liam'},
{'first_name': 'Ava'},
{'first_name': 'Noah'},
{'first_name': 'Sophia'},
{'first_name': 'Jackson'},
{'first_name': 'Isabella'},
{'first_name': 'Aiden'},
{'first_name': 'Mia'},
{'first_name': 'Lucas'}]},
'raw': 'first_name\nOlivia\nLiam\nAva\nNoah\nSophia\nJackson\nIsabella\nAiden\nMia\nLucas',
'errors': [],
'validated_data': {}} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, just want to get some clarification.
I want to prompt ChatGPT to generate a list and return it. I'm looking at the Kor docs but I'm not sure how to use the schema to specify to return a list? The list isn't of a fixed length so I can't create an Object with x Text values.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions