LLM을 Llama2Chat wrapper로 보강하여 Llama-2 chat prompt format을 지원하는 방법을 보여줍니다. LangChain의 여러 LLM 구현을 Llama-2 chat model의 인터페이스로 사용할 수 있습니다. 여기에는 ChatHuggingFace, LlamaCpp, GPT4All 등이 포함됩니다.
Llama2Chat은 BaseChatModel을 구현하는 범용 wrapper이므로 애플리케이션에서 chat model로 사용할 수 있습니다. Llama2Chat은 Message 목록을 필수 chat prompt format으로 변환하고 포맷된 prompt를 str로 래핑된 LLM에 전달합니다.
prompt_template을 사용합니다:
HuggingFaceTextGenInference LLM을 통한 Llama-2 Chat
HuggingFaceTextGenInference LLM은 text-generation-inference 서버에 대한 액세스를 캡슐화합니다. 다음 예제에서 inference 서버는 meta-llama/Llama-2-13b-chat-hf model을 제공합니다. 로컬에서 다음과 같이 시작할 수 있습니다:
--num_shard 값을 조정하세요. HF_API_TOKEN 환경 변수는 Hugging Face API token을 보유합니다.
HuggingFaceTextGenInference 인스턴스를 생성하고 이를 Llama2Chat으로 래핑합니다.
LLMChain에서 chat model을 prompt_template 및 대화 memory와 함께 사용할 준비가 됩니다.
LlamaCPP LLM을 통한 Llama-2 Chat
LlamaCPP LMM과 함께 Llama-2 chat model을 사용하려면 이 설치 지침을 사용하여 llama-cpp-python 라이브러리를 설치하세요. 다음 예제는 ~/Models/llama-2-7b-chat.Q4_0.gguf에 로컬로 저장된 양자화된 llama-2-7b-chat.Q4_0.gguf model을 사용합니다.
LlamaCpp 인스턴스를 생성한 후 llm은 다시 Llama2Chat으로 래핑됩니다
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.