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
2c6e0017
Unverified
Commit
2c6e0017
authored
Jul 16, 2023
by
Jyong
Committed by
GitHub
Jul 16, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add document limit check (#570)
parent
24f34569
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
1 deletion
+27
-1
config.py
api/config.py
+4
-1
dataset_service.py
api/services/dataset_service.py
+23
-0
No files found.
api/config.py
View file @
2c6e0017
...
...
@@ -50,7 +50,8 @@ DEFAULTS = {
'PDF_PREVIEW'
:
'True'
,
'LOG_LEVEL'
:
'INFO'
,
'DISABLE_PROVIDER_CONFIG_VALIDATION'
:
'False'
,
'DEFAULT_LLM_PROVIDER'
:
'openai'
'DEFAULT_LLM_PROVIDER'
:
'openai'
,
'TENANT_DOCUMENT_COUNT'
:
100
}
...
...
@@ -207,6 +208,8 @@ class Config:
self
.
NOTION_INTERNAL_SECRET
=
get_env
(
'NOTION_INTERNAL_SECRET'
)
self
.
NOTION_INTEGRATION_TOKEN
=
get_env
(
'NOTION_INTEGRATION_TOKEN'
)
self
.
TENANT_DOCUMENT_COUNT
=
get_env
(
'TENANT_DOCUMENT_COUNT'
)
class
CloudEditionConfig
(
Config
):
...
...
api/services/dataset_service.py
View file @
2c6e0017
...
...
@@ -4,6 +4,9 @@ import datetime
import
time
import
random
from
typing
import
Optional
,
List
from
flask
import
current_app
from
extensions.ext_redis
import
redis_client
from
flask_login
import
current_user
...
...
@@ -374,6 +377,12 @@ class DocumentService:
def
save_document_with_dataset_id
(
dataset
:
Dataset
,
document_data
:
dict
,
account
:
Account
,
dataset_process_rule
:
Optional
[
DatasetProcessRule
]
=
None
,
created_from
:
str
=
'web'
):
# check document limit
if
current_app
.
config
[
'EDITION'
]
==
'CLOUD'
:
documents_count
=
DocumentService
.
get_tenant_documents_count
()
tenant_document_count
=
int
(
current_app
.
config
[
'TENANT_DOCUMENT_COUNT'
])
if
documents_count
>
tenant_document_count
:
raise
ValueError
(
f
"over document limit {tenant_document_count}."
)
# if dataset is empty, update dataset data_source_type
if
not
dataset
.
data_source_type
:
dataset
.
data_source_type
=
document_data
[
"data_source"
][
"type"
]
...
...
@@ -521,6 +530,14 @@ class DocumentService:
)
return
document
@
staticmethod
def
get_tenant_documents_count
():
documents_count
=
Document
.
query
.
filter
(
Document
.
completed_at
.
isnot
(
None
),
Document
.
enabled
==
True
,
Document
.
archived
==
False
,
Document
.
tenant_id
==
current_user
.
current_tenant_id
)
.
count
()
return
documents_count
@
staticmethod
def
update_document_with_dataset_id
(
dataset
:
Dataset
,
document_data
:
dict
,
account
:
Account
,
dataset_process_rule
:
Optional
[
DatasetProcessRule
]
=
None
,
...
...
@@ -616,6 +633,12 @@ class DocumentService:
@
staticmethod
def
save_document_without_dataset_id
(
tenant_id
:
str
,
document_data
:
dict
,
account
:
Account
):
# check document limit
if
current_app
.
config
[
'EDITION'
]
==
'CLOUD'
:
documents_count
=
DocumentService
.
get_tenant_documents_count
()
tenant_document_count
=
int
(
current_app
.
config
[
'TENANT_DOCUMENT_COUNT'
])
if
documents_count
>
tenant_document_count
:
raise
ValueError
(
f
"over document limit {tenant_document_count}."
)
# save dataset
dataset
=
Dataset
(
tenant_id
=
tenant_id
,
...
...
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