generative_ui 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df2a6ce2fc73069777780c94ee27b0b5a42d547967e3fc2a10c71b000c8b8dfa
4
- data.tar.gz: fc79d3abe16ad49b5cca16d3afe605ec9dd324a88d212ae497c90f602452373b
3
+ metadata.gz: fb665b5e260116d8e3afdeadbb670906145e58b90231215ee2e6a055f0495d7d
4
+ data.tar.gz: 78499012634cab55dc364d04d316c801d41dc13e9ccaccb0c315d542232a2570
5
5
  SHA512:
6
- metadata.gz: e8d303d2d70e8e2bee59e84cbe7e512494233361a347c4e938550f21ddae1e6937c4e60cba11a3a9358388d7751f315388f074d4656c2a4309e75972918db988
7
- data.tar.gz: c5b6c4c975352d732b1f91696f4f3f65677bbc9654e3e6ce39c0aa071044e36b4d3deacb9fc28e8ed9c2ca43417fd662b15d9b25505b219a3b306f300ca1d43a
6
+ metadata.gz: dc82dc45a8d222d27c10704bf987a0141a85385af29543294b2da99685e52626a2ef1d9e47b95201df74481bcbbe6b8cabce5ddc2c47f9d5a86f8e345d05acf2
7
+ data.tar.gz: e68ce4aac53939817eb6064b0b3caf5f1a3972c8d5c42d13a1e6ccb150dede902a0c0f887647443f5c526930f5beaa891c2d0dd5732d6212497de75c27e0e140
data/README.md CHANGED
@@ -32,7 +32,7 @@ class ApplicationGenerativeCatalog < GenerativeUI::Catalog
32
32
  end
33
33
  ```
34
34
 
35
- Component attributes use `RubyLLM::Schema`. Structural refs use `one_component` for one child id and `many_components` for ordered child ids.
35
+ Component attributes use the `Schematist::Schema` DSL (the schema library behind RubyLLM 2.0 tools). Structural refs use `one_component` for one child id and `many_components` for ordered child ids.
36
36
 
37
37
  Register the default catalog explicitly:
38
38
 
@@ -82,7 +82,7 @@ chat.with_instructions(<<~PROMPT)
82
82
  - IMPORTANT: after calling generate_ui, do not add a final text answer.
83
83
  The tool call itself is the user-visible UI response.
84
84
  PROMPT
85
- chat.with_tool(tool)
85
+ chat.with_tools(tool)
86
86
 
87
87
  chat.ask("What programming language was designed to make developers happy and also turned out to be especially token-efficient for LLMs? Name its iconic web framework too, and present the answer as a titled card with one short explanation.")
88
88
  ```
@@ -112,7 +112,7 @@ The partial hides only `InvalidComponentTreeError`; configuration and rendering
112
112
 
113
113
  ```ruby
114
114
  tool = GenerativeUI::Tool.new(catalog: :support)
115
- chat.with_tool(tool)
115
+ chat.with_tools(tool)
116
116
  ```
117
117
 
118
118
  ```erb
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.require_paths = [ "lib" ]
27
27
 
28
28
  spec.add_dependency "activesupport", ">= 7.0"
29
- spec.add_dependency "ruby_llm", "~> 1.15"
29
+ spec.add_dependency "ruby_llm", "~> 2.0"
30
+ spec.add_dependency "schematist", "~> 1.1"
30
31
  spec.add_dependency "json_schemer", "~> 2.5"
31
32
  end
@@ -39,9 +39,14 @@ module GenerativeUI
39
39
  end
40
40
  end
41
41
 
42
+ # Schematist builds nested objects from a bare Schematist::Schema subclass, so
43
+ # `one_component`/`many_components` would be undefined inside an `object` block.
44
+ # Build them from the current class instead so the structural DSL stays available.
42
45
  module LocalSchemaBuilders
43
- def object_schema(description: nil, of: nil, &block)
44
- return determine_object_reference(of, description) if of
46
+ private
47
+
48
+ def build_object_schema(description, &block)
49
+ raise Schematist::InvalidObjectTypeError, 'An object needs a block or an `of:` schema to describe it.' unless block
45
50
 
46
51
  sub_schema = Class.new(self)
47
52
  result = sub_schema.class_eval(&block)
@@ -51,18 +56,14 @@ module GenerativeUI
51
56
  elsif schema_class?(result) && sub_schema.properties.empty?
52
57
  schema_class_to_inline_schema(result).merge(description ? { description: description } : {})
53
58
  else
54
- {
55
- type: 'object',
56
- properties: sub_schema.properties,
57
- required: sub_schema.required_properties,
58
- additionalProperties: sub_schema.additional_properties,
59
- description: description
60
- }.compact
59
+ schema = schema_for(sub_schema)
60
+ schema[:description] = description if description
61
+ schema
61
62
  end
62
63
  end
63
64
  end
64
65
 
65
- class Schema < RubyLLM::Schema
66
+ class Schema < Schematist::Schema
66
67
  extend StructuralDsl
67
68
  extend LocalSchemaBuilders
68
69
 
@@ -92,8 +93,15 @@ module GenerativeUI
92
93
  @schema_class = schema_class
93
94
  end
94
95
 
96
+ # The schema as declared, with snake_case names and structural-ref metadata intact.
97
+ # Schematist#to_json_schema stringifies keys and values and adds document headers,
98
+ # so read the schema body straight from the class instead.
99
+ def raw_schema
100
+ @raw_schema ||= schema_class.send(:schema_for, schema_class)
101
+ end
102
+
95
103
  def json_schema
96
- @json_schema ||= camelize_schema(schema_class.new.to_json_schema.fetch(:schema))
104
+ @json_schema ||= camelize_schema(raw_schema)
97
105
  end
98
106
 
99
107
  def structural_refs
@@ -239,7 +239,7 @@ module GenerativeUI
239
239
 
240
240
  def validate_component_fields!
241
241
  definitions.each do |definition|
242
- raw_schema = definition.attributes_definition&.schema_class&.new&.to_json_schema&.fetch(:schema)
242
+ raw_schema = definition.attributes_definition&.raw_schema
243
243
  next unless raw_schema
244
244
 
245
245
  validate_schema_fields!(definition, raw_schema)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ruby_llm/schema'
3
+ require 'schematist'
4
4
 
5
5
  module GenerativeUI
6
6
  class ComponentDefinition
@@ -46,8 +46,8 @@ module GenerativeUI
46
46
  TEXT
47
47
  end
48
48
 
49
- def params_schema
50
- @params_schema ||= JSON.parse(catalog.tool_arguments_schema.to_json)
49
+ def parameters_schema
50
+ @parameters_schema ||= JSON.parse(catalog.tool_arguments_schema.to_json)
51
51
  end
52
52
 
53
53
  def execute(**args)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GenerativeUI
4
- VERSION = '0.0.1'
4
+ VERSION = '0.1.0'
5
5
  end
data/lib/generative_ui.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require 'active_support'
4
4
  require 'active_support/concern'
5
5
  require 'active_support/core_ext'
6
- require 'ruby_llm/schema'
6
+ require 'schematist'
7
7
  require 'json'
8
8
 
9
9
  require_relative 'generative_ui/version'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: generative_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrey Samsonov
@@ -29,14 +29,28 @@ dependencies:
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: '1.15'
32
+ version: '2.0'
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '1.15'
39
+ version: '2.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: schematist
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.1'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.1'
40
54
  - !ruby/object:Gem::Dependency
41
55
  name: json_schemer
42
56
  requirement: !ruby/object:Gem::Requirement