[TOC]

  1. Title: Langchain Use Cases 2023
  2. Review Date: Sat, Aug 26, 2023
  3. url: https://python.langchain.com/docs/get_started/quickstart

Langchain quickstart

PromptTemplate

Chains: Combine LLMs and prompts in multi-step workflows

1
2
from langchain.chains import LLMChain
chain = LLMChain(llm=llm, prompt=prompt)

Agents: dynamically call chains based on user input

1
2
3
from langchain.agents import load_tools
from langchain.agents import initialize_agent
from langchain.llms import OpenAI

we can connect Google AI with ChatGPT

memory: add state to chains and agents

Langchain Schema

Chat Messages

Document

Langchain model

Language model

Chat model

Text embedding model

Prompt

example selector

SemanticSimilarityExampleSelector

image-20230826182346469

Output Parsers

Indexes โ€“ Structuring documents to LLMs

Document loaders

Text splitter

Memory

image-20230827112610400

Chains

Simple sequential chain

Summarisation chain

Agents

image-20230827113142482

Extraction

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# To help construct chat message 
from langchain.schema import HumanMessage
from langchain.prompts import PromptTemplate, ChatPromptTemplate, HumanMessagePromptTemplate

# to parse output and get structured data back
from langchain.output_parsers import StructuredOutputParser, ResponseSchema

output_parser = StructuredOutputParser.from_response_schemas(response_schema)
# the format instructions are LangChain makes, 
format_instructions = output_parser.get_format_instructions()

# the format_instruction will be refered as partial_variables in PromptTemplate

Question Answering

1
qa = VectorDBQA.from_chain_type(llm=OpenAI(), chain_type='stuff', vectorstore=docsearch, return_source_document=True)

NL Info to PDDL configs