SlideShare a Scribd company logo
1 of 20
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

Similar to Generative AI Application Development using LangChain and LangFlow

MuleSoft Surat Virtual Meetup#16 - Anypoint Deployment Option, API and Operat...
MuleSoft Surat Virtual Meetup#16 - Anypoint Deployment Option, API and Operat...MuleSoft Surat Virtual Meetup#16 - Anypoint Deployment Option, API and Operat...
MuleSoft Surat Virtual Meetup#16 - Anypoint Deployment Option, API and Operat...Jitendra Bafna
 
The Bespoke Software Product Factory (2007)
The Bespoke Software Product Factory (2007)The Bespoke Software Product Factory (2007)
The Bespoke Software Product Factory (2007)Peter Antman
 
Top 10 Software Testing Tools to Know as a Tester.pdf
Top 10 Software Testing Tools to Know as a Tester.pdfTop 10 Software Testing Tools to Know as a Tester.pdf
Top 10 Software Testing Tools to Know as a Tester.pdfAnanthReddy38
 
Top 10 Software Testing Tools to Know as a Tester.pdf
Top 10 Software Testing Tools to Know as a Tester.pdfTop 10 Software Testing Tools to Know as a Tester.pdf
Top 10 Software Testing Tools to Know as a Tester.pdfAnanthReddy38
 
Developing Highly Instrumented Applications with Minimal Effort
Developing Highly Instrumented Applications with Minimal EffortDeveloping Highly Instrumented Applications with Minimal Effort
Developing Highly Instrumented Applications with Minimal EffortTim Hobson
 
Database project edi
Database project ediDatabase project edi
Database project ediRey Jefferson
 
Vinayak_Sdet_DevOps_Bigdata_5_years
Vinayak_Sdet_DevOps_Bigdata_5_yearsVinayak_Sdet_DevOps_Bigdata_5_years
Vinayak_Sdet_DevOps_Bigdata_5_yearsVinayaka V Ladwa
 
Making the Strategic Shift to Open Source at Fujitsu Network Communication
Making the Strategic Shift to Open Source at Fujitsu Network CommunicationMaking the Strategic Shift to Open Source at Fujitsu Network Communication
Making the Strategic Shift to Open Source at Fujitsu Network CommunicationBlack Duck by Synopsys
 
Building and deploying LLM applications with Apache Airflow
Building and deploying LLM applications with Apache AirflowBuilding and deploying LLM applications with Apache Airflow
Building and deploying LLM applications with Apache AirflowKaxil Naik
 
Nyc mule soft_meetup_13_march_2021
Nyc mule soft_meetup_13_march_2021Nyc mule soft_meetup_13_march_2021
Nyc mule soft_meetup_13_march_2021NeerajKumar1965
 
Arunkumar_profile
Arunkumar_profileArunkumar_profile
Arunkumar_profileArunkumar P
 
SDLC and Software Process Models
SDLC and Software Process ModelsSDLC and Software Process Models
SDLC and Software Process ModelsNana Sarpong
 
Project report for final year project
Project report for final year projectProject report for final year project
Project report for final year projectsuneel singh
 

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

Jagrat_Mankad
Jagrat_MankadJagrat_Mankad
Jagrat_Mankad
 
MuleSoft Surat Virtual Meetup#16 - Anypoint Deployment Option, API and Operat...
MuleSoft Surat Virtual Meetup#16 - Anypoint Deployment Option, API and Operat...MuleSoft Surat Virtual Meetup#16 - Anypoint Deployment Option, API and Operat...
MuleSoft Surat Virtual Meetup#16 - Anypoint Deployment Option, API and Operat...
 
The Bespoke Software Product Factory (2007)
The Bespoke Software Product Factory (2007)The Bespoke Software Product Factory (2007)
The Bespoke Software Product Factory (2007)
 
Document Summarizer
Document SummarizerDocument Summarizer
Document Summarizer
 
Msr2021 tutorial-di penta
Msr2021 tutorial-di pentaMsr2021 tutorial-di penta
Msr2021 tutorial-di penta
 
Top 10 Software Testing Tools to Know as a Tester.pdf
Top 10 Software Testing Tools to Know as a Tester.pdfTop 10 Software Testing Tools to Know as a Tester.pdf
Top 10 Software Testing Tools to Know as a Tester.pdf
 
Top 10 Software Testing Tools to Know as a Tester.pdf
Top 10 Software Testing Tools to Know as a Tester.pdfTop 10 Software Testing Tools to Know as a Tester.pdf
Top 10 Software Testing Tools to Know as a Tester.pdf
 
SANJAY_SINGH
SANJAY_SINGHSANJAY_SINGH
SANJAY_SINGH
 
Vedic Calculator
Vedic CalculatorVedic Calculator
Vedic Calculator
 
Opentracing 101
Opentracing 101Opentracing 101
Opentracing 101
 
Developing Highly Instrumented Applications with Minimal Effort
Developing Highly Instrumented Applications with Minimal EffortDeveloping Highly Instrumented Applications with Minimal Effort
Developing Highly Instrumented Applications with Minimal Effort
 
Database project edi
Database project ediDatabase project edi
Database project edi
 
