Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions codemod/populate_custom_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions magic_hour/resources/v1/face_detection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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="."
Expand All @@ -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="."
Expand Down
Loading