LangChain Hub Client

0.1.21 · active · verified Mon Apr 13

LangChain Hub (pypi-slug: `langchainhub`) is an API client for the LangChain Hub, a centralized platform for sharing and discovering high-quality artifacts like prompts, chains, and agents for building LLM applications. It allows users to upload, browse, retrieve, and manage these components. The current version is 0.1.21. It's actively developed as part of the broader LangChain ecosystem, with releases typically tied to LangChain updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to pull a prompt from the LangChain Hub and use it with a LangChain LLM (ChatOpenAI) to form a simple question-answering chain. It assumes an OpenAI API key is available, preferably as an environment variable.

import os
from langchain import hub
from langchain_openai import ChatOpenAI

# Set your API key as an environment variable (or replace with your actual key for testing)
# os.environ["OPENAI_API_KEY"] = os.environ.get("OPENAI_API_KEY", "YOUR_API_KEY")

# Pull a prompt from the LangChain Hub
prompt = hub.pull("hwchase17/q-and-a-prompt")

# Initialize a chat model (requires langchain-openai to be installed)
llm = ChatOpenAI(openai_api_key=os.environ.get("OPENAI_API_KEY", ""))

# Create a simple chain
chain = prompt | llm

# Invoke the chain
response = chain.invoke({"question": "What is the capital of France?", "context": "Paris is the capital of France."})
print(response.content)

view raw JSON →