mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-03-20 03:57:30 +08:00
fix(agent): accept string-form sites list in search_torrents input
This commit is contained in:
@@ -4,7 +4,7 @@ import json
|
||||
import re
|
||||
from typing import List, Optional, Type
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
|
||||
from app.agent.tools.base import MoviePilotTool
|
||||
from app.chain.search import SearchChain
|
||||
@@ -28,6 +28,28 @@ class SearchTorrentsInput(BaseModel):
|
||||
filter_pattern: Optional[str] = Field(None,
|
||||
description="Regular expression pattern to filter torrent titles by resolution, quality, or other keywords (e.g., '4K|2160p|UHD' for 4K content, '1080p|BluRay' for 1080p BluRay)")
|
||||
|
||||
@field_validator("sites", mode="before")
|
||||
@classmethod
|
||||
def normalize_sites(cls, value):
|
||||
"""兼容字符串格式的站点列表(如 "[28]"、"28,30")"""
|
||||
if value is None:
|
||||
return value
|
||||
if isinstance(value, str):
|
||||
value = value.strip()
|
||||
if not value:
|
||||
return None
|
||||
try:
|
||||
parsed = json.loads(value)
|
||||
if isinstance(parsed, list):
|
||||
return parsed
|
||||
except Exception:
|
||||
pass
|
||||
if "," in value:
|
||||
return [v.strip() for v in value.split(",") if v.strip()]
|
||||
if value.isdigit():
|
||||
return [value]
|
||||
return value
|
||||
|
||||
|
||||
class SearchTorrentsTool(MoviePilotTool):
|
||||
name: str = "search_torrents"
|
||||
|
||||
Reference in New Issue
Block a user