Module: Exa::Types::Schema
- Defined in:
- lib/exa/types/schema.rb
Constant Summary collapse
- HAS_DSPY_SCHEMA =
begin require "dspy/schema" true rescue LoadError false end
Class Method Summary collapse
- .ensure_converter! ⇒ Object
- .maybe_convert(value) ⇒ Object
- .sorbet_type_object?(value) ⇒ Boolean
- .struct_class?(value) ⇒ Boolean
- .to_json_schema(type) ⇒ Object
- .type_alias?(value) ⇒ Boolean
Class Method Details
.ensure_converter! ⇒ Object
50 51 52 53 54 55 |
# File 'lib/exa/types/schema.rb', line 50 def ensure_converter! return if HAS_DSPY_SCHEMA raise NotImplementedError, "Sorbet JSON Schema converter not available. Install dspy-schema to enable this feature." end |
.maybe_convert(value) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/exa/types/schema.rb', line 22 def maybe_convert(value) return nil if value.nil? return value if value.is_a?(Hash) return nil unless HAS_DSPY_SCHEMA if struct_class?(value) to_json_schema(value) elsif type_alias?(value) to_json_schema(value) elsif sorbet_type_object?(value) to_json_schema(value) else nil end end |
.sorbet_type_object?(value) ⇒ Boolean
46 47 48 |
# File 'lib/exa/types/schema.rb', line 46 def sorbet_type_object?(value) defined?(T::Types::Base) && value.is_a?(T::Types::Base) end |
.struct_class?(value) ⇒ Boolean
38 39 40 |
# File 'lib/exa/types/schema.rb', line 38 def struct_class?(value) value.is_a?(Class) && !value.name.nil? && (value < T::Struct || value < T::Enum) end |
.to_json_schema(type) ⇒ Object
17 18 19 20 |
# File 'lib/exa/types/schema.rb', line 17 def to_json_schema(type) ensure_converter! DSPy::TypeSystem::SorbetJsonSchema.type_to_json_schema(type) end |
.type_alias?(value) ⇒ Boolean
42 43 44 |
# File 'lib/exa/types/schema.rb', line 42 def type_alias?(value) defined?(T::Private::Types::TypeAlias) && value.is_a?(T::Private::Types::TypeAlias) end |