Class: ObsceneGpt::Detector
- Inherits:
-
Object
- Object
- ObsceneGpt::Detector
- Defined in:
- lib/obscene_gpt/detector.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#prompt ⇒ Object
readonly
Returns the value of attribute prompt.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
-
#detect(text) ⇒ Object
Detects whether the given text contains obscene content See #detect_many for more details.
-
#detect_many(texts) ⇒ Array<Hash>
Detects whether the given texts contain obscene content.
-
#initialize(api_key: nil, model: nil, schema: nil, prompt: nil, request_timeout: nil) ⇒ Detector
constructor
A new instance of Detector.
Constructor Details
#initialize(api_key: nil, model: nil, schema: nil, prompt: nil, request_timeout: nil) ⇒ Detector
Returns a new instance of Detector.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/obscene_gpt/detector.rb', line 8 def initialize(api_key: nil, model: nil, schema: nil, prompt: nil, request_timeout: nil) api_key ||= ObsceneGpt.configuration.api_key @client = OpenAI::Client.new( access_token: api_key, request_timeout: request_timeout || ObsceneGpt.configuration.request_timeout, ) @model = model || ObsceneGpt.configuration.model @schema = schema || ObsceneGpt.configuration.schema @prompt = prompt || ObsceneGpt.configuration.prompt end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/obscene_gpt/detector.rb', line 6 def client @client end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
6 7 8 |
# File 'lib/obscene_gpt/detector.rb', line 6 def model @model end |
#prompt ⇒ Object (readonly)
Returns the value of attribute prompt.
6 7 8 |
# File 'lib/obscene_gpt/detector.rb', line 6 def prompt @prompt end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
6 7 8 |
# File 'lib/obscene_gpt/detector.rb', line 6 def schema @schema end |
Instance Method Details
#detect(text) ⇒ Object
Detects whether the given text contains obscene content See #detect_many for more details
38 39 40 |
# File 'lib/obscene_gpt/detector.rb', line 38 def detect(text) detect_many([text])[0] end |
#detect_many(texts) ⇒ Array<Hash>
Detects whether the given texts contain obscene content
27 28 29 30 31 32 33 34 |
# File 'lib/obscene_gpt/detector.rb', line 27 def detect_many(texts) if ObsceneGpt.configuration.test_mode test_detector = ObsceneGpt.configuration.test_detector_class.new(schema: @schema) return test_detector.detect_many(texts) end run_detect_many(texts) end |