-
Notifications
You must be signed in to change notification settings - Fork 19
Video api #377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Video api #377
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9e17597
Video API support
rishabh-bhargava 474d848
Small change
rishabh-bhargava 6b2e177
Update Video API PR with requested changes (#378)
blainekasten 0e7ba25
fix formatting
blainekasten b037ca2
change to the openai compatible api
blainekasten 40bfbcf
Update create api to have optional prompt and use string for seconds
blainekasten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,307 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import Any, Dict, List | ||
|
|
||
| from together.abstract import api_requestor | ||
| from together.together_response import TogetherResponse | ||
| from together.types import ( | ||
| TogetherClient, | ||
| TogetherRequest, | ||
| ) | ||
| from together.types.videos import ( | ||
| VideoGenerateResponse, | ||
| VideoRequest, | ||
| VideoStatusResponse, | ||
| ) | ||
|
|
||
|
|
||
| class Videos: | ||
| def __init__(self, client: TogetherClient) -> None: | ||
| self._client = client | ||
|
|
||
| def generate( | ||
| self, | ||
| *, | ||
| prompt: str, | ||
| model: str, | ||
| height: int | None = None, | ||
| width: int | None = None, | ||
| seconds: float | None = None, | ||
| fps: int | None = None, | ||
| steps: int | None = None, | ||
| seed: int | None = None, | ||
| guidance_scale: float | None = None, | ||
| output_format: str | None = None, | ||
| output_quality: int | None = None, | ||
| negative_prompt: str | None = None, | ||
| frame_images: List[Dict[str, Any]] | None = None, | ||
| reference_images: List[Dict[str, Any]] | None = None, | ||
blainekasten marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| metadata: Dict[str, Any] | None = None, | ||
| **kwargs: Any, | ||
| ) -> VideoGenerateResponse: | ||
| """ | ||
| Method to generate videos based on a given prompt using a specified model. | ||
|
|
||
| Args: | ||
| prompt (str): A description of the desired video. Positive prompt for the generation. | ||
|
|
||
| model (str): The model to use for video generation. | ||
|
|
||
| height (int, optional): Height of the video to generate in pixels. | ||
|
|
||
| width (int, optional): Width of the video to generate in pixels. | ||
|
|
||
| seconds (float, optional): Length of generated video in seconds. Min 1 max 10. | ||
|
|
||
| fps (int, optional): Frames per second, min 15 max 60. Defaults to 24. | ||
|
|
||
| steps (int, optional): The number of denoising steps the model performs during video | ||
| generation. More steps typically result in higher quality output but require longer | ||
| processing time. Min 10 max 50. Defaults to 20. | ||
|
|
||
| seed (int, optional): Seed to use in initializing the video generation. Using the same | ||
| seed allows deterministic video generation. If not provided, a random seed is | ||
| generated for each request. Note: When requesting multiple videos with the same | ||
| seed, the seed will be incremented by 1 (+1) for each video generated. | ||
|
|
||
| guidance_scale (float, optional): Controls how closely the video generation follows your | ||
| prompt. Higher values make the model adhere more strictly to your text description, | ||
| while lower values allow more creative freedom. Recommended range is 6.0-10.0 for | ||
| most video models. Values above 12 may cause over-guidance artifacts or unnatural | ||
| motion patterns. Defaults to 8. | ||
|
|
||
| output_format (str, optional): Specifies the format of the output video. Either "MP4" | ||
| or "WEBM". Defaults to "MP4". | ||
|
|
||
| output_quality (int, optional): Compression quality. Defaults to 20. | ||
|
|
||
| negative_prompt (str, optional): Similar to prompt, but specifies what to avoid instead | ||
| of what to include. Defaults to None. | ||
|
|
||
| frame_images (List[Dict[str, Any]], optional): Array of images to guide video generation, | ||
| like keyframes. If size 1, starting frame; if size 2, starting and ending frame; | ||
| if more than 2 then frame must be specified. Defaults to None. | ||
|
|
||
| reference_images (List[Dict[str, Any]], optional): An array containing reference images | ||
blainekasten marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| used to condition the generation process. These images provide visual guidance to | ||
| help the model generate content that aligns with the style, composition, or | ||
| characteristics of the reference materials. Defaults to None. | ||
|
|
||
| metadata (Dict[str, Any], optional): Additional metadata for the request. Defaults to None. | ||
blainekasten marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Returns: | ||
| VideoGenerateResponse: Object containing video generation job id | ||
| """ | ||
|
|
||
| requestor = api_requestor.APIRequestor( | ||
| client=self._client, | ||
| ) | ||
|
|
||
| parameter_payload = VideoRequest( | ||
| prompt=prompt, | ||
| model=model, | ||
| height=height, | ||
| width=width, | ||
| seconds=seconds, | ||
| fps=fps, | ||
| steps=steps, | ||
| seed=seed, | ||
| guidance_scale=guidance_scale, | ||
| output_format=output_format, | ||
| output_quality=output_quality, | ||
| negative_prompt=negative_prompt, | ||
| frame_images=frame_images, | ||
| reference_images=reference_images, | ||
| metadata=metadata, | ||
blainekasten marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| **kwargs, | ||
| ).model_dump(exclude_none=True) | ||
|
|
||
| response, _, _ = requestor.request( | ||
| options=TogetherRequest( | ||
| method="POST", | ||
| url="../v2/videos", | ||
blainekasten marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| params=parameter_payload, | ||
| ), | ||
| stream=False, | ||
| ) | ||
|
|
||
| assert isinstance(response, TogetherResponse) | ||
|
|
||
| return VideoGenerateResponse(**response.data) | ||
|
|
||
| def status( | ||
| self, | ||
| *, | ||
| id: str, | ||
| ) -> VideoStatusResponse: | ||
| """ | ||
| Method to check the status of a video generation job. | ||
|
|
||
| Args: | ||
| id (str): The ID of the video generation job to check. | ||
|
|
||
| Returns: | ||
| VideoStatusResponse: Object containing the current status and details of the video generation job | ||
| """ | ||
|
|
||
| requestor = api_requestor.APIRequestor( | ||
| client=self._client, | ||
| ) | ||
|
|
||
| response, _, _ = requestor.request( | ||
| options=TogetherRequest( | ||
| method="GET", | ||
| url=f"../v2/videos/status?id={id}", | ||
| ), | ||
| stream=False, | ||
| ) | ||
|
|
||
| assert isinstance(response, TogetherResponse) | ||
|
|
||
| return VideoStatusResponse(**response.data) | ||
|
|
||
|
|
||
| class AsyncVideos: | ||
| def __init__(self, client: TogetherClient) -> None: | ||
| self._client = client | ||
|
|
||
| async def generate( | ||
| self, | ||
| *, | ||
| prompt: str, | ||
| model: str, | ||
| height: int | None = None, | ||
| width: int | None = None, | ||
| seconds: float | None = None, | ||
| fps: int | None = None, | ||
| steps: int | None = None, | ||
| seed: int | None = None, | ||
| guidance_scale: float | None = None, | ||
| output_format: str | None = None, | ||
| output_quality: int | None = None, | ||
| negative_prompt: str | None = None, | ||
| frame_images: List[Dict[str, Any]] | None = None, | ||
| reference_images: List[Dict[str, Any]] | None = None, | ||
blainekasten marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| metadata: Dict[str, Any] | None = None, | ||
blainekasten marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| **kwargs: Any, | ||
| ) -> VideoGenerateResponse: | ||
| """ | ||
| Async method to generate videos based on a given prompt using a specified model. | ||
|
|
||
| Args: | ||
| prompt (str): A description of the desired video. Positive prompt for the generation. | ||
|
|
||
| model (str): The model to use for video generation. | ||
|
|
||
| height (int, optional): Height of the video to generate in pixels. | ||
|
|
||
| width (int, optional): Width of the video to generate in pixels. | ||
|
|
||
| seconds (float, optional): Length of generated video in seconds. Min 1 max 10. | ||
|
|
||
| fps (int, optional): Frames per second, min 15 max 60. Defaults to 24. | ||
|
|
||
| steps (int, optional): The number of denoising steps the model performs during video | ||
| generation. More steps typically result in higher quality output but require longer | ||
| processing time. Min 10 max 50. Defaults to 20. | ||
|
|
||
| seed (int, optional): Seed to use in initializing the video generation. Using the same | ||
| seed allows deterministic video generation. If not provided, a random seed is | ||
| generated for each request. Note: When requesting multiple videos with the same | ||
| seed, the seed will be incremented by 1 (+1) for each video generated. | ||
|
|
||
| guidance_scale (float, optional): Controls how closely the video generation follows your | ||
| prompt. Higher values make the model adhere more strictly to your text description, | ||
| while lower values allow more creative freedom. Recommended range is 6.0-10.0 for | ||
| most video models. Values above 12 may cause over-guidance artifacts or unnatural | ||
| motion patterns. Defaults to 8. | ||
|
|
||
| output_format (str, optional): Specifies the format of the output video. Either "MP4" | ||
| or "WEBM". Defaults to "MP4". | ||
|
|
||
| output_quality (int, optional): Compression quality. Defaults to 20. | ||
|
|
||
| negative_prompt (str, optional): Similar to prompt, but specifies what to avoid instead | ||
| of what to include. Defaults to None. | ||
|
|
||
| frame_images (List[Dict[str, Any]], optional): Array of images to guide video generation, | ||
| like keyframes. If size 1, starting frame; if size 2, starting and ending frame; | ||
| if more than 2 then frame must be specified. Defaults to None. | ||
|
|
||
| reference_images (List[Dict[str, Any]], optional): An array containing reference images | ||
blainekasten marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| used to condition the generation process. These images provide visual guidance to | ||
| help the model generate content that aligns with the style, composition, or | ||
| characteristics of the reference materials. Defaults to None. | ||
|
|
||
| metadata (Dict[str, Any], optional): Additional metadata for the request. Defaults to None. | ||
blainekasten marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Returns: | ||
| VideoGenerateResponse: Object containing video generation job id | ||
| """ | ||
|
|
||
| requestor = api_requestor.APIRequestor( | ||
| client=self._client, | ||
| ) | ||
|
|
||
| parameter_payload = VideoRequest( | ||
| prompt=prompt, | ||
| model=model, | ||
| height=height, | ||
| width=width, | ||
| seconds=seconds, | ||
| fps=fps, | ||
| steps=steps, | ||
| seed=seed, | ||
| guidance_scale=guidance_scale, | ||
| output_format=output_format, | ||
| output_quality=output_quality, | ||
| negative_prompt=negative_prompt, | ||
| frame_images=frame_images, | ||
| reference_images=reference_images, | ||
| metadata=metadata, | ||
blainekasten marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| **kwargs, | ||
| ).model_dump(exclude_none=True) | ||
|
|
||
| response, _, _ = await requestor.arequest( | ||
| options=TogetherRequest( | ||
| method="POST", | ||
| url="../v2/videos", | ||
| params=parameter_payload, | ||
| ), | ||
| stream=False, | ||
| ) | ||
|
|
||
| assert isinstance(response, TogetherResponse) | ||
|
|
||
| return VideoGenerateResponse(**response.data) | ||
|
|
||
| async def status( | ||
| self, | ||
| *, | ||
| id: str, | ||
| ) -> VideoStatusResponse: | ||
| """ | ||
| Async method to check the status of a video generation job. | ||
|
|
||
| Args: | ||
| id (str): The ID of the video generation job to check. | ||
|
|
||
| Returns: | ||
| VideoStatusResponse: Object containing the current status and details of the video generation job | ||
| """ | ||
|
|
||
| requestor = api_requestor.APIRequestor( | ||
| client=self._client, | ||
| ) | ||
|
|
||
| response, _, _ = await requestor.arequest( | ||
| options=TogetherRequest( | ||
| method="GET", | ||
| url=f"../v2/videos/status?id={id}", | ||
| ), | ||
| stream=False, | ||
| ) | ||
|
|
||
| assert isinstance(response, TogetherResponse) | ||
|
|
||
| return VideoStatusResponse(**response.data) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.