Llama2Chat 封装器来增强 Llama-2 LLM,以支持 Llama-2 聊天提示格式。LangChain 中的多个 LLM 实现可用作 Llama-2 聊天模型的接口,例如 ChatHuggingFace、LlamaCpp、GPT4All 等。
Llama2Chat 是一个通用封装器,实现了 BaseChatModel,因此可以在应用程序中作为聊天模型使用。Llama2Chat 将消息列表转换为所需的聊天提示格式,并将格式化后的提示以 str 形式转发给封装的 LLM。
prompt_template:
通过 HuggingFaceTextGenInference LLM 与 Llama-2 聊天
HuggingFaceTextGenInference LLM 封装了对 text-generation-inference 服务器的访问。在以下示例中,推理服务器提供 meta-llama/Llama-2-13b-chat-hf 模型。可以使用如下命令在本地启动:
--num_shard 值。HF_API_TOKEN 环境变量存放 Hugging Face API 令牌。
HuggingFaceTextGenInference 实例,并将其封装到 Llama2Chat 中。
LLMChain 中将聊天 model 与 prompt_template 及对话 memory 结合使用了。
通过 LlamaCPP LLM 与 Llama-2 聊天
要通过 LlamaCPP LMM 使用 Llama-2 聊天模型,请按照安装说明安装 llama-cpp-python 库。以下示例使用存储在本地 ~/Models/llama-2-7b-chat.Q4_0.gguf 路径下的量化 llama-2-7b-chat.Q4_0.gguf 模型。
创建 LlamaCpp 实例后,再次将 llm 封装到 Llama2Chat 中:
将这些文档连接到 Claude、VSCode 等,通过 MCP 获取实时解答。

