obscene_gpt 0.1.0 → 0.1.1

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: 6ef6875fbee1dd1d83f91a84405092e6a7c33bc5fdfcb41d539cb239d9620659
4
+ data.tar.gz: 92ebe600ec5cda5c9631024246f5b9506388ee5414352d741c1a149605f8d46c
5
5
  SHA512:
6
- metadata.gz: a76f7ba702c0bdc886f0ee805b26f72278bad23ca4f88a2e57387b342d0e213d2d93c30fce52800b0425a76b1f9ac7aa99078b6ba51d1236dc29fb18b0d84e6e
7
- data.tar.gz: '08145d5400a4b29d120824e51b286be6a6d4403ef5f8ecf18d260dd68f936b01486408bc041119aa22f39f5f05f803860191fc96a0f120e13499bfcc47384ac4'
6
+ metadata.gz: 2994590f0880cc27f53100e75fa4f06b237ca0f870de0f7e8ffe165c24684b23670d36c9ace1ad74811b4a2682a695c50b0afa8fcb878e6cf99c62859f63aa6f
7
+ data.tar.gz: fa5f3e64135529d62b275f85c177db364702f5aa8822a4fd1d40373b6d9b53ed216ea42b1c01091bc3c3d194975a78661ef4ee00e380667e0d7023e1ddc987ec
data/README.md CHANGED
@@ -308,6 +308,7 @@ Therefore, it is recommended to pass all the attributes you want to check to the
308
308
 
309
309
  - `threshold` (Float): Custom confidence threshold (0.0-1.0) for determining when content is considered inappropriate. Default: Uses `ObsceneGpt.configuration.profanity_threshold`
310
310
  - `message` (String): Custom error message to display when validation fails. Default: Uses AI reasoning if available, otherwise "contains inappropriate content"
311
+ - `ignore_errors` (Boolean): If true, the validator will not raise an error if the OpenAI API returns an error. Default: false
311
312
 
312
313
  ### Per-Attribute Options
313
314
 
@@ -349,6 +350,16 @@ class Post < ActiveRecord::Base
349
350
  end
350
351
  ```
351
352
 
353
+ **Basic validation with ignore_errors:**
354
+
355
+ If there is an error from the OpenAI API, the validator will just skip the validation and not raise an error.
356
+
357
+ ```ruby
358
+ class Post < ActiveRecord::Base
359
+ validates :content, obscene_content: { ignore_errors: true }
360
+ end
361
+ ```
362
+
352
363
  **With custom message:**
353
364
 
354
365
  ```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
@@ -43,7 +43,7 @@ module ObsceneGpt
43
43
 
44
44
  JSON.parse(response.dig("output", 0, "content", 0, "text"))["results"].map { |r| r.transform_keys(&:to_sym) }
45
45
  rescue OpenAI::Error, Faraday::Error => e
46
- body = e.respond_to?(:response) ? e.response[:body] : ""
46
+ body = e.respond_to?(:response) && e.response.is_a?(Hash) ? e.response[:body] : ""
47
47
  raise ObsceneGpt::Error, "OpenAI API error: #{e.message}\n#{body}"
48
48
  end
49
49
 
@@ -1,3 +1,3 @@
1
1
  module ObsceneGpt
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
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.1
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