# ai-replace-prompt
A utility library for crafting and managing AI image replacement prompts, simplifying integration with image generation services. This package provides a structured way to build prompts for specific image transformations.
## Installation
Add `ai_replace_prompt` to your list of dependencies in `mix.exs`:
elixir
def deps do
[
{:ai_replace_prompt, "~> 0.1.0"}
]
end
Then run `mix deps.get` to fetch the dependency.
## Usage
Here are a few examples of how to use `ai_replace_prompt` in your Elixir code:
**1. Basic Replacement:**
elixir
alias AiReplacePrompt.Builder
prompt =
Builder.new()
|> Builder.replace("sky")
|> Builder.with("a vibrant sunset")
|> Builder.to_string()
IO.puts(prompt) # Output: "replace sky with a vibrant sunset"
**2. Adding Subject and Style:**
elixir
alias AiReplacePrompt.Builder
prompt =
Builder.new()
|> Builder.replace("background")
|> Builder.with("a lush forest")
|> Builder.subject("portrait of a woman")
|> Builder.style("photorealistic")
|> Builder.to_string()
IO.puts(prompt) # Output: "replace background with a lush forest in the style of photorealistic featuring portrait of a woman"
**3. Complex Scenario with Negative Prompt:**
elixir
alias AiReplacePrompt.Builder
prompt =
Builder.new()
|> Builder.replace("the old car")
|> Builder.with("a sleek, modern sports car")
|> Builder.negative("out of focus, blurry")
|> Builder.to_string()
IO.puts(prompt) # Output: "replace the old car with a sleek, modern sports car, avoid: out of focus, blurry"
**4. Customizing the delimiter:**
elixir
alias AiReplacePrompt.Builder
prompt =
Builder.new(delimiter: "; ")
|> Builder.replace("lamp")
|> Builder.with("modern lamp")
|> Builder.subject("room")
|> Builder.style("minimalistic")
|> Builder.to_string()
IO.puts(prompt) # Output: "replace lamp with modern lamp; featuring room; in the style of minimalistic"
**5. Using Pattern Matching for Specific Replacement Types:**
elixir
defmodule PromptGenerator do
alias AiReplacePrompt.Builder
def generate_prompt(replacement_type, new_element) do
case replacement_type do
:sky ->
Builder.new()
|> Builder.replace("sky")
|> Builder.with(new_element)
|> Builder.style("dreamy")
|> Builder.to_string()
:object ->
Builder.new()
|> Builder.replace("object")
|> Builder.with(new_element)
|> Builder.to_string()
_ ->
"Invalid replacement type"
end
end
end
IO.puts(PromptGenerator.generate_prompt(:sky, "a clear blue sky with fluffy clouds"))
# Output: "replace sky with a clear blue sky with fluffy clouds in the style of dreamy"
IO.puts(PromptGenerator.generate_prompt(:object, "a vase of flowers"))
# Output: "replace object with a vase of flowers"
IO.puts(PromptGenerator.generate_prompt(:invalid, "something"))
# Output: "Invalid replacement type"
## Features
* Simple and intuitive API for building AI replacement prompts.
* Fluent interface for chaining prompt components.
* Supports replacing specific elements in an image.
* Allows specifying the new element to replace with.
* Provides options for adding subject, style, and negative prompts.
* Customizable delimiter for prompt sections.
* Encapsulates prompt construction logic for cleaner code.
## License
MIT
This package is part of the ai-replace-prompt ecosystem. For advanced features and enterprise-grade tools, visit: https://supermaker.ai/blog/best-ai-replace-prompts-to-transform-your-photos-instantly/