sublayer 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0a5a558f063c63cab9aca167a16ae3ac31300614e1a042097c544cc6361e3775
4
- data.tar.gz: 59eb567e5ccecc071e204685fbe81f8b10fee384dadd4a04ba96275b38e9235f
3
+ metadata.gz: 3b88b5a8d08e537fed46f26b445126a1482f13e79732a545b225c6b6447e9417
4
+ data.tar.gz: 7903ce4058e07fa95faee094bc937f41eb297d23a941a8f2287365c052773797
5
5
  SHA512:
6
- metadata.gz: a0006db5e1aaacc819cc883ac16094d66c9e99b17b3069c19f5d43af59803ab8e032f07c900a7225b66a3ae91c14f49229742240676a74e9ce0548e5b423daeb
7
- data.tar.gz: 3072682126490797db51ba03dde2c8accaccb869f7c861338cb5a1019152701079709d26340096cc1685318119716683842ca2b15d9d37833746835dfa89b34b
6
+ metadata.gz: 07701102f65938db5dc6e9c1ed3de303073c4a185ecde0fc12c458e6051294d3bd00def3f89219663dc6f6f879b4aac29f84163b000f310bf18831fa94d3e831
7
+ data.tar.gz: e5c34b702ba9aabb599e4d95e13671ef3a433c577dc0a68fd2d1a3ff938d137819da31908ee11cd8eed334fb16dc02f08cd99be21f33ef41dd00db3d5e728065
@@ -3,23 +3,41 @@ module Sublayer
3
3
  module OutputAdapters
4
4
  module Formattable
5
5
  def format_properties
6
+ build_json_schema(self.properties)
7
+ end
8
+
9
+ def build_json_schema(props)
6
10
  formatted_properties = {}
7
- self.properties.each do |prop|
8
- property = {
9
- type: prop.type,
10
- description: prop.description
11
- }
12
-
13
- property[:enum] = prop.enum if prop.respond_to?(:enum) && prop.enum
14
- property[:default] = prop.default if prop.respond_to?(:default) && !prop.default.nil?
15
- property[:minimum] = prop.minimum if prop.respond_to?(:minimum) && !prop.minimum.nil?
16
- property[:maximum] = prop.maximum if prop.respond_to?(:maximum) && !prop.maximum.nil?
17
- property[:items] = prop.items if prop.respond_to?(:items) && prop.items
18
- formatted_properties[prop.name.to_sym] = property
11
+
12
+ props.map do |prop|
13
+ formatted_property = format_property(prop)
14
+ formatted_properties[prop.name.to_sym] = formatted_property
19
15
  end
16
+
20
17
  formatted_properties
21
18
  end
22
19
 
20
+ def format_property(property)
21
+ result = {
22
+ type: property.type,
23
+ description: property.description
24
+ }
25
+
26
+ result[:enum] = property.enum if property.respond_to?(:enum) && property.enum
27
+ result[:default] = property.default if property.respond_to?(:default) && !property.default.nil?
28
+ result[:minimum] = property.minimum if property.respond_to?(:minimum) && !property.minimum.nil?
29
+ result[:maximum] = property.maximum if property.respond_to?(:maximum) && !property.maximum.nil?
30
+
31
+ case property.type
32
+ when 'array'
33
+ result[:items] = property.items.is_a?(OpenStruct) ? format_property(property.items) : property.items
34
+ when 'object'
35
+ result[:properties] = build_json_schema(property.properties) if property.properties
36
+ end
37
+
38
+ result
39
+ end
40
+
23
41
  def format_required
24
42
  self.properties.select(&:required).map(&:name)
25
43
  end
@@ -0,0 +1,31 @@
1
+ module Sublayer
2
+ module Components
3
+ module OutputAdapters
4
+ class NamedStrings
5
+ attr_reader :name, :description, :attributes
6
+
7
+ def initialize(options)
8
+ @name = options[:name]
9
+ @description = options[:description]
10
+ @attributes = options[:attributes]
11
+ end
12
+
13
+ def properties
14
+ [
15
+ OpenStruct.new(
16
+ name: @name,
17
+ type: "object",
18
+ description: @description,
19
+ required: true,
20
+ properties: @attributes.map { |attribute| OpenStruct.new(type: "string", description: attribute[:description], required: true, name: attribute[:name]) }
21
+ )
22
+ ]
23
+ end
24
+
25
+ def materialize_result(raw_result)
26
+ OpenStruct.new( @attributes.map { |attribute| [attribute[:name], raw_result[attribute[:name]]] }.to_h)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -10,7 +10,10 @@ module Sublayer
10
10
 
11
11
  def generate
12
12
  self.class::OUTPUT_ADAPTER.load_instance_data(self) if self.class::OUTPUT_ADAPTER.respond_to?(:load_instance_data)
13
- @results = Sublayer.configuration.ai_provider.call(prompt: prompt, output_adapter: self.class::OUTPUT_ADAPTER)
13
+
14
+ raw_results = Sublayer.configuration.ai_provider.call(prompt: prompt, output_adapter: self.class::OUTPUT_ADAPTER)
15
+
16
+ @results = self.class::OUTPUT_ADAPTER.respond_to?(:materialize_result) ? self.class::OUTPUT_ADAPTER.materialize_result(raw_results) : raw_results
14
17
  end
15
18
  end
16
19
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sublayer
4
- VERSION = "0.2.2"
4
+ VERSION = "0.2.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sublayer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Werner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-12 00:00:00.000000000 Z
11
+ date: 2024-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-openai
@@ -195,6 +195,7 @@ files:
195
195
  - lib/sublayer/components/output_adapters.rb
196
196
  - lib/sublayer/components/output_adapters/formattable.rb
197
197
  - lib/sublayer/components/output_adapters/list_of_strings.rb
198
+ - lib/sublayer/components/output_adapters/named_strings.rb
198
199
  - lib/sublayer/components/output_adapters/single_string.rb
199
200
  - lib/sublayer/components/output_adapters/string_selection_from_list.rb
200
201
  - lib/sublayer/generators/base.rb