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 +4 -4
- data/README.md +3 -3
- data/generative_ui.gemspec +2 -1
- data/lib/generative_ui/attributes.rb +19 -11
- data/lib/generative_ui/catalog.rb +1 -1
- data/lib/generative_ui/component_definition.rb +1 -1
- data/lib/generative_ui/tool.rb +2 -2
- data/lib/generative_ui/version.rb +1 -1
- data/lib/generative_ui.rb +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fb665b5e260116d8e3afdeadbb670906145e58b90231215ee2e6a055f0495d7d
|
|
4
|
+
data.tar.gz: 78499012634cab55dc364d04d316c801d41dc13e9ccaccb0c315d542232a2570
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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 `
|
|
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.
|
|
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.
|
|
115
|
+
chat.with_tools(tool)
|
|
116
116
|
```
|
|
117
117
|
|
|
118
118
|
```erb
|
data/generative_ui.gemspec
CHANGED
|
@@ -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", "~>
|
|
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
|
-
|
|
44
|
-
|
|
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
|
-
|
|
56
|
-
|
|
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 <
|
|
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(
|
|
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&.
|
|
242
|
+
raw_schema = definition.attributes_definition&.raw_schema
|
|
243
243
|
next unless raw_schema
|
|
244
244
|
|
|
245
245
|
validate_schema_fields!(definition, raw_schema)
|
data/lib/generative_ui/tool.rb
CHANGED
|
@@ -46,8 +46,8 @@ module GenerativeUI
|
|
|
46
46
|
TEXT
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
def
|
|
50
|
-
@
|
|
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)
|
data/lib/generative_ui.rb
CHANGED
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
|
|
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: '
|
|
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: '
|
|
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
|