制作Prompt模板
def create_prompt_template(retrieved_docs, query):
context = "\n".join([f"Document {i+1}:\n{doc}" for i, doc in enumerate(retrieved_docs)])
prompt = f"Context:\n{context}\n\nQuery: {query}\n\nAnswer:"
return prompt
# 创建Prompt Template
prompt_template = create_prompt_template(retrieved_docs, query)
print("Prompt Template:\n", prompt_template)
将知识嵌入模型Prompt中
检索到的文档内容:
- Document 1: "Paris is the capital and most populous city of France."
- Document 2: "France, officially the French Republic, is a country primarily located in Western Europe."
- Document 3: "The capital city of France is Paris, which is known for its art, fashion, and culture."
模型Prompt模板:
You should answer the Query by these contexts
Context:通过用户输入在向量库中检索到的相关文档
Que