mirror of https://github.com/langgenius/dify.git
Merge bab530209e into 075b8bf1ae
This commit is contained in:
commit
20cf5c5179
|
|
@ -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`).
|
||||
- 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
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import psycogreen.gevent as pscycogreen_gevent # type: ignore
|
||||
from grpc.experimental import gevent as grpc_gevent # type: ignore
|
||||
import psycogreen.gevent as pscycogreen_gevent # type: ignore[reportMissingTypeStubs]
|
||||
from grpc.experimental import gevent as grpc_gevent # type: ignore[reportMissingTypeStubs]
|
||||
|
||||
# grpc gevent
|
||||
grpc_gevent.init_gevent()
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
from .app_config import DifyConfig
|
||||
|
||||
dify_config = DifyConfig() # type: ignore
|
||||
dify_config = DifyConfig() # type: ignore[call-arg, assignment]
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ def capture_flask_context(user: Any = None) -> IExecutionContext:
|
|||
RuntimeError: If called outside Flask context
|
||||
"""
|
||||
# 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
|
||||
saved_user = user
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ class Site(BaseModel):
|
|||
show_workflow_steps: 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
|
||||
def icon_url(self) -> str | None:
|
||||
if self.icon and self.icon_type == IconType.IMAGE:
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ class AppApiKeyListResource(BaseApiKeyListResource):
|
|||
@console_ns.doc(description="Get all API keys for an app")
|
||||
@console_ns.doc(params={"resource_id": "App ID"})
|
||||
@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"""
|
||||
return super().get(resource_id)
|
||||
|
||||
|
|
@ -157,7 +157,7 @@ class AppApiKeyListResource(BaseApiKeyListResource):
|
|||
@console_ns.doc(params={"resource_id": "App ID"})
|
||||
@console_ns.response(201, "API key created successfully", api_key_item_model)
|
||||
@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"""
|
||||
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(params={"resource_id": "Dataset ID"})
|
||||
@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"""
|
||||
return super().get(resource_id)
|
||||
|
||||
|
|
@ -197,7 +197,7 @@ class DatasetApiKeyListResource(BaseApiKeyListResource):
|
|||
@console_ns.doc(params={"resource_id": "Dataset ID"})
|
||||
@console_ns.response(201, "API key created successfully", api_key_item_model)
|
||||
@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"""
|
||||
return super().post(resource_id)
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,6 @@ class AdvancedPromptTemplateList(Resource):
|
|||
@login_required
|
||||
@account_initialization_required
|
||||
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())
|
||||
|
|
|
|||
|
|
@ -44,6 +44,6 @@ class AgentLogApi(Resource):
|
|||
@get_app_model(mode=[AppMode.AGENT_CHAT])
|
||||
def get(self, app_model):
|
||||
"""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)
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ class AnnotationApi(Resource):
|
|||
@account_initialization_required
|
||||
@edit_permission_required
|
||||
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
|
||||
limit = args.limit
|
||||
keyword = args.keyword
|
||||
|
|
|
|||
|
|
@ -299,7 +299,7 @@ class Site(ResponseModel):
|
|||
updated_by: str | 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
|
||||
def icon_url(self) -> str | None:
|
||||
return _build_icon_url(self.icon_type, self.icon)
|
||||
|
|
@ -349,7 +349,7 @@ class AppPartial(ResponseModel):
|
|||
author_name: str | 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
|
||||
def icon_url(self) -> str | None:
|
||||
return _build_icon_url(self.icon_type, self.icon)
|
||||
|
|
@ -397,7 +397,7 @@ class AppDetailWithSite(AppDetail):
|
|||
deleted_tools: list[DeletedTool] = Field(default_factory=list)
|
||||
site: Site | None = None
|
||||
|
||||
@computed_field(return_type=str | None) # type: ignore
|
||||
@computed_field(return_type=str | None) # type: ignore[prop-decorator]
|
||||
@property
|
||||
def icon_url(self) -> str | None:
|
||||
return _build_icon_url(self.icon_type, self.icon)
|
||||
|
|
@ -473,7 +473,7 @@ class AppListApi(Resource):
|
|||
"""Get app list"""
|
||||
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()
|
||||
|
||||
# get app list
|
||||
|
|
@ -692,7 +692,7 @@ class AppExportApi(Resource):
|
|||
@edit_permission_required
|
||||
def get(self, app_model):
|
||||
"""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(
|
||||
data=AppDslService.export_dsl(
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ class TextModesApi(Resource):
|
|||
@account_initialization_required
|
||||
def get(self, app_model):
|
||||
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(
|
||||
tenant_id=app_model.tenant_id,
|
||||
|
|
|
|||
|
|
@ -342,7 +342,7 @@ class CompletionConversationApi(Resource):
|
|||
@edit_permission_required
|
||||
def get(self, app_model):
|
||||
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(
|
||||
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":
|
||||
query = (
|
||||
query.options(selectinload(Conversation.message_annotations)) # type: ignore[arg-type]
|
||||
.join( # type: ignore
|
||||
.join( # type: ignore[arg-type]
|
||||
MessageAnnotation, MessageAnnotation.conversation_id == Conversation.id
|
||||
)
|
||||
.distinct()
|
||||
|
|
@ -455,7 +455,7 @@ class ChatConversationApi(Resource):
|
|||
@edit_permission_required
|
||||
def get(self, app_model):
|
||||
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 = (
|
||||
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":
|
||||
query = (
|
||||
query.options(selectinload(Conversation.message_annotations)) # type: ignore[arg-type]
|
||||
.join( # type: ignore
|
||||
.join( # type: ignore[arg-type]
|
||||
MessageAnnotation, MessageAnnotation.conversation_id == Conversation.id
|
||||
)
|
||||
.distinct()
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ class ConversationVariablesApi(Resource):
|
|||
@get_app_model(mode=AppMode.ADVANCED_CHAT)
|
||||
@marshal_with(paginated_conversation_variable_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 = (
|
||||
select(ConversationVariable)
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ class TraceAppConfigApi(Resource):
|
|||
@login_required
|
||||
@account_initialization_required
|
||||
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:
|
||||
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
|
||||
def delete(self, app_id):
|
||||
"""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:
|
||||
result = OpsService.delete_tracing_app_config(app_id=app_id, tracing_provider=args.tracing_provider)
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ class DailyMessageStatistic(Resource):
|
|||
def get(self, app_model):
|
||||
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")
|
||||
sql_query = f"""SELECT
|
||||
|
|
@ -111,7 +111,7 @@ class DailyConversationStatistic(Resource):
|
|||
def get(self, app_model):
|
||||
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")
|
||||
sql_query = f"""SELECT
|
||||
|
|
@ -167,7 +167,7 @@ class DailyTerminalsStatistic(Resource):
|
|||
def get(self, app_model):
|
||||
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")
|
||||
sql_query = f"""SELECT
|
||||
|
|
@ -224,7 +224,7 @@ class DailyTokenCostStatistic(Resource):
|
|||
def get(self, app_model):
|
||||
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")
|
||||
sql_query = f"""SELECT
|
||||
|
|
@ -284,7 +284,7 @@ class AverageSessionInteractionStatistic(Resource):
|
|||
def get(self, app_model):
|
||||
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")
|
||||
sql_query = f"""SELECT
|
||||
|
|
@ -360,7 +360,7 @@ class UserSatisfactionRateStatistic(Resource):
|
|||
def get(self, app_model):
|
||||
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")
|
||||
sql_query = f"""SELECT
|
||||
|
|
@ -426,7 +426,7 @@ class AverageResponseTimeStatistic(Resource):
|
|||
def get(self, app_model):
|
||||
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")
|
||||
sql_query = f"""SELECT
|
||||
|
|
@ -482,7 +482,7 @@ class TokensPerSecondStatistic(Resource):
|
|||
@account_initialization_required
|
||||
def get(self, app_model):
|
||||
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")
|
||||
sql_query = f"""SELECT
|
||||
|
|
|
|||
|
|
@ -900,7 +900,7 @@ class DefaultBlockConfigApi(Resource):
|
|||
"""
|
||||
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
|
||||
if args.q:
|
||||
|
|
@ -968,7 +968,7 @@ class PublishedAllWorkflowApi(Resource):
|
|||
"""
|
||||
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
|
||||
limit = args.limit
|
||||
user_id = args.user_id
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class WorkflowAppLogQuery(BaseModel):
|
|||
def parse_datetime(cls, value: str | None) -> datetime | None:
|
||||
if value in (None, ""):
|
||||
return None
|
||||
return isoparse(value) # type: ignore
|
||||
return isoparse(value) # type: ignore[arg-type]
|
||||
|
||||
@field_validator("detail", mode="before")
|
||||
@classmethod
|
||||
|
|
@ -83,7 +83,7 @@ class WorkflowAppLogApi(Resource):
|
|||
"""
|
||||
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
|
||||
workflow_app_service = WorkflowAppService()
|
||||
|
|
@ -121,7 +121,7 @@ class WorkflowArchivedLogApi(Resource):
|
|||
"""
|
||||
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()
|
||||
with Session(db.engine) as session:
|
||||
|
|
|
|||
|
|
@ -233,7 +233,7 @@ class WorkflowVariableCollectionApi(Resource):
|
|||
"""
|
||||
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
|
||||
workflow_service = WorkflowService()
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ class AdvancedChatAppWorkflowRunListApi(Resource):
|
|||
"""
|
||||
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)
|
||||
|
||||
# Default to DEBUGGING if not specified
|
||||
|
|
@ -293,7 +293,7 @@ class AdvancedChatAppWorkflowRunCountApi(Resource):
|
|||
"""
|
||||
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)
|
||||
|
||||
# Default to DEBUGGING if not specified
|
||||
|
|
@ -337,7 +337,7 @@ class WorkflowRunListApi(Resource):
|
|||
"""
|
||||
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)
|
||||
|
||||
# Default to DEBUGGING for workflow if not specified (backward compatibility)
|
||||
|
|
@ -385,7 +385,7 @@ class WorkflowRunCountApi(Resource):
|
|||
"""
|
||||
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)
|
||||
|
||||
# Default to DEBUGGING for workflow if not specified (backward compatibility)
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ class WorkflowDailyRunsStatistic(Resource):
|
|||
def get(self, app_model):
|
||||
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
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ class WorkflowDailyTerminalsStatistic(Resource):
|
|||
def get(self, app_model):
|
||||
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
|
||||
|
||||
|
|
@ -133,7 +133,7 @@ class WorkflowDailyTokenCostStatistic(Resource):
|
|||
def get(self, app_model):
|
||||
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
|
||||
|
||||
|
|
@ -173,7 +173,7 @@ class WorkflowAverageAppInteractionStatistic(Resource):
|
|||
def get(self, app_model):
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ class WebhookTriggerApi(Resource):
|
|||
@marshal_with(webhook_trigger_model)
|
||||
def get(self, app_model: App):
|
||||
"""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
|
||||
|
||||
|
|
@ -114,9 +114,9 @@ class AppTriggersApi(Resource):
|
|||
url_prefix = dify_config.CONSOLE_API_URL + "/console/api/workspaces/current/tool-provider/builtin/"
|
||||
for trigger in triggers:
|
||||
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:
|
||||
trigger.icon = "" # type: ignore
|
||||
trigger.icon = "" # type: ignore[attr-defined]
|
||||
|
||||
return {"data": triggers}
|
||||
|
||||
|
|
@ -159,8 +159,8 @@ class AppTriggerEnableApi(Resource):
|
|||
# Add computed icon field
|
||||
url_prefix = dify_config.CONSOLE_API_URL + "/console/api/workspaces/current/tool-provider/builtin/"
|
||||
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:
|
||||
trigger.icon = "" # type: ignore
|
||||
trigger.icon = "" # type: ignore[attr-defined]
|
||||
|
||||
return trigger
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ class ActivateCheckApi(Resource):
|
|||
),
|
||||
)
|
||||
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
|
||||
token = args.token
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class Subscription(Resource):
|
|||
@only_edition_cloud
|
||||
def get(self):
|
||||
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)
|
||||
return BillingService.get_subscription(args.plan, args.interval, current_user.email, current_tenant_id)
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class ComplianceApi(Resource):
|
|||
@only_edition_cloud
|
||||
def get(self):
|
||||
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)
|
||||
device_info = request.headers.get("User-Agent", "Unknown device")
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from flask_restx import ( # type: ignore
|
||||
Resource, # type: ignore
|
||||
from flask_restx import (
|
||||
Resource,
|
||||
)
|
||||
from pydantic import BaseModel
|
||||
from werkzeug.exceptions import Forbidden
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
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 sqlalchemy.orm import Session
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import logging
|
|||
from typing import Any, Literal, cast
|
||||
|
||||
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 sqlalchemy.orm import Session
|
||||
from werkzeug.exceptions import BadRequest, Forbidden, InternalServerError, NotFound
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ class RecommendedAppListApi(Resource):
|
|||
@marshal_with(recommended_app_list_model)
|
||||
def get(self):
|
||||
# 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
|
||||
if language and language in languages:
|
||||
language_prefix = language
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class CodeBasedExtensionAPI(Resource):
|
|||
@login_required
|
||||
@account_initialization_required
|
||||
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)}
|
||||
|
||||
|
|
|
|||
|
|
@ -519,7 +519,7 @@ class EducationAutoCompleteApi(Resource):
|
|||
@cloud_edition_billing_enabled
|
||||
@marshal_with(data_fields)
|
||||
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)
|
||||
|
||||
return BillingService.EducationIdentity.autocomplete(args.keywords, args.page, args.limit)
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ class EndpointListApi(Resource):
|
|||
def get(self):
|
||||
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_size = args.page_size
|
||||
|
|
@ -171,7 +171,7 @@ class EndpointListForSinglePluginApi(Resource):
|
|||
def get(self):
|
||||
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_size = args.page_size
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ class ModelProviderListApi(Resource):
|
|||
_, current_tenant_id = current_account_with_tenant()
|
||||
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)
|
||||
|
||||
model_provider_service = ModelProviderService()
|
||||
|
|
@ -118,7 +118,7 @@ class ModelProviderCredentialApi(Resource):
|
|||
_, current_tenant_id = current_account_with_tenant()
|
||||
tenant_id = current_tenant_id
|
||||
# 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)
|
||||
|
||||
model_provider_service = ModelProviderService()
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ class DefaultModelApi(Resource):
|
|||
def get(self):
|
||||
_, 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()
|
||||
default_model_entity = model_provider_service.get_default_model_of_model_type(
|
||||
|
|
@ -261,7 +261,7 @@ class ModelProviderModelCredentialApi(Resource):
|
|||
def get(self, provider: str):
|
||||
_, 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()
|
||||
current_credential = model_provider_service.get_model_credential(
|
||||
|
|
@ -513,7 +513,7 @@ class ModelProviderModelParameterRuleApi(Resource):
|
|||
@login_required
|
||||
@account_initialization_required
|
||||
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()
|
||||
|
||||
model_provider_service = ModelProviderService()
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ class PluginListApi(Resource):
|
|||
@account_initialization_required
|
||||
def get(self):
|
||||
_, 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:
|
||||
plugins_with_total = PluginService.list_with_total(tenant_id, args.page, args.page_size)
|
||||
except PluginDaemonClientSideError as e:
|
||||
|
|
@ -261,7 +261,7 @@ class PluginIconApi(Resource):
|
|||
@console_ns.expect(console_ns.models[ParserIcon.__name__])
|
||||
@setup_required
|
||||
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:
|
||||
icon_bytes, mimetype = PluginService.get_asset(args.tenant_id, args.filename)
|
||||
|
|
@ -279,7 +279,7 @@ class PluginAssetApi(Resource):
|
|||
@login_required
|
||||
@account_initialization_required
|
||||
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()
|
||||
try:
|
||||
|
|
@ -421,7 +421,7 @@ class PluginFetchMarketplacePkgApi(Resource):
|
|||
@plugin_permission_required(install_required=True)
|
||||
def get(self):
|
||||
_, 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:
|
||||
return jsonable_encoder(
|
||||
|
|
@ -446,7 +446,7 @@ class PluginFetchManifestApi(Resource):
|
|||
def get(self):
|
||||
_, 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:
|
||||
return jsonable_encoder(
|
||||
|
|
@ -466,7 +466,7 @@ class PluginFetchInstallTasksApi(Resource):
|
|||
def get(self):
|
||||
_, 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:
|
||||
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()
|
||||
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:
|
||||
options = PluginParameterService.get_dynamic_select_options(
|
||||
|
|
@ -822,7 +822,7 @@ class PluginReadmeApi(Resource):
|
|||
@account_initialization_required
|
||||
def get(self):
|
||||
_, 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(
|
||||
{"readme": PluginService.fetch_plugin_readme(tenant_id, args.plugin_unique_identifier, args.language)}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -267,7 +267,7 @@ class ToolProviderListApi(Resource):
|
|||
raw_args = request.args.to_dict()
|
||||
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")
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ class WorkspaceListApi(Resource):
|
|||
@setup_required
|
||||
@admin_required
|
||||
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)
|
||||
|
||||
stmt = select(Tenant).order_by(Tenant.created_at.desc())
|
||||
|
|
|
|||
|
|
@ -313,7 +313,7 @@ def edit_permission_required(f: Callable[P, R]):
|
|||
from libs.login import current_user
|
||||
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):
|
||||
raise Forbidden()
|
||||
if not current_user.has_edit_permission:
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class ImagePreviewApi(Resource):
|
|||
def get(self, 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
|
||||
nonce = args.nonce
|
||||
sign = args.sign
|
||||
|
|
@ -100,7 +100,7 @@ class FilePreviewApi(Resource):
|
|||
def get(self, 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:
|
||||
generator, upload_file = FileService(db.engine).get_file_generator_by_file_id(
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ class PluginUploadFileApi(Resource):
|
|||
FileTooLargeError: File exceeds size limit
|
||||
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")
|
||||
if file is None:
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class BaseMail(Resource):
|
|||
to=args.to,
|
||||
subject=args.subject,
|
||||
body=args.body,
|
||||
substitutions=args.substitutions, # type: ignore
|
||||
substitutions=args.substitutions, # type: ignore[arg-type]
|
||||
)
|
||||
return {"message": "success"}, 200
|
||||
|
||||
|
|
|
|||
|
|
@ -89,8 +89,8 @@ def get_user_tenant(view_func: Callable[P, R]):
|
|||
user = get_user(tenant_id, user_id)
|
||||
kwargs["user_model"] = user
|
||||
|
||||
current_app.login_manager._update_request_context_with_user(user) # type: ignore
|
||||
user_logged_in.send(current_app._get_current_object(), user=current_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[attr-defined]
|
||||
|
||||
return view_func(*args, **kwargs)
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class FileApi(Resource):
|
|||
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__])
|
||||
def post(self, app_model: App, end_user: EndUser):
|
||||
"""Upload a file for use in conversations.
|
||||
|
|
|
|||
|
|
@ -101,8 +101,8 @@ def validate_app_token(
|
|||
kwargs["end_user"] = end_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
|
||||
user_logged_in.send(current_app._get_current_object(), 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[attr-defined]
|
||||
else:
|
||||
# For service API without end-user context, ensure an Account is logged in
|
||||
# so services relying on current_account_with_tenant() work correctly.
|
||||
|
|
@ -121,8 +121,8 @@ def validate_app_token(
|
|||
if tenant_owner_info:
|
||||
tenant_model, account = tenant_owner_info
|
||||
account.current_tenant = tenant_model
|
||||
current_app.login_manager._update_request_context_with_user(account) # type: ignore
|
||||
user_logged_in.send(current_app._get_current_object(), user=current_user) # 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[attr-defined]
|
||||
else:
|
||||
raise Unauthorized("Tenant owner account not found or tenant is not active.")
|
||||
|
||||
|
|
@ -303,8 +303,8 @@ def validate_dataset_token(
|
|||
# Login admin
|
||||
if account:
|
||||
account.current_tenant = tenant
|
||||
current_app.login_manager._update_request_context_with_user(account) # type: ignore
|
||||
user_logged_in.send(current_app._get_current_object(), user=current_user) # 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[attr-defined]
|
||||
else:
|
||||
raise Unauthorized("Tenant owner account does not exist.")
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ class AdvancedChatAppGenerator(MessageBasedAppGenerator):
|
|||
|
||||
if invoke_from == InvokeFrom.DEBUGGER:
|
||||
# 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
|
||||
application_generate_entity = AdvancedChatAppGenerateEntity(
|
||||
|
|
@ -504,7 +504,7 @@ class AdvancedChatAppGenerator(MessageBasedAppGenerator):
|
|||
worker_thread = threading.Thread(
|
||||
target=self._generate_worker,
|
||||
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,
|
||||
"queue_manager": queue_manager,
|
||||
"conversation_id": conversation.id,
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ class AgentChatAppGenerator(MessageBasedAppGenerator):
|
|||
worker_thread = threading.Thread(
|
||||
target=self._generate_worker,
|
||||
kwargs={
|
||||
"flask_app": current_app._get_current_object(), # type: ignore
|
||||
"flask_app": current_app._get_current_object(), # type: ignore[attr-defined]
|
||||
"context": context,
|
||||
"application_generate_entity": application_generate_entity,
|
||||
"queue_manager": queue_manager,
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ class ChatAppGenerator(MessageBasedAppGenerator):
|
|||
@copy_current_request_context
|
||||
def worker_with_context():
|
||||
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,
|
||||
queue_manager=queue_manager,
|
||||
conversation_id=conversation.id,
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ class CompletionAppGenerator(MessageBasedAppGenerator):
|
|||
@copy_current_request_context
|
||||
def worker_with_context():
|
||||
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,
|
||||
queue_manager=queue_manager,
|
||||
message_id=message.id,
|
||||
|
|
@ -327,7 +327,7 @@ class CompletionAppGenerator(MessageBasedAppGenerator):
|
|||
@copy_current_request_context
|
||||
def worker_with_context():
|
||||
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,
|
||||
queue_manager=queue_manager,
|
||||
message_id=message.id,
|
||||
|
|
|
|||
|
|
@ -217,7 +217,7 @@ class PipelineGenerator(BaseAppGenerator):
|
|||
)
|
||||
if invoke_from == InvokeFrom.DEBUGGER or is_retry:
|
||||
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(),
|
||||
pipeline=pipeline,
|
||||
workflow_id=workflow.id,
|
||||
|
|
@ -315,7 +315,7 @@ class PipelineGenerator(BaseAppGenerator):
|
|||
worker_thread = threading.Thread(
|
||||
target=self._generate_worker,
|
||||
kwargs={
|
||||
"flask_app": current_app._get_current_object(), # type: ignore
|
||||
"flask_app": current_app._get_current_object(), # type: ignore[attr-defined]
|
||||
"context": context,
|
||||
"queue_manager": queue_manager,
|
||||
"application_generate_entity": application_generate_entity,
|
||||
|
|
@ -428,7 +428,7 @@ class PipelineGenerator(BaseAppGenerator):
|
|||
)
|
||||
|
||||
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,
|
||||
workflow_id=workflow.id,
|
||||
user=user,
|
||||
|
|
@ -524,7 +524,7 @@ class PipelineGenerator(BaseAppGenerator):
|
|||
)
|
||||
|
||||
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,
|
||||
workflow_id=workflow.id,
|
||||
user=user,
|
||||
|
|
|
|||
|
|
@ -320,7 +320,7 @@ class WorkflowAppGenerator(BaseAppGenerator):
|
|||
worker_thread = threading.Thread(
|
||||
target=self._generate_worker,
|
||||
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,
|
||||
"queue_manager": queue_manager,
|
||||
"context": context,
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ class EasyUIBasedAppGenerateEntity(AppGenerateEntity):
|
|||
"""
|
||||
|
||||
# app config
|
||||
app_config: EasyUIBasedAppConfig = None # type: ignore
|
||||
app_config: EasyUIBasedAppConfig = None # type: ignore[assignment]
|
||||
model_conf: ModelConfigWithCredentialsEntity
|
||||
|
||||
query: str = ""
|
||||
|
|
@ -202,7 +202,7 @@ class AdvancedChatAppGenerateEntity(ConversationAppGenerateEntity):
|
|||
"""
|
||||
|
||||
# app config
|
||||
app_config: WorkflowUIBasedAppConfig = None # type: ignore
|
||||
app_config: WorkflowUIBasedAppConfig = None # type: ignore[assignment]
|
||||
|
||||
workflow_run_id: str | None = None
|
||||
query: str
|
||||
|
|
@ -234,7 +234,7 @@ class WorkflowAppGenerateEntity(AppGenerateEntity):
|
|||
"""
|
||||
|
||||
# app config
|
||||
app_config: WorkflowUIBasedAppConfig = None # type: ignore
|
||||
app_config: WorkflowUIBasedAppConfig = None # type: ignore[assignment]
|
||||
workflow_execution_id: str
|
||||
|
||||
class SingleIterationRunEntity(BaseModel):
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import logging
|
|||
import uuid
|
||||
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.layers.base import GraphEngineLayer
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ class MessageCycleManager:
|
|||
1,
|
||||
self._generate_conversation_name_worker,
|
||||
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,
|
||||
"query": query,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class LocalFileDatasourcePluginProviderController(DatasourcePluginProviderContro
|
|||
"""
|
||||
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
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class OnlineDocumentDatasourcePluginProviderController(DatasourcePluginProviderC
|
|||
"""
|
||||
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
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class OnlineDriveDatasourcePluginProviderController(DatasourcePluginProviderCont
|
|||
"""
|
||||
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
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class WebsiteCrawlDatasourcePluginProviderController(DatasourcePluginProviderCon
|
|||
"""
|
||||
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
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class ExternalDataFetch:
|
|||
for tool in external_data_tools:
|
||||
future: Future[tuple[str | None, str | None]] = executor.submit(
|
||||
self._query_external_data_tool,
|
||||
current_app._get_current_object(), # type: ignore
|
||||
current_app._get_current_object(), # type: ignore[attr-defined]
|
||||
tenant_id,
|
||||
app_id,
|
||||
tool,
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class ExternalDataToolFactory:
|
|||
"""
|
||||
extension_class = code_based_extension.extension_class(ExtensionModule.EXTERNAL_DATA_TOOL, name)
|
||||
# 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:
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -592,7 +592,7 @@ class IndexingRunner:
|
|||
# create keyword index
|
||||
create_keyword_thread = threading.Thread(
|
||||
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()
|
||||
|
||||
|
|
@ -615,7 +615,7 @@ class IndexingRunner:
|
|||
futures.append(
|
||||
executor.submit(
|
||||
self._process_chunk,
|
||||
current_app._get_current_object(), # type: ignore
|
||||
current_app._get_current_object(), # type: ignore[attr-defined]
|
||||
index_processor,
|
||||
chunk_documents,
|
||||
dataset,
|
||||
|
|
@ -742,7 +742,7 @@ class IndexingRunner:
|
|||
|
||||
if 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()
|
||||
|
||||
@staticmethod
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class ModerationFactory:
|
|||
"""
|
||||
extension_class = code_based_extension.extension_class(ExtensionModule.MODERATION, name)
|
||||
# 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:
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class OutputModeration(BaseModel):
|
|||
thread = threading.Thread(
|
||||
target=self.worker,
|
||||
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,
|
||||
},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -936,7 +936,7 @@ class TraceQueueManager:
|
|||
self.app_id = app_id
|
||||
self.user_id = user_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:
|
||||
self.start_timer()
|
||||
|
||||
|
|
@ -995,4 +995,4 @@ class TraceQueueManager:
|
|||
"file_id": file_id,
|
||||
"app_id": task.app_id,
|
||||
}
|
||||
process_trace_tasks.delay(file_info) # type: ignore
|
||||
process_trace_tasks.delay(file_info) # type: ignore[operator]
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ class BasePluginClient:
|
|||
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):
|
||||
yield type_(**json.loads(line)) # type: ignore
|
||||
yield type_(**json.loads(line)) # type: ignore[misc, operator]
|
||||
|
||||
def _request_with_model(
|
||||
self,
|
||||
|
|
@ -246,7 +246,7 @@ class BasePluginClient:
|
|||
if transformer:
|
||||
json_response = transformer(json_response)
|
||||
# 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:
|
||||
msg = (
|
||||
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):
|
||||
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):
|
||||
# TODO modify this when line_data has code and message
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ def merge_blob_chunks(
|
|||
meta=resp.meta,
|
||||
)
|
||||
assert isinstance(merged_message, (ToolInvokeMessage, AgentInvokeMessage))
|
||||
yield merged_message # type: ignore
|
||||
yield merged_message # type: ignore[misc]
|
||||
# Clean up the buffer
|
||||
del files[chunk_id]
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -629,7 +629,7 @@ class ProviderManager:
|
|||
provider_name=ModelProviderID(provider_name).provider_name,
|
||||
provider_type=ProviderType.SYSTEM,
|
||||
quota_type=quota.quota_type,
|
||||
quota_limit=0, # type: ignore
|
||||
quota_limit=0, # type: ignore[assignment]
|
||||
quota_used=0,
|
||||
is_valid=True,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class JiebaKeywordTableHandler:
|
|||
│ & cache to default │ │ _SimpleTFIDF │
|
||||
└────────────────────────┘ └─────────────────┘
|
||||
"""
|
||||
import jieba.analyse # type: ignore
|
||||
import jieba.analyse
|
||||
|
||||
tfidf = getattr(jieba.analyse, "default_tfidf", None)
|
||||
if tfidf is not None:
|
||||
|
|
@ -53,7 +53,7 @@ class JiebaKeywordTableHandler:
|
|||
tfidf_class = getattr(jieba.analyse, "TFIDF", None)
|
||||
if tfidf_class is None:
|
||||
try:
|
||||
from jieba.analyse.tfidf import TFIDF # type: ignore
|
||||
from jieba.analyse.tfidf import TFIDF
|
||||
|
||||
tfidf_class = TFIDF
|
||||
except Exception:
|
||||
|
|
@ -69,7 +69,7 @@ class JiebaKeywordTableHandler:
|
|||
@staticmethod
|
||||
def _build_fallback_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
|
||||
|
||||
|
|
|
|||
|
|
@ -115,14 +115,14 @@ class RetrievalService:
|
|||
exceptions: list[str] = []
|
||||
|
||||
# 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 = []
|
||||
retrieval_service = RetrievalService()
|
||||
if query:
|
||||
futures.append(
|
||||
executor.submit(
|
||||
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,
|
||||
dataset=dataset,
|
||||
query=query,
|
||||
|
|
@ -142,7 +142,7 @@ class RetrievalService:
|
|||
futures.append(
|
||||
executor.submit(
|
||||
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,
|
||||
dataset=dataset,
|
||||
query=None,
|
||||
|
|
@ -541,7 +541,7 @@ class RetrievalService:
|
|||
DocumentSegment.status == "completed",
|
||||
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:
|
||||
doc_segment_map[index_node_segment.id] = [index_node_segment.index_node_id]
|
||||
|
||||
|
|
@ -551,7 +551,7 @@ class RetrievalService:
|
|||
DocumentSegment.status == "completed",
|
||||
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:
|
||||
segments.extend(index_node_segments)
|
||||
|
|
@ -564,7 +564,7 @@ class RetrievalService:
|
|||
DocumentSegment.status == "completed",
|
||||
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)
|
||||
# Add summary segment IDs to segment_ids for summary query
|
||||
for seg in summary_segments:
|
||||
|
|
@ -747,13 +747,13 @@ class RetrievalService:
|
|||
with flask_app.app_context():
|
||||
all_documents_item: list[Document] = []
|
||||
# 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 = []
|
||||
if retrieval_method == RetrievalMethod.KEYWORD_SEARCH and query:
|
||||
futures.append(
|
||||
executor.submit(
|
||||
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,
|
||||
query=query,
|
||||
top_k=top_k,
|
||||
|
|
@ -767,7 +767,7 @@ class RetrievalService:
|
|||
futures.append(
|
||||
executor.submit(
|
||||
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,
|
||||
query=query,
|
||||
top_k=top_k,
|
||||
|
|
@ -784,7 +784,7 @@ class RetrievalService:
|
|||
futures.append(
|
||||
executor.submit(
|
||||
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,
|
||||
query=attachment_id,
|
||||
top_k=top_k,
|
||||
|
|
@ -801,7 +801,7 @@ class RetrievalService:
|
|||
futures.append(
|
||||
executor.submit(
|
||||
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,
|
||||
query=query,
|
||||
top_k=top_k,
|
||||
|
|
|
|||
|
|
@ -55,8 +55,8 @@ class AnalyticdbVectorOpenAPIConfig(BaseModel):
|
|||
class AnalyticdbVectorOpenAPI:
|
||||
def __init__(self, collection_name: str, config: AnalyticdbVectorOpenAPIConfig):
|
||||
try:
|
||||
from alibabacloud_gpdb20160503.client import Client # type: ignore
|
||||
from alibabacloud_tea_openapi import models as open_api_models # type: ignore
|
||||
from alibabacloud_gpdb20160503.client import Client
|
||||
from alibabacloud_tea_openapi import models as open_api_models
|
||||
except:
|
||||
raise ImportError(_import_err_msg)
|
||||
self._collection_name = collection_name.lower()
|
||||
|
|
@ -77,7 +77,7 @@ class AnalyticdbVectorOpenAPI:
|
|||
redis_client.set(database_exist_cache_key, 1, ex=3600)
|
||||
|
||||
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(
|
||||
dbinstance_id=self.config.instance_id,
|
||||
|
|
@ -89,7 +89,7 @@ class AnalyticdbVectorOpenAPI:
|
|||
|
||||
def _create_namespace_if_not_exists(self):
|
||||
from alibabacloud_gpdb20160503 import models as gpdb_20160503_models
|
||||
from Tea.exceptions import TeaException # type: ignore
|
||||
from Tea.exceptions import TeaException
|
||||
|
||||
try:
|
||||
request = gpdb_20160503_models.DescribeNamespaceRequest(
|
||||
|
|
|
|||
|
|
@ -6,12 +6,19 @@ from typing import Any
|
|||
|
||||
import numpy as np
|
||||
from pydantic import BaseModel, model_validator
|
||||
from pymochow import MochowClient # type: ignore
|
||||
from pymochow.auth.bce_credentials import BceCredentials # type: ignore
|
||||
from pymochow.configuration import Configuration # type: ignore
|
||||
from pymochow.exception import ServerError # type: ignore
|
||||
from pymochow import MochowClient
|
||||
from pymochow.auth.bce_credentials import BceCredentials
|
||||
from pymochow.configuration import Configuration
|
||||
from pymochow.exception import ServerError
|
||||
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 (
|
||||
AutoBuildRowCountIncrement,
|
||||
Field,
|
||||
|
|
@ -24,8 +31,14 @@ from pymochow.model.schema import (
|
|||
InvertedIndexParseMode,
|
||||
Schema,
|
||||
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 core.rag.datasource.vdb.field import Field as VDBField
|
||||
|
|
|
|||
|
|
@ -72,13 +72,13 @@ class ChromaVector(BaseVector):
|
|||
|
||||
collection = self._client.get_or_create_collection(self._collection_name)
|
||||
# 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
|
||||
|
||||
def delete_by_metadata_field(self, key: str, value: str):
|
||||
collection = self._client.get_or_create_collection(self._collection_name)
|
||||
# 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):
|
||||
self._client.delete_collection(self._collection_name)
|
||||
|
|
@ -101,10 +101,10 @@ class ChromaVector(BaseVector):
|
|||
results: QueryResult = collection.query(
|
||||
query_embeddings=query_vector,
|
||||
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:
|
||||
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)
|
||||
|
||||
# Check if results contain data
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ import time
|
|||
import uuid
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
import clickzetta # type: ignore
|
||||
import clickzetta
|
||||
from pydantic import BaseModel, model_validator
|
||||
|
||||
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 core.rag.datasource.vdb.field import Field
|
||||
|
|
|
|||
|
|
@ -5,14 +5,14 @@ import uuid
|
|||
from datetime import timedelta
|
||||
from typing import Any
|
||||
|
||||
from couchbase import search # type: ignore
|
||||
from couchbase.auth import PasswordAuthenticator # type: ignore
|
||||
from couchbase.cluster import Cluster # type: ignore
|
||||
from couchbase.management.search import SearchIndex # type: ignore
|
||||
from couchbase import search
|
||||
from couchbase.auth import PasswordAuthenticator
|
||||
from couchbase.cluster import Cluster
|
||||
from couchbase.management.search import SearchIndex
|
||||
|
||||
# needed for options -- cluster, timeout, SQL++ (N1QL) query, etc.
|
||||
from couchbase.options import ClusterOptions, SearchOptions # type: ignore
|
||||
from couchbase.vector_search import VectorQuery, VectorSearch # type: ignore
|
||||
from couchbase.options import ClusterOptions, SearchOptions
|
||||
from couchbase.vector_search import VectorQuery, VectorSearch
|
||||
from flask import current_app
|
||||
from pydantic import BaseModel, model_validator
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import logging
|
|||
import time
|
||||
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 psycopg import sql as psql
|
||||
from pydantic import BaseModel, model_validator
|
||||
|
|
|
|||
|
|
@ -268,7 +268,7 @@ class LindormVectorStore(BaseVector):
|
|||
try:
|
||||
params = {"timeout": self._client_config.request_timeout}
|
||||
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)
|
||||
except Exception:
|
||||
logger.exception("Error executing vector search, query: %s", search_query)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from collections.abc import Callable
|
|||
from functools import wraps
|
||||
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 configs import dify_config
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ from typing import Any
|
|||
|
||||
from packaging import version
|
||||
from pydantic import BaseModel, model_validator
|
||||
from pymilvus import MilvusClient, MilvusException # type: ignore
|
||||
from pymilvus.milvus_client import IndexParams # type: ignore
|
||||
from pymilvus import MilvusClient, MilvusException
|
||||
from pymilvus.milvus_client import IndexParams
|
||||
|
||||
from configs import dify_config
|
||||
from core.rag.datasource.vdb.field import Field
|
||||
|
|
@ -304,8 +304,14 @@ class MilvusVector(BaseVector):
|
|||
return
|
||||
# Grab the existing collection if it exists
|
||||
if not self._client.has_collection(self._collection_name):
|
||||
from pymilvus import CollectionSchema, DataType, FieldSchema, Function, FunctionType # type: ignore
|
||||
from pymilvus.orm.types import infer_dtype_bydata # type: ignore
|
||||
from pymilvus import (
|
||||
CollectionSchema,
|
||||
DataType,
|
||||
FieldSchema,
|
||||
Function,
|
||||
FunctionType,
|
||||
)
|
||||
from pymilvus.orm.types import infer_dtype_bydata
|
||||
|
||||
# Determine embedding dim
|
||||
dim = len(embeddings[0])
|
||||
|
|
|
|||
|
|
@ -4,7 +4,13 @@ import re
|
|||
from typing import Any, Literal
|
||||
|
||||
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.dialects.mysql import LONGTEXT
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import re
|
|||
import uuid
|
||||
from typing import Any
|
||||
|
||||
import jieba.posseg as pseg # type: ignore
|
||||
import jieba.posseg as pseg
|
||||
import numpy
|
||||
import oracledb
|
||||
from oracledb.connection import Connection
|
||||
|
|
@ -271,8 +271,8 @@ class OracleVector(BaseVector):
|
|||
|
||||
def search_by_full_text(self, query: str, **kwargs: Any) -> list[Document]:
|
||||
# lazy import
|
||||
import nltk # type: ignore
|
||||
from nltk.corpus import stopwords # type: ignore
|
||||
import nltk
|
||||
from nltk.corpus import stopwords
|
||||
|
||||
# Validate and sanitize top_k to prevent SQL injection
|
||||
top_k = kwargs.get("top_k", 5)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from typing import Any
|
|||
from uuid import UUID, uuid4
|
||||
|
||||
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 sqlalchemy import Float, create_engine, insert, select, text
|
||||
from sqlalchemy import text as sql_text
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ class RelytVector(BaseVector):
|
|||
redis_client.set(collection_exist_cache_key, 1, ex=3600)
|
||||
|
||||
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]
|
||||
metadatas = [d.metadata for d in documents if d.metadata is not None]
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import math
|
|||
from collections.abc import Iterable
|
||||
from typing import Any
|
||||
|
||||
import tablestore # type: ignore
|
||||
import tablestore
|
||||
from pydantic import BaseModel, model_validator
|
||||
from tablestore import BatchGetRowRequest, TableInBatchGetRowItem
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,16 @@ import math
|
|||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel
|
||||
from tcvdb_text.encoder import BM25Encoder # type: ignore
|
||||
from tcvectordb import RPCVectorDBClient, VectorDBException # type: ignore
|
||||
from tcvectordb.model import document, enum # type: ignore
|
||||
from tcvectordb.model import index as vdb_index # type: ignore
|
||||
from tcvectordb.model.document import AnnSearch, Filter, KeywordSearch, WeightedRerank # type: ignore
|
||||
from tcvdb_text.encoder import BM25Encoder
|
||||
from tcvectordb import RPCVectorDBClient, VectorDBException
|
||||
from tcvectordb.model import document, enum
|
||||
from tcvectordb.model import index as vdb_index
|
||||
from tcvectordb.model.document import (
|
||||
AnnSearch,
|
||||
Filter,
|
||||
KeywordSearch,
|
||||
WeightedRerank,
|
||||
)
|
||||
|
||||
from configs import dify_config
|
||||
from core.rag.datasource.vdb.vector_base import BaseVector
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ class TiDBVector(BaseVector):
|
|||
return VectorType.TIDB_VECTOR
|
||||
|
||||
def _table(self, dim: int) -> Table:
|
||||
from tidb_vector.sqlalchemy import VectorType # type: ignore
|
||||
from tidb_vector.sqlalchemy import VectorType
|
||||
|
||||
return Table(
|
||||
self._collection_name,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import json
|
|||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel
|
||||
from volcengine.viking_db import ( # type: ignore
|
||||
from volcengine.viking_db import (
|
||||
Data,
|
||||
DistanceType,
|
||||
Field,
|
||||
|
|
@ -126,7 +126,7 @@ class VikingDBVector(BaseVector):
|
|||
# FIXME: fix the type of metadata later
|
||||
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.CONTENT_KEY: page_content,
|
||||
vdb_Field.METADATA_KEY: json.dumps(metadata),
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ class CacheEmbedding(Embeddings):
|
|||
for vector in embedding_result.embeddings:
|
||||
try:
|
||||
# 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
|
||||
if np.isnan(normalized_embedding).any():
|
||||
# for issue #11827 float values are not json compliant
|
||||
|
|
@ -154,7 +154,7 @@ class CacheEmbedding(Embeddings):
|
|||
for vector in embedding_result.embeddings:
|
||||
try:
|
||||
# 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
|
||||
if np.isnan(normalized_embedding).any():
|
||||
# for issue #11827 float values are not json compliant
|
||||
|
|
@ -207,7 +207,7 @@ class CacheEmbedding(Embeddings):
|
|||
|
||||
embedding_results = embedding_result.embeddings[0]
|
||||
# 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():
|
||||
raise ValueError("Normalized embedding is nan please try again")
|
||||
except Exception as ex:
|
||||
|
|
@ -231,7 +231,7 @@ class CacheEmbedding(Embeddings):
|
|||
)
|
||||
raise ex
|
||||
|
||||
return embedding_results # type: ignore
|
||||
return embedding_results # type: ignore[return-value]
|
||||
|
||||
def embed_multimodal_query(self, multimodel_document: dict) -> list[float]:
|
||||
"""Embed multimodal documents."""
|
||||
|
|
@ -250,7 +250,7 @@ class CacheEmbedding(Embeddings):
|
|||
|
||||
embedding_results = embedding_result.embeddings[0]
|
||||
# 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():
|
||||
raise ValueError("Normalized embedding is nan please try again")
|
||||
except Exception as ex:
|
||||
|
|
@ -274,4 +274,4 @@ class CacheEmbedding(Embeddings):
|
|||
)
|
||||
raise ex
|
||||
|
||||
return embedding_results # type: ignore
|
||||
return embedding_results # type: ignore[return-value]
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class ExtractProcessor:
|
|||
suffix = ""
|
||||
# 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
|
||||
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)
|
||||
extract_setting = ExtractSetting(datasource_type=DatasourceType.FILE, document_model="text_model")
|
||||
if return_text:
|
||||
|
|
@ -100,7 +100,7 @@ class ExtractProcessor:
|
|||
upload_file: UploadFile = extract_setting.upload_file
|
||||
suffix = Path(upload_file.key).suffix
|
||||
# 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)
|
||||
input_file = Path(file_path)
|
||||
file_extension = input_file.suffix.lower()
|
||||
|
|
|
|||
|
|
@ -348,7 +348,7 @@ class NotionExtractor(BaseExtractor):
|
|||
|
||||
db.session.query(DocumentModel).filter_by(id=document_model.id).update(
|
||||
{DocumentModel.data_source_info: json.dumps(data_source_info)}
|
||||
) # type: ignore
|
||||
) # type: ignore[operator]
|
||||
db.session.commit()
|
||||
|
||||
def get_notion_last_edited_time(self) -> str:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import logging
|
||||
|
||||
import pypandoc # type: ignore
|
||||
import pypandoc
|
||||
|
||||
from configs import dify_config
|
||||
from core.rag.extractor.extractor_base import BaseExtractor
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ class IndexProcessor:
|
|||
|
||||
flask_app = None
|
||||
try:
|
||||
flask_app = current_app._get_current_object() # type: ignore
|
||||
flask_app = current_app._get_current_object() # type: ignore[attr-defined]
|
||||
except RuntimeError:
|
||||
logger.warning("No Flask application context available, summary generation may fail")
|
||||
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ class BaseIndexProcessor(ABC):
|
|||
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]:
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -294,7 +294,7 @@ class ParagraphIndexProcessor(BaseIndexProcessor):
|
|||
# Capture Flask app context for worker threads
|
||||
flask_app = None
|
||||
try:
|
||||
flask_app = current_app._get_current_object() # type: ignore
|
||||
flask_app = current_app._get_current_object() # type: ignore[attr-defined]
|
||||
except RuntimeError:
|
||||
logger.warning("No Flask application context available, summary generation may fail")
|
||||
|
||||
|
|
|
|||
|
|
@ -379,7 +379,7 @@ class ParentChildIndexProcessor(BaseIndexProcessor):
|
|||
# Capture Flask app context for worker threads
|
||||
flask_app = None
|
||||
try:
|
||||
flask_app = current_app._get_current_object() # type: ignore
|
||||
flask_app = current_app._get_current_object() # type: ignore[attr-defined]
|
||||
except RuntimeError:
|
||||
logger.warning("No Flask application context available, summary generation may fail")
|
||||
|
||||
|
|
|
|||
|
|
@ -87,8 +87,8 @@ class QAIndexProcessor(BaseIndexProcessor):
|
|||
all_documents.extend(split_documents)
|
||||
if preview:
|
||||
self._format_qa_document(
|
||||
current_app._get_current_object(), # type: ignore
|
||||
kwargs.get("tenant_id"), # type: ignore
|
||||
current_app._get_current_object(), # type: ignore[attr-defined]
|
||||
kwargs.get("tenant_id"), # type: ignore[arg-type]
|
||||
all_documents[0],
|
||||
all_qa_documents,
|
||||
kwargs.get("doc_language", "English"),
|
||||
|
|
@ -101,8 +101,8 @@ class QAIndexProcessor(BaseIndexProcessor):
|
|||
document_format_thread = threading.Thread(
|
||||
target=self._format_qa_document,
|
||||
kwargs={
|
||||
"flask_app": current_app._get_current_object(), # type: ignore
|
||||
"tenant_id": kwargs.get("tenant_id"), # type: ignore
|
||||
"flask_app": current_app._get_current_object(), # type: ignore[attr-defined]
|
||||
"tenant_id": kwargs.get("tenant_id"), # type: ignore[arg-type]
|
||||
"document_node": doc,
|
||||
"all_qa_documents": all_qa_documents,
|
||||
"document_language": kwargs.get("doc_language", "English"),
|
||||
|
|
@ -121,7 +121,7 @@ class QAIndexProcessor(BaseIndexProcessor):
|
|||
|
||||
try:
|
||||
# Skip the first row
|
||||
df = pd.read_csv(file) # type: ignore
|
||||
df = pd.read_csv(file) # type: ignore[misc]
|
||||
text_docs = []
|
||||
for _, row in df.iterrows():
|
||||
data = Document(page_content=row.iloc[0], metadata={"answer": row.iloc[1]})
|
||||
|
|
|
|||
|
|
@ -417,8 +417,8 @@ class DatasetRetrieval:
|
|||
query,
|
||||
tenant_id,
|
||||
user_id,
|
||||
retrieve_config.metadata_filtering_mode, # type: ignore
|
||||
retrieve_config.metadata_model_config, # type: ignore
|
||||
retrieve_config.metadata_filtering_mode, # type: ignore[arg-type]
|
||||
retrieve_config.metadata_model_config, # type: ignore[arg-type]
|
||||
retrieve_config.metadata_filtering_conditions,
|
||||
inputs,
|
||||
)
|
||||
|
|
@ -535,11 +535,11 @@ class DatasetRetrieval:
|
|||
DatasetDocument.enabled == True,
|
||||
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.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}
|
||||
document_map = {i.id: i for i in documents}
|
||||
for record in records:
|
||||
|
|
@ -709,7 +709,7 @@ class DatasetRetrieval:
|
|||
thread = threading.Thread(
|
||||
target=self._on_retrieval_end,
|
||||
kwargs={
|
||||
"flask_app": current_app._get_current_object(), # type: ignore
|
||||
"flask_app": current_app._get_current_object(), # type: ignore[attr-defined]
|
||||
"documents": results,
|
||||
"message_id": message_id,
|
||||
"timer": timer,
|
||||
|
|
@ -783,7 +783,7 @@ class DatasetRetrieval:
|
|||
query_thread = threading.Thread(
|
||||
target=self._multiple_retrieve_thread,
|
||||
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,
|
||||
"metadata_condition": metadata_condition,
|
||||
"metadata_filter_document_ids": metadata_filter_document_ids,
|
||||
|
|
@ -809,7 +809,7 @@ class DatasetRetrieval:
|
|||
attachment_thread = threading.Thread(
|
||||
target=self._multiple_retrieve_thread,
|
||||
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,
|
||||
"metadata_condition": metadata_condition,
|
||||
"metadata_filter_document_ids": metadata_filter_document_ids,
|
||||
|
|
@ -850,7 +850,7 @@ class DatasetRetrieval:
|
|||
retrieval_end_thread = threading.Thread(
|
||||
target=self._on_retrieval_end,
|
||||
kwargs={
|
||||
"flask_app": current_app._get_current_object(), # type: ignore
|
||||
"flask_app": current_app._get_current_object(), # type: ignore[attr-defined]
|
||||
"documents": all_documents,
|
||||
"message_id": message_id,
|
||||
"timer": timer,
|
||||
|
|
@ -1313,7 +1313,7 @@ class DatasetRetrieval:
|
|||
DatasetDocument.enabled == True,
|
||||
DatasetDocument.archived == False,
|
||||
)
|
||||
filters = [] # type: ignore
|
||||
filters = [] # type: ignore[var-annotated]
|
||||
metadata_condition = None
|
||||
if metadata_filtering_mode == "disabled":
|
||||
return None, None
|
||||
|
|
@ -1326,28 +1326,28 @@ class DatasetRetrieval:
|
|||
for sequence, filter in enumerate(automatic_metadata_filters):
|
||||
self.process_metadata_filter_func(
|
||||
sequence,
|
||||
filter.get("condition"), # type: ignore
|
||||
filter.get("metadata_name"), # type: ignore
|
||||
filter.get("condition"), # type: ignore[arg-type]
|
||||
filter.get("metadata_name"), # type: ignore[arg-type]
|
||||
filter.get("value"),
|
||||
filters, # type: ignore
|
||||
filters, # type: ignore[arg-type]
|
||||
)
|
||||
conditions.append(
|
||||
Condition(
|
||||
name=filter.get("metadata_name"), # type: ignore
|
||||
comparison_operator=filter.get("condition"), # type: ignore
|
||||
name=filter.get("metadata_name"), # type: ignore[arg-type]
|
||||
comparison_operator=filter.get("condition"), # type: ignore[arg-type]
|
||||
value=filter.get("value"),
|
||||
)
|
||||
)
|
||||
metadata_condition = MetadataCondition(
|
||||
logical_operator=metadata_filtering_conditions.logical_operator
|
||||
if metadata_filtering_conditions
|
||||
else "or", # type: ignore
|
||||
else "or", # type: ignore[assignment]
|
||||
conditions=conditions,
|
||||
)
|
||||
elif metadata_filtering_mode == "manual":
|
||||
if metadata_filtering_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
|
||||
expected_value = condition.value
|
||||
if expected_value is not None and condition.comparison_operator not in ("empty", "not empty"):
|
||||
|
|
@ -1374,15 +1374,15 @@ class DatasetRetrieval:
|
|||
else:
|
||||
raise ValueError("Invalid metadata filtering mode")
|
||||
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))
|
||||
else:
|
||||
document_query = document_query.where(or_(*filters))
|
||||
documents = document_query.all()
|
||||
# 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:
|
||||
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
|
||||
|
||||
def _replace_metadata_filter_value(self, text: str, inputs: dict) -> str:
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ class CeleryWorkflowExecutionRepository(WorkflowExecutionRepository):
|
|||
execution_data = execution.model_dump()
|
||||
|
||||
# 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,
|
||||
tenant_id=self._tenant_id,
|
||||
app_id=self._app_id or "",
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ class BuiltinToolProviderController(ToolProviderController):
|
|||
"""
|
||||
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
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -23,12 +23,12 @@ class ASRTool(BuiltinTool):
|
|||
message_id: str | None = None,
|
||||
) -> Generator[ToolInvokeMessage, None, None]:
|
||||
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")
|
||||
return
|
||||
audio_binary = io.BytesIO(download(file)) # type: ignore
|
||||
audio_binary = io.BytesIO(download(file)) # type: ignore[arg-type]
|
||||
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_instance = model_manager.get_model_instance(
|
||||
tenant_id=self.runtime.tenant_id,
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class TTSTool(BuiltinTool):
|
|||
app_id: str | None = None,
|
||||
message_id: str | 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}")
|
||||
model_manager = ModelManager()
|
||||
if not self.runtime:
|
||||
|
|
@ -40,7 +40,7 @@ class TTSTool(BuiltinTool):
|
|||
else:
|
||||
raise ValueError("Sorry, no voice available.")
|
||||
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,
|
||||
tenant_id=self.runtime.tenant_id,
|
||||
voice=voice,
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class LocaltimeToTimestampTool(BuiltinTool):
|
|||
timezone = None
|
||||
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:
|
||||
yield self.create_text_message(f"Invalid localtime: {localtime}")
|
||||
return
|
||||
|
|
@ -40,11 +40,11 @@ class LocaltimeToTimestampTool(BuiltinTool):
|
|||
try:
|
||||
local_time = datetime.strptime(localtime, time_format)
|
||||
if local_tz is None:
|
||||
localtime = local_time.astimezone() # type: ignore
|
||||
localtime = local_time.astimezone() # type: ignore[assignment, operator]
|
||||
elif isinstance(local_tz, str):
|
||||
local_tz = pytz.timezone(local_tz)
|
||||
localtime = local_tz.localize(local_time) # type: ignore
|
||||
timestamp = int(localtime.timestamp()) # type: ignore
|
||||
localtime = local_tz.localize(local_time) # type: ignore[operator]
|
||||
timestamp = int(localtime.timestamp()) # type: ignore[attr-defined, operator]
|
||||
return timestamp
|
||||
except Exception as e:
|
||||
raise ToolInvokeError(str(e))
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class TimezoneConversionTool(BuiltinTool):
|
|||
current_time = tool_parameters.get("current_time")
|
||||
current_timezone = tool_parameters.get("current_timezone", "Asia/Shanghai")
|
||||
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:
|
||||
yield self.create_text_message(
|
||||
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
Loading…
Reference in New Issue