Class: LangExtract::Providers::RubyLLMProvider

Inherits:
Base
  • Object
show all
Defined in:
lib/langextract/providers/ruby_llm.rb

Constant Summary collapse

INTERNAL_EXTRACTION_SCHEMA =
{
  "type" => "object",
  "properties" => {
    "extractions" => {
      "type" => "array",
      "items" => {
        "type" => "object",
        "properties" => {
          "text" => { "type" => "string" },
          "extraction_class" => { "type" => "string" },
          "description" => { "type" => "string" },
          "attributes" => { "type" => "object" },
          "group_id" => { "type" => "string" }
        },
        "required" => ["text"]
      }
    }
  },
  "required" => ["extractions"]
}.freeze

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from LangExtract::Providers::Base

Instance Method Details

#infer(prompt:) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/langextract/providers/ruby_llm.rb', line 32

def infer(prompt:)
  require "ruby_llm"

  response = build_chat.ask(prompt)
  InferenceResult.new(text: extract_text(response), raw: response)
rescue LoadError => e
  raise Core::ProviderConfigError, "ruby_llm is required for live provider inference: #{e.message}"
rescue StandardError => e
  error_class = provider_error_class(e)
  raise unless error_class

  raise error_class, "provider inference failed: #{e.message}"
end