mirror of
https://github.com/hwchase17/langchain
synced 2024-11-08 07:10:35 +00:00
parent
2984803597
commit
e8531769f7
@ -164,12 +164,13 @@ def format_document(doc: Document, prompt: BasePromptTemplate) -> str:
|
||||
|
||||
Example:
|
||||
.. code-block:: python
|
||||
from langchain.schema import Document
|
||||
from langchain.prompts import PromptTemplate
|
||||
doc = Document(page_content="This is a joke", metadata={"page": "1"})
|
||||
prompt = PromptTemplate.from_template("Page {page}: {page_content}")
|
||||
format_document(doc, prompt)
|
||||
>>> "Page 1: This is a joke"
|
||||
|
||||
from langchain.schema import Document
|
||||
from langchain.prompts import PromptTemplate
|
||||
doc = Document(page_content="This is a joke", metadata={"page": "1"})
|
||||
prompt = PromptTemplate.from_template("Page {page}: {page_content}")
|
||||
format_document(doc, prompt)
|
||||
>>> "Page 1: This is a joke"
|
||||
"""
|
||||
base_info = {"page_content": doc.page_content, **doc.metadata}
|
||||
missing_metadata = set(prompt.input_variables).difference(base_info)
|
||||
|
Loading…
Reference in New Issue
Block a user