mirror of
https://github.com/langgenius/dify-plugin-sdks.git
synced 2026-08-25 12:29:32 -04:00
0922b15e54
- Added new request models for datasource actions including validation, website crawling, and content retrieval. - Enhanced `PluginExecutor` with methods to validate datasource credentials, crawl websites, and retrieve pages and content. - Updated `PluginRegistration` to include methods for fetching datasource provider classes and handling website and online document datasources. - Refined the `DatasourceProvider` interface to use `Mapping` for credentials, improving type safety.
44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
from abc import ABC, abstractmethod
|
|
from collections.abc import Mapping
|
|
from typing import Any, final
|
|
|
|
from dify_plugin.core.runtime import Session
|
|
from dify_plugin.entities.datasource import DatasourceRuntime, GetWebsiteCrawlResponse
|
|
|
|
|
|
class WebsiteCrawlDatasource(ABC):
|
|
"""
|
|
Website Crawl Datasource abstract class
|
|
"""
|
|
|
|
runtime: DatasourceRuntime
|
|
session: Session
|
|
|
|
@final
|
|
def __init__(
|
|
self,
|
|
runtime: DatasourceRuntime,
|
|
session: Session,
|
|
):
|
|
"""
|
|
Initialize the datasource
|
|
|
|
NOTE:
|
|
- This method has been marked as final, DO NOT OVERRIDE IT.
|
|
"""
|
|
self.runtime = runtime
|
|
self.session = session
|
|
|
|
def website_crawl(self, datasource_parameters: Mapping[str, Any]) -> GetWebsiteCrawlResponse:
|
|
"""
|
|
Get the website crawl result
|
|
"""
|
|
return self._get_website_crawl(datasource_parameters)
|
|
|
|
@abstractmethod
|
|
def _get_website_crawl(self, datasource_parameters: Mapping[str, Any]) -> GetWebsiteCrawlResponse:
|
|
"""
|
|
Get the website crawl result
|
|
"""
|
|
raise NotImplementedError("This method should be implemented by a subclass")
|