#!/usr/bin/env python3
"""测试 ModelScope 模型获取器的原始输出"""

import requests
from typing import List

# 直接复制 ModelScopeFetcher 的代码，避免依赖问题

class ModelScopeFetcher:
    @property
    def provider(self) -> str:
        return "modelscope"

    def fetch_models(self) -> List[str]:
        url = "https://api-inference.modelscope.cn/v1/models"
        try:
            response = requests.get(url)
            response.raise_for_status()  # Raise an exception for HTTP errors
            data = response.json()
            # Assuming the API returns a list of model IDs directly or in a 'data' field
            # Adjust this based on the actual API response structure
            if isinstance(data, list):
                return data
            elif isinstance(data, dict) and "data" in data and isinstance(data["data"], list):
                return [model["id"] for model in data["data"]]
            else:
                print(f"Unexpected response format from ModelScope API: {data}")
                return []
        except requests.exceptions.RequestException as e:
            print(f"Error fetching models from ModelScope: {e}")
            return []

def test_modelscope_fetcher():
    fetcher = ModelScopeFetcher()
    result = fetcher.fetch_models()
    print(result)
    return result

if __name__ == "__main__":
    test_modelscope_fetcher()