(args: argparse.Namespace)
| 77 | |
| 78 | |
| 79 | def get_request_properties(url: str, task: str) -> Dict[str, Any]: |
| 80 | response = requests.get(f"{url.rstrip('/')}/openapi.json", timeout=30) |
| 81 | response.raise_for_status() |
| 82 | document = response.json() |
| 83 | schema = document["paths"]["/v1/tasks/sync"]["post"]["requestBody"]["content"]["application/json"]["schema"] |
| 84 | if "discriminator" in schema: |
| 85 | tasks = schema["discriminator"]["mapping"] |
| 86 | if task not in tasks: |
| 87 | raise ValueError(f"Task {task!r} is not available; choose from: {', '.join(tasks)}") |
| 88 | schema = {"$ref": tasks[task]} |
| 89 | if "$ref" in schema: |
| 90 | schema = document["components"]["schemas"][schema["$ref"].rsplit("/", 1)[-1]] |
| 91 | properties = schema["properties"] |
| 92 | if "task" in properties and properties["task"]["const"] != task: |
| 93 | raise ValueError(f"This endpoint requires task={properties['task']['const']!r}") |
| 94 | return properties |
| 95 | |
| 96 | |
| 97 | def build_payload(args: argparse.Namespace, properties: Dict[str, Any]) -> Dict[str, Any]: |
| 98 | payload: Dict[str, Any] = { |
| 99 | "prompt": args.prompt, |
| 100 | "negative_prompt": args.negative_prompt, |
| 101 | "seed": args.seed, |
| 102 | "aspect_ratio": args.aspect_ratio, |
| 103 | "save_result_path": args.save_result_path, |
| 104 | "presigned_url": args.presigned_url, |
| 105 | } |
no test coverage detected