File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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"
You can’t perform that action at this time.
0 commit comments