LiteLLM vs Pydantic AI
LiteLLM
LLM 모델 호출 통합 레이어(wrapper)
OpenAI 포맷 통합 SDK
모델마다 SDK가 달라도 completion(model=..., messages=...) 같은 OpenAI 형식 입/출력으로 통합 제공
하지만 모든 모델이 원래 OpenAI API를 지원하는 건 아님
ex) Gemini(Google AI Studio)
: 자체 API를 사용하지만 LiteLLM은 이를 OpenAI API와 동일한 인터페이스로 감싸서 호출 가능
일부 모델에는 추가 파라미터 제공
원래는 모델별 SDK가 제각각이라 SDK마다 호출 방식, 파라미터, 반환 구조가 달라서 번거로움
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(model="gpt-4o", messages=[...])
from anthropic import Anthropic
client = Anthropic()
response = client.messages.create(model="claude-3-opus", messages=[...])
LiteLLM을 사용해 모델 호출을 통합된 포맷으로 감쌀 수 있음
from litellm import completion
# OpenAI 모델 호출
response = completion(
model="gpt-4o",
messages=[{"role": "user", "content": "hi"}]
)
# 다른 모델 호출
response = completion(model="anthropic:claude-3", messages=[...])
response = completion(model="mistral:open-mixtral", messages=[...])
- 모델마다 다른 SDK API 차이를 LiteLLM이 통일된 호출 인터페이스로 감쌈
- OpenAI, Anthropic, Mistral 등 거의 모든 주요 LLM을 동일한 방식으로 호출 가능
- "순수 모델 호출 SDK" 역할이므로 Agent, Tool 호출, Memory, MCP 등은 직접 구현해야 함
PydanticAI
LLM기반 Agent Framework
from pydantic_ai import Agent
agent = Agent(model="openai:gpt-4o-mini")
result = agent.run("Summarize this text")
위 코드로 모델 호출, 응답 파싱, 타입 검증, Agent/Workflow 관리까지 자동 처리 가능
= 앱 수준에서 LLM을 쉽게 연결하고 타입 안전하게 결과를 다룰 수 있는 고수준 프레임워크
PydanticAI는 Model + Provider + profile 구조로 되어 있음
1. Model: LLM 호출 형식 정의 (OpenAIChatModel, AnthropicModel 등)
2. Provider: 실제 요청 전송 및 인증 처리 (OpenAIProvider, LiteLLMProvider 등)
3. Profile: 모델별 세부 규칙 (JSON schema 제한, temperature 기본값 등)
원래 PydanticAI는 모델 호출 시 각 모델 SDK에 맞춰서 호출해야 했음
최근 PydanticAI에서 LiteLLMProvider를 제공!
: PydanticAI에서 LiteLLM을 Provider로 연결하면 OpenAI API 포맷으로 감싸서 호출 가능
Agent/Workflow/타입 검증 등 PydanticAI 기능을은 그대로 쓰면서 실제 모델 호출은 LiteLLM이 처리 가능
지원하지 않는 모델은 자체 Provider 개발
'자연어 처리 > LLM' 카테고리의 다른 글
| AI Agent란? (0) | 2025.10.16 |
|---|