From c0de6a3ff5920bc3e3689d18b96ca77d6f7989e7 Mon Sep 17 00:00:00 2001 From: David <77736444+davidx33@users.noreply.github.com> Date: Fri, 18 Oct 2024 18:02:37 -0700 Subject: [PATCH] feat: pull prompts from langsmith (#388) --- backend/retrieval_graph/prompts.py | 113 ++++++----------------------- poetry.lock | 20 ++++- pyproject.toml | 1 + 3 files changed, 41 insertions(+), 93 deletions(-) diff --git a/backend/retrieval_graph/prompts.py b/backend/retrieval_graph/prompts.py index 31249406..e25333ae 100644 --- a/backend/retrieval_graph/prompts.py +++ b/backend/retrieval_graph/prompts.py @@ -1,94 +1,23 @@ -"""Default prompts.""" - -# Retrieval graph - -ROUTER_SYSTEM_PROMPT = """You are a LangChain Developer advocate. Your job is help people using LangChain answer any issues they are running into. - -A user will come to you with an inquiry. Your first job is to classify what type of inquiry it is. The types of inquiries you should classify it as are: - -## `more-info` -Classify a user inquiry as this if you need more information before you will be able to help them. Examples include: -- The user complains about an error but doesn't provide the error -- The user says something isn't working but doesn't explain why/how it's not working - -## `langchain` -Classify a user inquiry as this if it can be answered by looking up information related to LangChain open source package. The LangChain open source package \ -is a python library for working with LLMs. It integrates with various LLMs, databases and APIs. - -## `general` -Classify a user inquiry as this if it is just a general question""" - -GENERAL_SYSTEM_PROMPT = """You are a LangChain Developer advocate. Your job is help people using LangChain answer any issues they are running into. - -Your boss has determined that the user is asking a general question, not one related to LangChain. This was their logic: - - -{logic} - - -Respond to the user. Politely decline to answer and tell them you can only answer questions about LangChain-related topics, and that if their question is about LangChain they should clarify how it is.\ -Be nice to them though - they are still a user!""" - -MORE_INFO_SYSTEM_PROMPT = """You are a LangChain Developer advocate. Your job is help people using LangChain answer any issues they are running into. - -Your boss has determined that more information is needed before doing any research on behalf of the user. This was their logic: - - -{logic} - +from langchain import hub -Respond to the user and try to get any more relevant information. Do not overwhelm them! Be nice, and only ask them a single follow up question.""" - -RESEARCH_PLAN_SYSTEM_PROMPT = """You are a LangChain expert and a world-class researcher, here to assist with any and all questions or issues with LangChain, LangGraph, LangSmith, or any related functionality. Users may come to you with questions or issues. - -Based on the conversation below, generate a plan for how you will research the answer to their question. \ -The plan should generally not be more than 3 steps long, it can be as short as one. The length of the plan depends on the question. - -You have access to the following documentation sources: -- Conceptual docs -- Integration docs -- How-to guides - -You do not need to specify where you want to research for all steps of the plan, but it's sometimes helpful.""" - -RESPONSE_SYSTEM_PROMPT = """\ -You are an expert programmer and problem-solver, tasked with answering any question \ -about LangChain. - -Generate a comprehensive and informative answer for the \ -given question based solely on the provided search results (URL and content). \ -Do NOT ramble, and adjust your response length based on the question. If they ask \ -a question that can be answered in one sentence, do that. If 5 paragraphs of detail is needed, \ -do that. You must \ -only use information from the provided search results. Use an unbiased and \ -journalistic tone. Combine search results together into a coherent answer. Do not \ -repeat text. Cite search results using [${{number}}] notation. Only cite the most \ -relevant results that answer the question accurately. Place these citations at the end \ -of the individual sentence or paragraph that reference them. \ -Do not put them all at the end, but rather sprinkle them throughout. If \ -different results refer to different entities within the same name, write separate \ -answers for each entity. - -You should use bullet points in your answer for readability. Put citations where they apply -rather than putting them all at the end. DO NOT PUT THEM ALL THAT END, PUT THEM IN THE BULLET POINTS. - -If there is nothing in the context relevant to the question at hand, do NOT make up an answer. \ -Rather, tell them why you're unsure and ask for any additional information that may help you answer better. - -Sometimes, what a user is asking may NOT be possible. Do NOT tell them that things are possible if you don't \ -see evidence for it in the context below. If you don't see based in the information below that something is possible, \ -do NOT say that it is - instead say that you're not sure. - -Anything between the following `context` html blocks is retrieved from a knowledge \ -bank, not part of the conversation with the user. - - - {context} -""" - -# Researcher graph +"""Default prompts.""" -GENERATE_QUERIES_SYSTEM_PROMPT = """\ -Generate 3 search queries to search for to answer the user's question. \ -These search queries should be diverse in nature - do not generate \ -repetitive ones.""" +# fetch from langsmith +ROUTER_SYSTEM_PROMPT = ( + hub.pull("chat-langchain-router-prompt").messages[0].prompt.template +) +GENERATE_QUERIES_SYSTEM_PROMPT = ( + hub.pull("chat-langchain-generate-queries-prompt").messages[0].prompt.template +) +MORE_INFO_SYSTEM_PROMPT = ( + hub.pull("chat-langchain-more-info-prompt").messages[0].prompt.template +) +RESEARCH_PLAN_SYSTEM_PROMPT = ( + hub.pull("chat-langchain-research-plan-prompt").messages[0].prompt.template +) +GENERAL_SYSTEM_PROMPT = ( + hub.pull("chat-langchain-general-prompt").messages[0].prompt.template +) +RESPONSE_SYSTEM_PROMPT = ( + hub.pull("chat-langchain-response-prompt").messages[0].prompt.template +) diff --git a/poetry.lock b/poetry.lock index 0adf7bed..3525b604 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1656,6 +1656,22 @@ numpy = ">=1.26.2,<2.0.0" simsimd = ">=3.6.1,<5.0.0" weaviate-client = ">=4.0.0,<5.0.0" +[[package]] +name = "langchainhub" +version = "0.1.21" +description = "The LangChain Hub API client" +optional = false +python-versions = "<4.0,>=3.8.1" +files = [ + {file = "langchainhub-0.1.21-py3-none-any.whl", hash = "sha256:1cc002dc31e0d132a776afd044361e2b698743df5202618cf2bad399246b895f"}, + {file = "langchainhub-0.1.21.tar.gz", hash = "sha256:723383b3964a47dbaea6ad5d0ef728accefbc9d2c07480e800bdec43510a8c10"}, +] + +[package.dependencies] +packaging = ">=23.2,<25" +requests = ">=2,<3" +types-requests = ">=2.31.0.2,<3.0.0.0" + [[package]] name = "langgraph" version = "0.2.38" @@ -2503,6 +2519,7 @@ description = "Pure-Python implementation of ASN.1 types and DER/BER/CER codecs optional = false python-versions = ">=3.8" files = [ + {file = "pyasn1-0.6.1-py3-none-any.whl", hash = "sha256:0d632f46f2ba09143da3a8afe9e33fb6f92fa2320ab7e886e2d0f7672af84629"}, {file = "pyasn1-0.6.1.tar.gz", hash = "sha256:6f580d2bdd84365380830acf45550f2511469f673cb4a5ae3857a3170128b034"}, ] @@ -2513,6 +2530,7 @@ description = "A collection of ASN.1-based protocols modules" optional = false python-versions = ">=3.8" files = [ + {file = "pyasn1_modules-0.4.1-py3-none-any.whl", hash = "sha256:49bfa96b45a292b711e986f222502c1c9a5e1f4e568fc30e2574a6c7d07838fd"}, {file = "pyasn1_modules-0.4.1.tar.gz", hash = "sha256:c28e2dbf9c06ad61c71a075c7e0f9fd0f1b0bb2d2ad4377f240d33ac2ab60a7c"}, ] @@ -3695,4 +3713,4 @@ multidict = ">=4.0" [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "a51cbebf7897633e8743b54241fe3005d1fc44f98ad483c9535cc5dcfa135481" +content-hash = "e30581ab820fae871a325724f54b6c155b1ed3021210c498d8c3b4d3355dcb21" diff --git a/pyproject.toml b/pyproject.toml index 11856c5e..ef45eb6e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,6 +26,7 @@ lxml = "^4.9.3" voyageai = "^0.1.4" pillow = "^10.2.0" psycopg2-binary = "^2.9.9" +langchainhub = "^0.1.21" [tool.poetry.group.dev.dependencies] pytest = "^7.3.0"