thmsmlr / instructor_ex

Structured outputs for LLMs in Elixir
https://hexdocs.pm/instructor
430 stars 48 forks source link

Inconsistency in getting adapter from config via function params? #42

Open noozo opened 2 months ago

noozo commented 2 months ago

Hi all,

I noticed this function in completions.ex:

defp adapter(%{adapter: adapter}) when is_atom(adapter), do: adapter
defp adapter(_), do: Application.get_env(:instructor, :adapter, Instructor.Adapters.OpenAI)

Looking into how the adapters use the config internally, seems like they all expect config to be a keyword list, not a map. My take is that the first clause there is wrong and makes passing in the adapter via explicit config impossible atm.

Am i wrong?

noozo commented 2 months ago

Something like this would work?

defp adapter(config),
    do:
      if(config[:adapter],
        do: config[:adapter],
        else: Application.get_env(:instructor, :adapter, Instructor.Adapters.OpenAI)
      )
noozo commented 2 months ago

Created PR https://github.com/thmsmlr/instructor_ex/pull/43