Class: Nukitori::SchemaGenerator
- Inherits:
-
Object
- Object
- Nukitori::SchemaGenerator
- Defined in:
- lib/nukitori/schema_generator.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#create_extraction_schema_for(html) ⇒ Hash
Create extraction schema for given HTML.
-
#initialize(model: nil, &block) ⇒ SchemaGenerator
constructor
A new instance of SchemaGenerator.
Constructor Details
#initialize(model: nil, &block) ⇒ SchemaGenerator
Returns a new instance of SchemaGenerator.
22 23 24 25 26 27 |
# File 'lib/nukitori/schema_generator.rb', line 22 def initialize(model: nil, &block) raise ArgumentError, 'Block required for schema definition' unless block_given? @model = model @schema_block = block end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
7 8 9 |
# File 'lib/nukitori/schema_generator.rb', line 7 def model @model end |
Instance Method Details
#create_extraction_schema_for(html) ⇒ Hash
Create extraction schema for given HTML
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/nukitori/schema_generator.rb', line 36 def create_extraction_schema_for(html) doc = html.is_a?(Nokogiri::HTML::Document) ? html : Nokogiri::HTML(html) requirements = build_requirements(&@schema_block) processed_html = HtmlPreprocessor.process(doc) normalized_requirements = normalize_requirements(requirements) prompt = build_prompt(normalized_requirements) chat = ChatFactory.create(model:) chat.with_instructions(prompt) response = chat.ask(processed_html) ResponseParser.parse(response.content) end |