mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-19 19:11:33 +00:00
Update doc-string in few shot template (#8474)
Partial update of doc-string, need to update other instances in documentation
This commit is contained in:
parent
04ebdbe98f
commit
529cb2e30c
@ -190,12 +190,9 @@ class FewShotChatMessagePromptTemplate(
|
|||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
from langchain.schema import SystemMessage
|
|
||||||
from langchain.prompts import (
|
from langchain.prompts import (
|
||||||
FewShotChatMessagePromptTemplate,
|
FewShotChatMessagePromptTemplate,
|
||||||
HumanMessagePromptTemplate,
|
ChatPromptTemplate
|
||||||
SystemMessagePromptTemplate,
|
|
||||||
AIMessagePromptTemplate
|
|
||||||
)
|
)
|
||||||
|
|
||||||
examples = [
|
examples = [
|
||||||
@ -203,24 +200,23 @@ class FewShotChatMessagePromptTemplate(
|
|||||||
{"input": "2+3", "output": "5"},
|
{"input": "2+3", "output": "5"},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
example_prompt = ChatPromptTemplate.from_messages(
|
||||||
|
[('human', '{input}'), ('ai', '{output}')]
|
||||||
|
)
|
||||||
|
|
||||||
few_shot_prompt = FewShotChatMessagePromptTemplate(
|
few_shot_prompt = FewShotChatMessagePromptTemplate(
|
||||||
examples=examples,
|
examples=examples,
|
||||||
# This is a prompt template used to format each individual example.
|
# This is a prompt template used to format each individual example.
|
||||||
example_prompt=(
|
example_prompt=example_prompt,
|
||||||
HumanMessagePromptTemplate.from_template("{input}")
|
|
||||||
+ AIMessagePromptTemplate.from_template("{output}")
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
final_prompt = ChatPromptTemplate.from_messages(
|
||||||
final_prompt = (
|
[
|
||||||
SystemMessagePromptTemplate.from_template(
|
('system', 'You are a helpful AI Assistant'),
|
||||||
"You are a helpful AI Assistant"
|
few_shot_prompt,
|
||||||
)
|
('human', '{input}'),
|
||||||
+ few_shot_prompt
|
]
|
||||||
+ HumanMessagePromptTemplate.from_template("{input}")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
final_prompt.format(input="What is 4+4?")
|
final_prompt.format(input="What is 4+4?")
|
||||||
|
|
||||||
Prompt template with dynamically selected examples:
|
Prompt template with dynamically selected examples:
|
||||||
|
Loading…
Reference in New Issue
Block a user