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
983834cd
Unverified
Commit
983834cd
authored
Sep 11, 2023
by
takatost
Committed by
GitHub
Sep 11, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: spark check (#1134)
parent
96d10c8b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
1 deletion
+54
-1
model_providers.py
api/controllers/console/workspace/model_providers.py
+16
-0
provider_service.py
api/services/provider_service.py
+38
-1
No files found.
api/controllers/console/workspace/model_providers.py
View file @
983834cd
...
@@ -285,6 +285,20 @@ class ModelProviderFreeQuotaSubmitApi(Resource):
...
@@ -285,6 +285,20 @@ class ModelProviderFreeQuotaSubmitApi(Resource):
return
result
return
result
class
ModelProviderFreeQuotaQualificationVerifyApi
(
Resource
):
@
setup_required
@
login_required
@
account_initialization_required
def
get
(
self
,
provider_name
:
str
):
provider_service
=
ProviderService
()
result
=
provider_service
.
free_quota_qualification_verify
(
tenant_id
=
current_user
.
current_tenant_id
,
provider_name
=
provider_name
)
return
result
api
.
add_resource
(
ModelProviderListApi
,
'/workspaces/current/model-providers'
)
api
.
add_resource
(
ModelProviderListApi
,
'/workspaces/current/model-providers'
)
api
.
add_resource
(
ModelProviderValidateApi
,
'/workspaces/current/model-providers/<string:provider_name>/validate'
)
api
.
add_resource
(
ModelProviderValidateApi
,
'/workspaces/current/model-providers/<string:provider_name>/validate'
)
api
.
add_resource
(
ModelProviderUpdateApi
,
'/workspaces/current/model-providers/<string:provider_name>'
)
api
.
add_resource
(
ModelProviderUpdateApi
,
'/workspaces/current/model-providers/<string:provider_name>'
)
...
@@ -300,3 +314,5 @@ api.add_resource(ModelProviderPaymentCheckoutUrlApi,
...
@@ -300,3 +314,5 @@ api.add_resource(ModelProviderPaymentCheckoutUrlApi,
'/workspaces/current/model-providers/<string:provider_name>/checkout-url'
)
'/workspaces/current/model-providers/<string:provider_name>/checkout-url'
)
api
.
add_resource
(
ModelProviderFreeQuotaSubmitApi
,
api
.
add_resource
(
ModelProviderFreeQuotaSubmitApi
,
'/workspaces/current/model-providers/<string:provider_name>/free-quota-submit'
)
'/workspaces/current/model-providers/<string:provider_name>/free-quota-submit'
)
api
.
add_resource
(
ModelProviderFreeQuotaQualificationVerifyApi
,
'/workspaces/current/model-providers/<string:provider_name>/free-quota-qualification-verify'
)
api/services/provider_service.py
View file @
983834cd
...
@@ -518,7 +518,8 @@ class ProviderService:
...
@@ -518,7 +518,8 @@ class ProviderService:
def
free_quota_submit
(
self
,
tenant_id
:
str
,
provider_name
:
str
):
def
free_quota_submit
(
self
,
tenant_id
:
str
,
provider_name
:
str
):
api_key
=
os
.
environ
.
get
(
"FREE_QUOTA_APPLY_API_KEY"
)
api_key
=
os
.
environ
.
get
(
"FREE_QUOTA_APPLY_API_KEY"
)
api_url
=
os
.
environ
.
get
(
"FREE_QUOTA_APPLY_URL"
)
api_base_url
=
os
.
environ
.
get
(
"FREE_QUOTA_APPLY_BASE_URL"
)
api_url
=
api_base_url
+
'/api/v1/providers/apply'
headers
=
{
headers
=
{
'Content-Type'
:
'application/json'
,
'Content-Type'
:
'application/json'
,
...
@@ -546,3 +547,39 @@ class ProviderService:
...
@@ -546,3 +547,39 @@ class ProviderService:
'type'
:
rst
[
'type'
],
'type'
:
rst
[
'type'
],
'result'
:
'success'
'result'
:
'success'
}
}
def
free_quota_qualification_verify
(
self
,
tenant_id
:
str
,
provider_name
:
str
):
api_key
=
os
.
environ
.
get
(
"FREE_QUOTA_APPLY_API_KEY"
)
api_base_url
=
os
.
environ
.
get
(
"FREE_QUOTA_APPLY_BASE_URL"
)
api_url
=
api_base_url
+
'/api/v1/providers/qualification-verify'
headers
=
{
'Content-Type'
:
'application/json'
,
'Authorization'
:
f
"Bearer {api_key}"
}
response
=
requests
.
post
(
api_url
,
headers
=
headers
,
json
=
{
'workspace_id'
:
tenant_id
,
'provider_name'
:
provider_name
})
if
not
response
.
ok
:
logging
.
error
(
f
"Request FREE QUOTA APPLY SERVER Error: {response.status_code} "
)
raise
ValueError
(
f
"Error: {response.status_code} "
)
rst
=
response
.
json
()
if
rst
[
"code"
]
!=
'success'
:
raise
ValueError
(
f
"error: {rst['message']}"
)
data
=
rst
[
'data'
]
if
data
[
'qualified'
]
is
True
:
return
{
'result'
:
'success'
,
'provider_name'
:
provider_name
,
'flag'
:
True
}
else
:
return
{
'result'
:
'success'
,
'provider_name'
:
provider_name
,
'flag'
:
False
,
'reason'
:
data
[
'reason'
]
}
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