diff --git a/codemod/populate_custom_docs.py b/codemod/populate_custom_docs.py index 1a92a4ee..c7be5495 100644 --- a/codemod/populate_custom_docs.py +++ b/codemod/populate_custom_docs.py @@ -104,12 +104,16 @@ def _customize_docs_for_resource(self, content: str, resource_name: str) -> str: sync_generate_call = create_sync_params.replace( f"client.v1.{resource_name}.create(", f"client.v1.{resource_name}.generate(" ) - sync_generate_call = sync_generate_call + f"\n {generate_params}\n)" + sync_generate_call = self._append_generate_parameters( + sync_generate_call, generate_params + ) async_generate_call = create_async_params.replace( f"client.v1.{resource_name}.create(", f"client.v1.{resource_name}.generate(" ) - async_generate_call = async_generate_call + f"\n {generate_params}\n)" + async_generate_call = self._append_generate_parameters( + async_generate_call, generate_params + ) # Replace api-assets/id and image/id paths with /path/to paths in the code samples # Preserve the file ID and extension: api-assets/id/1234.mp4 -> /path/to/1234.mp4 @@ -172,6 +176,13 @@ def replacement(m: re.Match[str]) -> str: # Return the customized content - replacement will be handled by the caller return custom_docs_content + @staticmethod + def _append_generate_parameters(create_call: str, generate_params: str) -> str: + """Append generate-only parameters after a valid comma-separated create call.""" + create_call = create_call.rstrip() + separator = "" if create_call.endswith(",") else "," + return f"{create_call}{separator}\n {generate_params}\n)" + def _fallback_customization(self, content: str, resource_name: str) -> str: """Fallback customization when create samples aren't found.""" # This is the original approach as a fallback diff --git a/magic_hour/resources/v1/face_detection/README.md b/magic_hour/resources/v1/face_detection/README.md index 35c00e6c..abdfd661 100644 --- a/magic_hour/resources/v1/face_detection/README.md +++ b/magic_hour/resources/v1/face_detection/README.md @@ -32,7 +32,7 @@ from os import getenv client = Client(token=getenv("API_TOKEN")) res = client.v1.face_detection.generate( - assets={"target_file_path": "/path/to/1234.png"}, confidence_score=0.5 + assets={"target_file_path": "/path/to/1234.png"}, confidence_score=0.5, wait_for_completion=True, download_outputs=True, download_directory="." @@ -47,7 +47,7 @@ from os import getenv client = AsyncClient(token=getenv("API_TOKEN")) res = await client.v1.face_detection.generate( - assets={"target_file_path": "/path/to/1234.png"}, confidence_score=0.5 + assets={"target_file_path": "/path/to/1234.png"}, confidence_score=0.5, wait_for_completion=True, download_outputs=True, download_directory="."