A comprehensive Next.js application demonstrating all major LangChain.js capabilities with Google Gemini integration. This project showcases text generation, image analysis, speech processing, transcription, multimodal processing, and more.
- Features
- Tech Stack
- Setup Instructions
- Project Structure
- API Endpoints
- Usage Examples
- LangChain.js vs Vercel AI SDK
- Contributing
- Text Generation - Basic chat and structured output with Gemini
- Image Analysis - Upload images for OCR, content analysis, and visual Q&A
- Speech Processing - Generate speech scripts and analyze speech patterns
- Transcript Analysis - Process audio transcripts and extract insights
- Multimodal Processing - Handle multiple content types simultaneously
- Feature Comparison - AI-powered comparison between LangChain.js and Vercel AI SDK
- Streaming Support - Real-time text and structured output streaming
- Tool Calling - Function calling and external tool integration
- File Upload - Support for image files (PNG, JPEG)
- Schema Validation - Zod-based structured output validation
- Error Handling - Comprehensive error handling and validation
- Responsive UI - Modern, mobile-friendly interface
- Framework: Next.js 15 with App Router
- AI Framework: LangChain.js
- AI Model: Google Gemini 2.0 Flash
- Styling: Tailwind CSS
- Validation: Zod
- Language: TypeScript
- Deployment: Vercel-ready
- Node.js 18+
- npm or pnpm
- Google AI API key
git clone <your-repo-url>
cd langchainjs-examples
npm install
# or
pnpm install
Create a .env.local
file in the root directory:
GOOGLE_API_KEY=your_google_api_key_here
Getting Google API Key:
- Go to Google AI Studio
- Sign in with your Google account
- Click "Get API Key"
- Create a new API key
- Copy the key to your
.env.local
file
npm run dev
# or
pnpm dev
Navigate to http://localhost:3000
to see the application.
langchainjs-examples/
βββ app/
β βββ api/ # API routes
β β βββ text/route.ts # Text generation API
β β βββ image/route.ts # Image analysis API
β β βββ speech/route.ts # Speech processing API
β β βββ transcription/route.ts # Transcript analysis API
β βββ simple-chat-llm/ # Basic text generation examples
β β βββ chat.ts
β β βββ structured-chat.ts
β β βββ schema-examples.ts
β β βββ prompt-reveal.ts
β βββ streaming/ # Streaming examples
β β βββ stream-text.ts
β β βββ stream-structured.ts
β βββ tool-calling/ # Tool calling examples
β β βββ basic-tools.ts
β β βββ advanced-tools.ts
β βββ image-generation/ # Image processing
β β βββ image-prompts.ts
β β βββ image-analysis.ts
β β βββ page.tsx # UI for image analysis
β βββ speech/ # Speech processing
β β βββ speech-processing.ts
β β βββ page.tsx # UI for speech processing
β βββ transcription/ # Transcript processing
β β βββ transcript-processing.ts
β β βββ page.tsx # UI for transcript analysis
β βββ multimodal/ # Multimodal processing
β β βββ content-analysis.ts
β β βββ page.tsx # UI for multimodal processing
β βββ comparison/ # Feature comparison
β β βββ feature-comparison.ts
β β βββ page.tsx # UI for comparison
β βββ page.tsx # Main homepage
β βββ layout.tsx # App layout
βββ public/ # Static assets
βββ package.json
βββ tsconfig.json
βββ tailwind.config.js
βββ README.md
- POST
/api/text
- Body:
{ "prompt": "Your text prompt" }
- Response:
{ "success": true, "content": "AI response" }
- POST
/api/image
- Body: FormData with
image
file andprompt
text - Response:
{ "success": true, "content": "Image analysis" }
- POST
/api/speech
- Body:
{ "text": "Text to process", "processingType": "speech_script" }
- Response:
{ "success": true, "content": "Processed speech" }
- POST
/api/transcription
- Body:
{ "transcript": "Audio transcript", "analysisType": "summary" }
- Response:
{ "success": true, "content": "Analysis result" }
const response = await fetch('/api/text', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ prompt: 'Explain quantum computing' })
});
const data = await response.json();
console.log(data.content);
const formData = new FormData();
formData.append('image', imageFile);
formData.append('prompt', 'What do you see in this image?');
const response = await fetch('/api/image', {
method: 'POST',
body: formData
});
const data = await response.json();
console.log(data.content);
import { z } from "zod";
const schema = z.object({
answer: z.string().describe("The main answer"),
confidence: z.number().min(0).max(1)
});
const structuredModel = model.withStructuredOutput(schema);
const result = await structuredModel.invoke("What is AI?");
Feature | LangChain.js | Vercel AI SDK | Best For |
---|---|---|---|
Text Generation | model.invoke() |
generateText() |
LangChain: Complex workflows |
Structured Output | withStructuredOutput() |
generateObject() |
LangChain: Advanced schemas |
Streaming | model.stream() |
streamText() |
Both: Real-time apps |
Tool Calling | bindTools() |
Built-in | LangChain: Advanced tools |
State Management | Built-in chains | None | LangChain: Complex workflows |
Multimodal | Full support | Limited | LangChain: Image/audio |
React Components | None | Built-in | Vercel: Quick UI |
Learning Curve | Steeper | Gentle | Vercel: Simple apps |
Choose LangChain.js if:
- Building complex AI workflows
- Need advanced prompt engineering
- Want extensive tool integration
- Building enterprise applications
- Need multimodal capabilities
Choose Vercel AI SDK if:
- Building simple chat applications
- Need React components out of the box
- Want minimal setup
- Building Next.js applications
- Need quick prototyping
- LangChain.js is more powerful but has a steeper learning curve
- Vercel AI SDK is simpler but limited to basic text generation
- Both use the same underlying AI models - the difference is in the framework
- LangChain.js excels at complex workflows with state management and tool integration
- Vercel AI SDK excels at quick UI development with built-in React components
# Run specific examples
npx tsx app/simple-chat-llm/chat.ts
npx tsx app/streaming/stream-text.ts
npx tsx app/tool-calling/basic-tools.ts
npm run build
npm start
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
Built with β€οΈ using LangChain.js, Next.js, and Google Gemini