Class: Vangrail::Rails::Remote

Inherits:
Vangrail::Rail show all
Defined in:
lib/vangrail/rails/remote.rb

Overview

A NeMo Guardrails server as one rail among the local ones.

Wrapping the client in the rail protocol is what keeps the two paths from becoming two designs. A team migrating off the Python service can put this rail and a local one in the same ordered list, compare them on live traffic, and drop the remote one when the local rails cover it.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client: nil, base_url: nil, config_id: nil, api_key: nil, name: 'remote', sides: Rail::SIDES) ⇒ Remote

Returns a new instance of Remote.



17
18
19
20
21
# File 'lib/vangrail/rails/remote.rb', line 17

def initialize(client: nil, base_url: nil, config_id: nil, api_key: nil,
               name: 'remote', sides: Rail::SIDES)
  super(name: name, sides: sides)
  @client = client || Client.new(base_url: base_url, config_id: config_id, api_key: api_key)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



15
16
17
# File 'lib/vangrail/rails/remote.rb', line 15

def client
  @client
end

Instance Method Details

#cache_key(text, context) ⇒ Object



27
28
29
30
31
# File 'lib/vangrail/rails/remote.rb', line 27

def cache_key(text, context)
  return text if context[:side] == :input

  "#{context[:user_input]} #{text}"
end

#decide(text, context) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/vangrail/rails/remote.rb', line 33

def decide(text, context)
  result =
    if context[:side] == :output
      client.check_output(text, user_input: context[:user_input])
    else
      client.check_input(text)
    end
  result.with_rail(name)
end

#offline?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/vangrail/rails/remote.rb', line 23

def offline?
  false
end