Class: Nukitori::LlmExtractor
- Inherits:
-
Object
- Object
- Nukitori::LlmExtractor
- Defined in:
- lib/nukitori/llm_extractor.rb
Overview
Extracts data directly using LLM (no schema generation/caching)
Class Method Summary collapse
-
.extract(html, model: nil, &block) ⇒ Hash
Extract data from HTML using LLM directly.
Class Method Details
.extract(html, model: nil, &block) ⇒ Hash
Extract data from HTML using LLM directly
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/nukitori/llm_extractor.rb', line 12 def extract(html, model: nil, &block) raise ArgumentError, 'Block required for schema definition' unless block_given? schema_class = Class.new(RubyLLM::Schema, &block) processed_html = HtmlPreprocessor.process(html) chat = ChatFactory.create(model:) chat.with_schema(schema_class) if support_structured_output?(chat.model) chat.with_instructions(build_prompt(schema_class)) response = chat.ask(processed_html) ResponseParser.parse(response.content) end |