Packages

Converts an abstract schema into JSON schemas required by various AI providers, minimizing code changes when switching providers.

Current section

Files

Jump to
lang_schema lib lang_schema keyword openai nullable.ex
Raw

lib/lang_schema/keyword/openai/nullable.ex

defmodule LangSchema.Keyword.OpenAI.Nullable do
use LangSchema.Keyword
@impl LangSchema.Keyword
def convert(json_schema, :nullable, value) do
case value do
true ->
json_schema
|> Map.update!("type", fn type -> [type, "null"] end)
false ->
json_schema
end
end
end