Building applications with LLMs through composability
Project description
🦜️🔗 LangChain
⚡ Building applications with LLMs through composability ⚡
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:
- a comprehensive collection of pieces you would ever want to combine
- a flexible interface for combining pieces into a single comprehensive "chain"
- 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 set environment variables for the services that call out to authenticated APIs. You do not need to set an environment variable unless you plan on using that API. Please see below for a comprehensive list of the APIs that require an API key, and the associated environment variable that you should set.
- OpenAI:
OPENAI_API_KEY
- Cohere:
COHERE_API_KEY
- SerpAPI (Google Search):
SERPAPI_API_KEY
🚀 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:
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?")
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file langchain-0.0.1.tar.gz
.
File metadata
- Download URL: langchain-0.0.1.tar.gz
- Upload date:
- Size: 21.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbcf4c7f8a86afee5cafa07058faa90d1dfa767e3ef574d0445098cc86542029 |
|
MD5 | 76e930f9268b9e41e612053f76cc77cc |
|
BLAKE2b-256 | 8809beaf684e52756a21e1cfa88fbff12651edde735731afd6084001bbe9a310 |
File details
Details for the file langchain-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: langchain-0.0.1-py3-none-any.whl
- Upload date:
- Size: 33.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8ebb241341e7cdb17368ea1d1d365bb337be3062aa17b7355f615666a476abf |
|
MD5 | 8f62d8caf417dc940ca50a6e8e7474e7 |
|
BLAKE2b-256 | be0debe0bc01784a4f95b076c76c939b5ee923c3cf3c4919e8c4ee39f02962f9 |