Class: Boxcars::URLText

Inherits:
Boxcar
  • Object
show all
Defined in:
lib/boxcars/boxcar/url_text.rb

Overview

A Boxcar that reads text from a URL.

Constant Summary collapse

DESC =

Default description for this boxcar.

"useful when you want to get text from a URL."

Constants inherited from Boxcar

Boxcar::SCHEMA_KEY_ALIASES, Boxcar::TYPE_ALIASES

Instance Attribute Summary

Attributes inherited from Boxcar

#description, #name, #parameters, #return_direct

Instance Method Summary collapse

Methods inherited from Boxcar

#apply, assi, #conduct, #conduct_result, hist, #input_keys, #output_keys, #parameters_json_schema, #run, #run_result, #schema, syst, #tool_call_name, #tool_definition, #tool_spec, user, #validate_inputs, #validate_outputs

Constructor Details

#initialize(name: "FetchURL", description: DESC) ⇒ URLText

Create a URL text extraction boxcar.

Parameters:

  • name (String) (defaults to: "FetchURL")

    The name of the boxcar. Defaults to classname.

  • description (String) (defaults to: DESC)

    A description of the boxcar.



12
13
14
# File 'lib/boxcars/boxcar/url_text.rb', line 12

def initialize(name: "FetchURL", description: DESC)
  super
end

Instance Method Details

#call(inputs:) ⇒ Hash

Execute one URL text fetch using the normalized Boxcar input contract.

Parameters:

  • inputs (Hash)

    Expected to contain ‘:question` (or `“question”`) with a URL.

Returns:

  • (Hash)

    ‘{ answer: Boxcars::Result }`.



19
20
21
22
23
# File 'lib/boxcars/boxcar/url_text.rb', line 19

def call(inputs:)
  url = inputs[:question]
  parsed_url = URI.parse(url)
  { answer: do_encoding(get_answer(parsed_url)) }
end