# sora-ai-video
A robust Elixir library for interacting with AI video generation services. Simplifies the process of creating, manipulating, and managing AI-generated videos within your Elixir applications.
## Installation
Add `sora_ai_video` to your list of dependencies in `mix.exs`:
elixir
def deps do
[
{:sora_ai_video, "~> 0.1.0"} # Replace with the latest version
]
end
Then, run `mix deps.get` to fetch the dependency.
## Usage Examples
Here are a few examples demonstrating common use cases:
**1. Generating a Video from a Text Prompt:**
elixir
defmodule MyModule do
alias SoraAiVideo.Client
def generate_video(prompt) do
{:ok, video_data} =
Client.generate_video(prompt, %{duration: 10, resolution: "1280x720"})
|> handle_generation_result()
video_data
end
defp handle_generation_result({:ok, video_data}), do: {:ok, video_data}
defp handle_generation_result({:error, reason}), do: {:error, "Video generation failed: #{reason}"}
end
# Example usage:
# MyModule.generate_video("A cat playing the piano in a sunlit room.")
**2. Retrieving Video Details by ID:**
elixir
defmodule MyModule do
alias SoraAiVideo.Client
def get_video_details(video_id) do
case Client.get_video(video_id) do
{:ok, video} ->
IO.puts("Video Title: #{video.title}")
IO.puts("Video Duration: #{video.duration}")
video
{:error, reason} ->
IO.puts("Error retrieving video: #{reason}")
nil
end
end
end
# Example Usage:
# MyModule.get_video_details("some_video_id")
**3. Batch Processing Video Generation Prompts:**
elixir
defmodule MyModule do
alias SoraAiVideo.Client
def generate_videos(prompts) do
prompts
|> Enum.map(fn prompt ->
Task.async(fn -> Client.generate_video(prompt, %{duration: 5}) end)
end)
|> Enum.map(fn task -> Task.await(task) end)
|> Enum.each(fn
{:ok, video_data} -> IO.puts("Video generated successfully: #{video_data.id}")
{:error, reason} -> IO.puts("Video generation failed: #{reason}")
end)
end
end
# Example Usage:
# MyModule.generate_videos(["A dog chasing a ball.", "A bird flying over a mountain."])
**4. Using with a custom API Key:**
elixir
defmodule MyModule do
alias SoraAiVideo.Client
def generate_video(prompt, api_key) do
Client.new(api_key: api_key)
|> Client.generate_video(prompt, %{duration: 10, resolution: "1280x720"})
end
end
# Example Usage:
# MyModule.generate_video("A futuristic city at night.", "YOUR_API_KEY")
**5. Handling Errors and Retries:**
elixir
defmodule MyModule do
alias SoraAiVideo.Client
def generate_video_with_retry(prompt, retries \\ 3) do
case Client.generate_video(prompt, %{duration: 7}) do
{:ok, video} ->
{:ok, video}
{:error, _} when retries > 0 ->
IO.puts("Retrying video generation...")
Process.sleep(1000) # Wait for 1 second
generate_video_with_retry(prompt, retries - 1)
{:error, reason} ->
{:error, "Video generation failed after multiple retries: #{reason}"}
end
end
end
# Example usage:
# MyModule.generate_video_with_retry("A sunset over the ocean.")
## Feature Summary
* **Video Generation:** Create videos from text prompts.
* **Video Retrieval:** Fetch video details by ID.
* **Asynchronous Operations:** Utilizes `Task` for concurrent video processing.
* **Error Handling:** Provides robust error handling for API interactions.
* **Configuration:** Supports setting custom API keys.
* **Retry Logic:** Implements retry mechanisms for transient API errors.
## License
MIT
This package is part of the sora-ai-video ecosystem. For advanced features and enterprise-grade tools, visit: https://supermaker.ai/video/sora-ai-video/