AutoGen — vLLM 배포
AutoGen — vLLM 배포
AutoGen은 자율적으로 동작하거나 인간과 함께 작업할 수 있는 멀티에이전트 AI 애플리케이션을 만들기 위한 프레임워크입니다. vLLM을 백엔드로 두고 AutoGen 에이전트가 vLLM의 OpenAI 호환 API를 호출하도록 구성할 수 있습니다.
출처: 문서
본문
사전 준비 (Prerequisites)
vLLM과 AutoGen 환경을 설정합니다.
pip install vllm
# Extensions에서 AgentChat과 OpenAI 클라이언트 설치
# AutoGen은 Python 3.10 이상 필요
pip install -U "autogen-agentchat" "autogen-ext[openai]"
배포 (Deploy)
- 지원되는 채팅 완성 모델로 vLLM 서버를 시작합니다.
vllm serve mistralai/Mistral-7B-Instruct-v0.2
- AutoGen으로 호출합니다.
import asyncio
from autogen_core.models import UserMessage
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_core.models import ModelFamily
async def main() -> None:
# 모델 클라이언트 생성
model_client = OpenAIChatCompletionClient(
model="mistralai/Mistral-7B-Instruct-v0.2",
base_url="http://{your-vllm-host-ip}:{your-vllm-host-port}/v1",
api_key="EMPTY",
model_info={
"vision": False,
"function_calling": False,
"json_output": False,
"family": ModelFamily.MISTRAL,
"structured_output": True,
},
)
messages = [UserMessage(content="Write a very short story about a dragon.", source="user")]
# 스트림 생성
stream = model_client.create_stream(messages=messages)
# 스트림을 순회하며 응답 출력
print("Streamed responses:")
async for response in stream:
if isinstance(response, str):
# 부분 응답은 문자열
print(response, flush=True, end="")
else:
# 마지막 응답은 전체 메시지를 담은 CreateResult 객체
print("\n\n------------\n")
print("The complete response:", flush=True)
print(response.content, flush=True)
# 사용이 끝나면 클라이언트 닫기
await model_client.close()
asyncio.run(main())
핵심 포인트는 base_url을 vLLM 서버의 /v1 엔드포인트로, api_key는 "EMPTY"로 두고 OpenAI 호환 클라이언트를 연결하는 것입니다. model_info에 해당 모델이 어떤 기능(비전, 함수 호출, JSON 출력, 구조화 출력)을 지원하는지 알려주어 AutoGen이 올바르게 행동하게 합니다.
자세한 내용은 튜토리얼을 참고하세요.
- AutoGen에서 vLLM 사용하기 (Using vLLM in AutoGen)
- OpenAI 호환 API 예제 (OpenAI-compatible API examples)
더 알아보기 (Learn more)
- 모든 배포 프레임워크 — vLLM과 연동되는 프레임워크 목록
- OpenAI 호환 서버 — vLLM의 OpenAI 호환 API 사용법