03. LangChain Hub

Next is LangChain Hub Here is an example of receiving a prompt and executing it.

At the address below LangChain Hub You can check the prompt.

You can get the ID value of the prompt repo by using the method of receiving, and you can also get the prompt for a specific version by attaching the commit id.

Hub from Prompt receive

from langchain import hub

# Get the latest version of the prompt.
prompt = hub.pull("rlm/rag-prompt")
# Print prompt contents
print(prompt)
input_variables=['context', 'question'] metadata={'lc_hub_owner': 'rlm', 'lc_hub_repo': 'rag-prompt', 'lc_hub_commit_hash': '50442af133e61576e74536c6556cefe1fac147cad032f4377b60c436e6cdcb6e'} messages=[HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=['context', 'question'], template="You are an assistant for question-answering tasks. Use the following pieces of retrieved context to answer the question. If you don't know the answer, just say that you don't know. Use three sentences maximum and keep the answer concise.\nQuestion: {question} \nContext: {context} \nAnswer:"))]
# Specify a version hash to get a specific version of the prompt.
prompt = hub.pull("rlm/rag-prompt:50442af1")
prompt
ChatPromptTemplate(input_variables=['context', 'question'], metadata={'lc_hub_owner': 'rlm', 'lc_hub_repo': 'rag-prompt', 'lc_hub_commit_hash': '50442af133e61576e74536c6556cefe1fac147cad032f4377b60c436e6cdcb6e'}, messages=[HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=['context', 'question'], template="You are an assistant for question-answering tasks. Use the following pieces of retrieved context to answer the question. If you don't know the answer, just say that you don't know. Use three sentences maximum and keep the answer concise.\nQuestion: {question} \nContext: {context} \nAnswer:"))])

Prompt Hub Register your own prompt

from langchain.prompts import ChatPromptTemplate


prompt = ChatPromptTemplate.from_template(
    "Summarize the following sentences based on the given content. Your answer must be written in Korean: {context}\n\nSUMMARY:"
)
prompt

Below is the output after successful upload to Hub.

id

output of power: 'https://smith.langchain.com/hub/teddynote/simple-summary-korean/0e296563'

Last updated