langchain-ai / langchain-nextjs-template

LangChain + Next.js starter template
https://langchain-nextjs-template.vercel.app
MIT License
1.29k stars 254 forks source link

Why does the template use a JsonOutputFunctionParser? #25

Open ishaangandhi opened 4 months ago

ishaangandhi commented 4 months ago

https://github.com/langchain-ai/langchain-nextjs-template/blob/03e4a849c45573812b853383f946bfa56c4cf339/app/api/chat/structured_output/route.ts#L69C23-L69C38

I can't tell why you need this. What is the benefit of this approach over StructuredOutputParser.fromZodSchema as described in https://js.langchain.com/docs/modules/model_io/output_parsers/types/structured?

jacoblee93 commented 4 months ago

It's to take advantage of function calling to have greater assurance of the output matching the schema vs. prompt engineering - this could use an update though as we've updated the best way to do this!

Function calling: https://js.langchain.com/docs/modules/model_io/chat/function_calling New withStructuredOutput method: https://js.langchain.com/docs/use_cases/extraction/quickstart