This commit is contained in:
Bowen Liang 2026-03-24 10:08:49 +08:00 committed by GitHub
commit 20cf5c5179
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
156 changed files with 380 additions and 345 deletions

View File

@ -51,6 +51,7 @@ This is the default standard for backend code in this repo. Follow it for new co
- Use Ruff for formatting and linting (follow `.ruff.toml`). - Use Ruff for formatting and linting (follow `.ruff.toml`).
- Keep each line under 120 characters (including spaces). - Keep each line under 120 characters (including spaces).
- Avoid using bare `# type: ignore` to ignore all type violations. Always specify an error code (e.g. `# type: ignore[operator, attr-defined]`).
### Naming Conventions ### Naming Conventions

View File

@ -1,5 +1,5 @@
import psycogreen.gevent as pscycogreen_gevent # type: ignore import psycogreen.gevent as pscycogreen_gevent # type: ignore[reportMissingTypeStubs]
from grpc.experimental import gevent as grpc_gevent # type: ignore from grpc.experimental import gevent as grpc_gevent # type: ignore[reportMissingTypeStubs]
# grpc gevent # grpc gevent
grpc_gevent.init_gevent() grpc_gevent.init_gevent()

View File

@ -1,3 +1,3 @@
from .app_config import DifyConfig from .app_config import DifyConfig
dify_config = DifyConfig() # type: ignore dify_config = DifyConfig() # type: ignore[call-arg, assignment]

View File

@ -72,7 +72,7 @@ def capture_flask_context(user: Any = None) -> IExecutionContext:
RuntimeError: If called outside Flask context RuntimeError: If called outside Flask context
""" """
# Get Flask app instance # Get Flask app instance
flask_app = current_app._get_current_object() # type: ignore flask_app = current_app._get_current_object() # type: ignore[attr-defined]
# Save current user if available # Save current user if available
saved_user = user saved_user = user

View File

@ -51,7 +51,7 @@ class Site(BaseModel):
show_workflow_steps: bool show_workflow_steps: bool
use_icon_as_answer_icon: bool use_icon_as_answer_icon: bool
@computed_field(return_type=str | None) # type: ignore @computed_field(return_type=str | None) # type: ignore[prop-decorator]
@property @property
def icon_url(self) -> str | None: def icon_url(self) -> str | None:
if self.icon and self.icon_type == IconType.IMAGE: if self.icon and self.icon_type == IconType.IMAGE:

View File

@ -148,7 +148,7 @@ class AppApiKeyListResource(BaseApiKeyListResource):
@console_ns.doc(description="Get all API keys for an app") @console_ns.doc(description="Get all API keys for an app")
@console_ns.doc(params={"resource_id": "App ID"}) @console_ns.doc(params={"resource_id": "App ID"})
@console_ns.response(200, "Success", api_key_list_model) @console_ns.response(200, "Success", api_key_list_model)
def get(self, resource_id): # type: ignore def get(self, resource_id): # type: ignore[misc]
"""Get all API keys for an app""" """Get all API keys for an app"""
return super().get(resource_id) return super().get(resource_id)
@ -157,7 +157,7 @@ class AppApiKeyListResource(BaseApiKeyListResource):
@console_ns.doc(params={"resource_id": "App ID"}) @console_ns.doc(params={"resource_id": "App ID"})
@console_ns.response(201, "API key created successfully", api_key_item_model) @console_ns.response(201, "API key created successfully", api_key_item_model)
@console_ns.response(400, "Maximum keys exceeded") @console_ns.response(400, "Maximum keys exceeded")
def post(self, resource_id): # type: ignore def post(self, resource_id): # type: ignore[misc]
"""Create a new API key for an app""" """Create a new API key for an app"""
return super().post(resource_id) return super().post(resource_id)
@ -188,7 +188,7 @@ class DatasetApiKeyListResource(BaseApiKeyListResource):
@console_ns.doc(description="Get all API keys for a dataset") @console_ns.doc(description="Get all API keys for a dataset")
@console_ns.doc(params={"resource_id": "Dataset ID"}) @console_ns.doc(params={"resource_id": "Dataset ID"})
@console_ns.response(200, "Success", api_key_list_model) @console_ns.response(200, "Success", api_key_list_model)
def get(self, resource_id): # type: ignore def get(self, resource_id): # type: ignore[misc]
"""Get all API keys for a dataset""" """Get all API keys for a dataset"""
return super().get(resource_id) return super().get(resource_id)
@ -197,7 +197,7 @@ class DatasetApiKeyListResource(BaseApiKeyListResource):
@console_ns.doc(params={"resource_id": "Dataset ID"}) @console_ns.doc(params={"resource_id": "Dataset ID"})
@console_ns.response(201, "API key created successfully", api_key_item_model) @console_ns.response(201, "API key created successfully", api_key_item_model)
@console_ns.response(400, "Maximum keys exceeded") @console_ns.response(400, "Maximum keys exceeded")
def post(self, resource_id): # type: ignore def post(self, resource_id): # type: ignore[misc]
"""Create a new API key for a dataset""" """Create a new API key for a dataset"""
return super().post(resource_id) return super().post(resource_id)

View File

@ -34,6 +34,6 @@ class AdvancedPromptTemplateList(Resource):
@login_required @login_required
@account_initialization_required @account_initialization_required
def get(self): def get(self):
args = AdvancedPromptTemplateQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = AdvancedPromptTemplateQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
return AdvancedPromptTemplateService.get_prompt(args.model_dump()) return AdvancedPromptTemplateService.get_prompt(args.model_dump())

View File

@ -44,6 +44,6 @@ class AgentLogApi(Resource):
@get_app_model(mode=[AppMode.AGENT_CHAT]) @get_app_model(mode=[AppMode.AGENT_CHAT])
def get(self, app_model): def get(self, app_model):
"""Get agent logs""" """Get agent logs"""
args = AgentLogQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = AgentLogQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
return AgentService.get_agent_logs(app_model, args.conversation_id, args.message_id) return AgentService.get_agent_logs(app_model, args.conversation_id, args.message_id)

View File

@ -206,7 +206,7 @@ class AnnotationApi(Resource):
@account_initialization_required @account_initialization_required
@edit_permission_required @edit_permission_required
def get(self, app_id): def get(self, app_id):
args = AnnotationListQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = AnnotationListQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
page = args.page page = args.page
limit = args.limit limit = args.limit
keyword = args.keyword keyword = args.keyword

View File

