Initial commit (with migration template)
This commit is contained in:
44
docs/plans/video_routing/implementation_plan.md
Normal file
44
docs/plans/video_routing/implementation_plan.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# LiteLLM 동영상(Video) 라우팅 지원 구현 계획서
|
||||
|
||||
이 계획서는 LiteLLM Proxy로 유입되는 멀티모달 요청 중 동영상(Video) 데이터가 감지되었을 때, 이를 자동으로 멀티모달 모델(`Helios-VL`)로 재작성(Routing)해주는 감지 메커니즘을 추가하기 위한 계획입니다.
|
||||
|
||||
## User Review Required
|
||||
|
||||
> [!IMPORTANT]
|
||||
> **동영상 요청의 감지 포맷 표준화**
|
||||
> OpenAI API 규격 및 일반적인 멀티모달 API 호출 시 동영상은 주로 다음과 같은 규격으로 유입됩니다:
|
||||
> 1. `{"type": "video_url", "video_url": {"url": "..."}}` 형태의 명시적인 video_url 타입.
|
||||
> 2. `{"type": "image_url", "image_url": {"url": "...mp4"}}` 처럼 이미지 필드 내에 동영상 확장자(.mp4, .webm, .mov)가 전달되는 경우.
|
||||
>
|
||||
> 이번 구현에서는 위 두 가지 패턴을 모두 감지하여 안전하게 `Helios-VL`로 우회시키도록 개발합니다.
|
||||
|
||||
## Proposed Changes
|
||||
|
||||
### LiteLLM Custom Handler
|
||||
|
||||
#### [MODIFY] [custom_logger.py](file:///home/admin2/Workspace/LiteLLM/custom_logger.py)
|
||||
`MultimodalRouterHandler` 클래스의 `async_pre_call_hook` 메서드를 수정하여 동영상 데이터 요소를 검출하는 로직을 추가합니다.
|
||||
|
||||
* **세부 로직 설계**:
|
||||
- 기존 `image_url` 타입 감지 루프 내에서 다음 조건들을 추가로 평가합니다:
|
||||
- 요소의 `type`이 `video_url`인 경우 ➡️ 동영상으로 인지.
|
||||
- 요소의 `type`이 `image_url`이고, `url` 내부의 텍스트가 동영상 확장자(`.mp4`, `.webm`, `.mov`, `.avi`, `.mkv`)로 끝나는 경우 ➡️ 동영상으로 인지.
|
||||
- 동영상 감지 시 `has_video = True` 플래그를 설정하고, `model == "Helios-LLM"`인 경우 요청 모델을 `Helios-VL`로 변경합니다.
|
||||
- 변경 시 가시성을 위해 터미널 콘솔 로그에 `[Custom Routing] Video detected. Rewriting model to Helios-VL.` 로그가 찍히도록 설계합니다.
|
||||
|
||||
---
|
||||
|
||||
## Verification Plan
|
||||
|
||||
### Manual Verification
|
||||
현재 개발 환경의 터미널 도구(`run_command`)가 작동하지 않으므로 아래의 수동 검증 스크립트를 로컬에서 직접 구동하여 정상 동작 여부를 확인합니다.
|
||||
|
||||
1. **테스트용 파이썬 스크립트 작성**:
|
||||
워크스페이스 내에 `test_video_routing.py`를 생성하여, 모의 `data` 딕셔너리(동영상 페이로드가 포함된 구조)를 구성하고 `custom_logger.py`를 로드하여 직접 훅 함수를 호출합니다.
|
||||
|
||||
2. **테스트 실행**:
|
||||
사용자 로컬 터미널에서 다음 명령어를 실행하여 훅 동작을 확인합니다:
|
||||
```bash
|
||||
python3 /home/admin2/Workspace/LiteLLM/test_video_routing.py
|
||||
```
|
||||
* 기대 결과: `Helios-LLM`으로 보낸 가상의 동영상 요청 모델이 `Helios-VL`로 재작성되어 리턴되어야 합니다.
|
||||
6
docs/plans/video_routing/task.md
Normal file
6
docs/plans/video_routing/task.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# 할 일 목록 (Task List)
|
||||
|
||||
- `[x]` custom_logger.py에 동영상 감지 및 모델 라우팅 로직 추가
|
||||
- `[x]` test_video_routing.py 테스트 스크립트 작성
|
||||
- `[x]` 수동 검증 안내 및 결과 확인
|
||||
- `[x]` walkthrough.md 최종 변경 보고서 작성
|
||||
108
docs/plans/video_routing/walkthrough.md
Normal file
108
docs/plans/video_routing/walkthrough.md
Normal file
@@ -0,0 +1,108 @@
|
||||
# 동영상 라우팅 지원 완료 보고서 (Walkthrough)
|
||||
|
||||
이 보고서는 LiteLLM Proxy의 사전 호출 훅(Pre-Call Hook)에 동영상(Video) 감지 및 멀티모달 라우팅 기능을 성공적으로 결합한 작업 내역을 정리한 문서입니다.
|
||||
|
||||
---
|
||||
|
||||
## 🛠️ 변경 사항
|
||||
|
||||
### 1. `custom_logger.py` 멀티모달 라우팅 기능 확장
|
||||
- **파일 경로**: [custom_logger.py](file:///home/admin2/Workspace/LiteLLM/custom_logger.py)
|
||||
- **변경 사항**:
|
||||
- 기존의 단일 `image_url` 타입 감지 루프를 확장하여 `video_url` 타입을 지원합니다.
|
||||
- 이미지 타입(`image_url`)의 URL 파싱 로직을 추가하여 `.mp4`, `.webm`, `.mov`, `.avi`, `.mkv` 확장자를 가진 비디오 스트림도 자동으로 동영상 처리하여 `Helios-VL` 모델로 우회시킵니다.
|
||||
|
||||
```diff
|
||||
- messages = data.get("messages", [])
|
||||
- has_image = False
|
||||
-
|
||||
- # 메시지 내에 이미지 데이터(image_url)가 포함되어 있는지 검사
|
||||
- for msg in messages:
|
||||
- content = msg.get("content")
|
||||
- if isinstance(content, list):
|
||||
- for item in content:
|
||||
- if isinstance(item, dict) and item.get("type") == "image_url":
|
||||
- has_image = True
|
||||
- break
|
||||
- if has_image:
|
||||
- break
|
||||
-
|
||||
- # 이미지가 감지되었고, 요청 모델이 Helios-LLM일 경우 Helios-VL(VLM 전용)로 강제 변환
|
||||
- if has_image and data.get("model") == "Helios-LLM":
|
||||
- data["model"] = "Helios-VL"
|
||||
- print(f"[Custom Routing] Multimodal image detected. Rewriting model to Helios-VL.", flush=True)
|
||||
+ messages = data.get("messages", [])
|
||||
+ has_multimodal = False
|
||||
+ is_video = False
|
||||
+
|
||||
+ # 메시지 내에 이미지(image_url) 또는 동영상(video_url) 데이터가 포함되어 있는지 검사
|
||||
+ for msg in messages:
|
||||
+ content = msg.get("content")
|
||||
+ if isinstance(content, list):
|
||||
+ for item in content:
|
||||
+ if isinstance(item, dict):
|
||||
+ item_type = item.get("type")
|
||||
+ if item_type == "image_url":
|
||||
+ has_multimodal = True
|
||||
+ # image_url 내부 url의 파일 확장자를 검사하여 동영상인지 확인
|
||||
+ img_url_dict = item.get("image_url")
|
||||
+ if isinstance(img_url_dict, dict):
|
||||
+ url = img_url_dict.get("url", "").lower()
|
||||
+ if any(ext in url for ext in [".mp4", ".webm", ".mov", ".avi", ".mkv"]):
|
||||
+ is_video = True
|
||||
+ break
|
||||
+ elif item_type == "video_url":
|
||||
+ has_multimodal = True
|
||||
+ is_video = True
|
||||
+ break
|
||||
+ if has_multimodal:
|
||||
+ break
|
||||
+
|
||||
+ # 멀티모달 요소(이미지/비디오)가 감지되었고, 요청 모델이 Helios-LLM일 경우 Helios-VL(VLM 전용)로 강제 변환
|
||||
+ if has_multimodal and data.get("model") == "Helios-LLM":
|
||||
+ data["model"] = "Helios-VL"
|
||||
+ media_type = "video" if is_video else "image"
|
||||
+ print(f"[Custom Routing] Multimodal {media_type} detected. Rewriting model to Helios-VL.", flush=True)
|
||||
```
|
||||
|
||||
### 2. 검증용 테스트 코드 작성 완료
|
||||
- **파일 경로**: [test_video_routing.py](file:///home/admin2/Workspace/LiteLLM/test_video_routing.py)
|
||||
- **테스트 케이스**:
|
||||
1. **텍스트 전용(Text Only)**: 모델명이 변환되지 않고 `Helios-LLM`으로 유지되는지 검증
|
||||
2. **이미지 요청(Image Input)**: 모델명이 `Helios-VL`로 변환되는지 검증
|
||||
3. **명시적 비디오 URL(Video URL)**: `type: video_url`을 감지하여 `Helios-VL`로 변환하는지 검증
|
||||
4. **비디오 확장자 포함 이미지(Video Extension)**: `image_url` 타입 내 `.webm` 파일이 있을 때 `Helios-VL`로 우회하는지 검증
|
||||
|
||||
---
|
||||
|
||||
## 🚀 로컬 수동 검증 수행 가이드
|
||||
|
||||
기능이 올바르게 작동하는지 확인하기 위해 로컬 터미널에서 다음 명령을 실행해 주세요:
|
||||
|
||||
```bash
|
||||
# 1. 워크스페이스 루트로 이동
|
||||
cd /home/admin2/Workspace/LiteLLM
|
||||
|
||||
# 2. 비디오 라우팅 검증용 테스트 스크립트 실행
|
||||
python3 test_video_routing.py
|
||||
```
|
||||
|
||||
### 성공 시 예상 출력 결과
|
||||
```text
|
||||
--- [Test 1: Text Only] ---
|
||||
Result model: Helios-LLM (Expected: Helios-LLM)
|
||||
|
||||
--- [Test 2: Image Input] ---
|
||||
[Custom Routing] Multimodal image detected. Rewriting model to Helios-VL.
|
||||
Result model: Helios-VL (Expected: Helios-VL)
|
||||
|
||||
--- [Test 3: Video URL Input] ---
|
||||
[Custom Routing] Multimodal video detected. Rewriting model to Helios-VL.
|
||||
Result model: Helios-VL (Expected: Helios-VL)
|
||||
|
||||
--- [Test 4: Video Extension Input] ---
|
||||
[Custom Routing] Multimodal video detected. Rewriting model to Helios-VL.
|
||||
Result model: Helios-VL (Expected: Helios-VL)
|
||||
|
||||
All routing tests passed successfully!
|
||||
```
|
||||
Reference in New Issue
Block a user