gkamradt / langchain-tutorials

Overview and tutorial of the LangChain Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

predict_and_parse is depracated

rsher60 opened this issue · comments

chain = create_extraction_chain(llm, schema, encoder_or_encoder_class='json')
output = chain.predict_and_parse(text="please add 15 more units sold to 2023")['data']

printOutput(output)

Running this code block throws a TypeError : initial_value must be str or None, not dict.

I was able to get output in json format using:

chain.predict(text=text)["data"]

Kind of a hacky way but do this:

chain = create_extraction_chain(llm, person_schema)
text = ## The text you want ##
output = chain.run(text=text)["data"]

Hate to say this but here are two external resources that should help

https://python.langchain.com/docs/use_cases/extraction#option-2-parsing
https://python.langchain.com/docs/modules/model_io/output_parsers/types/pydantic

I will do an overhaul of the files here in a few weeks