StringPromptValue(text='tell me a funny joke about chickens')
方法二
1
prompt.format(topic='funny', content='chickens')
'tell me a funny joke about chickens'
方法三
1 2 3 4 5 6 7 8
chat_template = ChatPromptTemplate.from_messages( [ ("system", "You are a helpful AI bot. Your name is {name}."), ("human", "Hello, how are you doing?"), ("ai", "I'm doing well, thanks!"), ("human", "{user_input}"), ] )
1 2
# 组装提示词 chat_template.format_messages(name='Bob', user_input='What is your name?')
[SystemMessage(content='You are a helpful AI bot. Your name is Bob.'),
HumanMessage(content='Hello, how are you doing?'),
AIMessage(content="I'm doing well, thanks!"),
HumanMessage(content='What is your name?')]
RAG实战:利用现有知识库开发一个聊天机器人
下载三个库:
pip install pypdf
pip install qdrant-client
pip install rapidocr-onnxruntime
1 2 3 4 5 6 7 8
from langchain_community.vectorstores import Qdrant # 向量数据库 from langchain_core.output_parsers import StrOutputParser # 输出解析器 from langchain_core.prompts import ChatPromptTemplate # 提示词管理模板 from langchain_core.runnables import RunnableParallel, RunnablePassthrough # 计算问题与文档切片的相似度 from langchain_community.chat_models import ErnieBotChat # 文心大模型 from langchain_community.embeddings import ErnieEmbeddings # 文心大模型的词嵌入工具(tokens) from langchain.text_splitter import RecursiveCharacterTextSplitter # 文档切分工具 from langchain_community.document_loaders import TextLoader, PyPDFLoader # 文件读取器