@ -299,7 +299,7 @@ class Site(ResponseModel):
updated_by: str | None = None updated_by: str | None = None
updated_at: int | None = None updated_at: int | None = None
@computed_field(return_type=str | None) # type: ignore @computed_field(return_type=str | None) # type: ignore[prop-decorator]
@property @property
def icon_url(self) -> str | None: def icon_url(self) -> str | None:
return _build_icon_url(self.icon_type, self.icon) return _build_icon_url(self.icon_type, self.icon)
@ -349,7 +349,7 @@ class AppPartial(ResponseModel):
author_name: str | None = None author_name: str | None = None
has_draft_trigger: bool | None = None has_draft_trigger: bool | None = None
@computed_field(return_type=str | None) # type: ignore @computed_field(return_type=str | None) # type: ignore[prop-decorator]
@property @property
def icon_url(self) -> str | None: def icon_url(self) -> str | None:
return _build_icon_url(self.icon_type, self.icon) return _build_icon_url(self.icon_type, self.icon)
@ -397,7 +397,7 @@ class AppDetailWithSite(AppDetail):
deleted_tools: list[DeletedTool] = Field(default_factory=list) deleted_tools: list[DeletedTool] = Field(default_factory=list)
site: Site | None = None site: Site | None = None
@computed_field(return_type=str | None) # type: ignore @computed_field(return_type=str | None) # type: ignore[prop-decorator]
@property @property
def icon_url(self) -> str | None: def icon_url(self) -> str | None:
return _build_icon_url(self.icon_type, self.icon) return _build_icon_url(self.icon_type, self.icon)
@ -473,7 +473,7 @@ class AppListApi(Resource):
"""Get app list""" """Get app list"""
current_user, current_tenant_id = current_account_with_tenant() current_user, current_tenant_id = current_account_with_tenant()
args = AppListQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = AppListQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
args_dict = args.model_dump() args_dict = args.model_dump()
# get app list # get app list
@ -692,7 +692,7 @@ class AppExportApi(Resource):
@edit_permission_required @edit_permission_required
def get(self, app_model): def get(self, app_model):
"""Export app""" """Export app"""
args = AppExportQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = AppExportQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
payload = AppExportResponse( payload = AppExportResponse(
data=AppDslService.export_dsl( data=AppDslService.export_dsl(

View File

@ -173,7 +173,7 @@ class TextModesApi(Resource):
@account_initialization_required @account_initialization_required
def get(self, app_model): def get(self, app_model):
try: try:
args = TextToSpeechVoiceQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = TextToSpeechVoiceQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
response = AudioService.transcript_tts_voices( response = AudioService.transcript_tts_voices(
tenant_id=app_model.tenant_id, tenant_id=app_model.tenant_id,

View File

@ -342,7 +342,7 @@ class CompletionConversationApi(Resource):
@edit_permission_required @edit_permission_required
def get(self, app_model): def get(self, app_model):
current_user, _ = current_account_with_tenant() current_user, _ = current_account_with_tenant()
args = CompletionConversationQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = CompletionConversationQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
query = sa.select(Conversation).where( query = sa.select(Conversation).where(
Conversation.app_id == app_model.id, Conversation.mode == "completion", Conversation.is_deleted.is_(False) Conversation.app_id == app_model.id, Conversation.mode == "completion", Conversation.is_deleted.is_(False)
@ -378,7 +378,7 @@ class CompletionConversationApi(Resource):
if args.annotation_status == "annotated": if args.annotation_status == "annotated":
query = ( query = (
query.options(selectinload(Conversation.message_annotations)) # type: ignore[arg-type] query.options(selectinload(Conversation.message_annotations)) # type: ignore[arg-type]
.join( # type: ignore .join( # type: ignore[arg-type]
MessageAnnotation, MessageAnnotation.conversation_id == Conversation.id MessageAnnotation, MessageAnnotation.conversation_id == Conversation.id
) )
.distinct() .distinct()
@ -455,7 +455,7 @@ class ChatConversationApi(Resource):
@edit_permission_required @edit_permission_required
def get(self, app_model): def get(self, app_model):
current_user, _ = current_account_with_tenant() current_user, _ = current_account_with_tenant()
args = ChatConversationQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = ChatConversationQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
subquery = ( subquery = (
sa.select(Conversation.id.label("conversation_id"), EndUser.session_id.label("from_end_user_session_id")) sa.select(Conversation.id.label("conversation_id"), EndUser.session_id.label("from_end_user_session_id"))
@ -515,7 +515,7 @@ class ChatConversationApi(Resource):
case "annotated": case "annotated":
query = ( query = (
query.options(selectinload(Conversation.message_annotations)) # type: ignore[arg-type] query.options(selectinload(Conversation.message_annotations)) # type: ignore[arg-type]
.join( # type: ignore .join( # type: ignore[arg-type]
MessageAnnotation, MessageAnnotation.conversation_id == Conversation.id MessageAnnotation, MessageAnnotation.conversation_id == Conversation.id
) )
.distinct() .distinct()

View File

@ -55,7 +55,7 @@ class ConversationVariablesApi(Resource):
@get_app_model(mode=AppMode.ADVANCED_CHAT) @get_app_model(mode=AppMode.ADVANCED_CHAT)
@marshal_with(paginated_conversation_variable_model) @marshal_with(paginated_conversation_variable_model)
def get(self, app_model): def get(self, app_model):
args = ConversationVariablesQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = ConversationVariablesQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
stmt = ( stmt = (
select(ConversationVariable) select(ConversationVariable)

View File

@ -50,7 +50,7 @@ class TraceAppConfigApi(Resource):
@login_required @login_required
@account_initialization_required @account_initialization_required
def get(self, app_id): def get(self, app_id):
args = TraceProviderQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = TraceProviderQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
try: try:
trace_config = OpsService.get_tracing_app_config(app_id=app_id, tracing_provider=args.tracing_provider) trace_config = OpsService.get_tracing_app_config(app_id=app_id, tracing_provider=args.tracing_provider)
@ -121,7 +121,7 @@ class TraceAppConfigApi(Resource):
@account_initialization_required @account_initialization_required
def delete(self, app_id): def delete(self, app_id):
"""Delete an existing trace app configuration""" """Delete an existing trace app configuration"""
args = TraceProviderQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = TraceProviderQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
try: try:
result = OpsService.delete_tracing_app_config(app_id=app_id, tracing_provider=args.tracing_provider) result = OpsService.delete_tracing_app_config(app_id=app_id, tracing_provider=args.tracing_provider)

View File

@ -54,7 +54,7 @@ class DailyMessageStatistic(Resource):
def get(self, app_model): def get(self, app_model):
account, _ = current_account_with_tenant() account, _ = current_account_with_tenant()
args = StatisticTimeRangeQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = StatisticTimeRangeQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
converted_created_at = convert_datetime_to_date("created_at") converted_created_at = convert_datetime_to_date("created_at")
sql_query = f"""SELECT sql_query = f"""SELECT
@ -111,7 +111,7 @@ class DailyConversationStatistic(Resource):
def get(self, app_model): def get(self, app_model):
account, _ = current_account_with_tenant() account, _ = current_account_with_tenant()
args = StatisticTimeRangeQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = StatisticTimeRangeQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
converted_created_at = convert_datetime_to_date("created_at") converted_created_at = convert_datetime_to_date("created_at")
sql_query = f"""SELECT sql_query = f"""SELECT
@ -167,7 +167,7 @@ class DailyTerminalsStatistic(Resource):
def get(self, app_model): def get(self, app_model):
account, _ = current_account_with_tenant() account, _ = current_account_with_tenant()
args = StatisticTimeRangeQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = StatisticTimeRangeQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
converted_created_at = convert_datetime_to_date("created_at") converted_created_at = convert_datetime_to_date("created_at")
sql_query = f"""SELECT sql_query = f"""SELECT
@ -224,7 +224,7 @@ class DailyTokenCostStatistic(Resource):
def get(self, app_model): def get(self, app_model):
account, _ = current_account_with_tenant() account, _ = current_account_with_tenant()
args = StatisticTimeRangeQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = StatisticTimeRangeQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
converted_created_at = convert_datetime_to_date("created_at") converted_created_at = convert_datetime_to_date("created_at")
sql_query = f"""SELECT sql_query = f"""SELECT
@ -284,7 +284,7 @@ class AverageSessionInteractionStatistic(Resource):
def get(self, app_model): def get(self, app_model):
account, _ = current_account_with_tenant() account, _ = current_account_with_tenant()
args = StatisticTimeRangeQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = StatisticTimeRangeQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
converted_created_at = convert_datetime_to_date("c.created_at") converted_created_at = convert_datetime_to_date("c.created_at")
sql_query = f"""SELECT sql_query = f"""SELECT
@ -360,7 +360,7 @@ class UserSatisfactionRateStatistic(Resource):
def get(self, app_model): def get(self, app_model):
account, _ = current_account_with_tenant() account, _ = current_account_with_tenant()
args = StatisticTimeRangeQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = StatisticTimeRangeQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
converted_created_at = convert_datetime_to_date("m.created_at") converted_created_at = convert_datetime_to_date("m.created_at")
sql_query = f"""SELECT sql_query = f"""SELECT
@ -426,7 +426,7 @@ class AverageResponseTimeStatistic(Resource):
def get(self, app_model): def get(self, app_model):
account, _ = current_account_with_tenant() account, _ = current_account_with_tenant()
args = StatisticTimeRangeQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = StatisticTimeRangeQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
converted_created_at = convert_datetime_to_date("created_at") converted_created_at = convert_datetime_to_date("created_at")
sql_query = f"""SELECT sql_query = f"""SELECT
@ -482,7 +482,7 @@ class TokensPerSecondStatistic(Resource):
@account_initialization_required @account_initialization_required
def get(self, app_model): def get(self, app_model):
account, _ = current_account_with_tenant() account, _ = current_account_with_tenant()
args = StatisticTimeRangeQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = StatisticTimeRangeQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
converted_created_at = convert_datetime_to_date("created_at") converted_created_at = convert_datetime_to_date("created_at")
sql_query = f"""SELECT sql_query = f"""SELECT

View File

@ -900,7 +900,7 @@ class DefaultBlockConfigApi(Resource):
""" """
Get default block config Get default block config
""" """
args = DefaultBlockConfigQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = DefaultBlockConfigQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
filters = None filters = None
if args.q: if args.q:
@ -968,7 +968,7 @@ class PublishedAllWorkflowApi(Resource):
""" """
current_user, _ = current_account_with_tenant() current_user, _ = current_account_with_tenant()
args = WorkflowListQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = WorkflowListQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
page = args.page page = args.page
limit = args.limit limit = args.limit
user_id = args.user_id user_id = args.user_id

View File

@ -41,7 +41,7 @@ class WorkflowAppLogQuery(BaseModel):
def parse_datetime(cls, value: str | None) -> datetime | None: def parse_datetime(cls, value: str | None) -> datetime | None:
if value in (None, ""): if value in (None, ""):
return None return None
return isoparse(value) # type: ignore return isoparse(value) # type: ignore[arg-type]
@field_validator("detail", mode="before") @field_validator("detail", mode="before")
@classmethod @classmethod
@ -83,7 +83,7 @@ class WorkflowAppLogApi(Resource):
""" """
Get workflow app logs Get workflow app logs
""" """
args = WorkflowAppLogQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = WorkflowAppLogQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
# get paginate workflow app logs # get paginate workflow app logs
workflow_app_service = WorkflowAppService() workflow_app_service = WorkflowAppService()
@ -121,7 +121,7 @@ class WorkflowArchivedLogApi(Resource):
""" """
Get workflow archived logs Get workflow archived logs
""" """
args = WorkflowAppLogQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = WorkflowAppLogQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
workflow_app_service = WorkflowAppService() workflow_app_service = WorkflowAppService()
with Session(db.engine) as session: with Session(db.engine) as session:

View File

@ -233,7 +233,7 @@ class WorkflowVariableCollectionApi(Resource):
""" """
Get draft workflow Get draft workflow
""" """
args = WorkflowDraftVariableListQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = WorkflowDraftVariableListQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
# fetch draft workflow by app_model # fetch draft workflow by app_model
workflow_service = WorkflowService() workflow_service = WorkflowService()

View File

@ -195,7 +195,7 @@ class AdvancedChatAppWorkflowRunListApi(Resource):
""" """
Get advanced chat app workflow run list Get advanced chat app workflow run list
""" """
args_model = WorkflowRunListQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args_model = WorkflowRunListQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
args = args_model.model_dump(exclude_none=True) args = args_model.model_dump(exclude_none=True)
# Default to DEBUGGING if not specified # Default to DEBUGGING if not specified
@ -293,7 +293,7 @@ class AdvancedChatAppWorkflowRunCountApi(Resource):
""" """
Get advanced chat workflow runs count statistics Get advanced chat workflow runs count statistics
""" """
args_model = WorkflowRunCountQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args_model = WorkflowRunCountQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
args = args_model.model_dump(exclude_none=True) args = args_model.model_dump(exclude_none=True)
# Default to DEBUGGING if not specified # Default to DEBUGGING if not specified
@ -337,7 +337,7 @@ class WorkflowRunListApi(Resource):
""" """
Get workflow run list Get workflow run list
""" """
args_model = WorkflowRunListQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args_model = WorkflowRunListQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
args = args_model.model_dump(exclude_none=True) args = args_model.model_dump(exclude_none=True)
# Default to DEBUGGING for workflow if not specified (backward compatibility) # Default to DEBUGGING for workflow if not specified (backward compatibility)
@ -385,7 +385,7 @@ class WorkflowRunCountApi(Resource):
""" """
Get workflow runs count statistics Get workflow runs count statistics
""" """
args_model = WorkflowRunCountQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args_model = WorkflowRunCountQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
args = args_model.model_dump(exclude_none=True) args = args_model.model_dump(exclude_none=True)
# Default to DEBUGGING for workflow if not specified (backward compatibility) # Default to DEBUGGING for workflow if not specified (backward compatibility)

View File

@ -53,7 +53,7 @@ class WorkflowDailyRunsStatistic(Resource):
def get(self, app_model): def get(self, app_model):
account, _ = current_account_with_tenant() account, _ = current_account_with_tenant()
args = WorkflowStatisticQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = WorkflowStatisticQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
assert account.timezone is not None assert account.timezone is not None
@ -93,7 +93,7 @@ class WorkflowDailyTerminalsStatistic(Resource):
def get(self, app_model): def get(self, app_model):
account, _ = current_account_with_tenant() account, _ = current_account_with_tenant()
args = WorkflowStatisticQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = WorkflowStatisticQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
assert account.timezone is not None assert account.timezone is not None
@ -133,7 +133,7 @@ class WorkflowDailyTokenCostStatistic(Resource):
def get(self, app_model): def get(self, app_model):
account, _ = current_account_with_tenant() account, _ = current_account_with_tenant()
args = WorkflowStatisticQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = WorkflowStatisticQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
assert account.timezone is not None assert account.timezone is not None
@ -173,7 +173,7 @@ class WorkflowAverageAppInteractionStatistic(Resource):
def get(self, app_model): def get(self, app_model):
account, _ = current_account_with_tenant() account, _ = current_account_with_tenant()
args = WorkflowStatisticQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = WorkflowStatisticQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
assert account.timezone is not None assert account.timezone is not None

View File

@ -60,7 +60,7 @@ class WebhookTriggerApi(Resource):
@marshal_with(webhook_trigger_model) @marshal_with(webhook_trigger_model)
def get(self, app_model: App): def get(self, app_model: App):
"""Get webhook trigger for a node""" """Get webhook trigger for a node"""
args = Parser.model_validate(request.args.to_dict(flat=True)) # type: ignore args = Parser.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
node_id = args.node_id node_id = args.node_id
@ -114,9 +114,9 @@ class AppTriggersApi(Resource):
url_prefix = dify_config.CONSOLE_API_URL + "/console/api/workspaces/current/tool-provider/builtin/" url_prefix = dify_config.CONSOLE_API_URL + "/console/api/workspaces/current/tool-provider/builtin/"
for trigger in triggers: for trigger in triggers:
if trigger.trigger_type == "trigger-plugin": if trigger.trigger_type == "trigger-plugin":
trigger.icon = url_prefix + trigger.provider_name + "/icon" # type: ignore trigger.icon = url_prefix + trigger.provider_name + "/icon" # type: ignore[attr-defined,operator]
else: else:
trigger.icon = "" # type: ignore trigger.icon = "" # type: ignore[attr-defined]
return {"data": triggers} return {"data": triggers}
@ -159,8 +159,8 @@ class AppTriggerEnableApi(Resource):
# Add computed icon field # Add computed icon field
url_prefix = dify_config.CONSOLE_API_URL + "/console/api/workspaces/current/tool-provider/builtin/" url_prefix = dify_config.CONSOLE_API_URL + "/console/api/workspaces/current/tool-provider/builtin/"
if trigger.trigger_type == "trigger-plugin": if trigger.trigger_type == "trigger-plugin":
trigger.icon = url_prefix + trigger.provider_name + "/icon" # type: ignore trigger.icon = url_prefix + trigger.provider_name + "/icon" # type: ignore[attr-defined,operator]
else: else:
trigger.icon = "" # type: ignore trigger.icon = "" # type: ignore[attr-defined]
return trigger return trigger

View File

@ -60,7 +60,7 @@ class ActivateCheckApi(Resource):
), ),
) )
def get(self): def get(self):
args = ActivateCheckQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = ActivateCheckQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
workspaceId = args.workspace_id workspaceId = args.workspace_id
token = args.token token = args.token

View File

@ -36,7 +36,7 @@ class Subscription(Resource):
@only_edition_cloud @only_edition_cloud
def get(self): def get(self):
current_user, current_tenant_id = current_account_with_tenant() current_user, current_tenant_id = current_account_with_tenant()
args = SubscriptionQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = SubscriptionQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
BillingService.is_tenant_owner_or_admin(current_user) BillingService.is_tenant_owner_or_admin(current_user)
return BillingService.get_subscription(args.plan, args.interval, current_user.email, current_tenant_id) return BillingService.get_subscription(args.plan, args.interval, current_user.email, current_tenant_id)

View File

@ -31,7 +31,7 @@ class ComplianceApi(Resource):
@only_edition_cloud @only_edition_cloud
def get(self): def get(self):
current_user, current_tenant_id = current_account_with_tenant() current_user, current_tenant_id = current_account_with_tenant()
args = ComplianceDownloadQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = ComplianceDownloadQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
ip_address = extract_remote_ip(request) ip_address = extract_remote_ip(request)
device_info = request.headers.get("User-Agent", "Unknown device") device_info = request.headers.get("User-Agent", "Unknown device")

View File

@ -1,5 +1,5 @@
from flask_restx import ( # type: ignore from flask_restx import (
Resource, # type: ignore Resource,
) )
from pydantic import BaseModel from pydantic import BaseModel
from werkzeug.exceptions import Forbidden from werkzeug.exceptions import Forbidden

View File

@ -1,5 +1,5 @@
from flask import request from flask import request
from flask_restx import Resource, fields, marshal_with # type: ignore from flask_restx import Resource, fields, marshal_with
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
from sqlalchemy.orm import Session from sqlalchemy.orm import Session

View File

@ -3,7 +3,7 @@ import logging
from typing import Any, Literal, cast from typing import Any, Literal, cast
from flask import abort, request from flask import abort, request
from flask_restx import Resource, marshal_with # type: ignore from flask_restx import Resource, marshal_with
from pydantic import BaseModel, Field from pydantic import BaseModel, Field
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
from werkzeug.exceptions import BadRequest, Forbidden, InternalServerError, NotFound from werkzeug.exceptions import BadRequest, Forbidden, InternalServerError, NotFound

View File

@ -63,7 +63,7 @@ class RecommendedAppListApi(Resource):
@marshal_with(recommended_app_list_model) @marshal_with(recommended_app_list_model)
def get(self): def get(self):
# language args # language args
args = RecommendedAppsQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = RecommendedAppsQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
language = args.language language = args.language
if language and language in languages: if language and language in languages:
language_prefix = language language_prefix = language

View File

@ -49,7 +49,7 @@ class CodeBasedExtensionAPI(Resource):
@login_required @login_required
@account_initialization_required @account_initialization_required
def get(self): def get(self):
query = CodeBasedExtensionQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore query = CodeBasedExtensionQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
return {"module": query.module, "data": CodeBasedExtensionService.get_code_based_extension(query.module)} return {"module": query.module, "data": CodeBasedExtensionService.get_code_based_extension(query.module)}

View File

@ -519,7 +519,7 @@ class EducationAutoCompleteApi(Resource):
@cloud_edition_billing_enabled @cloud_edition_billing_enabled
@marshal_with(data_fields) @marshal_with(data_fields)
def get(self): def get(self):
payload = request.args.to_dict(flat=True) # type: ignore payload = request.args.to_dict(flat=True) # type: ignore[arg-type]
args = EducationAutocompleteQuery.model_validate(payload) args = EducationAutocompleteQuery.model_validate(payload)
return BillingService.EducationIdentity.autocomplete(args.keywords, args.page, args.limit) return BillingService.EducationIdentity.autocomplete(args.keywords, args.page, args.limit)

View File

@ -138,7 +138,7 @@ class EndpointListApi(Resource):
def get(self): def get(self):
user, tenant_id = current_account_with_tenant() user, tenant_id = current_account_with_tenant()
args = EndpointListQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = EndpointListQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
page = args.page page = args.page
page_size = args.page_size page_size = args.page_size
@ -171,7 +171,7 @@ class EndpointListForSinglePluginApi(Resource):
def get(self): def get(self):
user, tenant_id = current_account_with_tenant() user, tenant_id = current_account_with_tenant()
args = EndpointListForPluginQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = EndpointListForPluginQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
page = args.page page = args.page
page_size = args.page_size page_size = args.page_size

View File

@ -99,7 +99,7 @@ class ModelProviderListApi(Resource):
_, current_tenant_id = current_account_with_tenant() _, current_tenant_id = current_account_with_tenant()
tenant_id = current_tenant_id tenant_id = current_tenant_id
payload = request.args.to_dict(flat=True) # type: ignore payload = request.args.to_dict(flat=True) # type: ignore[arg-type]
args = ParserModelList.model_validate(payload) args = ParserModelList.model_validate(payload)
model_provider_service = ModelProviderService() model_provider_service = ModelProviderService()
@ -118,7 +118,7 @@ class ModelProviderCredentialApi(Resource):
_, current_tenant_id = current_account_with_tenant() _, current_tenant_id = current_account_with_tenant()
tenant_id = current_tenant_id tenant_id = current_tenant_id
# if credential_id is not provided, return current used credential # if credential_id is not provided, return current used credential
payload = request.args.to_dict(flat=True) # type: ignore payload = request.args.to_dict(flat=True) # type: ignore[arg-type]
args = ParserCredentialId.model_validate(payload) args = ParserCredentialId.model_validate(payload)
model_provider_service = ModelProviderService() model_provider_service = ModelProviderService()

View File

@ -133,7 +133,7 @@ class DefaultModelApi(Resource):
def get(self): def get(self):
_, tenant_id = current_account_with_tenant() _, tenant_id = current_account_with_tenant()
args = ParserGetDefault.model_validate(request.args.to_dict(flat=True)) # type: ignore args = ParserGetDefault.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
model_provider_service = ModelProviderService() model_provider_service = ModelProviderService()
default_model_entity = model_provider_service.get_default_model_of_model_type( default_model_entity = model_provider_service.get_default_model_of_model_type(
@ -261,7 +261,7 @@ class ModelProviderModelCredentialApi(Resource):
def get(self, provider: str): def get(self, provider: str):
_, tenant_id = current_account_with_tenant() _, tenant_id = current_account_with_tenant()
args = ParserGetCredentials.model_validate(request.args.to_dict(flat=True)) # type: ignore args = ParserGetCredentials.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
model_provider_service = ModelProviderService() model_provider_service = ModelProviderService()
current_credential = model_provider_service.get_model_credential( current_credential = model_provider_service.get_model_credential(
@ -513,7 +513,7 @@ class ModelProviderModelParameterRuleApi(Resource):
@login_required @login_required
@account_initialization_required @account_initialization_required
def get(self, provider: str): def get(self, provider: str):
args = ParserParameter.model_validate(request.args.to_dict(flat=True)) # type: ignore args = ParserParameter.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
_, tenant_id = current_account_with_tenant() _, tenant_id = current_account_with_tenant()
model_provider_service = ModelProviderService() model_provider_service = ModelProviderService()

View File

@ -211,7 +211,7 @@ class PluginListApi(Resource):
@account_initialization_required @account_initialization_required
def get(self): def get(self):
_, tenant_id = current_account_with_tenant() _, tenant_id = current_account_with_tenant()
args = ParserList.model_validate(request.args.to_dict(flat=True)) # type: ignore args = ParserList.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
try: try:
plugins_with_total = PluginService.list_with_total(tenant_id, args.page, args.page_size) plugins_with_total = PluginService.list_with_total(tenant_id, args.page, args.page_size)
except PluginDaemonClientSideError as e: except PluginDaemonClientSideError as e:
@ -261,7 +261,7 @@ class PluginIconApi(Resource):
@console_ns.expect(console_ns.models[ParserIcon.__name__]) @console_ns.expect(console_ns.models[ParserIcon.__name__])
@setup_required @setup_required
def get(self): def get(self):
args = ParserIcon.model_validate(request.args.to_dict(flat=True)) # type: ignore args = ParserIcon.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
try: try:
icon_bytes, mimetype = PluginService.get_asset(args.tenant_id, args.filename) icon_bytes, mimetype = PluginService.get_asset(args.tenant_id, args.filename)
@ -279,7 +279,7 @@ class PluginAssetApi(Resource):
@login_required @login_required
@account_initialization_required @account_initialization_required
def get(self): def get(self):
args = ParserAsset.model_validate(request.args.to_dict(flat=True)) # type: ignore args = ParserAsset.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
_, tenant_id = current_account_with_tenant() _, tenant_id = current_account_with_tenant()
try: try:
@ -421,7 +421,7 @@ class PluginFetchMarketplacePkgApi(Resource):
@plugin_permission_required(install_required=True) @plugin_permission_required(install_required=True)
def get(self): def get(self):
_, tenant_id = current_account_with_tenant() _, tenant_id = current_account_with_tenant()
args = ParserPluginIdentifierQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = ParserPluginIdentifierQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
try: try:
return jsonable_encoder( return jsonable_encoder(
@ -446,7 +446,7 @@ class PluginFetchManifestApi(Resource):
def get(self): def get(self):
_, tenant_id = current_account_with_tenant() _, tenant_id = current_account_with_tenant()
args = ParserPluginIdentifierQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = ParserPluginIdentifierQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
try: try:
return jsonable_encoder( return jsonable_encoder(
@ -466,7 +466,7 @@ class PluginFetchInstallTasksApi(Resource):
def get(self): def get(self):
_, tenant_id = current_account_with_tenant() _, tenant_id = current_account_with_tenant()
args = ParserTasks.model_validate(request.args.to_dict(flat=True)) # type: ignore args = ParserTasks.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
try: try:
return jsonable_encoder({"tasks": PluginService.fetch_install_tasks(tenant_id, args.page, args.page_size)}) return jsonable_encoder({"tasks": PluginService.fetch_install_tasks(tenant_id, args.page, args.page_size)})
@ -660,7 +660,7 @@ class PluginFetchDynamicSelectOptionsApi(Resource):
current_user, tenant_id = current_account_with_tenant() current_user, tenant_id = current_account_with_tenant()
user_id = current_user.id user_id = current_user.id
args = ParserDynamicOptions.model_validate(request.args.to_dict(flat=True)) # type: ignore args = ParserDynamicOptions.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
try: try:
options = PluginParameterService.get_dynamic_select_options( options = PluginParameterService.get_dynamic_select_options(
@ -822,7 +822,7 @@ class PluginReadmeApi(Resource):
@account_initialization_required @account_initialization_required
def get(self): def get(self):
_, tenant_id = current_account_with_tenant() _, tenant_id = current_account_with_tenant()
args = ParserReadme.model_validate(request.args.to_dict(flat=True)) # type: ignore args = ParserReadme.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
return jsonable_encoder( return jsonable_encoder(
{"readme": PluginService.fetch_plugin_readme(tenant_id, args.plugin_unique_identifier, args.language)} {"readme": PluginService.fetch_plugin_readme(tenant_id, args.plugin_unique_identifier, args.language)}
) )

View File

@ -267,7 +267,7 @@ class ToolProviderListApi(Resource):
raw_args = request.args.to_dict() raw_args = request.args.to_dict()
query = ToolProviderListQuery.model_validate(raw_args) query = ToolProviderListQuery.model_validate(raw_args)
return ToolCommonService.list_tool_providers(user_id, tenant_id, query.type) # type: ignore return ToolCommonService.list_tool_providers(user_id, tenant_id, query.type) # type: ignore[arg-type, operator]
@console_ns.route("/workspaces/current/tool-provider/builtin/<path:provider>/tools") @console_ns.route("/workspaces/current/tool-provider/builtin/<path:provider>/tools")

View File

@ -155,7 +155,7 @@ class WorkspaceListApi(Resource):
@setup_required @setup_required
@admin_required @admin_required
def get(self): def get(self):
payload = request.args.to_dict(flat=True) # type: ignore payload = request.args.to_dict(flat=True) # type: ignore[arg-type]
args = WorkspaceListQuery.model_validate(payload) args = WorkspaceListQuery.model_validate(payload)
stmt = select(Tenant).order_by(Tenant.created_at.desc()) stmt = select(Tenant).order_by(Tenant.created_at.desc())

View File

@ -313,7 +313,7 @@ def edit_permission_required(f: Callable[P, R]):
from libs.login import current_user from libs.login import current_user
from models import Account from models import Account
user = current_user._get_current_object() # type: ignore user = current_user._get_current_object() # type: ignore[attr-defined]
if not isinstance(user, Account): if not isinstance(user, Account):
raise Forbidden() raise Forbidden()
if not current_user.has_edit_permission: if not current_user.has_edit_permission:

View File

@ -58,7 +58,7 @@ class ImagePreviewApi(Resource):
def get(self, file_id): def get(self, file_id):
file_id = str(file_id) file_id = str(file_id)
args = FileSignatureQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = FileSignatureQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
timestamp = args.timestamp timestamp = args.timestamp
nonce = args.nonce nonce = args.nonce
sign = args.sign sign = args.sign
@ -100,7 +100,7 @@ class FilePreviewApi(Resource):
def get(self, file_id): def get(self, file_id):
file_id = str(file_id) file_id = str(file_id)
args = FilePreviewQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = FilePreviewQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
try: try:
generator, upload_file = FileService(db.engine).get_file_generator_by_file_id( generator, upload_file = FileService(db.engine).get_file_generator_by_file_id(

View File

@ -69,7 +69,7 @@ class PluginUploadFileApi(Resource):
FileTooLargeError: File exceeds size limit FileTooLargeError: File exceeds size limit
UnsupportedFileTypeError: File type not supported UnsupportedFileTypeError: File type not supported
""" """
args = PluginUploadQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore args = PluginUploadQuery.model_validate(request.args.to_dict(flat=True)) # type: ignore[arg-type]
file = request.files.get("file") file = request.files.get("file")
if file is None: if file is None:

View File

@ -32,7 +32,7 @@ class BaseMail(Resource):
to=args.to, to=args.to,
subject=args.subject, subject=args.subject,
body=args.body, body=args.body,
substitutions=args.substitutions, # type: ignore substitutions=args.substitutions, # type: ignore[arg-type]
) )
return {"message": "success"}, 200 return {"message": "success"}, 200

View File

@ -89,8 +89,8 @@ def get_user_tenant(view_func: Callable[P, R]):
user = get_user(tenant_id, user_id) user = get_user(tenant_id, user_id)
kwargs["user_model"] = user kwargs["user_model"] = user
current_app.login_manager._update_request_context_with_user(user) # type: ignore current_app.login_manager._update_request_context_with_user(user) # type: ignore[attr-defined]
user_logged_in.send(current_app._get_current_object(), user=current_user) # type: ignore user_logged_in.send(current_app._get_current_object(), user=current_user) # type: ignore[attr-defined]
return view_func(*args, **kwargs) return view_func(*args, **kwargs)

View File

@ -34,7 +34,7 @@ class FileApi(Resource):
415: "Unsupported file type", 415: "Unsupported file type",
} }
) )
@validate_app_token(fetch_user_arg=FetchUserArg(fetch_from=WhereisUserArg.FORM)) # type: ignore @validate_app_token(fetch_user_arg=FetchUserArg(fetch_from=WhereisUserArg.FORM)) # type: ignore[misc]
@service_api_ns.response(HTTPStatus.CREATED, "File uploaded", service_api_ns.models[FileResponse.__name__]) @service_api_ns.response(HTTPStatus.CREATED, "File uploaded", service_api_ns.models[FileResponse.__name__])
def post(self, app_model: App, end_user: EndUser): def post(self, app_model: App, end_user: EndUser):
"""Upload a file for use in conversations. """Upload a file for use in conversations.

View File

@ -101,8 +101,8 @@ def validate_app_token(
kwargs["end_user"] = end_user kwargs["end_user"] = end_user
# Set EndUser as current logged-in user for flask_login.current_user # Set EndUser as current logged-in user for flask_login.current_user
current_app.login_manager._update_request_context_with_user(end_user) # type: ignore current_app.login_manager._update_request_context_with_user(end_user) # type: ignore[attr-defined]
user_logged_in.send(current_app._get_current_object(), user=end_user) # type: ignore user_logged_in.send(current_app._get_current_object(), user=end_user) # type: ignore[attr-defined]
else: else:
# For service API without end-user context, ensure an Account is logged in # For service API without end-user context, ensure an Account is logged in
# so services relying on current_account_with_tenant() work correctly. # so services relying on current_account_with_tenant() work correctly.
@ -121,8 +121,8 @@ def validate_app_token(
if tenant_owner_info: if tenant_owner_info:
tenant_model, account = tenant_owner_info tenant_model, account = tenant_owner_info
account.current_tenant = tenant_model account.current_tenant = tenant_model
current_app.login_manager._update_request_context_with_user(account) # type: ignore current_app.login_manager._update_request_context_with_user(account) # type: ignore[attr-defined]
user_logged_in.send(current_app._get_current_object(), user=current_user) # type: ignore user_logged_in.send(current_app._get_current_object(), user=current_user) # type: ignore[attr-defined]
else: else:
raise Unauthorized("Tenant owner account not found or tenant is not active.") raise Unauthorized("Tenant owner account not found or tenant is not active.")
@ -303,8 +303,8 @@ def validate_dataset_token(
# Login admin # Login admin
if account: if account:
account.current_tenant = tenant account.current_tenant = tenant
current_app.login_manager._update_request_context_with_user(account) # type: ignore current_app.login_manager._update_request_context_with_user(account) # type: ignore[attr-defined]
user_logged_in.send(current_app._get_current_object(), user=current_user) # type: ignore user_logged_in.send(current_app._get_current_object(), user=current_user) # type: ignore[attr-defined]
else: else:
raise Unauthorized("Tenant owner account does not exist.") raise Unauthorized("Tenant owner account does not exist.")
else: else:

View File

@ -171,7 +171,7 @@ class AdvancedChatAppGenerator(MessageBasedAppGenerator):
if invoke_from == InvokeFrom.DEBUGGER: if invoke_from == InvokeFrom.DEBUGGER:
# always enable retriever resource in debugger mode # always enable retriever resource in debugger mode
app_config.additional_features.show_retrieve_source = True # type: ignore app_config.additional_features.show_retrieve_source = True # type: ignore[attr-defined]
# init application generate entity # init application generate entity
application_generate_entity = AdvancedChatAppGenerateEntity( application_generate_entity = AdvancedChatAppGenerateEntity(
@ -504,7 +504,7 @@ class AdvancedChatAppGenerator(MessageBasedAppGenerator):
worker_thread = threading.Thread( worker_thread = threading.Thread(
target=self._generate_worker, target=self._generate_worker,
kwargs={ kwargs={
"flask_app": current_app._get_current_object(), # type: ignore "flask_app": current_app._get_current_object(), # type: ignore[attr-defined]
"application_generate_entity": application_generate_entity, "application_generate_entity": application_generate_entity,
"queue_manager": queue_manager, "queue_manager": queue_manager,
"conversation_id": conversation.id, "conversation_id": conversation.id,

View File

@ -191,7 +191,7 @@ class AgentChatAppGenerator(MessageBasedAppGenerator):
worker_thread = threading.Thread( worker_thread = threading.Thread(
target=self._generate_worker, target=self._generate_worker,
kwargs={ kwargs={
"flask_app": current_app._get_current_object(), # type: ignore "flask_app": current_app._get_current_object(), # type: ignore[attr-defined]
"context": context, "context": context,
"application_generate_entity": application_generate_entity, "application_generate_entity": application_generate_entity,
"queue_manager": queue_manager, "queue_manager": queue_manager,

View File

@ -181,7 +181,7 @@ class ChatAppGenerator(MessageBasedAppGenerator):
@copy_current_request_context @copy_current_request_context
def worker_with_context(): def worker_with_context():
return self._generate_worker( return self._generate_worker(
flask_app=current_app._get_current_object(), # type: ignore flask_app=current_app._get_current_object(), # type: ignore[attr-defined]
application_generate_entity=application_generate_entity, application_generate_entity=application_generate_entity,
queue_manager=queue_manager, queue_manager=queue_manager,
conversation_id=conversation.id, conversation_id=conversation.id,

View File

@ -164,7 +164,7 @@ class CompletionAppGenerator(MessageBasedAppGenerator):
@copy_current_request_context @copy_current_request_context
def worker_with_context(): def worker_with_context():
return self._generate_worker( return self._generate_worker(
flask_app=current_app._get_current_object(), # type: ignore flask_app=current_app._get_current_object(), # type: ignore[attr-defined]
application_generate_entity=application_generate_entity, application_generate_entity=application_generate_entity,
queue_manager=queue_manager, queue_manager=queue_manager,
message_id=message.id, message_id=message.id,
@ -327,7 +327,7 @@ class CompletionAppGenerator(MessageBasedAppGenerator):
@copy_current_request_context @copy_current_request_context
def worker_with_context(): def worker_with_context():
return self._generate_worker( return self._generate_worker(
flask_app=current_app._get_current_object(), # type: ignore flask_app=current_app._get_current_object(), # type: ignore[attr-defined]
application_generate_entity=application_generate_entity, application_generate_entity=application_generate_entity,
queue_manager=queue_manager, queue_manager=queue_manager,
message_id=message.id, message_id=message.id,

View File

@ -217,7 +217,7 @@ class PipelineGenerator(BaseAppGenerator):
) )
if invoke_from == InvokeFrom.DEBUGGER or is_retry: if invoke_from == InvokeFrom.DEBUGGER or is_retry:
return self._generate( return self._generate(
flask_app=current_app._get_current_object(), # type: ignore flask_app=current_app._get_current_object(), # type: ignore[attr-defined]
context=contextvars.copy_context(), context=contextvars.copy_context(),
pipeline=pipeline, pipeline=pipeline,
workflow_id=workflow.id, workflow_id=workflow.id,
@ -315,7 +315,7 @@ class PipelineGenerator(BaseAppGenerator):
worker_thread = threading.Thread( worker_thread = threading.Thread(
target=self._generate_worker, target=self._generate_worker,
kwargs={ kwargs={
"flask_app": current_app._get_current_object(), # type: ignore "flask_app": current_app._get_current_object(), # type: ignore[attr-defined]
"context": context, "context": context,
"queue_manager": queue_manager, "queue_manager": queue_manager,
"application_generate_entity": application_generate_entity, "application_generate_entity": application_generate_entity,
@ -428,7 +428,7 @@ class PipelineGenerator(BaseAppGenerator):
) )
return self._generate( return self._generate(
flask_app=current_app._get_current_object(), # type: ignore flask_app=current_app._get_current_object(), # type: ignore[attr-defined]
pipeline=pipeline, pipeline=pipeline,
workflow_id=workflow.id, workflow_id=workflow.id,
user=user, user=user,
@ -524,7 +524,7 @@ class PipelineGenerator(BaseAppGenerator):
) )
return self._generate( return self._generate(
flask_app=current_app._get_current_object(), # type: ignore flask_app=current_app._get_current_object(), # type: ignore[attr-defined]
pipeline=pipeline, pipeline=pipeline,
workflow_id=workflow.id, workflow_id=workflow.id,
user=user, user=user,

View File

@ -320,7 +320,7 @@ class WorkflowAppGenerator(BaseAppGenerator):
worker_thread = threading.Thread( worker_thread = threading.Thread(
target=self._generate_worker, target=self._generate_worker,
kwargs={ kwargs={
"flask_app": current_app._get_current_object(), # type: ignore "flask_app": current_app._get_current_object(), # type: ignore[attr-defined]
"application_generate_entity": application_generate_entity, "application_generate_entity": application_generate_entity,
"queue_manager": queue_manager, "queue_manager": queue_manager,
"context": context, "context": context,

View File

@ -138,7 +138,7 @@ class EasyUIBasedAppGenerateEntity(AppGenerateEntity):
""" """
# app config # app config
app_config: EasyUIBasedAppConfig = None # type: ignore app_config: EasyUIBasedAppConfig = None # type: ignore[assignment]
model_conf: ModelConfigWithCredentialsEntity model_conf: ModelConfigWithCredentialsEntity
query: str = "" query: str = ""
@ -202,7 +202,7 @@ class AdvancedChatAppGenerateEntity(ConversationAppGenerateEntity):
""" """
# app config # app config
app_config: WorkflowUIBasedAppConfig = None # type: ignore app_config: WorkflowUIBasedAppConfig = None # type: ignore[assignment]
workflow_run_id: str | None = None workflow_run_id: str | None = None
query: str query: str
@ -234,7 +234,7 @@ class WorkflowAppGenerateEntity(AppGenerateEntity):
""" """
# app config # app config
app_config: WorkflowUIBasedAppConfig = None # type: ignore app_config: WorkflowUIBasedAppConfig = None # type: ignore[assignment]
workflow_execution_id: str workflow_execution_id: str
class SingleIterationRunEntity(BaseModel): class SingleIterationRunEntity(BaseModel):

View File

@ -2,7 +2,7 @@ import logging
import uuid import uuid
from typing import ClassVar from typing import ClassVar
from apscheduler.schedulers.background import BackgroundScheduler # type: ignore from apscheduler.schedulers.background import BackgroundScheduler # type: ignore[reportMissingTypeStubs]
from dify_graph.graph_engine.entities.commands import CommandType, GraphEngineCommand from dify_graph.graph_engine.entities.commands import CommandType, GraphEngineCommand
from dify_graph.graph_engine.layers.base import GraphEngineLayer from dify_graph.graph_engine.layers.base import GraphEngineLayer

View File

@ -100,7 +100,7 @@ class MessageCycleManager:
1, 1,
self._generate_conversation_name_worker, self._generate_conversation_name_worker,
kwargs={ kwargs={
"flask_app": current_app._get_current_object(), # type: ignore "flask_app": current_app._get_current_object(), # type: ignore[attr-defined]
"conversation_id": conversation_id, "conversation_id": conversation_id,
"query": query, "query": query,
}, },

View File

@ -31,7 +31,7 @@ class LocalFileDatasourcePluginProviderController(DatasourcePluginProviderContro
""" """
pass pass
def get_datasource(self, datasource_name: str) -> LocalFileDatasourcePlugin: # type: ignore def get_datasource(self, datasource_name: str) -> LocalFileDatasourcePlugin: # type: ignore[return-value]
""" """
return datasource with given name return datasource with given name
""" """

View File

@ -23,7 +23,7 @@ class OnlineDocumentDatasourcePluginProviderController(DatasourcePluginProviderC
""" """
return DatasourceProviderType.ONLINE_DOCUMENT return DatasourceProviderType.ONLINE_DOCUMENT
def get_datasource(self, datasource_name: str) -> OnlineDocumentDatasourcePlugin: # type: ignore def get_datasource(self, datasource_name: str) -> OnlineDocumentDatasourcePlugin: # type: ignore[return-value]
""" """
return datasource with given name return datasource with given name
""" """

View File

@ -23,7 +23,7 @@ class OnlineDriveDatasourcePluginProviderController(DatasourcePluginProviderCont
""" """
return DatasourceProviderType.ONLINE_DRIVE return DatasourceProviderType.ONLINE_DRIVE
def get_datasource(self, datasource_name: str) -> OnlineDriveDatasourcePlugin: # type: ignore def get_datasource(self, datasource_name: str) -> OnlineDriveDatasourcePlugin: # type: ignore[return-value]
""" """
return datasource with given name return datasource with given name
""" """

View File

@ -27,7 +27,7 @@ class WebsiteCrawlDatasourcePluginProviderController(DatasourcePluginProviderCon
""" """
return DatasourceProviderType.WEBSITE_CRAWL return DatasourceProviderType.WEBSITE_CRAWL
def get_datasource(self, datasource_name: str) -> WebsiteCrawlDatasourcePlugin: # type: ignore def get_datasource(self, datasource_name: str) -> WebsiteCrawlDatasourcePlugin: # type: ignore[return-value]
""" """
return datasource with given name return datasource with given name
""" """

View File

@ -37,7 +37,7 @@ class ExternalDataFetch:
for tool in external_data_tools: for tool in external_data_tools:
future: Future[tuple[str | None, str | None]] = executor.submit( future: Future[tuple[str | None, str | None]] = executor.submit(
self._query_external_data_tool, self._query_external_data_tool,
current_app._get_current_object(), # type: ignore current_app._get_current_object(), # type: ignore[attr-defined]
tenant_id, tenant_id,
app_id, app_id,
tool, tool,

View File

@ -24,7 +24,7 @@ class ExternalDataToolFactory:
""" """
extension_class = code_based_extension.extension_class(ExtensionModule.EXTERNAL_DATA_TOOL, name) extension_class = code_based_extension.extension_class(ExtensionModule.EXTERNAL_DATA_TOOL, name)
# FIXME mypy issue here, figure out how to fix it # FIXME mypy issue here, figure out how to fix it
extension_class.validate_config(tenant_id, config) # type: ignore extension_class.validate_config(tenant_id, config) # type: ignore[attr-defined, operator]
def query(self, inputs: Mapping[str, Any], query: str | None = None) -> str: def query(self, inputs: Mapping[str, Any], query: str | None = None) -> str:
""" """

View File

@ -592,7 +592,7 @@ class IndexingRunner:
# create keyword index # create keyword index
create_keyword_thread = threading.Thread( create_keyword_thread = threading.Thread(
target=self._process_keyword_index, target=self._process_keyword_index,
args=(current_app._get_current_object(), dataset.id, dataset_document.id, documents), # type: ignore args=(current_app._get_current_object(), dataset.id, dataset_document.id, documents), # type: ignore[attr-defined]
) )
create_keyword_thread.start() create_keyword_thread.start()
@ -615,7 +615,7 @@ class IndexingRunner:
futures.append( futures.append(
executor.submit( executor.submit(
self._process_chunk, self._process_chunk,
current_app._get_current_object(), # type: ignore current_app._get_current_object(), # type: ignore[attr-defined]
index_processor, index_processor,
chunk_documents, chunk_documents,
dataset, dataset,
@ -742,7 +742,7 @@ class IndexingRunner:
if extra_update_params: if extra_update_params:
update_params.update(extra_update_params) update_params.update(extra_update_params)
db.session.query(DatasetDocument).filter_by(id=document_id).update(update_params) # type: ignore db.session.query(DatasetDocument).filter_by(id=document_id).update(update_params) # type: ignore[arg-type, operator]
db.session.commit() db.session.commit()
@staticmethod @staticmethod

View File

@ -22,7 +22,7 @@ class ModerationFactory:
""" """
extension_class = code_based_extension.extension_class(ExtensionModule.MODERATION, name) extension_class = code_based_extension.extension_class(ExtensionModule.MODERATION, name)
# FIXME: mypy error, try to fix it instead of using type: ignore # FIXME: mypy error, try to fix it instead of using type: ignore
extension_class.validate_config(tenant_id, config) # type: ignore extension_class.validate_config(tenant_id, config) # type: ignore[attr-defined, operator]
def moderation_for_inputs(self, inputs: dict, query: str = "") -> ModerationInputsResult: def moderation_for_inputs(self, inputs: dict, query: str = "") -> ModerationInputsResult:
""" """

View File

@ -75,7 +75,7 @@ class OutputModeration(BaseModel):
thread = threading.Thread( thread = threading.Thread(
target=self.worker, target=self.worker,
kwargs={ kwargs={
"flask_app": current_app._get_current_object(), # type: ignore "flask_app": current_app._get_current_object(), # type: ignore[attr-defined]
"buffer_size": buffer_size if buffer_size > 0 else dify_config.MODERATION_BUFFER_SIZE, "buffer_size": buffer_size if buffer_size > 0 else dify_config.MODERATION_BUFFER_SIZE,
}, },
) )

View File

@ -936,7 +936,7 @@ class TraceQueueManager:
self.app_id = app_id self.app_id = app_id
self.user_id = user_id self.user_id = user_id
self.trace_instance = OpsTraceManager.get_ops_trace_instance(app_id) self.trace_instance = OpsTraceManager.get_ops_trace_instance(app_id)
self.flask_app = current_app._get_current_object() # type: ignore self.flask_app = current_app._get_current_object() # type: ignore[attr-defined]
if trace_manager_timer is None: if trace_manager_timer is None:
self.start_timer() self.start_timer()
@ -995,4 +995,4 @@ class TraceQueueManager:
"file_id": file_id, "file_id": file_id,
"app_id": task.app_id, "app_id": task.app_id,
} }
process_trace_tasks.delay(file_info) # type: ignore process_trace_tasks.delay(file_info) # type: ignore[operator]

View File

@ -198,7 +198,7 @@ class BasePluginClient:
Make a stream request to the plugin daemon inner API and yield the response as a model. Make a stream request to the plugin daemon inner API and yield the response as a model.
""" """
for line in self._stream_request(method, path, params, headers, data, files): for line in self._stream_request(method, path, params, headers, data, files):
yield type_(**json.loads(line)) # type: ignore yield type_(**json.loads(line)) # type: ignore[misc, operator]
def _request_with_model( def _request_with_model(
self, self,
@ -246,7 +246,7 @@ class BasePluginClient:
if transformer: if transformer:
json_response = transformer(json_response) json_response = transformer(json_response)
# https://stackoverflow.com/questions/59634937/variable-foo-class-is-not-valid-as-type-but-why # https://stackoverflow.com/questions/59634937/variable-foo-class-is-not-valid-as-type-but-why
rep = PluginDaemonBasicResponse[type_].model_validate(json_response) # type: ignore rep = PluginDaemonBasicResponse[type_].model_validate(json_response) # type: ignore[valid-type, operator]
except Exception: except Exception:
msg = ( msg = (
f"Failed to parse response from plugin daemon to PluginDaemonBasicResponse [{str(type_.__name__)}]," f"Failed to parse response from plugin daemon to PluginDaemonBasicResponse [{str(type_.__name__)}],"
@ -283,7 +283,7 @@ class BasePluginClient:
""" """
for line in self._stream_request(method, path, params, headers, data, files): for line in self._stream_request(method, path, params, headers, data, files):
try: try:
rep = PluginDaemonBasicResponse[type_].model_validate_json(line) # type: ignore rep = PluginDaemonBasicResponse[type_].model_validate_json(line) # type: ignore[valid-type, operator]
except (ValueError, TypeError): except (ValueError, TypeError):
# TODO modify this when line_data has code and message # TODO modify this when line_data has code and message
try: try:

View File

@ -88,7 +88,7 @@ def merge_blob_chunks(
meta=resp.meta, meta=resp.meta,
) )
assert isinstance(merged_message, (ToolInvokeMessage, AgentInvokeMessage)) assert isinstance(merged_message, (ToolInvokeMessage, AgentInvokeMessage))
yield merged_message # type: ignore yield merged_message # type: ignore[misc]
# Clean up the buffer # Clean up the buffer
del files[chunk_id] del files[chunk_id]
else: else:

View File

@ -629,7 +629,7 @@ class ProviderManager:
provider_name=ModelProviderID(provider_name).provider_name, provider_name=ModelProviderID(provider_name).provider_name,
provider_type=ProviderType.SYSTEM, provider_type=ProviderType.SYSTEM,
quota_type=quota.quota_type, quota_type=quota.quota_type,
quota_limit=0, # type: ignore quota_limit=0, # type: ignore[assignment]
quota_used=0, quota_used=0,
is_valid=True, is_valid=True,
) )

View File

@ -44,7 +44,7 @@ class JiebaKeywordTableHandler:
& cache to default _SimpleTFIDF & cache to default _SimpleTFIDF
""" """
import jieba.analyse # type: ignore import jieba.analyse
tfidf = getattr(jieba.analyse, "default_tfidf", None) tfidf = getattr(jieba.analyse, "default_tfidf", None)
if tfidf is not None: if tfidf is not None:
@ -53,7 +53,7 @@ class JiebaKeywordTableHandler:
tfidf_class = getattr(jieba.analyse, "TFIDF", None) tfidf_class = getattr(jieba.analyse, "TFIDF", None)
if tfidf_class is None: if tfidf_class is None:
try: try:
from jieba.analyse.tfidf import TFIDF # type: ignore from jieba.analyse.tfidf import TFIDF
tfidf_class = TFIDF tfidf_class = TFIDF
except Exception: except Exception:
@ -69,7 +69,7 @@ class JiebaKeywordTableHandler:
@staticmethod @staticmethod
def _build_fallback_tfidf(): def _build_fallback_tfidf():
"""Fallback lightweight TFIDF for environments missing jieba's TFIDF.""" """Fallback lightweight TFIDF for environments missing jieba's TFIDF."""
import jieba # type: ignore import jieba
from core.rag.datasource.keyword.jieba.stopwords import STOPWORDS from core.rag.datasource.keyword.jieba.stopwords import STOPWORDS

View File

@ -115,14 +115,14 @@ class RetrievalService:
exceptions: list[str] = [] exceptions: list[str] = []
# Optimize multithreading with thread pools # Optimize multithreading with thread pools
with ThreadPoolExecutor(max_workers=dify_config.RETRIEVAL_SERVICE_EXECUTORS) as executor: # type: ignore with ThreadPoolExecutor(max_workers=dify_config.RETRIEVAL_SERVICE_EXECUTORS) as executor: # type: ignore[operator]
futures = [] futures = []
retrieval_service = RetrievalService() retrieval_service = RetrievalService()
if query: if query:
futures.append( futures.append(
executor.submit( executor.submit(
retrieval_service._retrieve, retrieval_service._retrieve,
flask_app=current_app._get_current_object(), # type: ignore flask_app=current_app._get_current_object(), # type: ignore[attr-defined]
retrieval_method=retrieval_method, retrieval_method=retrieval_method,
dataset=dataset, dataset=dataset,
query=query, query=query,
@ -142,7 +142,7 @@ class RetrievalService:
futures.append( futures.append(
executor.submit( executor.submit(
retrieval_service._retrieve, retrieval_service._retrieve,
flask_app=current_app._get_current_object(), # type: ignore flask_app=current_app._get_current_object(), # type: ignore[attr-defined]
retrieval_method=retrieval_method, retrieval_method=retrieval_method,
dataset=dataset, dataset=dataset,
query=None, query=None,
@ -541,7 +541,7 @@ class RetrievalService:
DocumentSegment.status == "completed", DocumentSegment.status == "completed",
DocumentSegment.index_node_id.in_(index_node_ids), DocumentSegment.index_node_id.in_(index_node_ids),
) )
index_node_segments = session.execute(document_segment_stmt).scalars().all() # type: ignore index_node_segments = session.execute(document_segment_stmt).scalars().all() # type: ignore[assignment, operator]
for index_node_segment in index_node_segments: for index_node_segment in index_node_segments:
doc_segment_map[index_node_segment.id] = [index_node_segment.index_node_id] doc_segment_map[index_node_segment.id] = [index_node_segment.index_node_id]
@ -551,7 +551,7 @@ class RetrievalService:
DocumentSegment.status == "completed", DocumentSegment.status == "completed",
DocumentSegment.id.in_(segment_ids), DocumentSegment.id.in_(segment_ids),
) )
segments = session.execute(document_segment_stmt).scalars().all() # type: ignore segments = session.execute(document_segment_stmt).scalars().all() # type: ignore[assignment, operator]
if index_node_segments: if index_node_segments:
segments.extend(index_node_segments) segments.extend(index_node_segments)
@ -564,7 +564,7 @@ class RetrievalService:
DocumentSegment.status == "completed", DocumentSegment.status == "completed",
DocumentSegment.id.in_(summary_segment_ids_list), DocumentSegment.id.in_(summary_segment_ids_list),
) )
summary_segments = session.execute(summary_segment_stmt).scalars().all() # type: ignore summary_segments = session.execute(summary_segment_stmt).scalars().all() # type: ignore[operator]
segments.extend(summary_segments) segments.extend(summary_segments)
# Add summary segment IDs to segment_ids for summary query # Add summary segment IDs to segment_ids for summary query
for seg in summary_segments: for seg in summary_segments:
@ -747,13 +747,13 @@ class RetrievalService:
with flask_app.app_context(): with flask_app.app_context():
all_documents_item: list[Document] = [] all_documents_item: list[Document] = []
# Optimize multithreading with thread pools # Optimize multithreading with thread pools
with ThreadPoolExecutor(max_workers=dify_config.RETRIEVAL_SERVICE_EXECUTORS) as executor: # type: ignore with ThreadPoolExecutor(max_workers=dify_config.RETRIEVAL_SERVICE_EXECUTORS) as executor: # type: ignore[operator]
futures = [] futures = []
if retrieval_method == RetrievalMethod.KEYWORD_SEARCH and query: if retrieval_method == RetrievalMethod.KEYWORD_SEARCH and query:
futures.append( futures.append(
executor.submit( executor.submit(
self.keyword_search, self.keyword_search,
flask_app=current_app._get_current_object(), # type: ignore flask_app=current_app._get_current_object(), # type: ignore[attr-defined]
dataset_id=dataset.id, dataset_id=dataset.id,
query=query, query=query,
top_k=top_k, top_k=top_k,
@ -767,7 +767,7 @@ class RetrievalService:
futures.append( futures.append(
executor.submit( executor.submit(
self.embedding_search, self.embedding_search,
flask_app=current_app._get_current_object(), # type: ignore flask_app=current_app._get_current_object(), # type: ignore[attr-defined]
dataset_id=dataset.id, dataset_id=dataset.id,
query=query, query=query,
top_k=top_k, top_k=top_k,
@ -784,7 +784,7 @@ class RetrievalService:
futures.append( futures.append(
executor.submit( executor.submit(
self.embedding_search, self.embedding_search,
flask_app=current_app._get_current_object(), # type: ignore flask_app=current_app._get_current_object(), # type: ignore[attr-defined]
dataset_id=dataset.id, dataset_id=dataset.id,
query=attachment_id, query=attachment_id,
top_k=top_k, top_k=top_k,
@ -801,7 +801,7 @@ class RetrievalService:
futures.append( futures.append(
executor.submit( executor.submit(
self.full_text_index_search, self.full_text_index_search,
flask_app=current_app._get_current_object(), # type: ignore flask_app=current_app._get_current_object(), # type: ignore[attr-defined]
dataset_id=dataset.id, dataset_id=dataset.id,
query=query, query=query,
top_k=top_k, top_k=top_k,

View File

@ -55,8 +55,8 @@ class AnalyticdbVectorOpenAPIConfig(BaseModel):
class AnalyticdbVectorOpenAPI: class AnalyticdbVectorOpenAPI:
def __init__(self, collection_name: str, config: AnalyticdbVectorOpenAPIConfig): def __init__(self, collection_name: str, config: AnalyticdbVectorOpenAPIConfig):
try: try:
from alibabacloud_gpdb20160503.client import Client # type: ignore from alibabacloud_gpdb20160503.client import Client
from alibabacloud_tea_openapi import models as open_api_models # type: ignore from alibabacloud_tea_openapi import models as open_api_models
except: except:
raise ImportError(_import_err_msg) raise ImportError(_import_err_msg)
self._collection_name = collection_name.lower() self._collection_name = collection_name.lower()
@ -77,7 +77,7 @@ class AnalyticdbVectorOpenAPI:
redis_client.set(database_exist_cache_key, 1, ex=3600) redis_client.set(database_exist_cache_key, 1, ex=3600)
def _initialize_vector_database(self): def _initialize_vector_database(self):
from alibabacloud_gpdb20160503 import models as gpdb_20160503_models # type: ignore from alibabacloud_gpdb20160503 import models as gpdb_20160503_models
request = gpdb_20160503_models.InitVectorDatabaseRequest( request = gpdb_20160503_models.InitVectorDatabaseRequest(
dbinstance_id=self.config.instance_id, dbinstance_id=self.config.instance_id,
@ -89,7 +89,7 @@ class AnalyticdbVectorOpenAPI:
def _create_namespace_if_not_exists(self): def _create_namespace_if_not_exists(self):
from alibabacloud_gpdb20160503 import models as gpdb_20160503_models from alibabacloud_gpdb20160503 import models as gpdb_20160503_models
from Tea.exceptions import TeaException # type: ignore from Tea.exceptions import TeaException
try: try:
request = gpdb_20160503_models.DescribeNamespaceRequest( request = gpdb_20160503_models.DescribeNamespaceRequest(

View File

@ -6,12 +6,19 @@ from typing import Any
import numpy as np import numpy as np
from pydantic import BaseModel, model_validator from pydantic import BaseModel, model_validator
from pymochow import MochowClient # type: ignore from pymochow import MochowClient
from pymochow.auth.bce_credentials import BceCredentials # type: ignore from pymochow.auth.bce_credentials import BceCredentials
from pymochow.configuration import Configuration # type: ignore from pymochow.configuration import Configuration
from pymochow.exception import ServerError # type: ignore from pymochow.exception import ServerError
from pymochow.model.database import Database from pymochow.model.database import Database
from pymochow.model.enum import FieldType, IndexState, IndexType, MetricType, ServerErrCode, TableState # type: ignore from pymochow.model.enum import (
FieldType,
IndexState,
IndexType,
MetricType,
ServerErrCode,
TableState,
)
from pymochow.model.schema import ( from pymochow.model.schema import (
AutoBuildRowCountIncrement, AutoBuildRowCountIncrement,
Field, Field,
@ -24,8 +31,14 @@ from pymochow.model.schema import (
InvertedIndexParseMode, InvertedIndexParseMode,
Schema, Schema,
VectorIndex, VectorIndex,
) # type: ignore )
from pymochow.model.table import AnnSearch, BM25SearchRequest, HNSWSearchParams, Partition, Row # type: ignore from pymochow.model.table import (
AnnSearch,
BM25SearchRequest,
HNSWSearchParams,
Partition,
Row,
)
from configs import dify_config from configs import dify_config
from core.rag.datasource.vdb.field import Field as VDBField from core.rag.datasource.vdb.field import Field as VDBField

View File

@ -72,13 +72,13 @@ class ChromaVector(BaseVector):
collection = self._client.get_or_create_collection(self._collection_name) collection = self._client.get_or_create_collection(self._collection_name)
# FIXME: chromadb using numpy array, fix the type error later # FIXME: chromadb using numpy array, fix the type error later
collection.upsert(ids=uuids, documents=texts, embeddings=embeddings, metadatas=metadatas) # type: ignore collection.upsert(ids=uuids, documents=texts, embeddings=embeddings, metadatas=metadatas) # type: ignore[arg-type, operator]
return uuids return uuids
def delete_by_metadata_field(self, key: str, value: str): def delete_by_metadata_field(self, key: str, value: str):
collection = self._client.get_or_create_collection(self._collection_name) collection = self._client.get_or_create_collection(self._collection_name)
# FIXME: fix the type error later # FIXME: fix the type error later
collection.delete(where={key: {"$eq": value}}) # type: ignore collection.delete(where={key: {"$eq": value}}) # type: ignore[arg-type, dict-item]
def delete(self): def delete(self):
self._client.delete_collection(self._collection_name) self._client.delete_collection(self._collection_name)
@ -101,10 +101,10 @@ class ChromaVector(BaseVector):
results: QueryResult = collection.query( results: QueryResult = collection.query(
query_embeddings=query_vector, query_embeddings=query_vector,
n_results=kwargs.get("top_k", 4), n_results=kwargs.get("top_k", 4),
where={"document_id": {"$in": document_ids_filter}}, # type: ignore where={"document_id": {"$in": document_ids_filter}}, # type: ignore[arg-type, dict-item]
) )
else: else:
results: QueryResult = collection.query(query_embeddings=query_vector, n_results=kwargs.get("top_k", 4)) # type: ignore results: QueryResult = collection.query(query_embeddings=query_vector, n_results=kwargs.get("top_k", 4)) # type: ignore[arg-type, no-redef]
score_threshold = float(kwargs.get("score_threshold") or 0.0) score_threshold = float(kwargs.get("score_threshold") or 0.0)
# Check if results contain data # Check if results contain data

View File

@ -10,11 +10,11 @@ import time
import uuid import uuid
from typing import TYPE_CHECKING, Any from typing import TYPE_CHECKING, Any
import clickzetta # type: ignore import clickzetta
from pydantic import BaseModel, model_validator from pydantic import BaseModel, model_validator
if TYPE_CHECKING: if TYPE_CHECKING:
from clickzetta.connector.v0.connection import Connection # type: ignore from clickzetta.connector.v0.connection import Connection
from configs import dify_config from configs import dify_config
from core.rag.datasource.vdb.field import Field from core.rag.datasource.vdb.field import Field

View File

@ -5,14 +5,14 @@ import uuid
from datetime import timedelta from datetime import timedelta
from typing import Any from typing import Any
from couchbase import search # type: ignore from couchbase import search
from couchbase.auth import PasswordAuthenticator # type: ignore from couchbase.auth import PasswordAuthenticator
from couchbase.cluster import Cluster # type: ignore from couchbase.cluster import Cluster
from couchbase.management.search import SearchIndex # type: ignore from couchbase.management.search import SearchIndex
# needed for options -- cluster, timeout, SQL++ (N1QL) query, etc. # needed for options -- cluster, timeout, SQL++ (N1QL) query, etc.
from couchbase.options import ClusterOptions, SearchOptions # type: ignore from couchbase.options import ClusterOptions, SearchOptions
from couchbase.vector_search import VectorQuery, VectorSearch # type: ignore from couchbase.vector_search import VectorQuery, VectorSearch
from flask import current_app from flask import current_app
from pydantic import BaseModel, model_validator from pydantic import BaseModel, model_validator

View File

@ -3,7 +3,7 @@ import logging
import time import time
from typing import Any from typing import Any
import holo_search_sdk as holo # type: ignore import holo_search_sdk as holo
from holo_search_sdk.types import BaseQuantizationType, DistanceType, TokenizerType from holo_search_sdk.types import BaseQuantizationType, DistanceType, TokenizerType
from psycopg import sql as psql from psycopg import sql as psql
from pydantic import BaseModel, model_validator from pydantic import BaseModel, model_validator

View File

@ -268,7 +268,7 @@ class LindormVectorStore(BaseVector):
try: try:
params = {"timeout": self._client_config.request_timeout} params = {"timeout": self._client_config.request_timeout}
if self._using_ugc: if self._using_ugc:
params["routing"] = self._routing # type: ignore params["routing"] = self._routing # type: ignore[arg-type, assignment]
response = self._client.search(index=self._collection_name, body=search_query, params=params) response = self._client.search(index=self._collection_name, body=search_query, params=params)
except Exception: except Exception:
logger.exception("Error executing vector search, query: %s", search_query) logger.exception("Error executing vector search, query: %s", search_query)

View File

@ -5,7 +5,7 @@ from collections.abc import Callable
from functools import wraps from functools import wraps
from typing import Any, Concatenate, ParamSpec, TypeVar from typing import Any, Concatenate, ParamSpec, TypeVar
from mo_vector.client import MoVectorClient # type: ignore from mo_vector.client import MoVectorClient
from pydantic import BaseModel, model_validator from pydantic import BaseModel, model_validator
from configs import dify_config from configs import dify_config

View File

@ -4,8 +4,8 @@ from typing import Any
from packaging import version from packaging import version
from pydantic import BaseModel, model_validator from pydantic import BaseModel, model_validator
from pymilvus import MilvusClient, MilvusException # type: ignore from pymilvus import MilvusClient, MilvusException
from pymilvus.milvus_client import IndexParams # type: ignore from pymilvus.milvus_client import IndexParams
from configs import dify_config from configs import dify_config
from core.rag.datasource.vdb.field import Field from core.rag.datasource.vdb.field import Field
@ -304,8 +304,14 @@ class MilvusVector(BaseVector):
return return
# Grab the existing collection if it exists # Grab the existing collection if it exists
if not self._client.has_collection(self._collection_name): if not self._client.has_collection(self._collection_name):
from pymilvus import CollectionSchema, DataType, FieldSchema, Function, FunctionType # type: ignore from pymilvus import (
from pymilvus.orm.types import infer_dtype_bydata # type: ignore CollectionSchema,
DataType,
FieldSchema,
Function,
FunctionType,
)
from pymilvus.orm.types import infer_dtype_bydata
# Determine embedding dim # Determine embedding dim
dim = len(embeddings[0]) dim = len(embeddings[0])

View File

@ -4,7 +4,13 @@ import re
from typing import Any, Literal from typing import Any, Literal
from pydantic import BaseModel, model_validator from pydantic import BaseModel, model_validator
from pyobvector import VECTOR, ObVecClient, cosine_distance, inner_product, l2_distance # type: ignore from pyobvector import (
VECTOR,
ObVecClient,
cosine_distance,
inner_product,
l2_distance,
)
from sqlalchemy import JSON, Column, String from sqlalchemy import JSON, Column, String
from sqlalchemy.dialects.mysql import LONGTEXT from sqlalchemy.dialects.mysql import LONGTEXT
from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.exc import SQLAlchemyError

View File

@ -5,7 +5,7 @@ import re
import uuid import uuid
from typing import Any from typing import Any
import jieba.posseg as pseg # type: ignore import jieba.posseg as pseg
import numpy import numpy
import oracledb import oracledb
from oracledb.connection import Connection from oracledb.connection import Connection
@ -271,8 +271,8 @@ class OracleVector(BaseVector):
def search_by_full_text(self, query: str, **kwargs: Any) -> list[Document]: def search_by_full_text(self, query: str, **kwargs: Any) -> list[Document]:
# lazy import # lazy import
import nltk # type: ignore import nltk
from nltk.corpus import stopwords # type: ignore from nltk.corpus import stopwords
# Validate and sanitize top_k to prevent SQL injection # Validate and sanitize top_k to prevent SQL injection
top_k = kwargs.get("top_k", 5) top_k = kwargs.get("top_k", 5)

View File

@ -4,7 +4,7 @@ from typing import Any
from uuid import UUID, uuid4 from uuid import UUID, uuid4
from numpy import ndarray from numpy import ndarray
from pgvecto_rs.sqlalchemy import VECTOR # type: ignore from pgvecto_rs.sqlalchemy import VECTOR
from pydantic import BaseModel, model_validator from pydantic import BaseModel, model_validator
from sqlalchemy import Float, create_engine, insert, select, text from sqlalchemy import Float, create_engine, insert, select, text
from sqlalchemy import text as sql_text from sqlalchemy import text as sql_text

View File

@ -108,7 +108,7 @@ class RelytVector(BaseVector):
redis_client.set(collection_exist_cache_key, 1, ex=3600) redis_client.set(collection_exist_cache_key, 1, ex=3600)
def add_texts(self, documents: list[Document], embeddings: list[list[float]], **kwargs): def add_texts(self, documents: list[Document], embeddings: list[list[float]], **kwargs):
from pgvecto_rs.sqlalchemy import VECTOR # type: ignore from pgvecto_rs.sqlalchemy import VECTOR
ids = [str(uuid.uuid1()) for _ in documents] ids = [str(uuid.uuid1()) for _ in documents]
metadatas = [d.metadata for d in documents if d.metadata is not None] metadatas = [d.metadata for d in documents if d.metadata is not None]

View File

@ -4,7 +4,7 @@ import math
from collections.abc import Iterable from collections.abc import Iterable
from typing import Any from typing import Any
import tablestore # type: ignore import tablestore
from pydantic import BaseModel, model_validator from pydantic import BaseModel, model_validator
from tablestore import BatchGetRowRequest, TableInBatchGetRowItem from tablestore import BatchGetRowRequest, TableInBatchGetRowItem

View File

@ -4,11 +4,16 @@ import math
from typing import Any from typing import Any
from pydantic import BaseModel from pydantic import BaseModel
from tcvdb_text.encoder import BM25Encoder # type: ignore from tcvdb_text.encoder import BM25Encoder
from tcvectordb import RPCVectorDBClient, VectorDBException # type: ignore from tcvectordb import RPCVectorDBClient, VectorDBException
from tcvectordb.model import document, enum # type: ignore from tcvectordb.model import document, enum
from tcvectordb.model import index as vdb_index # type: ignore from tcvectordb.model import index as vdb_index
from tcvectordb.model.document import AnnSearch, Filter, KeywordSearch, WeightedRerank # type: ignore from tcvectordb.model.document import (
AnnSearch,
Filter,
KeywordSearch,
WeightedRerank,
)
from configs import dify_config from configs import dify_config
from core.rag.datasource.vdb.vector_base import BaseVector from core.rag.datasource.vdb.vector_base import BaseVector

View File

@ -50,7 +50,7 @@ class TiDBVector(BaseVector):
return VectorType.TIDB_VECTOR return VectorType.TIDB_VECTOR
def _table(self, dim: int) -> Table: def _table(self, dim: int) -> Table:
from tidb_vector.sqlalchemy import VectorType # type: ignore from tidb_vector.sqlalchemy import VectorType
return Table( return Table(
self._collection_name, self._collection_name,

View File

@ -2,7 +2,7 @@ import json
from typing import Any from typing import Any
from pydantic import BaseModel from pydantic import BaseModel
from volcengine.viking_db import ( # type: ignore from volcengine.viking_db import (
Data, Data,
DistanceType, DistanceType,
Field, Field,
@ -126,7 +126,7 @@ class VikingDBVector(BaseVector):
# FIXME: fix the type of metadata later # FIXME: fix the type of metadata later
doc = Data( doc = Data(
{ {
vdb_Field.PRIMARY_KEY: metadatas[i]["doc_id"], # type: ignore vdb_Field.PRIMARY_KEY: metadatas[i]["doc_id"], # type: ignore[operator]
vdb_Field.VECTOR: embeddings[i] if embeddings else None, vdb_Field.VECTOR: embeddings[i] if embeddings else None,
vdb_Field.CONTENT_KEY: page_content, vdb_Field.CONTENT_KEY: page_content,
vdb_Field.METADATA_KEY: json.dumps(metadata), vdb_Field.METADATA_KEY: json.dumps(metadata),

View File

@ -71,7 +71,7 @@ class CacheEmbedding(Embeddings):
for vector in embedding_result.embeddings: for vector in embedding_result.embeddings:
try: try:
# FIXME: type ignore for numpy here # FIXME: type ignore for numpy here
normalized_embedding = (vector / np.linalg.norm(vector)).tolist() # type: ignore normalized_embedding = (vector / np.linalg.norm(vector)).tolist() # type: ignore[call-overload, operator]
# stackoverflow best way: https://stackoverflow.com/questions/20319813/how-to-check-list-containing-nan # stackoverflow best way: https://stackoverflow.com/questions/20319813/how-to-check-list-containing-nan
if np.isnan(normalized_embedding).any(): if np.isnan(normalized_embedding).any():
# for issue #11827 float values are not json compliant # for issue #11827 float values are not json compliant
@ -154,7 +154,7 @@ class CacheEmbedding(Embeddings):
for vector in embedding_result.embeddings: for vector in embedding_result.embeddings:
try: try:
# FIXME: type ignore for numpy here # FIXME: type ignore for numpy here
normalized_embedding = (vector / np.linalg.norm(vector)).tolist() # type: ignore normalized_embedding = (vector / np.linalg.norm(vector)).tolist() # type: ignore[call-overload, operator]
# stackoverflow best way: https://stackoverflow.com/questions/20319813/how-to-check-list-containing-nan # stackoverflow best way: https://stackoverflow.com/questions/20319813/how-to-check-list-containing-nan
if np.isnan(normalized_embedding).any(): if np.isnan(normalized_embedding).any():
# for issue #11827 float values are not json compliant # for issue #11827 float values are not json compliant
@ -207,7 +207,7 @@ class CacheEmbedding(Embeddings):
embedding_results = embedding_result.embeddings[0] embedding_results = embedding_result.embeddings[0]
# FIXME: type ignore for numpy here # FIXME: type ignore for numpy here
embedding_results = (embedding_results / np.linalg.norm(embedding_results)).tolist() # type: ignore embedding_results = (embedding_results / np.linalg.norm(embedding_results)).tolist() # type: ignore[call-overload, operator]
if np.isnan(embedding_results).any(): if np.isnan(embedding_results).any():
raise ValueError("Normalized embedding is nan please try again") raise ValueError("Normalized embedding is nan please try again")
except Exception as ex: except Exception as ex:
@ -231,7 +231,7 @@ class CacheEmbedding(Embeddings):
) )
raise ex raise ex
return embedding_results # type: ignore return embedding_results # type: ignore[return-value]
def embed_multimodal_query(self, multimodel_document: dict) -> list[float]: def embed_multimodal_query(self, multimodel_document: dict) -> list[float]:
"""Embed multimodal documents.""" """Embed multimodal documents."""
@ -250,7 +250,7 @@ class CacheEmbedding(Embeddings):
embedding_results = embedding_result.embeddings[0] embedding_results = embedding_result.embeddings[0]
# FIXME: type ignore for numpy here # FIXME: type ignore for numpy here
embedding_results = (embedding_results / np.linalg.norm(embedding_results)).tolist() # type: ignore embedding_results = (embedding_results / np.linalg.norm(embedding_results)).tolist() # type: ignore[call-overload, operator]
if np.isnan(embedding_results).any(): if np.isnan(embedding_results).any():
raise ValueError("Normalized embedding is nan please try again") raise ValueError("Normalized embedding is nan please try again")
except Exception as ex: except Exception as ex:
@ -274,4 +274,4 @@ class CacheEmbedding(Embeddings):
) )
raise ex raise ex
return embedding_results # type: ignore return embedding_results # type: ignore[return-value]

View File

@ -75,7 +75,7 @@ class ExtractProcessor:
suffix = "" suffix = ""
# https://stackoverflow.com/questions/26541416/generate-temporary-file-names-without-creating-actual-file-in-python#comment90414256_26541521 # https://stackoverflow.com/questions/26541416/generate-temporary-file-names-without-creating-actual-file-in-python#comment90414256_26541521
# Generate a temporary filename under the created temp_dir and ensure the directory exists # Generate a temporary filename under the created temp_dir and ensure the directory exists
file_path = f"{temp_dir}/{next(tempfile._get_candidate_names())}{suffix}" # type: ignore file_path = f"{temp_dir}/{next(tempfile._get_candidate_names())}{suffix}" # type: ignore[attr-defined, operator]
Path(file_path).write_bytes(response.content) Path(file_path).write_bytes(response.content)
extract_setting = ExtractSetting(datasource_type=DatasourceType.FILE, document_model="text_model") extract_setting = ExtractSetting(datasource_type=DatasourceType.FILE, document_model="text_model")
if return_text: if return_text:
@ -100,7 +100,7 @@ class ExtractProcessor:
upload_file: UploadFile = extract_setting.upload_file upload_file: UploadFile = extract_setting.upload_file
suffix = Path(upload_file.key).suffix suffix = Path(upload_file.key).suffix
# FIXME mypy: Cannot determine type of 'tempfile._get_candidate_names' better not use it here # FIXME mypy: Cannot determine type of 'tempfile._get_candidate_names' better not use it here
file_path = f"{temp_dir}/{next(tempfile._get_candidate_names())}{suffix}" # type: ignore file_path = f"{temp_dir}/{next(tempfile._get_candidate_names())}{suffix}" # type: ignore[attr-defined, operator]
storage.download(upload_file.key, file_path) storage.download(upload_file.key, file_path)
input_file = Path(file_path) input_file = Path(file_path)
file_extension = input_file.suffix.lower() file_extension = input_file.suffix.lower()

View File

@ -348,7 +348,7 @@ class NotionExtractor(BaseExtractor):
db.session.query(DocumentModel).filter_by(id=document_model.id).update( db.session.query(DocumentModel).filter_by(id=document_model.id).update(
{DocumentModel.data_source_info: json.dumps(data_source_info)} {DocumentModel.data_source_info: json.dumps(data_source_info)}
) # type: ignore ) # type: ignore[operator]
db.session.commit() db.session.commit()
def get_notion_last_edited_time(self) -> str: def get_notion_last_edited_time(self) -> str:

View File

@ -1,6 +1,6 @@
import logging import logging
import pypandoc # type: ignore import pypandoc
from configs import dify_config from configs import dify_config
from core.rag.extractor.extractor_base import BaseExtractor from core.rag.extractor.extractor_base import BaseExtractor

View File

@ -175,7 +175,7 @@ class IndexProcessor:
flask_app = None flask_app = None
try: try:
flask_app = current_app._get_current_object() # type: ignore flask_app = current_app._get_current_object() # type: ignore[attr-defined]
except RuntimeError: except RuntimeError:
logger.warning("No Flask application context available, summary generation may fail") logger.warning("No Flask application context available, summary generation may fail")

View File

@ -147,7 +147,7 @@ class BaseIndexProcessor(ABC):
embedding_model_instance=embedding_model_instance, embedding_model_instance=embedding_model_instance,
) )
return character_splitter # type: ignore return character_splitter # type: ignore[return-value]
def _get_content_files(self, document: Document, current_user: Account | None = None) -> list[AttachmentDocument]: def _get_content_files(self, document: Document, current_user: Account | None = None) -> list[AttachmentDocument]:
""" """

View File

@ -294,7 +294,7 @@ class ParagraphIndexProcessor(BaseIndexProcessor):
# Capture Flask app context for worker threads # Capture Flask app context for worker threads
flask_app = None flask_app = None
try: try:
flask_app = current_app._get_current_object() # type: ignore flask_app = current_app._get_current_object() # type: ignore[attr-defined]
except RuntimeError: except RuntimeError:
logger.warning("No Flask application context available, summary generation may fail") logger.warning("No Flask application context available, summary generation may fail")

View File

@ -379,7 +379,7 @@ class ParentChildIndexProcessor(BaseIndexProcessor):
# Capture Flask app context for worker threads # Capture Flask app context for worker threads
flask_app = None flask_app = None
try: try:
flask_app = current_app._get_current_object() # type: ignore flask_app = current_app._get_current_object() # type: ignore[attr-defined]
except RuntimeError: except RuntimeError:
logger.warning("No Flask application context available, summary generation may fail") logger.warning("No Flask application context available, summary generation may fail")

View File

@ -87,8 +87,8 @@ class QAIndexProcessor(BaseIndexProcessor):
all_documents.extend(split_documents) all_documents.extend(split_documents)
if preview: if preview:
self._format_qa_document( self._format_qa_document(
current_app._get_current_object(), # type: ignore current_app._get_current_object(), # type: ignore[attr-defined]
kwargs.get("tenant_id"), # type: ignore kwargs.get("tenant_id"), # type: ignore[arg-type]
all_documents[0], all_documents[0],
all_qa_documents, all_qa_documents,
kwargs.get("doc_language", "English"), kwargs.get("doc_language", "English"),
@ -101,8 +101,8 @@ class QAIndexProcessor(BaseIndexProcessor):
document_format_thread = threading.Thread( document_format_thread = threading.Thread(
target=self._format_qa_document, target=self._format_qa_document,
kwargs={ kwargs={
"flask_app": current_app._get_current_object(), # type: ignore "flask_app": current_app._get_current_object(), # type: ignore[attr-defined]
"tenant_id": kwargs.get("tenant_id"), # type: ignore "tenant_id": kwargs.get("tenant_id"), # type: ignore[arg-type]
"document_node": doc, "document_node": doc,
"all_qa_documents": all_qa_documents, "all_qa_documents": all_qa_documents,
"document_language": kwargs.get("doc_language", "English"), "document_language": kwargs.get("doc_language", "English"),
@ -121,7 +121,7 @@ class QAIndexProcessor(BaseIndexProcessor):
try: try:
# Skip the first row # Skip the first row
df = pd.read_csv(file) # type: ignore df = pd.read_csv(file) # type: ignore[misc]
text_docs = [] text_docs = []
for _, row in df.iterrows(): for _, row in df.iterrows():
data = Document(page_content=row.iloc[0], metadata={"answer": row.iloc[1]}) data = Document(page_content=row.iloc[0], metadata={"answer": row.iloc[1]})

View File

@ -417,8 +417,8 @@ class DatasetRetrieval:
query, query,
tenant_id, tenant_id,
user_id, user_id,
retrieve_config.metadata_filtering_mode, # type: ignore retrieve_config.metadata_filtering_mode, # type: ignore[arg-type]
retrieve_config.metadata_model_config, # type: ignore retrieve_config.metadata_model_config, # type: ignore[arg-type]
retrieve_config.metadata_filtering_conditions, retrieve_config.metadata_filtering_conditions,
inputs, inputs,
) )
@ -535,11 +535,11 @@ class DatasetRetrieval:
DatasetDocument.enabled == True, DatasetDocument.enabled == True,
DatasetDocument.archived == False, DatasetDocument.archived == False,
) )
documents = db.session.execute(dataset_document_stmt).scalars().all() # type: ignore documents = db.session.execute(dataset_document_stmt).scalars().all() # type: ignore[operator]
dataset_stmt = select(Dataset).where( dataset_stmt = select(Dataset).where(
Dataset.id.in_(dataset_ids), Dataset.id.in_(dataset_ids),
) )
datasets = db.session.execute(dataset_stmt).scalars().all() # type: ignore datasets = db.session.execute(dataset_stmt).scalars().all() # type: ignore[operator]
dataset_map = {i.id: i for i in datasets} dataset_map = {i.id: i for i in datasets}
document_map = {i.id: i for i in documents} document_map = {i.id: i for i in documents}
for record in records: for record in records:
@ -709,7 +709,7 @@ class DatasetRetrieval:
thread = threading.Thread( thread = threading.Thread(
target=self._on_retrieval_end, target=self._on_retrieval_end,
kwargs={ kwargs={
"flask_app": current_app._get_current_object(), # type: ignore "flask_app": current_app._get_current_object(), # type: ignore[attr-defined]
"documents": results, "documents": results,
"message_id": message_id, "message_id": message_id,
"timer": timer, "timer": timer,
@ -783,7 +783,7 @@ class DatasetRetrieval:
query_thread = threading.Thread( query_thread = threading.Thread(
target=self._multiple_retrieve_thread, target=self._multiple_retrieve_thread,
kwargs={ kwargs={
"flask_app": current_app._get_current_object(), # type: ignore "flask_app": current_app._get_current_object(), # type: ignore[attr-defined]
"available_datasets": available_datasets, "available_datasets": available_datasets,
"metadata_condition": metadata_condition, "metadata_condition": metadata_condition,
"metadata_filter_document_ids": metadata_filter_document_ids, "metadata_filter_document_ids": metadata_filter_document_ids,
@ -809,7 +809,7 @@ class DatasetRetrieval:
attachment_thread = threading.Thread( attachment_thread = threading.Thread(
target=self._multiple_retrieve_thread, target=self._multiple_retrieve_thread,
kwargs={ kwargs={
"flask_app": current_app._get_current_object(), # type: ignore "flask_app": current_app._get_current_object(), # type: ignore[attr-defined]
"available_datasets": available_datasets, "available_datasets": available_datasets,
"metadata_condition": metadata_condition, "metadata_condition": metadata_condition,
"metadata_filter_document_ids": metadata_filter_document_ids, "metadata_filter_document_ids": metadata_filter_document_ids,
@ -850,7 +850,7 @@ class DatasetRetrieval:
retrieval_end_thread = threading.Thread( retrieval_end_thread = threading.Thread(
target=self._on_retrieval_end, target=self._on_retrieval_end,
kwargs={ kwargs={
"flask_app": current_app._get_current_object(), # type: ignore "flask_app": current_app._get_current_object(), # type: ignore[attr-defined]
"documents": all_documents, "documents": all_documents,
"message_id": message_id, "message_id": message_id,
"timer": timer, "timer": timer,
@ -1313,7 +1313,7 @@ class DatasetRetrieval:
DatasetDocument.enabled == True, DatasetDocument.enabled == True,
DatasetDocument.archived == False, DatasetDocument.archived == False,
) )
filters = [] # type: ignore filters = [] # type: ignore[var-annotated]
metadata_condition = None metadata_condition = None
if metadata_filtering_mode == "disabled": if metadata_filtering_mode == "disabled":
return None, None return None, None
@ -1326,28 +1326,28 @@ class DatasetRetrieval:
for sequence, filter in enumerate(automatic_metadata_filters): for sequence, filter in enumerate(automatic_metadata_filters):
self.process_metadata_filter_func( self.process_metadata_filter_func(
sequence, sequence,
filter.get("condition"), # type: ignore filter.get("condition"), # type: ignore[arg-type]
filter.get("metadata_name"), # type: ignore filter.get("metadata_name"), # type: ignore[arg-type]
filter.get("value"), filter.get("value"),
filters, # type: ignore filters, # type: ignore[arg-type]
) )
conditions.append( conditions.append(
Condition( Condition(
name=filter.get("metadata_name"), # type: ignore name=filter.get("metadata_name"), # type: ignore[arg-type]
comparison_operator=filter.get("condition"), # type: ignore comparison_operator=filter.get("condition"), # type: ignore[arg-type]
value=filter.get("value"), value=filter.get("value"),
) )
) )
metadata_condition = MetadataCondition( metadata_condition = MetadataCondition(
logical_operator=metadata_filtering_conditions.logical_operator logical_operator=metadata_filtering_conditions.logical_operator
if metadata_filtering_conditions if metadata_filtering_conditions
else "or", # type: ignore else "or", # type: ignore[assignment]
conditions=conditions, conditions=conditions,
) )
elif metadata_filtering_mode == "manual": elif metadata_filtering_mode == "manual":
if metadata_filtering_conditions: if metadata_filtering_conditions:
conditions = [] conditions = []
for sequence, condition in enumerate(metadata_filtering_conditions.conditions): # type: ignore for sequence, condition in enumerate(metadata_filtering_conditions.conditions): # type: ignore[arg-type]
metadata_name = condition.name metadata_name = condition.name
expected_value = condition.value expected_value = condition.value
if expected_value is not None and condition.comparison_operator not in ("empty", "not empty"): if expected_value is not None and condition.comparison_operator not in ("empty", "not empty"):
@ -1374,15 +1374,15 @@ class DatasetRetrieval:
else: else:
raise ValueError("Invalid metadata filtering mode") raise ValueError("Invalid metadata filtering mode")
if filters: if filters:
if metadata_filtering_conditions and metadata_filtering_conditions.logical_operator == "and": # type: ignore if metadata_filtering_conditions and metadata_filtering_conditions.logical_operator == "and": # type: ignore[assignment]
document_query = document_query.where(and_(*filters)) document_query = document_query.where(and_(*filters))
else: else:
document_query = document_query.where(or_(*filters)) document_query = document_query.where(or_(*filters))
documents = document_query.all() documents = document_query.all()
# group by dataset_id # group by dataset_id
metadata_filter_document_ids = defaultdict(list) if documents else None # type: ignore metadata_filter_document_ids = defaultdict(list) if documents else None # type: ignore[var-annotated]
for document in documents: for document in documents:
metadata_filter_document_ids[document.dataset_id].append(document.id) # type: ignore metadata_filter_document_ids[document.dataset_id].append(document.id) # type: ignore[index]
return metadata_filter_document_ids, metadata_condition return metadata_filter_document_ids, metadata_condition
def _replace_metadata_filter_value(self, text: str, inputs: dict) -> str: def _replace_metadata_filter_value(self, text: str, inputs: dict) -> str:

View File

@ -108,7 +108,7 @@ class CeleryWorkflowExecutionRepository(WorkflowExecutionRepository):
execution_data = execution.model_dump() execution_data = execution.model_dump()
# Queue the save operation as a Celery task (fire and forget) # Queue the save operation as a Celery task (fire and forget)
save_workflow_execution_task.delay( # type: ignore save_workflow_execution_task.delay( # type: ignore[operator]
execution_data=execution_data, execution_data=execution_data,
tenant_id=self._tenant_id, tenant_id=self._tenant_id,
app_id=self._app_id or "", app_id=self._app_id or "",

View File

@ -162,7 +162,7 @@ class BuiltinToolProviderController(ToolProviderController):
""" """
return self._get_builtin_tools() return self._get_builtin_tools()
def get_tool(self, tool_name: str) -> BuiltinTool | None: # type: ignore def get_tool(self, tool_name: str) -> BuiltinTool | None: # type: ignore[override, return-value]
""" """
returns the tool that the provider can provide returns the tool that the provider can provide
""" """

View File

@ -23,12 +23,12 @@ class ASRTool(BuiltinTool):
message_id: str | None = None, message_id: str | None = None,
) -> Generator[ToolInvokeMessage, None, None]: ) -> Generator[ToolInvokeMessage, None, None]:
file = tool_parameters.get("audio_file") file = tool_parameters.get("audio_file")
if file.type != FileType.AUDIO: # type: ignore if file.type != FileType.AUDIO: # type: ignore[attr-defined, union-attr]
yield self.create_text_message("not a valid audio file") yield self.create_text_message("not a valid audio file")
return return
audio_binary = io.BytesIO(download(file)) # type: ignore audio_binary = io.BytesIO(download(file)) # type: ignore[arg-type]
audio_binary.name = "temp.mp3" audio_binary.name = "temp.mp3"
provider, model = tool_parameters.get("model").split("#") # type: ignore provider, model = tool_parameters.get("model").split("#") # type: ignore[operator, union-attr]
model_manager = ModelManager() model_manager = ModelManager()
model_instance = model_manager.get_model_instance( model_instance = model_manager.get_model_instance(
tenant_id=self.runtime.tenant_id, tenant_id=self.runtime.tenant_id,

View File

@ -20,7 +20,7 @@ class TTSTool(BuiltinTool):
app_id: str | None = None, app_id: str | None = None,
message_id: str | None = None, message_id: str | None = None,
) -> Generator[ToolInvokeMessage, None, None]: ) -> Generator[ToolInvokeMessage, None, None]:
provider, model = tool_parameters.get("model").split("#") # type: ignore provider, model = tool_parameters.get("model").split("#") # type: ignore[operator, union-attr]
voice = tool_parameters.get(f"voice#{provider}#{model}") voice = tool_parameters.get(f"voice#{provider}#{model}")
model_manager = ModelManager() model_manager = ModelManager()
if not self.runtime: if not self.runtime:
@ -40,7 +40,7 @@ class TTSTool(BuiltinTool):
else: else:
raise ValueError("Sorry, no voice available.") raise ValueError("Sorry, no voice available.")
tts = model_instance.invoke_tts( tts = model_instance.invoke_tts(
content_text=tool_parameters.get("text"), # type: ignore content_text=tool_parameters.get("text"), # type: ignore[arg-type]
user=user_id, user=user_id,
tenant_id=self.runtime.tenant_id, tenant_id=self.runtime.tenant_id,
voice=voice, voice=voice,

View File

@ -27,7 +27,7 @@ class LocaltimeToTimestampTool(BuiltinTool):
timezone = None timezone = None
time_format = "%Y-%m-%d %H:%M:%S" time_format = "%Y-%m-%d %H:%M:%S"
timestamp = self.localtime_to_timestamp(localtime, time_format, timezone) # type: ignore timestamp = self.localtime_to_timestamp(localtime, time_format, timezone) # type: ignore[arg-type, misc]
if not timestamp: if not timestamp:
yield self.create_text_message(f"Invalid localtime: {localtime}") yield self.create_text_message(f"Invalid localtime: {localtime}")
return return
@ -40,11 +40,11 @@ class LocaltimeToTimestampTool(BuiltinTool):
try: try:
local_time = datetime.strptime(localtime, time_format) local_time = datetime.strptime(localtime, time_format)
if local_tz is None: if local_tz is None:
localtime = local_time.astimezone() # type: ignore localtime = local_time.astimezone() # type: ignore[assignment, operator]
elif isinstance(local_tz, str): elif isinstance(local_tz, str):
local_tz = pytz.timezone(local_tz) local_tz = pytz.timezone(local_tz)
localtime = local_tz.localize(local_time) # type: ignore localtime = local_tz.localize(local_time) # type: ignore[operator]
timestamp = int(localtime.timestamp()) # type: ignore timestamp = int(localtime.timestamp()) # type: ignore[attr-defined, operator]
return timestamp return timestamp
except Exception as e: except Exception as e:
raise ToolInvokeError(str(e)) raise ToolInvokeError(str(e))

View File

@ -24,7 +24,7 @@ class TimezoneConversionTool(BuiltinTool):
current_time = tool_parameters.get("current_time") current_time = tool_parameters.get("current_time")
current_timezone = tool_parameters.get("current_timezone", "Asia/Shanghai") current_timezone = tool_parameters.get("current_timezone", "Asia/Shanghai")
target_timezone = tool_parameters.get("target_timezone", "Asia/Tokyo") target_timezone = tool_parameters.get("target_timezone", "Asia/Tokyo")
target_time = self.timezone_convert(current_time, current_timezone, target_timezone) # type: ignore target_time = self.timezone_convert(current_time, current_timezone, target_timezone) # type: ignore[arg-type, misc]
if not target_time: if not target_time:
yield self.create_text_message( yield self.create_text_message(
f"Invalid datetime and timezone: {current_time},{current_timezone},{target_timezone}" f"Invalid datetime and timezone: {current_time},{current_timezone},{target_timezone}"

Some files were not shown because too many files have changed in this diff Show More