Thanks to visit codestin.com
Credit goes to github.com

Skip to content

LangSmith Masterclass is a comprehensive, hands-on repository designed to teach and demonstrate advanced concepts in building LLM-powered applications using LangChain, LangSmith, and LangGraph.

Notifications You must be signed in to change notification settings

SM0311/LangSmith-Master

Repository files navigation

LangSmith Masterclass

LangSmith Masterclass is a comprehensive, hands-on repository designed to teach and demonstrate advanced concepts in building LLM-powered applications using LangChain, LangSmith, and LangGraph. The project covers:

  • Simple LLM prompt chaining
  • Sequential multi-step chains
  • Retrieval-Augmented Generation (RAG) pipelines with PDF data
  • Custom agents with web search and API tools
  • Graph-based workflows for structured evaluation

Each script is crafted for clarity and experimentation, making this repo ideal for learners, researchers, and developers who want to master modern AI application development.


Table of Contents


Project Structure

langsmith-masterclass/
├── 1_simple_llm_call.py
├── 2_sequential_chain.py
├── 3_rag_v1.py
├── 3_rag_v2.py
├── 3_rag_v3.py
├── 3_rag_v4.py
├── 4_agent.py
├── 5_langgraph.py
├── islr.pdf
├── requirements.txt
├── myvenv/
│   └── ... (virtual environment files)
└── .gitignore
  • 1_simple_llm_call.py: Basic LLM prompt chaining example.
  • 2_sequential_chain.py: Sequential multi-step LLM chain for report generation and summarization.
  • 3_rag_v1.py - 3_rag_v4.py: Progressive Retrieval-Augmented Generation (RAG) pipelines using PDFs, embeddings, and FAISS vector stores. Each version adds more features (tracing, caching, modularity).
  • 4_agent.py: Custom agent using LangChain's ReAct framework, with web search and weather data tools.
  • 5_langgraph.py: Advanced graph-based workflow using LangGraph for structured evaluation and feedback.
  • islr.pdf: Sample PDF for RAG demos.
  • requirements.txt: All required Python packages.
  • myvenv/: Local Python virtual environment.
  • .gitignore: Standard ignores for Python, virtualenv, Jupyter, and VS Code files.

Setup Instructions

  1. Clone the repository

    git clone <repo-url>
    cd langsmith-masterclass
  2. Create and activate a virtual environment

    python -m venv myvenv
    .\myvenv\Scripts\Activate.ps1
  3. Install dependencies

    pip install -r requirements.txt
  4. Set up environment variables

    • Create a .env file in the root directory with your API keys:
      OPENAI_API_KEY=your_openai_key
      LANGCHAIN_API_KEY=your_langchain_key
      LANGCHAIN_TRACING_V2=true
      LANGCHAIN_PROJECT=your_project_name

Environment Variables

  • OPENAI_API_KEY: Required for OpenAI LLM and embedding models.
  • LANGCHAIN_API_KEY: Required for LangSmith tracing and analytics.
  • LANGCHAIN_TRACING_V2: Enables advanced tracing (recommended: true).
  • LANGCHAIN_PROJECT: Project name for LangSmith dashboard.

Detailed File Explanations

1_simple_llm_call.py

  • Loads environment variables.
  • Sets up a simple prompt and runs a question through an OpenAI chat model.

2_sequential_chain.py

  • Demonstrates a multi-step chain: generates a report, then summarizes it.
  • Uses two different LLM models and prompt templates.
  • Shows how to pass config metadata for tracing.

3_rag_v1.py

  • Loads a PDF, splits it into chunks, embeds with OpenAI, and builds a FAISS vector store.
  • Runs a RAG pipeline to answer questions from the PDF context.

3_rag_v2.py

  • Adds LangSmith tracing to each pipeline step using @traceable decorators.
  • Shows how to organize and trace modular pipeline functions.

3_rag_v3.py

  • Further modularizes the RAG pipeline and traces parent setup functions.
  • Demonstrates advanced tracing and pipeline composition.

3_rag_v4.py

  • Adds caching, fingerprinting, and index management for efficient RAG workflows.
  • Uses Path, hashlib, and JSON for robust file handling.

4_agent.py

  • Implements a ReAct agent with custom tools (web search, weather API).
  • Uses LangChain Hub for prompt templates.
  • Demonstrates agent creation, tool registration, and invocation.

5_langgraph.py

  • Builds a graph-based workflow for essay evaluation using LangGraph.
  • Defines structured schemas and feedback models.
  • Shows how to use state graphs and custom evaluation logic.

Requirements

All dependencies are listed in requirements.txt. Key packages include:

  • langchain, langchain-openai, langchain-community, langsmith, langgraph
  • faiss-cpu, pypdf, python-dotenv, openai, pandas, streamlit, etc.
  • See the full list in requirements.txt for exact versions.

Usage Guide

  • Run any script directly after activating the virtual environment:
    python 1_simple_llm_call.py
    python 2_sequential_chain.py
    python 3_rag_v1.py
    # ... and so on
  • For RAG scripts, ensure islr.pdf is present in the root directory.
  • For agent scripts, internet access is required for API calls.
  • For LangSmith tracing, ensure your API keys and project name are set in .env.

Troubleshooting

  • Missing packages: Run pip install -r requirements.txt again.
  • API errors: Check your .env file for correct keys.
  • PDF not found: Ensure islr.pdf exists in the root directory.
  • Virtual environment issues: Recreate with python -m venv myvenv.
  • Windows activation: Use Activate.ps1 for PowerShell.

References


For questions or contributions, please open an issue or pull request.

About

LangSmith Masterclass is a comprehensive, hands-on repository designed to teach and demonstrate advanced concepts in building LLM-powered applications using LangChain, LangSmith, and LangGraph.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages