A collection of simple, practical examples demonstrating basic LangChain methods, functions, and concepts. This repository serves as a learning resource for developers getting started with LangChain.
- Python 3.8 or higher
- pip (Python package installer)
-
Clone the repository:
git clone https://github.com/nicolasfmc/langchain_basics.git cd langchain_basics
-
Create a virtual environment:
# Create virtual environment python -m venv venv # Activate virtual environment # On Windows: venv\Scripts\activate # On macOS/Linux: source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
Create a
.env
file in the root directory and add your API keys:OPENAI_API_KEY=your_openai_api_key_here # Add other API keys as needed
- Basic - Introduction to basics
- Simple Sequential Chain - Basic sequential chain implementation
- Conversation Buffer Memory - Basic memory management for conversations
- Conversation Buffer Window Memory - Windowed memory for chat history
- Conversation Summary Memory - Summarized conversation memory
- LCEL Basic - The basic of LangChain Expression Language (LCEL)
- LCEL Join Chains - LangChain Expression Language (LCEL) + Join chains
- Conversation Buffer Custom Chain - Custom chain with buffer memory
- JSON Output Parser - Parsing structured JSON outputs
- Retrieval QA Tasks - Document retrieval and Q&A
- Retrieval QA - Intermediate retrieval-based question answering
- Basic LangChain Setup: Environment configuration and basic usage
- Memory Management: Different types of conversation memory (buffer, window, summary)
- Chain Operations: Sequential chains and custom chain implementations
- Output Parsing: Structured data extraction and JSON parsing
- Retrieval Systems: Document-based question answering and retrieval-augmented generation (RAG)
- Advanced Patterns: Custom chains and complex workflow implementations
Each Python file in this repository is a standalone example. To run any example:
python filename.py
For example:
python simple_sequential_chain.py
Virtual environments help you:
- Keep project dependencies isolated
- Avoid conflicts between different projects
- Maintain consistent development environments
- Easy dependency management
Activate the environment (do this every time you work on the project):
# Windows
venv\Scripts\activate
# macOS/Linux
source venv/bin/activate
Deactivate when done:
deactivate
Update requirements.txt when you add new packages:
pip freeze > requirements.txt
The requirements.txt
file contains all necessary dependencies. Key packages include:
langchain
- Core LangChain libraryopenai
- OpenAI API integrationpython-dotenv
- Environment variable management- Additional utilities for specific examples
Feel free to contribute by:
- Adding new examples
- Improving existing code
- Adding documentation
- Reporting issues
This project is open source and available under the MIT License.
Common Issues:
- Import errors: Make sure your virtual environment is activated and dependencies are installed
- API key errors: Verify your
.env
file is properly configured - Module not found: Check that you're running commands from the project root directory
Getting Help:
- Check the official LangChain documentation
- Review individual file comments for specific usage instructions
- Open an issue in this repository for bug reports or questions
Happy coding! 🚀