Skip to main content

🦜️🔗 LangChain

⚡ Building applications with LLMs through composability ⚡

lint test License: MIT

Quick Install

pip install langchain

🤔 What is this?

Large language models (LLMs) are emerging as a transformative technology, enabling developers to build applications that they previously could not. But using these LLMs in isolation is often not enough to create a truly powerful app - the real power comes when you are able to combine them with other sources of computation or knowledge.

This library is aimed at assisting in the development of those types of applications. It aims to create:

  1. a comprehensive collection of pieces you would ever want to combine
  2. a flexible interface for combining pieces into a single comprehensive "chain"
  3. a schema for easily saving and sharing those chains

🔧 Setting up your environment

Besides the installation of this python package, you will also need to install packages and set environment variables depending on which chains you want to use.

Note: the reason these packages are not included in the dependencies by default is that as we imagine scaling this package, we do not want to force dependencies that are not needed.

The following use cases require specific installs and environment variables:

  • OpenAI:
    • Install requirements with pip install openai
    • Set the following environment variable: OPENAI_API_KEY
  • Cohere:
    • Install requirements with pip install cohere
    • Set the following environment variable: COHERE_API_KEY
  • HuggingFace Hub
    • Install requirements with pip install huggingface_hub
    • Set the following environment variable: HUGGINGFACEHUB_API_TOKEN
  • SerpAPI:
    • Install requirements with pip install google-search-results
    • Set the following environment variable: SERPAPI_API_KEY
  • NatBot:
    • Install requirements with pip install playwright

🚀 What can I do with this

This project was largely inspired by a few projects seen on Twitter for which we thought it would make sense to have more explicit tooling. A lot of the initial functionality was done in an attempt to recreate those. Those are:

Self-ask-with-search

To recreate this paper, use the following code snippet or checkout the example notebook.

from langchain import SelfAskWithSearchChain, OpenAI, SerpAPIChain

llm = OpenAI(temperature=0)
search = SerpAPIChain()

self_ask_with_search = SelfAskWithSearchChain(llm=llm, search_chain=search)

self_ask_with_search.run("What is the hometown of the reigning men's U.S. Open champion?")

LLM Math

To recreate this example, use the following code snippet or check out the example notebook.

from langchain import OpenAI, LLMMathChain

llm = OpenAI(temperature=0)
llm_math = LLMMathChain(llm=llm)

llm_math.run("How many of the integers between 0 and 99 inclusive are divisible by 8?")

Generic Prompting

You can also use this for simple prompting pipelines, as in the below example and this example notebook.

from langchain import Prompt, OpenAI, LLMChain

template = """Question: {question}

Answer: Let's think step by step."""
prompt = Prompt(template=template, input_variables=["question"])
llm_chain = LLMChain(prompt=prompt, llm=OpenAI(temperature=0))

question = "What NFL team won the Super Bowl in the year Justin Beiber was born?"

llm_chain.predict(question=question)

📖 Documentation

The above examples are probably the most user friendly documentation that exists, but full API docs can be found here.

Metadata

Release files for langchain 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain 0.0.3
File Size Uploaded Provenance Actions
langchain-0.0.3.tar.gz 27.4 kB Without provenance Details for langchain-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for langchain 0.0.3
File Interpreter ABI Platform Actions
langchain-0.0.3-py3-none-any.whl Python 3 none any Details for langchain-0.0.3-py3-none-any.whl

Total release size: 72.5 kB

Release files / langchain-0.0.3.tar.gz

Download URL langchain-0.0.3.tar.gz
Size 27.4 kB
Tags Source
SHA-256 checksum
How to use checksums
be541865b13a253d4a10458dc46e216c5ea220c841633d48ca3a088effc59415
BLAKE2b-256 checksum
How to use checksums
84658c6ea7c6f657874770bdacf020e218d65d186144e4f1980bd34cc51765f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.7.6

Release files / langchain-0.0.3-py3-none-any.whl

Download URL langchain-0.0.3-py3-none-any.whl
Size 45.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5a5536c464a67a0b34d69babe2678e99ea77858e39f0b62806d3f91e84e7c304
BLAKE2b-256 checksum
How to use checksums
8e8d1b6b08f71568d8387c0107c945bc7e9d25ec847956f3887726969ab3bc1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.7.6

Security for langchain 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page