json rpc commander 封装
This commit is contained in:
@@ -191,42 +191,3 @@ def parse_request(request_str: str) -> Dict[str, Any]:
|
||||
except json.JSONDecodeError as e:
|
||||
raise ValueError(f"Invalid JSON: {e}")
|
||||
|
||||
|
||||
def example_video_generation():
|
||||
"""Example of how to use JSON-RPC for video generation"""
|
||||
rpc = create_response_handler("video_gen_001")
|
||||
progress = create_progress_reporter()
|
||||
|
||||
try:
|
||||
# Report progress steps
|
||||
progress.step("upload", "[1/4] 正在上传图片到云存储...")
|
||||
# ... upload logic ...
|
||||
|
||||
progress.step("submit", "[2/4] 正在提交视频生成任务...")
|
||||
# ... submit logic ...
|
||||
|
||||
progress.step("wait", "[3/4] 正在等待视频生成完成...")
|
||||
# ... wait logic ...
|
||||
|
||||
progress.step("download", "[4/4] 正在下载视频到本地...")
|
||||
# ... download logic ...
|
||||
|
||||
progress.complete("[完成] 视频生成并下载成功")
|
||||
|
||||
# Send final result
|
||||
result = {
|
||||
"status": True,
|
||||
"video_path": "/path/to/video.mp4",
|
||||
"video_url": "https://example.com/video.mp4",
|
||||
"message": "视频生成并下载成功"
|
||||
}
|
||||
rpc.success(result)
|
||||
|
||||
except Exception as e:
|
||||
progress.error(f"生成失败: {str(e)}")
|
||||
rpc.error(JSONRPCError.GENERATION_FAILED, "Video generation failed", str(e))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Test the JSON-RPC module
|
||||
example_video_generation()
|
||||
|
||||
Reference in New Issue
Block a user