A Node.js project exploring LangChain's structured output capabilities with OpenAI. Features include generating structured jokes using GPT-4o with both simple and chained approaches.
- Node.js v20.17.0
- npm (latest stable)
- OpenAI API key
- Install dependencies:
npm install- Configure environment:
cp .env.example .envEdit .env and add your OpenAI API key.
node simple.jsDemonstrates basic structured output using a Zod schema to generate a joke with setup and punchline.
node chain.jsShows a more complex example that generates a joke and then rates it using a chain of operations.
simple.js- Simple structured output examplechain.js- Advanced chaining example with joke generation and rating.env- Environment configuration (not in git).env.example- Environment template
- @langchain/core
- @langchain/openai
- langchain
- zod
- dotenv
The project uses GPT-4o for optimal results. Ensure your OpenAI API key has GPT-4o access.