Vinayak_Sdet_DevOps_Bigdata_5_years
Vinayak_Sdet_DevOps_Bigdata_5_yearsVinayak_Sdet_DevOps_Bigdata_5_years
Vinayak_Sdet_DevOps_Bigdata_5_years
 
Making the Strategic Shift to Open Source at Fujitsu Network Communication
Making the Strategic Shift to Open Source at Fujitsu Network CommunicationMaking the Strategic Shift to Open Source at Fujitsu Network Communication
Making the Strategic Shift to Open Source at Fujitsu Network Communication
 
Building and deploying LLM applications with Apache Airflow
Building and deploying LLM applications with Apache AirflowBuilding and deploying LLM applications with Apache Airflow
Building and deploying LLM applications with Apache Airflow
 
kishore
kishorekishore
kishore
 
Nyc mule soft_meetup_13_march_2021
Nyc mule soft_meetup_13_march_2021Nyc mule soft_meetup_13_march_2021
Nyc mule soft_meetup_13_march_2021
 
Arunkumar_profile
Arunkumar_profileArunkumar_profile
Arunkumar_profile
 
SDLC and Software Process Models
SDLC and Software Process ModelsSDLC and Software Process Models
SDLC and Software Process Models
 
Project report for final year project
Project report for final year projectProject report for final year project
Project report for final year project
 

More from Gene Leybzon

Generative AI Use cases for Enterprise - Second Session
Generative AI Use cases for Enterprise - Second SessionGenerative AI Use cases for Enterprise - Second Session
Generative AI Use cases for Enterprise - Second SessionGene Leybzon
 
Generative AI Use-cases for Enterprise - First Session
Generative AI Use-cases for Enterprise - First SessionGenerative AI Use-cases for Enterprise - First Session
Generative AI Use-cases for Enterprise - First SessionGene Leybzon
 
Non-fungible tokens (nfts)
Non-fungible tokens (nfts)Non-fungible tokens (nfts)
Non-fungible tokens (nfts)Gene Leybzon
 
Introduction to Solidity and Smart Contract Development (9).pptx
Introduction to Solidity and Smart Contract Development (9).pptxIntroduction to Solidity and Smart Contract Development (9).pptx
Introduction to Solidity and Smart Contract Development (9).pptxGene Leybzon
 
Ethereum in Enterprise.pptx
Ethereum in Enterprise.pptxEthereum in Enterprise.pptx
Ethereum in Enterprise.pptxGene Leybzon
 
ERC-4907 Rentable NFT Standard.pptx
ERC-4907 Rentable NFT Standard.pptxERC-4907 Rentable NFT Standard.pptx
ERC-4907 Rentable NFT Standard.pptxGene Leybzon
 
Onchain Decentralized Governance 2.pptx
Onchain Decentralized Governance 2.pptxOnchain Decentralized Governance 2.pptx
Onchain Decentralized Governance 2.pptxGene Leybzon
 
Onchain Decentralized Governance.pptx
Onchain Decentralized Governance.pptxOnchain Decentralized Governance.pptx
Onchain Decentralized Governance.pptxGene Leybzon
 
Web3 File Storage Options
Web3 File Storage OptionsWeb3 File Storage Options
Web3 File Storage OptionsGene Leybzon
 
Web3 Full Stack Development
Web3 Full Stack DevelopmentWeb3 Full Stack Development
Web3 Full Stack DevelopmentGene Leybzon
 
Instantly tradeable NFT contracts based on ERC-1155 standard
Instantly tradeable NFT contracts based on ERC-1155 standardInstantly tradeable NFT contracts based on ERC-1155 standard
Instantly tradeable NFT contracts based on ERC-1155 standardGene Leybzon
 
Non-fungible tokens. From smart contract code to marketplace
Non-fungible tokens. From smart contract code to marketplaceNon-fungible tokens. From smart contract code to marketplace
Non-fungible tokens. From smart contract code to marketplaceGene Leybzon
 
The Art of non-fungible tokens
The Art of non-fungible tokensThe Art of non-fungible tokens
The Art of non-fungible tokensGene Leybzon
 
Graph protocol for accessing information about blockchains and d apps
Graph protocol for accessing information about blockchains and d appsGraph protocol for accessing information about blockchains and d apps
Graph protocol for accessing information about blockchains and d appsGene Leybzon
 
Substrate Framework
Substrate FrameworkSubstrate Framework
Substrate FrameworkGene Leybzon
 
OpenZeppelin + Remix + BNB smart chain
OpenZeppelin + Remix + BNB smart chainOpenZeppelin + Remix + BNB smart chain
OpenZeppelin + Remix + BNB smart chainGene Leybzon
 
Chainlink, Cosmos, Kusama, Polkadot: Approaches to the Internet of Blockchains
Chainlink, Cosmos, Kusama, Polkadot:   Approaches to the Internet of BlockchainsChainlink, Cosmos, Kusama, Polkadot:   Approaches to the Internet of Blockchains
Chainlink, Cosmos, Kusama, Polkadot: Approaches to the Internet of BlockchainsGene Leybzon
 

More from Gene Leybzon (20)

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

Recently uploaded

The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 

Recently uploaded (20)

The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 

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