Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
b1352ff8
Unverified
Commit
b1352ff8
authored
Oct 11, 2023
by
takatost
Committed by
GitHub
Oct 11, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: using random sampling to check if it violates the review mechan… (#1308)
parent
cc63c849
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
12 deletions
+14
-12
moderation.py
api/core/helper/moderation.py
+14
-12
No files found.
api/core/helper/moderation.py
View file @
b1352ff8
import
logging
import
random
import
openai
...
...
@@ -16,10 +17,11 @@ def check_moderation(model_provider: BaseModelProvider, text: str) -> bool:
length
=
2000
text_chunks
=
[
text
[
i
:
i
+
length
]
for
i
in
range
(
0
,
len
(
text
),
length
)]
max_text_chunks
=
32
chunks
=
[
text_chunks
[
i
:
i
+
max_text_chunks
]
for
i
in
range
(
0
,
len
(
text_chunks
),
max_text_chunks
)]
if
len
(
text_chunks
)
==
0
:
return
True
text_chunk
=
random
.
choice
(
text_chunks
)
for
text_chunk
in
chunks
:
try
:
moderation_result
=
openai
.
Moderation
.
create
(
input
=
text_chunk
,
api_key
=
hosted_model_providers
.
openai
.
api_key
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment