Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/req_llm.ex
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,15 @@ defmodule ReqLLM do
"""
@spec model(model_input()) :: {:ok, LLMDB.Model.t()} | {:error, term()}
def model(%LLMDB.Model{} = model) do
model
|> Map.from_struct()
|> Enum.reject(fn {_key, value} -> is_nil(value) end)
|> Map.new()
|> LLMDB.Enrich.enrich_model()
non_nil =
model
|> Map.from_struct()
|> Enum.reject(fn {_key, value} -> is_nil(value) end)
|> Map.new()

enriched = LLMDB.Enrich.enrich_model(non_nil)

Map.merge(enriched, non_nil)
|> LLMDB.Model.new()
|> normalize_model_result()
end
Expand Down
22 changes: 22 additions & 0 deletions test/req_llm_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,28 @@ defmodule ReqLLMTest do
}} = ReqLLM.model(model)
end

test "preserves caller-provided fields from LLMDB.Model structs" do
model =
LLMDB.Model.new!(%{
id: "test-model-not-in-catalog",
provider: :openai,
base_url: "http://my-custom-endpoint.example.com",
capabilities: %{
chat: true,
json: %{schema: true},
tools: %{enabled: true, strict: true},
reasoning: %{enabled: true}
}
})

{:ok, result} = ReqLLM.model(model)

assert result.base_url == "http://my-custom-endpoint.example.com"
assert result.capabilities.json.schema == true
assert result.capabilities.tools.enabled == true
assert result.capabilities.reasoning.enabled == true
end

test "returns error for map missing required fields" do
assert {:error, error} = ReqLLM.model(%{id: "no-provider"})
assert Exception.message(error) =~ "Inline model specs require :provider"
Expand Down
Loading