Compare commits

...

8 Commits

Author SHA1 Message Date
isaac hershenson
a45b5721bb adding question to suffix 2024-07-11 10:02:00 -07:00
isaac hershenson
6975818050 fmt 2024-07-10 13:17:40 -07:00
isaac hershenson
9ae7b6ad3b adding input variables 2024-07-10 13:11:48 -07:00
isaac hershenson
7f0e415cea remove testing 2024-07-10 12:27:11 -07:00
isaac hershenson
9a15b8ae00 Merge branch 'isaac/fewshotpromptdocs' of https://github.com/langchain-ai/langchain into isaac/fewshotpromptdocs 2024-07-10 12:24:08 -07:00
isaac hershenson
9fe8f1d5b3 ignore testing 2024-07-10 12:23:07 -07:00
isaac hershenson
4e4c09481a fmt 2024-07-10 12:21:35 -07:00
isaac hershenson
0fdbae3260 first draft 2024-07-10 12:21:20 -07:00
7 changed files with 22 additions and 15 deletions

View File

@@ -55,8 +55,7 @@
" ]\n",
")\n",
"few_shot_prompt = FewShotChatMessagePromptTemplate(\n",
" example_prompt=example_prompt,\n",
" examples=examples,\n",
" example_prompt=example_prompt, examples=examples, input_variables=[]\n",
")"
]
},

View File

@@ -258,7 +258,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 8,
"id": "80c5ac5c",
"metadata": {},
"outputs": [
@@ -295,6 +295,7 @@
" Chroma,\n",
" # This is the number of examples to produce.\n",
" k=1,\n",
" input_keys=[\"question\"],\n",
")\n",
"\n",
"# Select the most similar example to the input.\n",
@@ -317,7 +318,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 10,
"id": "de69a214",
"metadata": {},
"outputs": [
@@ -335,7 +336,7 @@
"So the final answer is: Joseph Ball\n",
"\n",
"\n",
"Question: Who was the father of Mary Ball Washington?\n"
"Asking about: Mary Ball Washington. Question: Who was the father of Mary Ball Washington?\n"
]
}
],
@@ -343,12 +344,17 @@
"prompt = FewShotPromptTemplate(\n",
" example_selector=example_selector,\n",
" example_prompt=example_prompt,\n",
" suffix=\"Question: {input}\",\n",
" input_variables=[\"input\"],\n",
" suffix=\"Asking about: {input}. Question: {question}\",\n",
" input_variables=[\"input\", \"question\"],\n",
")\n",
"\n",
"print(\n",
" prompt.invoke({\"input\": \"Who was the father of Mary Ball Washington?\"}).to_string()\n",
" prompt.invoke(\n",
" {\n",
" \"question\": \"Who was the father of Mary Ball Washington?\",\n",
" \"input\": \"Mary Ball Washington\",\n",
" }\n",
" ).to_string()\n",
")"
]
},

View File

@@ -162,6 +162,7 @@
"few_shot_prompt = FewShotChatMessagePromptTemplate(\n",
" example_prompt=example_prompt,\n",
" examples=examples,\n",
" input_variables=[],\n",
")\n",
"\n",
"print(few_shot_prompt.invoke({}).to_messages())"
@@ -347,8 +348,6 @@
"\n",
"# Define the few-shot prompt.\n",
"few_shot_prompt = FewShotChatMessagePromptTemplate(\n",
" # The input variables select the values to pass to the example_selector\n",
" input_variables=[\"input\"],\n",
" example_selector=example_selector,\n",
" # Define how each example will be formatted.\n",
" # In this case, each example will become 2 messages:\n",
@@ -356,6 +355,7 @@
" example_prompt=ChatPromptTemplate.from_messages(\n",
" [(\"human\", \"{input}\"), (\"ai\", \"{output}\")]\n",
" ),\n",
" input_variables=[],\n",
")\n",
"\n",
"print(few_shot_prompt.invoke(input=\"What's 3 🦜 3?\").to_messages())"

View File

@@ -171,6 +171,7 @@
"few_shot_prompt = FewShotChatMessagePromptTemplate(\n",
" example_prompt=example_prompt,\n",
" examples=examples,\n",
" input_variables=[],\n",
")\n",
"\n",
"final_prompt = ChatPromptTemplate.from_messages(\n",

View File

@@ -280,6 +280,7 @@ class FewShotChatMessagePromptTemplate(
examples=examples,
# This is a prompt template used to format each individual example.
example_prompt=example_prompt,
input_variables=[],
)
final_prompt = ChatPromptTemplate.from_messages(
@@ -323,8 +324,6 @@ class FewShotChatMessagePromptTemplate(
from langchain_core.prompts.few_shot import FewShotChatMessagePromptTemplate
few_shot_prompt = FewShotChatMessagePromptTemplate(
# Which variable(s) will be passed to the example selector.
input_variables=["input"],
example_selector=example_selector,
# Define how each example will be formatted.
# In this case, each example will become 2 messages:
@@ -333,6 +332,7 @@ class FewShotChatMessagePromptTemplate(
HumanMessagePromptTemplate.from_template("{input}")
+ AIMessagePromptTemplate.from_template("{output}")
),
input_variables=[],
)
# Define the overall prompt.
final_prompt = (

View File

@@ -326,9 +326,9 @@ async def test_few_shot_chat_message_prompt_template() -> None:
)
few_shot_prompt = FewShotChatMessagePromptTemplate(
input_variables=["input"],
example_prompt=example_prompt,
examples=examples,
input_variables=[],
)
final_prompt: ChatPromptTemplate = (
SystemMessagePromptTemplate.from_template("You are a helpful AI Assistant")
@@ -401,9 +401,9 @@ def test_few_shot_chat_message_prompt_template_with_selector() -> None:
)
few_shot_prompt = FewShotChatMessagePromptTemplate(
input_variables=["input"],
example_prompt=example_prompt,
example_selector=example_selector,
input_variables=[],
)
final_prompt: ChatPromptTemplate = (
SystemMessagePromptTemplate.from_template("You are a helpful AI Assistant")
@@ -475,9 +475,9 @@ async def test_few_shot_chat_message_prompt_template_with_selector_async() -> No
)
few_shot_prompt = FewShotChatMessagePromptTemplate(
input_variables=["input"],
example_prompt=example_prompt,
example_selector=example_selector,
input_variables=[],
)
final_prompt: ChatPromptTemplate = (
SystemMessagePromptTemplate.from_template("You are a helpful AI Assistant")

View File

@@ -32,6 +32,7 @@ example_prompt = ChatPromptTemplate.from_messages(
few_shot_prompt = FewShotChatMessagePromptTemplate(
example_prompt=example_prompt,
examples=examples,
input_variables=[],
)
prompt = ChatPromptTemplate.from_messages(