Skip to content

Commit

Permalink
Merge pull request #1167 from julep-ai/x/ffmpeg-fix
Browse files Browse the repository at this point in the history
fix(integrations): updated ffmpeg file input to support list of strings
  • Loading branch information
Vedantsahai18 authored Feb 17, 2025
2 parents 0ce88ed + 651b464 commit fc337bd
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 620 deletions.
4 changes: 2 additions & 2 deletions agents-api/agents_api/autogen/Tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ class FfmpegSearchArguments(BaseModel):
"""
The bash command string
"""
file: str | None = None
file: str | list[str] | None = None
"""
The base64 string of the file
"""
Expand All @@ -1217,7 +1217,7 @@ class FfmpegSearchArgumentsUpdate(BaseModel):
"""
The bash command string
"""
file: str | None = None
file: str | list[str] | None = None
"""
The base64 string of the file
"""
Expand Down
5 changes: 5 additions & 0 deletions agents-api/agents_api/workflows/task_execution/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,11 @@ async def _handle_YieldStep(

yield_transition_type, yield_next_target = self.outcome.transition_to
workflow.logger.info(f"Yield step: Transitioning to {yield_transition_type}")

if self.context is None:
msg = "Context must not be None"
raise ApplicationError(msg)

await transition(
self.context,
output=output,
Expand Down
4 changes: 4 additions & 0 deletions agents-api/agents_api/workflows/task_execution/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ async def continue_as_child(
info.workflow_type, *args, **kwargs
)

if execution_input.execution is None:
msg = "Execution input execution cannot be None"
raise ApplicationError(msg)

execution_id = execution_input.execution.id
execution_id_key = SearchAttributeKey.for_keyword("CustomStringField")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ To get started with the Cloudinary integration, follow these steps to configure
- **_tool_**: Refers to the tool defined earlier (`cloudinary_tool`).
- **_arguments_**: Specifies the input parameters for the tool:
<Accordion title="media_upload">
- **_file_**: The URL of the file to upload.
- **_file_**: The URL of the file to upload. More details can be found in the [Cloudinary documentation](https://cloudinary.com/documentation/image_upload_api_reference#upload).
- **_public_id_**: (optional) Optional public ID for the uploaded file. Defaults to None.
- **_upload_params_**: (optional) Optional transformations for the upload. Defaults to None.
- **_return_base64_**: (optional) Whether to return the file in base64 encoding. Defaults to False.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ To get started with the FFmpeg integration, follow these steps to configure and
cmd: "ffmpeg -i input.mp4 -vn -acodec copy output.aac"
file: "base64_encoded_file"
```
<Info>
The `base64_encoded_file` is the base64 encoded file to process which in this case is the `input.mp4` file.
The `file` argument can accept either a single base64 encoded string or a list of base64 encoded strings.
However, even when passing a list of files, the FFmpeg command can only use a single input file (single `-i` flag).
Multiple input files with multiple `-i` flags are not supported.
</Info>
</Step>
</Steps>

Expand All @@ -53,7 +60,7 @@ To get started with the FFmpeg integration, follow these steps to configure and
- **_tool_**: Refers to the tool defined earlier (`ffmpeg_tool`).
- **_arguments_**: Specifies the input parameters for the tool:
- **_cmd_**: The FFmpeg command to execute.
- **_file_**: The base64 encoded file to process.
- **_file_**: The base64 encoded file to process. Can be a single base64 encoded string or a list of base64 encoded strings.
</Accordion>
</AccordionGroup>

Expand Down
4 changes: 2 additions & 2 deletions integrations-service/integrations/autogen/Tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ class FfmpegSearchArguments(BaseModel):
"""
The bash command string
"""
file: str | None = None
file: str | list[str] | None = None
"""
The base64 string of the file
"""
Expand All @@ -1217,7 +1217,7 @@ class FfmpegSearchArgumentsUpdate(BaseModel):
"""
The bash command string
"""
file: str | None = None
file: str | list[str] | None = None
"""
The base64 string of the file
"""
Expand Down
33 changes: 27 additions & 6 deletions integrations-service/integrations/utils/integrations/ffmpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,35 @@ async def bash_cmd(arguments: FfmpegSearchArguments) -> FfmpegSearchOutput:

# Decode base64 input
try:
input_data = base64.b64decode(arguments.file)
if isinstance(arguments.file, str):
input_data = [base64.b64decode(arguments.file)] # Convert single str to list
elif isinstance(arguments.file, list):
input_data = [base64.b64decode(file) for file in arguments.file]
else:
msg = "Invalid file input"
raise ValueError(msg)
except Exception:
return FfmpegSearchOutput(
fileoutput="Error: Invalid base64 input", result=False, mime_type=None
)

# Validate input format
is_valid, input_mime = await validate_format(input_data)

if not is_valid:
if not isinstance(input_data, list):
return FfmpegSearchOutput(
fileoutput="Error: Unsupported input file format",
fileoutput="Error: Input data must be a list",
result=False,
mime_type=None,
)

for data in input_data:
is_valid, input_mime = await validate_format(data)
if not is_valid:
return FfmpegSearchOutput(
fileoutput="Error: Unsupported input file format",
result=False,
mime_type=None,
)

# Create temporary directory
temp_dir = tempfile.mkdtemp()

Expand All @@ -104,8 +117,16 @@ async def bash_cmd(arguments: FfmpegSearchArguments) -> FfmpegSearchOutput:
stderr=asyncio.subprocess.PIPE,
)

# Write each decoded image to FFmpeg's stdin
for image_data in input_data:
process.stdin.write(image_data) # Send image to stdin
await process.stdin.drain() # Ensure smooth streaming

# Close stdin to signal end of input
process.stdin.close()

# Process FFmpeg output
stdout, stderr = await process.communicate(input=input_data)
stdout, stderr = await process.communicate()
success = process.returncode == 0

if success and os.path.exists(output_path):
Expand Down
Loading

0 comments on commit fc337bd

Please # to comment.