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 +4 -4
- data/README.md +12 -0
- data/lib/obscene_gpt/active_model.rb +2 -0
- data/lib/obscene_gpt/configuration.rb +3 -1
- data/lib/obscene_gpt/detector.rb +6 -3
- data/lib/obscene_gpt/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '059e9f88337ce5353b70a7a58ca15c9c7962382cf4b532ba5fe59dca2977f11b'
|
4
|
+
data.tar.gz: ed809dd449d25cc46817e1ac6ded52d6a6b5a83fa530edd208bfb85a29d43c4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
@@ -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,
|
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
|
data/lib/obscene_gpt/detector.rb
CHANGED
@@ -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(
|
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
|
|
data/lib/obscene_gpt/version.rb
CHANGED
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.
|
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-
|
10
|
+
date: 2025-07-03 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: ruby-openai
|