Skip to content

shrutikakapade/Regular-LLMs-with-LangChain-Google-Gemini

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Regular LLMs with LangChain & Google Gemini

πŸ“˜ Learning & Exploration Notebook

This repository is a learning-focused, beginner-to-intermediate friendly hub that explains how Large Language Models (LLMs) work in practice using Google Gemini integrated through LangChain.

It starts from fundamental concepts and gradually moves toward practical, industry-relevant usage patterns, making it ideal for learners who want clarity before moving to advanced chat-based systems.

Note: This repository focuses on Regular (non-chat) LLM usage. In the next repository, we explore ChatGoogleGenerativeAI for building conversational LLM applications.

🧠 Foundations: What & Why

What is an LLM (Large Language Model)?

A Large Language Model (LLM) is an AI system trained on massive amounts of text data to understand, generate, and reason using natural language.

LLMs can be used to:

  • Answer questions
  • Generate text and explanations
  • Summarize documents
  • Assist in reasoning and decision-making

Google Gemini is a modern, high-performance LLM designed for fast, reliable, and high-quality text generation.


What is LangChain?

LangChain is a framework that simplifies working with LLMs by providing structured abstractions and utilities.

It helps developers by offering:

  • Standardized interfaces for LLMs
  • Prompt templates for reusable prompting
  • Execution methods like invoke and batch
  • Reliability features such as retries and timeouts

LangChain allows you to focus on prompt design and application logic instead of low-level API handling.


Why Integrate LangChain with Google Gemini?

Combining LangChain with Google Gemini enables:

  • Clean and flexible LLM configuration
  • Controlled output behavior using prompt templates
  • Multiple execution patterns (invoke, batch, stream)
  • Scalable and production-ready LLM workflows

This integration is popular because it balances power, flexibility, and developer productivity.


πŸ“‚ What This Notebook Covers

This notebook provides a structured walkthrough of using Google Gemini as a Regular LLM with LangChain.


βœ… Core Topics Explained

1️⃣ LLM Configuration (Gemini Model Setup)

Demonstrates how to initialize Google Gemini using LangChain.

Key configuration parameters include:

  • model
  • api_key
  • temperature
  • max_tokens
  • retries
  • request_timeout

This helps learners understand how configuration directly affects LLM behavior, creativity, output length, and reliability.


2️⃣ Prompt Templates (Prompt Engineering Basics)

Explains how to create reusable prompt templates using LangChain.

  • How prompt structure influences responses
  • Why prompt engineering matters
  • How templates improve consistency

This section builds a strong foundation in prompt engineering.


3️⃣ Invoke Method (Single Request Execution)

Demonstrates the invoke() method for one-time prompt execution.

Best suited for:

  • Quick experimentation
  • Query answering
  • Prompt debugging
  • Real-time interactions

4️⃣ Batch Execution (Multiple Inputs Together)

Shows how to process multiple prompts simultaneously using batch execution.

  • invoke() β†’ Single request
  • batch() β†’ Multiple requests

Introduces scalability and bulk inference workflows.


5️⃣ Error Handling & Performance Controls

Covers essential reliability practices such as:

  • Retries
  • Timeouts
  • Token limits

These concepts are critical for building stable, production-ready LLM systems.


🎯 Why This Repository Is Useful for Learning

  • Builds a clear mental model of LangChain + Gemini integration
  • Explains LLM behavior from configuration to execution
  • Covers both interactive and scalable usage patterns
  • Introduces production-aligned best practices
  • Structured for clarity and self-paced learning

πŸ“‚ Project Structure

project/
β”œβ”€β”€ files/
β”‚   β”œβ”€β”€ .env        # API key configuration
β”‚   β”œβ”€β”€ main.py     # Streamlit chat interface
β”‚   └── req.txt     # Required dependencies
β”œβ”€β”€ Include/
β”œβ”€β”€ Lib/
β”œβ”€β”€ Scripts/
β”œβ”€β”€ share/
β”œβ”€β”€ langchain project.code-workspace
└── pyvenv.cfg

The files/ folder contains all application-specific files required to run the project.


βš™οΈ Environment Setup (Step-by-Step)

1️⃣ Create a Virtual Environment

python -m venv project

2️⃣ Activate the Virtual Environment

Windows:

project\Scripts\activate

macOS / Linux:

source project/bin/activate

3️⃣ Install Required Dependencies

pip install -r req.txt

This installs LangChain, Google Generative AI integrations, Streamlit, and python-dotenv.


πŸ” API Key Management (dotenv)

To securely manage your API key:

  1. Create a .env file inside the files/ folder
  2. Add your Google Gemini API key:
API_KEY="your_api_key_here"

The key is loaded at runtime using python-dotenv.


πŸ“˜ File Explanation

1. Main.py (Streamlit Chat App)

This file provides a simple web-based chat interface using GoogleGenerativeAI.

  • Streamlit-based UI
  • Secure API loading via dotenv
  • Real-time conversational interaction

▢️ Running the Application

streamlit run main.py

This launches a browser-based chat interface for interacting with the Gemini chat model.


πŸŽ₯ Video Demonstration

A video recording of the project execution is provided for reference.

  • Virtual environment activation
  • VS Code folder structure
  • Live chat execution
Regular_LLM.Googlegenerativeai.model.recording.1.mp4


πŸ”œ What’s Next?

After understanding Regular LLMs, the next repository explores:

Chat-Based LLMs with LangChain & Google Gemini

  • Message-based prompting
  • Conversation context
  • System, Human, and AI messages
  • Chat-oriented LLM workflows

Both repositories are designed to work in sync, providing a smooth learning transition from basic LLMs to conversational AI systems.


About

Explore how to integrate Google Gemini as a regular LLM using LangChain, with practical examples of prompt templates, single and batch execution, and reliability-focused LLM workflows.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors