My code:
class Person(BaseModel):
name: str
age: int
epo_id = "mistralai/Mistral-7B-Instruct-v0.1"
llm = HuggingFaceEndpoint(
repo_id=repo_id,
max_new_tokens=500,
repetition_penalty=1.15,
do_sample=True,
top_k=10,
# num_return_sequences=1,
# token=os.environ.get("HUGGINGFACEHUB_API_TOKEN")
)
passage = "Here is a passage: John, a 30-year-old software engineer, is working on a new project."
prompt_template_string = "Based on the passage, extract the name and age of the person."
prompt_template = PromptTemplate(
template=prompt_template_string,
input_variables=["user_question"]
)
extraction_chain = create_structured_output_runnable(output_schema=Person, llm=llm, prompt=prompt_template)
extracted_data = extraction_chain.invoke(input = {
"input": passage
})
print(f"Extracted name: {extracted_data.name}")
print(f"Extracted age: {extracted_data.age}")
Getting this error when trying to run it:
raise OutputParserException(
langchain_core.exceptions.OutputParserException: This output parser can only be used with a chat generation.```
So I put two print() statements in to see what was triggering the error (`print(generation)` and `print(type(generation))`):
class OutputFunctionsParser(BaseGenerationOutputParser[Any]):
...
def parse_result(self, result: List[Generation], *, partial: bool = False) -> Any:
generation = result[0]
print(generation)
print(type(generation))
if not isinstance(generation, ChatGeneration):
raise OutputParserException(
"This output parser can only be used with a chat generation."
)
Prints as:
text='\nA: Unnamed, 25'
<class 'langchain_core.outputs.generation.Generation'>
Why isn't the internal method returning a ChatGeneration?