Skip to main content

Building applications with LLMs through composability

Project description

🦜️🔗 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
  • Wikipedia:
    • Install requirements with pip install wikipedia

🚀 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.

🤖 Developer Guide

To begin developing on this project, first clone to the repo locally. To install requirements, run pip install -r requirments.txt. This will install all requirements for running the package, examples, linting, formatting, and tests.

Formatting for this project is a combination of Black and isort. To run formatting for this project, run make format.

Linting for this project is a combination of Black, isort, flake8, and mypy. To run linting for this project, run make lint. We recognize linting can be annoying - if you do not want to do it, please contact a project maintainer and they can help you with it. We do not want this to be a blocker for good code getting contributed.

Unit tests cover modular logic that does not require calls to outside apis. To run unit tests, run make tests. If you add new logic, please add a unit test.

Integration tests cover logic that requires making calls to outside APIs (often integration with other services). To run integration tests, run make integration_tests. If you add support for a new external API, please add a new integration test.

Docs are largely autogenerated by sphinx from the code. For that reason, we ask that you add good documentation to all classes and methods. Similar to linting, we recognize documentation can be annoying - if you do not want to do it, please contact a project maintainer and they can help you with it. We do not want this to be a blocker for good code getting contributed.

Project details


Release history Release notifications | RSS feed

This version

0.0.6

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain-0.0.6.tar.gz (36.2 kB view details)

Uploaded Source

Built Distribution

langchain-0.0.6-py3-none-any.whl (60.4 kB view details)

Uploaded Python 3

File details

Details for the file langchain-0.0.6.tar.gz.

File metadata

  • Download URL: langchain-0.0.6.tar.gz
  • Upload date:
  • Size: 36.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.6

File hashes

Hashes for langchain-0.0.6.tar.gz
Algorithm Hash digest
SHA256 d526a026c95e5c03ce43b99f72f0504435060a28dc60d14f81205cf80d016c23
MD5 86bbefe7a27458f48e993b81b638f481
BLAKE2b-256 c7d8dbc532ee2284e7884fdd270bed4537934e84950f95c350ab1aaa8eb6ba08

See more details on using hashes here.

File details

Details for the file langchain-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: langchain-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 60.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.6

File hashes

Hashes for langchain-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 1a0d960109a5805d2b29ea6a0c04673e2c9588252a740ce55bbb93c4fee34d6a
MD5 fb57ca1b52d5d443ac9070af567f6aaf
BLAKE2b-256 a865bb4dd9197c1212b5ce9690aff1e0b1f6f440014598763b82cc6ab7945be5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page