SlideShare a Scribd company logo
4
Most read
13
Most read
19
Most read
LangChain and LangFlow
Gene Leybzon, Jim Steele
February 1, 2023
DISCLAIMER
§ The views and opinions expressed by the Presenter are those of the Presenter.
§ Presentation is not intended as legal or financial advice and may not be used as legal or
financial advice.
§ Every effort has been made to assure this information is up-to-date as of the date of
publication.
Agenda for today
1. LangChain Concept
2. Demo
3. LangFlow
4. Q&A
LangChain
Value Proposition:
LangChain is designed as a comprehensive toolkit for
developers working with large language models (LLMs).
It aims to facilitate the creation of applications that are
context-aware and capable of reasoning, thereby
enhancing the practical utility of LLMs in various
scenarios.
Purpose:
LangChain simplifies the transition from prototype to
production, offering a suite of tools for debugging, testing,
evaluation, and monitoring.
Parts of LangChain Framework
https://www.langchain.com/
•Libraries: Available in Python and JavaScript, these
libraries offer interfaces and integrations for various
components, a runtime for creating chains and agents,
and ready-made chain and agent implementations.
•Templates: This is a set of deployable reference
architectures for diverse tasks, facilitating ease of
deployment.
•LangServe: A specialized library for converting
LangChain chains into a REST API, enhancing
accessibility and integration.
•LangSmith: A comprehensive developer platform
designed for debugging, testing, evaluating, and
monitoring chains created with any LLM framework,
fully compatible with LangChain.
GenAI Application Development with LangChain
Develop
• Streamlined Prototyping:
Simplifies the process of
creating prototypes with large
language models.
• Context-Aware Systems:
Facilitates the building of
applications that understand
and utilize context effectively.
• Integration Support: Offers
tools for integrating various
data sources and components.
• Production Readiness: Provides
resources for debugging, testing,
evaluating, and monitoring
applications.
• Collaborative Development:
Encourages and supports
collaborative efforts in the
developer community.
• Diverse Applications: Suitable
for a wide range of
applications, from chatbots to
document analysis.
Turn into product
• Scalability: Provides tools to
scale applications from small
prototypes to larger,
production-level systems.
• Robust Testing: Offers robust
testing frameworks to ensure
application reliability.
• Monitoring Tools: Includes
monitoring capabilities to track
performance and user
interactions.
• Deployment Ease: Simplifies the
deployment process, making it
easier to launch applications.
• Continuous Improvement:
Supports ongoing development
and refinement of applications
post-launch.
Deploy
• LangServe: A library that allows
for the deployment of
LangChain chains as REST APIs,
making applications easily
accessible and integrable.
• Deployment Templates: Ready-
to-use reference architectures
that streamline the deployment
process for various tasks.
• Scalability Tools: Supports the
scaling of applications from
development to production level.
• Ease of Integration: Ensures
seamless integration with
existing systems and workflows.
• Production-Grade Support:
Offers features for ensuring
stability and performance in
production environments.
LangChain Components
LangChain components are designed
to enhance the development and
deployment of applications using large
language models. Components are
modular and easy-to-use, whether you
are using the rest of the LangChain
framework or not
https://python.langchain.com/docs/integrations
/components
LangChain Libraries
langchain-
core
• Base
abstractions
• LangChain
Expression
Language
langchain-
community
• Chat
Models
• Email Tools
• Database
integrations
langchain
• Chains
• Agents
• Data
Retrieval
Strategies
Base Abstractions
LangChain Base abstractions are
designed to simplify the process of
integrating and utilizing Large Language
Models (LLMs) in various applications.
These abstractions likely include
components for handling different
aspects of LLM integration, such as data
processing, model interaction, and
response generation. They are structured
to provide a foundation for building
complex LLM-based solutions,
streamlining development and allowing
for more efficient deployment. For a
detailed list and explanation of these
base abstractions, you would need to
refer to Langchain documentation or their
GitHub repository.
1.Languagemodels: This abstraction deals with the interaction with
language models. It includes the functionality to send prompts to a
language model and receive responses.
2.Chains: Chains are sequences of operations or transformations
applied to data. In Langchain, chains are used to process the input and
output of language models, allowing for complex workflows.
3.Apps: This abstraction is about building applications that use
language models. Apps combine different chains and models to create
an end-to-end application.
4.Actuators: Actuators are about taking action based on the output of
a language model. This could include sending an email, generating a
report, or any other action that results from the language model's
output.
5.World Models: These are abstractions for representing and
understanding the state of the world. They can be used to maintain
context or state across interactions with a language model.
6.Orchestrators: Orchestrators manage and coordinate the
interactions between different components of the system, such as the
language model, chains, actuators, and world models.
7.Components: These are smaller building blocks used within
chains. Components can be anything from a simple text processing
function to a complex neural network.
8.Data Sources: Abstractions for managing and accessing data that
the language model or other components might need. This could
include databases, APIs, or file systems.
LANGCHAIN DEMO
INSTALLATION AND CONFIGURATION
pip install langchain
pip install langchain-openai OPENAI_API_KEY
sudo vi /etc/launchd.conf
export OPENAI_API_KEY = “K
Install LangChain and OpenAI Model: Set up API KEY for OpenAI:
HELLO OPENAI LANGCHAIN
from langchain_openai import ChatOpenAI
llm = ChatOpenAI()
r = llm.invoke("how can langsmith help with testing?")
print(r)
PROMPT TEMPLATE
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
llm = ChatOpenAI()
prompt = ChatPromptTemplate.from_messages([
("system", "You are world class technical documentation writer."),
("user", "{input}")
])
chain = prompt | llm
r = chain.invoke({"input": "how can langsmith help with testing?"})
print(r)
OUTPUT PARSER
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
llm = ChatOpenAI()
prompt = ChatPromptTemplate.from_messages([
("system", "You are world class technical documentation writer."),
("user", "{input}")
])
output_parser = StrOutputParser()
chain = prompt | llm | output_parser
r = chain.invoke({"input": "how can langsmith help with testing?"})
print(r)
“RANDOM” AGENT
import sys
import random
from langchain_openai import ChatOpenAI
from langchain.agents import tool
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_community.tools.convert_to_openai import format_tool_to_openai_function
from langchain.agents.format_scratchpad import format_to_openai_function_messages
from langchain.agents.output_parsers import OpenAIFunctionsAgentOutputParser
from langchain.agents import AgentExecutor
@tool
def get_word_length(word: str) -> int:
"""Returns the length of a word."""
return len(word)
@tool
def random_number() -> int:
"""Returns random number"""
return random.randint(0, sys.maxsize)
tools = [get_word_length, random_number]
llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0)
prompt = ChatPromptTemplate.from_messages(
[
(
"system",
"You are very powerful assistant, but don't know current events",
),
("user", "{input}"),
MessagesPlaceholder(variable_name="agent_scratchpad"),
]
)
llm_with_tools = llm.bind(functions=[format_tool_to_openai_function(t) for t in tools])
agent = (
{
"input": lambda x: x["input"],
"agent_scratchpad": lambda x: format_to_openai_function_messages(
x["intermediate_steps"]
),
}
| prompt
| llm_with_tools
| OpenAIFunctionsAgentOutputParser()
)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
agent_executor.invoke({"input": "How many letters in the word educator"})
agent_executor.invoke({"input": "Generate 10 random numbers"})
THE ROLE OF ART AND POETRY
# Import necessary modules and classes
import os
import json
import datetime
from langchain.agents import load_tools, initialize_agent, AgentType, ZeroShotAgent, Tool, AgentExecutor
from langchain_community.utilities import SerpAPIWrapper
from typing import List, Dict, Callable
from langchain.chains import ConversationChain
from langchain_openai import OpenAI, ChatOpenAI
from langchain.memory import ConversationBufferMemory
from langchain.prompts.prompt import PromptTemplate
from langchain.schema import AIMessage, HumanMessage, SystemMessage, BaseMessage
from jinja2 import Environment, FileSystemLoader
# Set environment variables for API keys and configurations
#os.environ['OPENAI_API_KEY'] = str("")
#os.environ["SERPAPI_API_KEY"] = str("")
os.environ["LANGCHAIN_TRACING_V2"]="false"
os.environ["LANGCHAIN_ENDPOINT"]="https://api.smith.langchain.com"
#os.environ["LANGCHAIN_API_KEY"]="" #https://smith.langchain.com/
os.environ["LANGCHAIN_PROJECT"]="pt-wooden-infix-62"
#Constants
#topic = "Ethics and the Good Life"
topic = "The Role of Art and Poetry"
word_limit = 300
names = {
"Plato": ["arxiv", "ddg-search", "wikipedia"],
"Aristotle": ["arxiv", "ddg-search", "wikipedia"],
}
max_dialogue_rounds = 8
#Language Model Initialization
llm = OpenAI(temperature=0, model_name='gpt-4-1106-preview’)
...
Plato Aristotle
Your name is {name}.
Your description is as follows: {description}
Your goal is to persuade your conversation partner of your point of view.
DO look up information with your tool to refute your partner's claims.
DO cite your sources.
DO NOT fabricate fake citations.
DO NOT cite any source that you did not look up.
Do not add anything else.
Stop speaking the moment you finish speaking from your perspective.
LANGFLOW
LANGFLOW – GUI FOR LANGCHAIN
QUESTIONS?
About Presenter
https://www.meetup.com/members/9074420/
https://www.linkedin.com/in/leybzon/

More Related Content

What's hot (20)

PDF
How Does Generative AI Actually Work? (a quick semi-technical introduction to...
ssuser4edc93
 
PDF
Large Language Models - Chat AI.pdf
David Rostcheck
 
PDF
LanGCHAIN Framework
Keymate.AI
 
PDF
The current state of generative AI
Benjaminlapid1
 
PDF
Using the power of Generative AI at scale
Maxim Salnikov
 
PDF
Neural Language Generation Head to Toe
Hady Elsahar
 
PDF
Unlocking the Power of Generative AI An Executive's Guide.pdf
PremNaraindas1
 
PDF
The Rise of the LLMs - How I Learned to Stop Worrying & Love the GPT!
taozen
 
PDF
Cavalry Ventures | Deep Dive: Generative AI
Cavalry Ventures
 
PPTX
Journey of Generative AI
thomasjvarghese49
 
PPTX
A brief primer on OpenAI's GPT-3
Ishan Jain
 
PDF
gpt3_presentation.pdf
Giacomo Frisoni
 
PDF
Let's talk about GPT: A crash course in Generative AI for researchers
Steven Van Vaerenbergh
 
PDF
Generative-AI-in-enterprise-20230615.pdf
Liming Zhu
 
PDF
Microsoft + OpenAI: Recent Updates (Machine Learning 15minutes! Broadcast #74)
Naoki (Neo) SATO
 
PDF
Generative AI: Past, Present, and Future – A Practitioner's Perspective
Huahai Yang
 
PDF
Best Practice on using Azure OpenAI Service
Kumton Suttiraksiri
 
PDF
An Introduction to Generative AI - May 18, 2023
CoriFaklaris1
 
PPTX
Using Generative AI
Mark DeLoura
 
PPTX
Generative AI.pptx
RohitRadhakrishnan8
 
How Does Generative AI Actually Work? (a quick semi-technical introduction to...
ssuser4edc93
 
Large Language Models - Chat AI.pdf
David Rostcheck
 
LanGCHAIN Framework
Keymate.AI
 
The current state of generative AI
Benjaminlapid1
 
Using the power of Generative AI at scale
Maxim Salnikov
 
Neural Language Generation Head to Toe
Hady Elsahar
 
Unlocking the Power of Generative AI An Executive's Guide.pdf
PremNaraindas1
 
The Rise of the LLMs - How I Learned to Stop Worrying & Love the GPT!
taozen
 
Cavalry Ventures | Deep Dive: Generative AI
Cavalry Ventures
 
Journey of Generative AI
thomasjvarghese49
 
A brief primer on OpenAI's GPT-3
Ishan Jain
 
gpt3_presentation.pdf
Giacomo Frisoni
 
Let's talk about GPT: A crash course in Generative AI for researchers
Steven Van Vaerenbergh
 
Generative-AI-in-enterprise-20230615.pdf
Liming Zhu
 
Microsoft + OpenAI: Recent Updates (Machine Learning 15minutes! Broadcast #74)
Naoki (Neo) SATO
 
Generative AI: Past, Present, and Future – A Practitioner's Perspective
Huahai Yang
 
Best Practice on using Azure OpenAI Service
Kumton Suttiraksiri
 
An Introduction to Generative AI - May 18, 2023
CoriFaklaris1
 
Using Generative AI
Mark DeLoura
 
Generative AI.pptx
RohitRadhakrishnan8
 

Similar to Generative AI Application Development using LangChain and LangFlow (20)

PDF
Build an LLM-powered application using LangChain.pdf
MatthewHaws4
 
PPTX
Langchain Explained | What is Langchain? | Langchain Tutorial For Beginners |...
Simplilearn
 
PPTX
Langchain Explained | What is Langchain? | Langchain Tutorial For Beginners |...
mayankbanoula2
 
PPTX
Day_16_LangChain_HuggingFace_Groq_Sp25.pptx
nealonkyle
 
PDF
How Langchain Frameworks Work An In-depth Exploration.pdf
Aivada
 
PPTX
Langchainfdgdfsggfdgfsdgsdgdfsgfdgfdgfdgfd
topstar00416
 
PDF
clicks2conversations.pdf
Marie-Alice Blete
 
PDF
Intro to Generative-AI(Gen AI Study Jams GDGC ZHCET)
fiza1892003
 
PDF
Collborative Agents with Tools & Knowledge (Graphs) using LangGraph & LangChain
Tilores
 
PDF
Building Agents with LangGraph & Gemini
HusseinMalikMammadli
 
PDF
LangChain Intro by KeyMate.AI
OzgurOscarOzkan
 
PPTX
PyBay23: Understanding LangChain Agents and Tools with Twilio (or with SMS)....
Elizabeth (Lizzie) Siegle
 
PPTX
62-AI-langchain and how it is revolutionzing artificial intelligence.pptx
Doug Ortiz
 
PPTX
GenAI_Langchain_LlamaIndex_NLP_to_SQL.pptx
sachintripathi513074
 
PDF
Agentic AI Use Cases using GenAI LLM models
Manish Chopra
 
PPTX
Generative AI in CSharp with Semantic Kernel.pptx
Alon Fliess
 
PDF
1Z0-1127-24 Exam Dumps (Oracle Cloud Infrastructure 2024 Generative AI Profes...
Mark Soia
 
PDF
Developing Apps with GPT-4 and ChatGPT_ Build Intelligent Chatbots, Content G...
BIHI Oussama
 
PPTX
Deep dive into LangChain integration with Neo4j.pptx
TomazBratanic1
 
PDF
Luigi presentation NYC Data Science
Erik Bernhardsson
 
Build an LLM-powered application using LangChain.pdf
MatthewHaws4
 
Langchain Explained | What is Langchain? | Langchain Tutorial For Beginners |...
Simplilearn
 
Langchain Explained | What is Langchain? | Langchain Tutorial For Beginners |...
mayankbanoula2
 
Day_16_LangChain_HuggingFace_Groq_Sp25.pptx
nealonkyle
 
How Langchain Frameworks Work An In-depth Exploration.pdf
Aivada
 
Langchainfdgdfsggfdgfsdgsdgdfsgfdgfdgfdgfd
topstar00416
 
clicks2conversations.pdf
Marie-Alice Blete
 
Intro to Generative-AI(Gen AI Study Jams GDGC ZHCET)
fiza1892003
 
Collborative Agents with Tools & Knowledge (Graphs) using LangGraph & LangChain
Tilores
 
Building Agents with LangGraph & Gemini
HusseinMalikMammadli
 
LangChain Intro by KeyMate.AI
OzgurOscarOzkan
 
PyBay23: Understanding LangChain Agents and Tools with Twilio (or with SMS)....
Elizabeth (Lizzie) Siegle
 
62-AI-langchain and how it is revolutionzing artificial intelligence.pptx
Doug Ortiz
 
GenAI_Langchain_LlamaIndex_NLP_to_SQL.pptx
sachintripathi513074
 
Agentic AI Use Cases using GenAI LLM models
Manish Chopra
 
Generative AI in CSharp with Semantic Kernel.pptx
Alon Fliess
 
1Z0-1127-24 Exam Dumps (Oracle Cloud Infrastructure 2024 Generative AI Profes...
Mark Soia
 
Developing Apps with GPT-4 and ChatGPT_ Build Intelligent Chatbots, Content G...
BIHI Oussama
 
Deep dive into LangChain integration with Neo4j.pptx
TomazBratanic1
 
Luigi presentation NYC Data Science
Erik Bernhardsson
 
Ad

More from Gene Leybzon (20)

PPTX
Chat GPTs
Gene Leybzon
 
PPTX
Generative AI Use cases for Enterprise - Second Session
Gene Leybzon
 
PPTX
Generative AI Use-cases for Enterprise - First Session
Gene Leybzon
 
PPTX
Non-fungible tokens (nfts)
Gene Leybzon
 
PPTX
Introduction to Solidity and Smart Contract Development (9).pptx
Gene Leybzon
 
PPTX
Ethereum in Enterprise.pptx
Gene Leybzon
 
PPTX
ERC-4907 Rentable NFT Standard.pptx
Gene Leybzon
 
PPTX
Onchain Decentralized Governance 2.pptx
Gene Leybzon
 
PPTX
Onchain Decentralized Governance.pptx
Gene Leybzon
 
PPTX
Web3 File Storage Options
Gene Leybzon
 
PPTX
Web3 Full Stack Development
Gene Leybzon
 
PPTX
Instantly tradeable NFT contracts based on ERC-1155 standard
Gene Leybzon
 
PPTX
Non-fungible tokens. From smart contract code to marketplace
Gene Leybzon
 
PPTX
The Art of non-fungible tokens
Gene Leybzon
 
PPTX
Graph protocol for accessing information about blockchains and d apps
Gene Leybzon
 
PPTX
Substrate Framework
Gene Leybzon
 
PPTX
Chainlink
Gene Leybzon
 
PPTX
OpenZeppelin + Remix + BNB smart chain
Gene Leybzon
 
PPTX
Chainlink, Cosmos, Kusama, Polkadot: Approaches to the Internet of Blockchains
Gene Leybzon
 
PPTX
Dex and Uniswap
Gene Leybzon
 
Chat GPTs
Gene Leybzon
 
Generative AI Use cases for Enterprise - Second Session
Gene Leybzon
 
Generative AI Use-cases for Enterprise - First Session
Gene Leybzon
 
Non-fungible tokens (nfts)
Gene Leybzon
 
Introduction to Solidity and Smart Contract Development (9).pptx
Gene Leybzon
 
Ethereum in Enterprise.pptx
Gene Leybzon
 
ERC-4907 Rentable NFT Standard.pptx
Gene Leybzon
 
Onchain Decentralized Governance 2.pptx
Gene Leybzon
 
Onchain Decentralized Governance.pptx
Gene Leybzon
 
Web3 File Storage Options
Gene Leybzon
 
Web3 Full Stack Development
Gene Leybzon
 
Instantly tradeable NFT contracts based on ERC-1155 standard
Gene Leybzon
 
Non-fungible tokens. From smart contract code to marketplace
Gene Leybzon
 
The Art of non-fungible tokens
Gene Leybzon
 
Graph protocol for accessing information about blockchains and d apps
Gene Leybzon
 
Substrate Framework
Gene Leybzon
 
Chainlink
Gene Leybzon
 
OpenZeppelin + Remix + BNB smart chain
Gene Leybzon
 
Chainlink, Cosmos, Kusama, Polkadot: Approaches to the Internet of Blockchains
Gene Leybzon
 
Dex and Uniswap
Gene Leybzon
 
Ad

Recently uploaded (20)

PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PPTX
Build a Custom Agent for Agentic Testing.pptx
klpathrudu
 
PPTX
Get Started with Maestro: Agent, Robot, and Human in Action – Session 5 of 5
klpathrudu
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
PDF
Salesforce Experience Cloud Consultant.pdf
VALiNTRY360
 
PPTX
Function & Procedure: Function Vs Procedure in PL/SQL
Shani Tiwari
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PDF
Why is partnering with a SaaS development company crucial for enterprise succ...
Nextbrain Technologies
 
PPTX
UI5con_2025_Accessibility_Ever_Evolving_
gerganakremenska1
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
PDF
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
PDF
Best Web development company in india 2025
Greenusys
 
PDF
Meet in the Middle: Solving the Low-Latency Challenge for Agentic AI
Alluxio, Inc.
 
PPTX
Library_Management_System_PPT111111.pptx
nmtnissancrm
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
Build a Custom Agent for Agentic Testing.pptx
klpathrudu
 
Get Started with Maestro: Agent, Robot, and Human in Action – Session 5 of 5
klpathrudu
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
Salesforce Experience Cloud Consultant.pdf
VALiNTRY360
 
Function & Procedure: Function Vs Procedure in PL/SQL
Shani Tiwari
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Why is partnering with a SaaS development company crucial for enterprise succ...
Nextbrain Technologies
 
UI5con_2025_Accessibility_Ever_Evolving_
gerganakremenska1
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
 
Best Web development company in india 2025
Greenusys
 
Meet in the Middle: Solving the Low-Latency Challenge for Agentic AI
Alluxio, Inc.
 
Library_Management_System_PPT111111.pptx
nmtnissancrm
 

Generative AI Application Development using LangChain and LangFlow

  • 1. LangChain and LangFlow Gene Leybzon, Jim Steele February 1, 2023
  • 2. DISCLAIMER § The views and opinions expressed by the Presenter are those of the Presenter. § Presentation is not intended as legal or financial advice and may not be used as legal or financial advice. § Every effort has been made to assure this information is up-to-date as of the date of publication.
  • 3. Agenda for today 1. LangChain Concept 2. Demo 3. LangFlow 4. Q&A
  • 4. LangChain Value Proposition: LangChain is designed as a comprehensive toolkit for developers working with large language models (LLMs). It aims to facilitate the creation of applications that are context-aware and capable of reasoning, thereby enhancing the practical utility of LLMs in various scenarios. Purpose: LangChain simplifies the transition from prototype to production, offering a suite of tools for debugging, testing, evaluation, and monitoring.
  • 5. Parts of LangChain Framework https://www.langchain.com/ •Libraries: Available in Python and JavaScript, these libraries offer interfaces and integrations for various components, a runtime for creating chains and agents, and ready-made chain and agent implementations. •Templates: This is a set of deployable reference architectures for diverse tasks, facilitating ease of deployment. •LangServe: A specialized library for converting LangChain chains into a REST API, enhancing accessibility and integration. •LangSmith: A comprehensive developer platform designed for debugging, testing, evaluating, and monitoring chains created with any LLM framework, fully compatible with LangChain.
  • 6. GenAI Application Development with LangChain Develop • Streamlined Prototyping: Simplifies the process of creating prototypes with large language models. • Context-Aware Systems: Facilitates the building of applications that understand and utilize context effectively. • Integration Support: Offers tools for integrating various data sources and components. • Production Readiness: Provides resources for debugging, testing, evaluating, and monitoring applications. • Collaborative Development: Encourages and supports collaborative efforts in the developer community. • Diverse Applications: Suitable for a wide range of applications, from chatbots to document analysis. Turn into product • Scalability: Provides tools to scale applications from small prototypes to larger, production-level systems. • Robust Testing: Offers robust testing frameworks to ensure application reliability. • Monitoring Tools: Includes monitoring capabilities to track performance and user interactions. • Deployment Ease: Simplifies the deployment process, making it easier to launch applications. • Continuous Improvement: Supports ongoing development and refinement of applications post-launch. Deploy • LangServe: A library that allows for the deployment of LangChain chains as REST APIs, making applications easily accessible and integrable. • Deployment Templates: Ready- to-use reference architectures that streamline the deployment process for various tasks. • Scalability Tools: Supports the scaling of applications from development to production level. • Ease of Integration: Ensures seamless integration with existing systems and workflows. • Production-Grade Support: Offers features for ensuring stability and performance in production environments.
  • 7. LangChain Components LangChain components are designed to enhance the development and deployment of applications using large language models. Components are modular and easy-to-use, whether you are using the rest of the LangChain framework or not https://python.langchain.com/docs/integrations /components
  • 8. LangChain Libraries langchain- core • Base abstractions • LangChain Expression Language langchain- community • Chat Models • Email Tools • Database integrations langchain • Chains • Agents • Data Retrieval Strategies
  • 9. Base Abstractions LangChain Base abstractions are designed to simplify the process of integrating and utilizing Large Language Models (LLMs) in various applications. These abstractions likely include components for handling different aspects of LLM integration, such as data processing, model interaction, and response generation. They are structured to provide a foundation for building complex LLM-based solutions, streamlining development and allowing for more efficient deployment. For a detailed list and explanation of these base abstractions, you would need to refer to Langchain documentation or their GitHub repository. 1.Languagemodels: This abstraction deals with the interaction with language models. It includes the functionality to send prompts to a language model and receive responses. 2.Chains: Chains are sequences of operations or transformations applied to data. In Langchain, chains are used to process the input and output of language models, allowing for complex workflows. 3.Apps: This abstraction is about building applications that use language models. Apps combine different chains and models to create an end-to-end application. 4.Actuators: Actuators are about taking action based on the output of a language model. This could include sending an email, generating a report, or any other action that results from the language model's output. 5.World Models: These are abstractions for representing and understanding the state of the world. They can be used to maintain context or state across interactions with a language model. 6.Orchestrators: Orchestrators manage and coordinate the interactions between different components of the system, such as the language model, chains, actuators, and world models. 7.Components: These are smaller building blocks used within chains. Components can be anything from a simple text processing function to a complex neural network. 8.Data Sources: Abstractions for managing and accessing data that the language model or other components might need. This could include databases, APIs, or file systems.
  • 11. INSTALLATION AND CONFIGURATION pip install langchain pip install langchain-openai OPENAI_API_KEY sudo vi /etc/launchd.conf export OPENAI_API_KEY = “K Install LangChain and OpenAI Model: Set up API KEY for OpenAI:
  • 12. HELLO OPENAI LANGCHAIN from langchain_openai import ChatOpenAI llm = ChatOpenAI() r = llm.invoke("how can langsmith help with testing?") print(r)
  • 13. PROMPT TEMPLATE from langchain_openai import ChatOpenAI from langchain_core.prompts import ChatPromptTemplate from langchain_core.output_parsers import StrOutputParser llm = ChatOpenAI() prompt = ChatPromptTemplate.from_messages([ ("system", "You are world class technical documentation writer."), ("user", "{input}") ]) chain = prompt | llm r = chain.invoke({"input": "how can langsmith help with testing?"}) print(r)
  • 14. OUTPUT PARSER from langchain_openai import ChatOpenAI from langchain_core.prompts import ChatPromptTemplate from langchain_core.output_parsers import StrOutputParser llm = ChatOpenAI() prompt = ChatPromptTemplate.from_messages([ ("system", "You are world class technical documentation writer."), ("user", "{input}") ]) output_parser = StrOutputParser() chain = prompt | llm | output_parser r = chain.invoke({"input": "how can langsmith help with testing?"}) print(r)
  • 15. “RANDOM” AGENT import sys import random from langchain_openai import ChatOpenAI from langchain.agents import tool from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder from langchain_community.tools.convert_to_openai import format_tool_to_openai_function from langchain.agents.format_scratchpad import format_to_openai_function_messages from langchain.agents.output_parsers import OpenAIFunctionsAgentOutputParser from langchain.agents import AgentExecutor @tool def get_word_length(word: str) -> int: """Returns the length of a word.""" return len(word) @tool def random_number() -> int: """Returns random number""" return random.randint(0, sys.maxsize) tools = [get_word_length, random_number] llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0) prompt = ChatPromptTemplate.from_messages( [ ( "system", "You are very powerful assistant, but don't know current events", ), ("user", "{input}"), MessagesPlaceholder(variable_name="agent_scratchpad"), ] ) llm_with_tools = llm.bind(functions=[format_tool_to_openai_function(t) for t in tools]) agent = ( { "input": lambda x: x["input"], "agent_scratchpad": lambda x: format_to_openai_function_messages( x["intermediate_steps"] ), } | prompt | llm_with_tools | OpenAIFunctionsAgentOutputParser() ) agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True) agent_executor.invoke({"input": "How many letters in the word educator"}) agent_executor.invoke({"input": "Generate 10 random numbers"})
  • 16. THE ROLE OF ART AND POETRY # Import necessary modules and classes import os import json import datetime from langchain.agents import load_tools, initialize_agent, AgentType, ZeroShotAgent, Tool, AgentExecutor from langchain_community.utilities import SerpAPIWrapper from typing import List, Dict, Callable from langchain.chains import ConversationChain from langchain_openai import OpenAI, ChatOpenAI from langchain.memory import ConversationBufferMemory from langchain.prompts.prompt import PromptTemplate from langchain.schema import AIMessage, HumanMessage, SystemMessage, BaseMessage from jinja2 import Environment, FileSystemLoader # Set environment variables for API keys and configurations #os.environ['OPENAI_API_KEY'] = str("") #os.environ["SERPAPI_API_KEY"] = str("") os.environ["LANGCHAIN_TRACING_V2"]="false" os.environ["LANGCHAIN_ENDPOINT"]="https://api.smith.langchain.com" #os.environ["LANGCHAIN_API_KEY"]="" #https://smith.langchain.com/ os.environ["LANGCHAIN_PROJECT"]="pt-wooden-infix-62" #Constants #topic = "Ethics and the Good Life" topic = "The Role of Art and Poetry" word_limit = 300 names = { "Plato": ["arxiv", "ddg-search", "wikipedia"], "Aristotle": ["arxiv", "ddg-search", "wikipedia"], } max_dialogue_rounds = 8 #Language Model Initialization llm = OpenAI(temperature=0, model_name='gpt-4-1106-preview’) ... Plato Aristotle Your name is {name}. Your description is as follows: {description} Your goal is to persuade your conversation partner of your point of view. DO look up information with your tool to refute your partner's claims. DO cite your sources. DO NOT fabricate fake citations. DO NOT cite any source that you did not look up. Do not add anything else. Stop speaking the moment you finish speaking from your perspective.
  • 18. LANGFLOW – GUI FOR LANGCHAIN