Make URL target a config option to allow for easier local testing and mocking
rwdaigle opened this issue · comments
Describe the feature or improvement you're requesting
I would like to be able use Bypass, or similar, to write local integrations tests without having to hit the actual OpenAI API. Key to this is the ability to set openai.ex's URL, currently hardcoded as @openai_url
within OpenAI.Config
.
I would like to propose that the openai_url
be overridable by a new api_url
config option:
config :openai,
api_key: "your-api-key",
organization_key: "your-organization-key",
api_url: "http://localhost/",
http_options: [recv_timeout: 2_000]
This could then be overridden in a test setup block like so:
setup %{conn: conn} do
# Setup mock OpenAI server
bypass = Bypass.open()
Application.put_env(:openai, :api_url, "http://localhost:#{bypass.port}/")
# ...
{:ok, bypass: bypass, conn: conn}
end
Thoughts?
Additional context
No response
Hey, thanks for the suggestion and for the contribution! I merged your PR, and it is released in 0.4.0
Release log: https://github.com/mgallo/openai.ex/releases/tag/v0.4.0
Hex.pm: https://hexdocs.pm/openai/0.4.0/api-reference.html
🙏