Class: Vangrail::Rails::Remote
- Inherits:
-
Vangrail::Rail
- Object
- Vangrail::Rail
- Vangrail::Rails::Remote
- 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.
Constant Summary
Constants inherited from Vangrail::Rail
Vangrail::Rail::DEFAULT_SIDES, Vangrail::Rail::SIDES
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Attributes inherited from Vangrail::Rail
Instance Method Summary collapse
- #cache_key(text, context) ⇒ Object
- #call(text, context) ⇒ Object
-
#initialize(client: nil, base_url: nil, config_id: nil, api_key: nil, name: 'remote', sides: Rail::SIDES) ⇒ Remote
constructor
A new instance of Remote.
Methods inherited from Vangrail::Rail
#applies_to?, #offline?, #placeholder?, #to_s
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
#client ⇒ Object (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
23 24 25 26 27 |
# File 'lib/vangrail/rails/remote.rb', line 23 def cache_key(text, context) return text if context[:side] == :input "#{context[:user_input]} #{text}" end |
#call(text, context) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/vangrail/rails/remote.rb', line 29 def call(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 |