Skip to main content

Pull/push a prompt

Install packages

pip install -U langchain langchainhub langchain-openai

Configure environment variables

If you already have LANGCHAIN_API_KEY set to a personal organization's api key from LangSmith, you can skip this step.

Otherwise, get an API key for your Personal organization by navigating to Settings > API Keys > Create API Key in LangSmith. (The hub will not work with your non-personal organization's api key!)

Set your environment variable.

export LANGCHAIN_HUB_API_KEY="ls_..."

Pull a prompt and use it

You can pull your own prompts and all of the public prompts in the LangChain Hub.

from langchain import hub

# pull a chat prompt
prompt = hub.pull("efriis/my-first-prompt")

# create a model to use it with
from langchain_openai import ChatOpenAI
model = ChatOpenAI()

# use it in a runnable
runnable = prompt | model
response = runnable.invoke({
"profession": "biologist",
"question": "What is special about parrots?",
})

print(response)

You can also pull a specific commit of a prompt by specifying the commit hash.

prompt = hub.pull("efriis/my-first-prompt:56489e79")

Push a prompt to your personal organization

For this step, you'll need the handle for your account!

from langchain import hub
from langchain.prompts.chat import ChatPromptTemplate

prompt = ChatPromptTemplate.from_template("tell me a joke about {topic}")

hub.push("<handle>/topic-joke-generator", prompt, new_repo_is_public=False)

Was this page helpful?


You can leave detailed feedback on GitHub.