MetaLlamaChatGenerator
MetaLlamaChatGenerator
Meta Llama API에서 사용 가능한 어떤 호스팅 모델로든 채팅 완성을 만들어주는 컴포넌트예요. 주로 ChatPromptBuilder 뒤에 두면 돼요.
본문
중단된 통합 안내
Meta가 2026년 7월 6일에 공개 미리보기 Llama API를 종료했어요. 그 결과 meta-llama-haystack 통합은 보관(archived)되고 더 이상 동작하지 않아요.
Llama 모델을 계속 쓰려면 LlamaStackChatGenerator, LlamaCppChatGenerator, OllamaChatGenerator, OpenRouterChatGenerator 같은 다른 지원 통합으로 전환하세요.
개요
MetaLlamaChatGenerator는 Meta Llama API에 채팅 완성 호출을 해 여러 Meta Llama 모델을 사용할 수 있게 해줘요. 기본 모델은 Llama-4-Scout-17B-16E-Instruct-FP8이에요.
현재 사용 가능한 모델은 다음과 같아요.
| 모델 ID | 입력 컨텍스트 길이 | 출력 컨텍스트 길이 | 입력 모달리티 | 출력 모달리티 |
|---|---|---|---|---|
Llama-4-Scout-17B-16E-Instruct-FP8 |
128k | 4028 | Text, Image | Text |
Llama-4-Maverick-17B-128E-Instruct-FP8 |
128k | 4028 | Text, Image | Text |
Llama-3.3-70B-Instruct |
128k | 4028 | Text | Text |
Llama-3.3-8B-Instruct |
128k | 4028 | Text | Text |
이 컴포넌트는 구조화된 입출력을 위해 다른 Haystack Chat Generator와 같은 ChatMessage 형식을 사용해요. 자세한 내용은 ChatMessage 문서를 확인하세요.
도구 지원
MetaLlamaChatGenerator는 tools 파라미터를 통해 함수 호출을 지원해요. 유연한 도구 구성을 받아들여요.
- Tool 객체 목록: 개별 도구를 리스트로 전달.
- 단일 Toolset: 전체 Toolset을 바로 전달.
- 도구·Toolset 혼합: 여러 Toolset을 독립 도구와 한 리스트에 결합.
관련 도구를 논리적 그룹으로 묶으면서 필요할 때 독립 도구도 포함할 수 있어요.
from haystack.tools import Tool, Toolset
from haystack_integrations.components.generators.meta_llama import (
MetaLlamaChatGenerator,
)
# Create individual tools
weather_tool = Tool(
name="weather", description="Get weather info", parameters=..., function=...
)
news_tool = Tool(
name="news", description="Get latest news", parameters=..., function=...
)
# Group related tools into a toolset
math_toolset = Toolset([add_tool, subtract_tool, multiply_tool])
# Pass mixed tools and toolsets to the generator
generator = MetaLlamaChatGenerator(
tools=[math_toolset, weather_tool, news_tool] # Mix of Toolset and Tool objects
)
도구 작업에 대한 자세한 내용은 Tool과 Toolset 문서를 참고하세요.
초기화
이 통합을 쓰려면 Meta Llama API 키가 있어야 해요. LLAMA_API_KEY 환경 변수로 제공하거나 Secret을 사용할 수 있어요.
그런 다음 meta-llama-haystack 통합을 설치해요.
pip install meta-llama-haystack
스트리밍
MetaLlamaChatGenerator는 LLM의 스트리밍 응답을 지원해서, 토큰이 생성되는 대로 출력할 수 있어요. 초기화 때 streaming_callback 파라미터에 호출 가능한 객체를 전달하면 스트리밍이 켜져요.
사용법
단독 사용:
from haystack.dataclasses import ChatMessage
from haystack_integrations.components.generators.meta_llama import (
MetaLlamaChatGenerator,
)
llm = MetaLlamaChatGenerator()
response = llm.run([ChatMessage.from_user("What are Agentic Pipelines? Be brief.")])
print(response["replies"][0].text)
스트리밍과 모델 라우팅:
from haystack.dataclasses import ChatMessage
from haystack_integrations.components.generators.meta_llama import (
MetaLlamaChatGenerator,
)
llm = MetaLlamaChatGenerator(
model="Llama-3.3-8B-Instruct",
streaming_callback=lambda chunk: print(chunk.content, end="", flush=True),
)
response = llm.run([ChatMessage.from_user("What are Agentic Pipelines? Be brief.")])
# check the model used for the response
print("\n\n Model used: ", response["replies"][0].meta["model"])
멀티모달 입력:
from haystack.dataclasses import ChatMessage, ImageContent
from haystack_integrations.components.generators.meta_llama import (
MetaLlamaChatGenerator,
)
llm = MetaLlamaChatGenerator(model="Llama-4-Scout-17B-16E-Instruct-FP8")
image = ImageContent.from_file_path("apple.jpg")
user_message = ChatMessage.from_user(
content_parts=["What does the image show? Max 5 words.", image],
)
response = llm.run([user_message])["replies"][0].text
print(response)
# Red apple on straw.
파이프라인 안에서:
# To run this example, you will need to set a `LLAMA_API_KEY` environment variable.
from haystack import Document, Pipeline
from haystack.components.builders.chat_prompt_builder import ChatPromptBuilder
from haystack.components.generators.utils import print_streaming_chunk
from haystack.components.retrievers.in_memory import InMemoryBM25Retriever
from haystack.dataclasses import ChatMessage
from haystack.document_stores.in_memory import InMemoryDocumentStore
from haystack.utils import Secret
from haystack_integrations.components.generators.meta_llama import (
MetaLlamaChatGenerator,
)
# Write documents to InMemoryDocumentStore
document_store = InMemoryDocumentStore()
document_store.write_documents(
[
Document(content="My name is Jean and I live in Paris."),
Document(content="My name is Mark and I live in Berlin."),
Document(content="My name is Giorgio and I live in Rome."),
],
)
# Build a RAG pipeline
prompt_template = [
ChatMessage.from_user(
"Given these documents, answer the question.\n"
"Documents:\n{% for doc in documents %}{{ doc.content }}{% endfor %}\n"
"Question: {{question}}\n"
"Answer:",
),
]
# Define required variables explicitly
prompt_builder = ChatPromptBuilder(
template=prompt_template,
required_variables={"question", "documents"},
)
retriever = InMemoryBM25Retriever(document_store=document_store)
llm = MetaLlamaChatGenerator(
api_key=Secret.from_env_var("LLAMA_API_KEY"),
streaming_callback=print_streaming_chunk,
)
rag_pipeline = Pipeline()
rag_pipeline.add_component("retriever", retriever)
rag_pipeline.add_component("prompt_builder", prompt_builder)
rag_pipeline.add_component("llm", llm)
rag_pipeline.connect("retriever", "prompt_builder.documents")
rag_pipeline.connect("prompt_builder", "llm.messages")
# Ask a question
question = "Who lives in Paris?"
rag_pipeline.run(
{
"retriever": {"query": question},
"prompt_builder": {"question": question},
},
)
더 알아보기 (Learn more)
- 참고: 이 통합은 더 이상 동작하지 않아요. 대신 LlamaStackChatGenerator나 LlamaCppChatGenerator 같은 통합을 사용하세요.