A powerful backend API built with LangChain.js and Hono, demonstrating various LLM agent capabilities and use cases.
- Streaming Chat API - Real-time streaming responses from LLM
- Memory-enabled Chat - Conversational memory with LangGraph
- Ollama Integration - Local LLM support with configurable models
- Hono Framework - Fast, lightweight web framework
- TypeScript Support - Full type safety and IntelliSense
Endpoint | Method | Description | Request Body |
---|---|---|---|
/ |
GET | Health check | - |
/llm/stream |
POST | Streaming chat response | {"message": "your question"} |
/llm/memory |
POST | Chat with conversation memory | {"message": "your question"} |
-
Clone the repository
git clone <your-repo-url> cd langchain
-
Install dependencies
bun install
-
Set up environment variables Create a
.env
file in the root directory:MODEL_NAME=llama3.2:3b MODEL_URL=http://localhost:11434 MODEL_TEMPERATURE=0.7
-
Start Ollama and pull a model
ollama serve ollama pull llama3.2:3b
-
Run the development server
bun run dev
-
Access the API Open http://localhost:3000
curl -X POST http://localhost:3000/llm/stream \
-H "Content-Type: application/json" \
-d '{"message": "Explain quantum computing in simple terms"}'
curl -X POST http://localhost:3000/llm/memory \
-H "Content-Type: application/json" \
-d '{"message": "What did we talk about earlier?"}'
// Streaming example
const response = await fetch('http://localhost:3000/llm/stream', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: 'Tell me a joke' })
});
const reader = response.body?.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
console.log(decoder.decode(value));
}
src/
├── index.ts # Main Hono app and routes
└── llm/
├── model.ts # LLM configuration (Ollama)
├── memory.ts # Memory-enabled chat with LangGraph
└── stream.ts # Streaming chat implementation
- Document Q&A Agent - Upload and query documents
- Code Assistant - Code generation and debugging
- Multi-modal Support - Image and text processing
- Tool Calling - Function calling and external API integration
- Research Agent - Web search and information gathering
- Data Analysis Agent - CSV/JSON data processing
- Email Assistant - Email composition and management
- Calendar Agent - Schedule management and planning
- Authentication & Rate Limiting
- Database Integration - Persistent conversation storage
- WebSocket Support - Real-time bidirectional communication
- Agent Orchestration - Multi-agent workflows
- Monitoring & Analytics - Performance tracking
- Customer Support Bot - Ticket classification and responses
- Content Generation - Blog posts, social media content
- Translation Service - Multi-language support
- Code Review Agent - Automated code analysis
- Financial Analysis - Market data processing
- Create new LLM module in
src/llm/
- Add API endpoint in
src/index.ts
- Update documentation and examples
- Add tests for new functionality
Variable | Description | Default |
---|---|---|
MODEL_NAME |
Ollama model name | llama3.2:3b |
MODEL_URL |
Ollama server URL | http://localhost:11434 |
MODEL_TEMPERATURE |
LLM temperature | 0.7 |
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- LangChain.js - LLM framework
- Hono - Web framework
- Ollama - Local LLM server
- Bun - JavaScript runtime
Ready to build the future of AI-powered applications! 🚀