Packages
A spec-compliant Open Responses server for Elixir and Phoenix, with pluggable provider adapters and first-class streaming.
Current section
Files
Jump to
Current section
Files
lib/mix/tasks/open_responses.install.ex
defmodule Mix.Tasks.OpenResponses.Install do
@moduledoc """
Installs Open Responses into an existing Phoenix application.
Usage:
mix open_responses.install
What this does:
- Adds `OpenResponses.Responses` to your Ash domains config
- Mounts `POST /v1/responses` in your router
- Adds required children to your application supervisor
- Creates a default provider config block in `config/runtime.exs`
"""
use Igniter.Mix.Task
@impl Igniter.Mix.Task
def info(_argv, _composing_task) do
%Igniter.Mix.Task.Info{
installs: [],
adds_deps: [{:cachex, "~> 3.6"}],
extra_args?: false
}
end
@impl Igniter.Mix.Task
def igniter(igniter) do
igniter
|> add_ash_domain_to_config()
|> add_supervisor_children()
|> mount_router_scope()
|> add_runtime_config()
end
defp add_ash_domain_to_config(igniter) do
Igniter.Project.Config.configure(
igniter,
"config.exs",
:open_responses,
[:ash_domains],
[OpenResponses.Responses]
)
end
defp add_supervisor_children(igniter) do
igniter
|> Igniter.Project.Application.add_new_child({Cachex, name: :response_cache})
|> Igniter.Project.Application.add_new_child(OpenResponses.LoopSupervisor)
end
defp mount_router_scope(igniter) do
Igniter.Libs.Phoenix.add_scope(
igniter,
"/v1",
"""
pipe_through :api
post "/responses", OpenResponsesWeb.ResponseController, :create
""",
router: Igniter.Libs.Phoenix.select_router(igniter)
)
end
defp add_runtime_config(igniter) do
Igniter.Project.Config.configure(
igniter,
"runtime.exs",
:open_responses,
[:provider_config],
%{
openai: [api_key: {:env, "OPENAI_API_KEY"}],
anthropic: [api_key: {:env, "ANTHROPIC_API_KEY"}],
gemini: [api_key: {:env, "GEMINI_API_KEY"}]
}
)
end
end