Class: Boxcars::Swagger

Inherits:
EngineBoxcar show all
Defined in:
lib/boxcars/boxcar/swagger.rb

Overview

A Boxcar that interprets a prompt and executes API calls to get an answer.

Constant Summary collapse

DESC =

the description of this engine boxcar

"useful for when you need to make Open API calls to get an answer."

Instance Attribute Summary collapse

Attributes inherited from EngineBoxcar

#engine, #prompt, #stop, #top_k

Attributes inherited from Boxcar

#description, #name, #parameters, #return_direct

Instance Method Summary collapse

Methods inherited from EngineBoxcar

#apply, #call, #check_output_keys, #extract_code, #generate, #input_key, #input_keys, #output_key, #output_keys, #predict, #prediction_input, #prediction_variables

Methods inherited from Boxcar

#apply, assi, #call, #conduct, hist, #input_keys, #load, #output_keys, #run, #save, #schema, syst, user, #validate_inputs, #validate_outputs

Constructor Details

#initialize(swagger_url:, engine: nil, prompt: nil, context: "", **kwargs) ⇒ Swagger

Returns a new instance of Swagger.

Parameters:

  • swagger_url (String)

    The URL of the Open API Swagger file to use.

  • engine (Boxcars::Engine) (defaults to: nil)

    The engine to user for this boxcar. Can be inherited from a train if nil.

  • prompt (Boxcars::Prompt) (defaults to: nil)

    The prompt to use for this boxcar. Defaults to built-in prompt.

  • context (String) (defaults to: "")

    Additional context to use for the prompt.

  • kwargs (Hash)

    Any other keyword arguments to pass to the parent class.



17
18
19
20
21
22
23
24
25
# File 'lib/boxcars/boxcar/swagger.rb', line 17

def initialize(swagger_url:, engine: nil, prompt: nil, context: "", **kwargs)
  @swagger_url = swagger_url
  @context = context
  the_prompt = prompt || my_prompt
  kwargs[:stop] ||= ["```output"]
  kwargs[:name] ||= "Swagger API"
  kwargs[:description] ||= DESC
  super(engine: engine, prompt: the_prompt, **kwargs)
end

Instance Attribute Details

#contextObject

Returns the value of attribute context.



10
11
12
# File 'lib/boxcars/boxcar/swagger.rb', line 10

def context
  @context
end

#swagger_urlObject

Returns the value of attribute swagger_url.



10
11
12
# File 'lib/boxcars/boxcar/swagger.rb', line 10

def swagger_url
  @swagger_url
end

Instance Method Details

#prediction_additional(_inputs) ⇒ Object

Returns Hash The additional variables for this boxcar.

Returns:

  • Hash The additional variables for this boxcar.



28
29
30
# File 'lib/boxcars/boxcar/swagger.rb', line 28

def prediction_additional(_inputs)
  { swagger_url: swagger_url, context: context }.merge super
end