Download api_utils/utils_ext/helper.py from dakl45646/sd: direct link, hf CLI and curl.
- Browser
- Download file 1 kB
-
https://huggingface.co/spaces/dakl45646/sd/resolve/main/api_utils/utils_ext/helper.py
- Command line
-
hf download hf://spaces/dakl45646/sd/api_utils/utils_ext/helper.py
-
curl -L -o helper.py https://huggingface.co/spaces/dakl45646/sd/resolve/main/api_utils/utils_ext/helper.py
1 kB
| from typing import AsyncGenerator | |
| async def use_helper_get_response(helper_endpoint: str, helper_sapisid: str) -> AsyncGenerator[str, None]: | |
| from server import logger | |
| import aiohttp | |
| logger.info(f"正在尝试使用Helper端点: {helper_endpoint}") | |
| try: | |
| async with aiohttp.ClientSession() as session: | |
| headers = { | |
| 'Content-Type': 'application/json', | |
| 'Cookie': f'SAPISID={helper_sapisid}' if helper_sapisid else '' | |
| } | |
| async with session.get(helper_endpoint, headers=headers) as response: | |
| if response.status == 200: | |
| async for chunk in response.content.iter_chunked(1024): | |
| if chunk: | |
| yield chunk.decode('utf-8', errors='ignore') | |
| else: | |
| logger.error(f"Helper端点返回错误状态: {response.status}") | |
| except Exception as e: | |
| logger.error(f"使用Helper端点时出错: {e}") | |