Skip to content

Commit c14d508

Browse files
mhsdefclaude
andcommitted
fix: preserve capabilities when model/1 receives a populated LLMDB.Model struct
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3608711 commit c14d508

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

lib/req_llm.ex

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -288,11 +288,15 @@ defmodule ReqLLM do
288288
"""
289289
@spec model(model_input()) :: {:ok, LLMDB.Model.t()} | {:error, term()}
290290
def model(%LLMDB.Model{} = model) do
291-
model
292-
|> Map.from_struct()
293-
|> Enum.reject(fn {_key, value} -> is_nil(value) end)
294-
|> Map.new()
295-
|> LLMDB.Enrich.enrich_model()
291+
non_nil =
292+
model
293+
|> Map.from_struct()
294+
|> Enum.reject(fn {_key, value} -> is_nil(value) end)
295+
|> Map.new()
296+
297+
enriched = LLMDB.Enrich.enrich_model(non_nil)
298+
299+
Map.merge(enriched, non_nil)
296300
|> LLMDB.Model.new()
297301
|> normalize_model_result()
298302
end

test/req_llm_test.exs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,28 @@ defmodule ReqLLMTest do
176176
}} = ReqLLM.model(model)
177177
end
178178

179+
test "preserves caller-provided fields from LLMDB.Model structs" do
180+
model =
181+
LLMDB.Model.new!(%{
182+
id: "test-model-not-in-catalog",
183+
provider: :openai,
184+
base_url: "http://my-custom-endpoint.example.com",
185+
capabilities: %{
186+
chat: true,
187+
json: %{schema: true},
188+
tools: %{enabled: true, strict: true},
189+
reasoning: %{enabled: true}
190+
}
191+
})
192+
193+
{:ok, result} = ReqLLM.model(model)
194+
195+
assert result.base_url == "http://my-custom-endpoint.example.com"
196+
assert result.capabilities.json.schema == true
197+
assert result.capabilities.tools.enabled == true
198+
assert result.capabilities.reasoning.enabled == true
199+
end
200+
179201
test "returns error for map missing required fields" do
180202
assert {:error, error} = ReqLLM.model(%{id: "no-provider"})
181203
assert Exception.message(error) =~ "Inline model specs require :provider"

0 commit comments

Comments
 (0)