forked from langgenius/dify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/firecrawl data source (langgenius#5232)
Co-authored-by: Nicolas <[email protected]> Co-authored-by: chenhe <[email protected]> Co-authored-by: takatost <[email protected]>
- Loading branch information
1 parent
e34449e
commit b82aa82
Showing
36 changed files
with
1,174 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from flask_login import current_user | ||
from flask_restful import Resource, reqparse | ||
from werkzeug.exceptions import Forbidden | ||
|
||
from controllers.console import api | ||
from controllers.console.auth.error import ApiKeyAuthFailedError | ||
from libs.login import login_required | ||
from services.auth.api_key_auth_service import ApiKeyAuthService | ||
|
||
from ..setup import setup_required | ||
from ..wraps import account_initialization_required | ||
|
||
|
||
class ApiKeyAuthDataSource(Resource): | ||
@setup_required | ||
@login_required | ||
@account_initialization_required | ||
def get(self): | ||
# The role of the current user in the table must be admin or owner | ||
if not current_user.is_admin_or_owner: | ||
raise Forbidden() | ||
data_source_api_key_bindings = ApiKeyAuthService.get_provider_auth_list(current_user.current_tenant_id) | ||
if data_source_api_key_bindings: | ||
return { | ||
'settings': [data_source_api_key_binding.to_dict() for data_source_api_key_binding in | ||
data_source_api_key_bindings]} | ||
return {'settings': []} | ||
|
||
|
||
class ApiKeyAuthDataSourceBinding(Resource): | ||
@setup_required | ||
@login_required | ||
@account_initialization_required | ||
def post(self): | ||
# The role of the current user in the table must be admin or owner | ||
if not current_user.is_admin_or_owner: | ||
raise Forbidden() | ||
parser = reqparse.RequestParser() | ||
parser.add_argument('category', type=str, required=True, nullable=False, location='json') | ||
parser.add_argument('provider', type=str, required=True, nullable=False, location='json') | ||
parser.add_argument('credentials', type=dict, required=True, nullable=False, location='json') | ||
args = parser.parse_args() | ||
ApiKeyAuthService.validate_api_key_auth_args(args) | ||
try: | ||
ApiKeyAuthService.create_provider_auth(current_user.current_tenant_id, args) | ||
except Exception as e: | ||
raise ApiKeyAuthFailedError(str(e)) | ||
return {'result': 'success'}, 200 | ||
|
||
|
||
class ApiKeyAuthDataSourceBindingDelete(Resource): | ||
@setup_required | ||
@login_required | ||
@account_initialization_required | ||
def delete(self, binding_id): | ||
# The role of the current user in the table must be admin or owner | ||
if not current_user.is_admin_or_owner: | ||
raise Forbidden() | ||
|
||
ApiKeyAuthService.delete_provider_auth(current_user.current_tenant_id, binding_id) | ||
|
||
return {'result': 'success'}, 200 | ||
|
||
|
||
api.add_resource(ApiKeyAuthDataSource, '/api-key-auth/data-source') | ||
api.add_resource(ApiKeyAuthDataSourceBinding, '/api-key-auth/data-source/binding') | ||
api.add_resource(ApiKeyAuthDataSourceBindingDelete, '/api-key-auth/data-source/<uuid:binding_id>') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from libs.exception import BaseHTTPException | ||
|
||
|
||
class ApiKeyAuthFailedError(BaseHTTPException): | ||
error_code = 'auth_failed' | ||
description = "{message}" | ||
code = 500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from flask_restful import Resource, reqparse | ||
|
||
from controllers.console import api | ||
from controllers.console.datasets.error import WebsiteCrawlError | ||
from controllers.console.setup import setup_required | ||
from controllers.console.wraps import account_initialization_required | ||
from libs.login import login_required | ||
from services.website_service import WebsiteService | ||
|
||
|
||
class WebsiteCrawlApi(Resource): | ||
|
||
@setup_required | ||
@login_required | ||
@account_initialization_required | ||
def post(self): | ||
parser = reqparse.RequestParser() | ||
parser.add_argument('provider', type=str, choices=['firecrawl'], | ||
required=True, nullable=True, location='json') | ||
parser.add_argument('url', type=str, required=True, nullable=True, location='json') | ||
parser.add_argument('options', type=dict, required=True, nullable=True, location='json') | ||
args = parser.parse_args() | ||
WebsiteService.document_create_args_validate(args) | ||
# crawl url | ||
try: | ||
result = WebsiteService.crawl_url(args) | ||
except Exception as e: | ||
raise WebsiteCrawlError(str(e)) | ||
return result, 200 | ||
|
||
|
||
class WebsiteCrawlStatusApi(Resource): | ||
@setup_required | ||
@login_required | ||
@account_initialization_required | ||
def get(self, job_id: str): | ||
parser = reqparse.RequestParser() | ||
parser.add_argument('provider', type=str, choices=['firecrawl'], required=True, location='args') | ||
args = parser.parse_args() | ||
# get crawl status | ||
try: | ||
result = WebsiteService.get_crawl_status(job_id, args['provider']) | ||
except Exception as e: | ||
raise WebsiteCrawlError(str(e)) | ||
return result, 200 | ||
|
||
|
||
api.add_resource(WebsiteCrawlApi, '/website/crawl') | ||
api.add_resource(WebsiteCrawlStatusApi, '/website/crawl/status/<string:job_id>') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
class DatasourceType(Enum): | ||
FILE = "upload_file" | ||
NOTION = "notion_import" | ||
WEBSITE = "website_crawl" |
Oops, something went wrong.