Normandy.LLM.OpenAICompatibleAdapter (normandy v1.2.0)

View Source

Adapter implementing Normandy.Agents.Model against any OpenAI-compatible Chat Completions endpoint (OpenAI, DigitalOcean Inference, etc.).

Text-completion only (v1): tool/function calling is not supported and a non-empty opts[:tools] raises. Structured output + prose fallback reuse the same Normandy.LLM.JsonDeserializer path as Normandy.LLM.ClaudioAdapter.

client = %Normandy.LLM.OpenAICompatibleAdapter{
  api_key: System.get_env("OPENAI_API_KEY"),
  base_url: "https://api.openai.com/v1"
}

Transport injection (testing)

Pass a custom Req :adapter function via options[:req_options] to stub the HTTP layer in tests without network access:

adapter_fn = fn request ->
  response = Req.Response.json(%{"choices" => [%{"message" => %{"content" => "hi"}}]})
  {request, response}
end

client = %Normandy.LLM.OpenAICompatibleAdapter{
  api_key: "test",
  options: %{req_options: [adapter: adapter_fn]}
}

Summary

Types

t()

@type t() :: %Normandy.LLM.OpenAICompatibleAdapter{
  __meta__: term(),
  api_key: String.t(),
  base_url: String.t(),
  finch: atom() | nil,
  options: map()
}