obscene_gpt 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 57b6cd7a7afe7daa9400f7a24e1609c1195f96bb74d66c16bb28ef20d18ee1f0
4
- data.tar.gz: d3d01454d54408acb0ebe8e97e020afb47dd49d1da39c2c5921314bb38c224c6
3
+ metadata.gz: '059e9f88337ce5353b70a7a58ca15c9c7962382cf4b532ba5fe59dca2977f11b'
4
+ data.tar.gz: ed809dd449d25cc46817e1ac6ded52d6a6b5a83fa530edd208bfb85a29d43c4d
5
5
  SHA512:
6
- metadata.gz: a76f7ba702c0bdc886f0ee805b26f72278bad23ca4f88a2e57387b342d0e213d2d93c30fce52800b0425a76b1f9ac7aa99078b6ba51d1236dc29fb18b0d84e6e
7
- data.tar.gz: '08145d5400a4b29d120824e51b286be6a6d4403ef5f8ecf18d260dd68f936b01486408bc041119aa22f39f5f05f803860191fc96a0f120e13499bfcc47384ac4'
6
+ metadata.gz: dadc5fab4cc61a074afe39ec58e86f67d5924b27415298a642ea1c2217b6b2d989586abcac84082eb628c385d14b5a744a7c3aa69a891f4d9c2cb7909650d042
7
+ data.tar.gz: 137094bbbfa37348eb386d06036029f14b4adf4d3d25e525be7184211f043d04fdd258a478f7e2ff476afde06a5ebc9276487140bafcbfe47f585ec339458c17
data/README.md CHANGED
@@ -38,6 +38,7 @@ export OPENAI_API_KEY="your-openai-api-key-here"
38
38
  ObsceneGpt.configure do |config|
39
39
  config.api_key = "your-openai-api-key-here"
40
40
  config.model = "gpt-4.1-nano"
41
+ config.request_timeout = 5 # Optional, defaults to 10 seconds
41
42
  end
42
43
  ```
43
44
 
@@ -308,6 +309,7 @@ Therefore, it is recommended to pass all the attributes you want to check to the
308
309
 
309
310
  - `threshold` (Float): Custom confidence threshold (0.0-1.0) for determining when content is considered inappropriate. Default: Uses `ObsceneGpt.configuration.profanity_threshold`
310
311
  - `message` (String): Custom error message to display when validation fails. Default: Uses AI reasoning if available, otherwise "contains inappropriate content"
312
+ - `ignore_errors` (Boolean): If true, the validator will not raise an error if the OpenAI API returns an error. Default: false
311
313
 
312
314
  ### Per-Attribute Options
313
315
 
@@ -349,6 +351,16 @@ class Post < ActiveRecord::Base
349
351
  end
350
352
  ```
351
353
 
354
+ **Basic validation with ignore_errors:**
355
+
356
+ If there is an error from the OpenAI API, the validator will just skip the validation and not raise an error.
357
+
358
+ ```ruby
359
+ class Post < ActiveRecord::Base
360
+ validates :content, obscene_content: { ignore_errors: true }
361
+ end
362
+ ```
363
+
352
364
  **With custom message:**
353
365
 
354
366
  ```ruby
@@ -12,6 +12,8 @@ if defined?(ActiveModel)
12
12
 
13
13
  results = ObsceneGpt.detect_many(to_validate.values)
14
14
  format_errors(record, to_validate, results)
15
+ rescue ObsceneGpt::Error => e
16
+ raise e unless options[:ignore_errors]
15
17
  end
16
18
 
17
19
  private
@@ -10,7 +10,8 @@ module ObsceneGpt
10
10
  end
11
11
 
12
12
  class Configuration
13
- attr_accessor :api_key, :model, :schema, :prompt, :profanity_threshold, :test_mode, :test_detector_class
13
+ attr_accessor :api_key, :model, :schema, :prompt, :profanity_threshold, :test_mode,
14
+ :test_detector_class, :request_timeout
14
15
 
15
16
  def initialize
16
17
  @api_key = ENV.fetch("OPENAI_API_KEY", nil)
@@ -20,6 +21,7 @@ module ObsceneGpt
20
21
  @profanity_threshold = 0.8
21
22
  @test_mode = false
22
23
  @test_detector_class = TestDetector
24
+ @request_timeout = 10
23
25
  end
24
26
  end
25
27
  end
@@ -5,10 +5,13 @@ module ObsceneGpt
5
5
  class Detector
6
6
  attr_reader :client, :model, :schema, :prompt
7
7
 
8
- def initialize(api_key: nil, model: nil, schema: nil, prompt: nil)
8
+ def initialize(api_key: nil, model: nil, schema: nil, prompt: nil, request_timeout: nil)
9
9
  api_key ||= ObsceneGpt.configuration.api_key
10
10
 
11
- @client = OpenAI::Client.new(access_token: api_key)
11
+ @client = OpenAI::Client.new(
12
+ access_token: api_key,
13
+ request_timeout: request_timeout || ObsceneGpt.configuration.request_timeout,
14
+ )
12
15
  @model = model || ObsceneGpt.configuration.model
13
16
  @schema = schema || ObsceneGpt.configuration.schema
14
17
  @prompt = prompt || ObsceneGpt.configuration.prompt
@@ -43,7 +46,7 @@ module ObsceneGpt
43
46
 
44
47
  JSON.parse(response.dig("output", 0, "content", 0, "text"))["results"].map { |r| r.transform_keys(&:to_sym) }
45
48
  rescue OpenAI::Error, Faraday::Error => e
46
- body = e.respond_to?(:response) ? e.response[:body] : ""
49
+ body = e.respond_to?(:response) && e.response.is_a?(Hash) ? e.response[:body] : ""
47
50
  raise ObsceneGpt::Error, "OpenAI API error: #{e.message}\n#{body}"
48
51
  end
49
52
 
@@ -1,3 +1,3 @@
1
1
  module ObsceneGpt
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obscene_gpt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Perez
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-06-30 00:00:00.000000000 Z
10
+ date: 2025-07-03 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: ruby-openai