Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

ci: enable Ruff UP032 (#44092)

Asuka Minato56f1dc2cb840
diff --git a/api/.ruff.toml b/api/.ruff.toml
index da5a1b70a08..f3353ee1cfd 100644
--- a/api/.ruff.toml
+++ b/api/.ruff.toml
@@ -64,7 +64,6 @@ ignore = [
"F841", # unused-variable
"FURB113", # repeated-append
"UP007", # non-pep604-annotation
- "UP032", # f-string
"B007", # unused-loop-control-variable
"B026", # star-arg-unpacking-after-keyword-arg
"B901", # allow return in yield
diff --git a/api/core/external_data_tool/api/api.py b/api/core/external_data_tool/api/api.py
index 30fcbc230f0..2cffd4c1350 100644
--- a/api/core/external_data_tool/api/api.py
+++ b/api/core/external_data_tool/api/api.py
@@ -73,9 +73,8 @@ class ApiExternalDataTool(ExternalDataTool):
if not api_based_extension:
raise ValueError(
- "[External data tool] API query failed, variable: {}, error: api_based_extension_id is invalid".format(
- self.variable
- )
+ f"[External data tool] API query failed, variable: {self.variable}, "
+ "error: api_based_extension_id is invalid"
)
# decrypt api_key
@@ -94,9 +93,7 @@ class ApiExternalDataTool(ExternalDataTool):
if "result" not in response_json:
raise ValueError(
- "[External data tool] API query failed, variable: {}, error: result not found in response".format(
- self.variable
- )
+ f"[External data tool] API query failed, variable: {self.variable}, error: result not found in response"
)
if not isinstance(response_json["result"], str):
diff --git a/api/core/model_manager.py b/api/core/model_manager.py
index 418d56fb3b9..20f681ff6ad 100644
--- a/api/core/model_manager.py
+++ b/api/core/model_manager.py
@@ -1039,9 +1039,7 @@ class LBModelManager:
Strategy: Round Robin
:return:
"""
- cache_key = "model_lb_index:{}:{}:{}:{}".format(
- self._tenant_id, self._provider, self._model_type.value, self._model
- )
+ cache_key = f"model_lb_index:{self._tenant_id}:{self._provider}:{self._model_type.value}:{self._model}"
cooldown_load_balancing_configs = []
max_index = len(self._load_balancing_configs)
@@ -1115,8 +1113,9 @@ model: %s""",
:param expire: cooldown time
:return:
"""
- cooldown_cache_key = "model_lb_index:cooldown:{}:{}:{}:{}:{}".format(
- self._tenant_id, self._provider, self._model_type.value, self._model, config.id
+ cooldown_cache_key = (
+ f"model_lb_index:cooldown:{self._tenant_id}:{self._provider}:"
+ f"{self._model_type.value}:{self._model}:{config.id}"
)
redis_client.setex(cooldown_cache_key, expire, "true")
@@ -1127,8 +1126,9 @@ model: %s""",
:param config: model load balancing config
:return:
"""
- cooldown_cache_key = "model_lb_index:cooldown:{}:{}:{}:{}:{}".format(
- self._tenant_id, self._provider, self._model_type.value, self._model, config.id
+ cooldown_cache_key = (
+ f"model_lb_index:cooldown:{self._tenant_id}:{self._provider}:"
+ f"{self._model_type.value}:{self._model}:{config.id}"
)
res: bool = redis_client.exists(cooldown_cache_key)
@@ -1147,9 +1147,7 @@ model: %s""",
:param config_id: model load balancing config id
:return:
"""
- cooldown_cache_key = "model_lb_index:cooldown:{}:{}:{}:{}:{}".format(
- tenant_id, provider, model_type.value, model, config_id
- )
+ cooldown_cache_key = f"model_lb_index:cooldown:{tenant_id}:{provider}:{model_type.value}:{model}:{config_id}"
ttl = redis_client.ttl(cooldown_cache_key)
if ttl == -2:
diff --git a/api/libs/helper.py b/api/libs/helper.py
index 613db1f074f..355ddfc2a07 100644
--- a/api/libs/helper.py
+++ b/api/libs/helper.py
@@ -329,9 +329,7 @@ class StrLen:
def __call__(self, value):
length = len(value)
if length > self.max_length:
- error = "Invalid {arg}: {val}. {arg} cannot exceed length {length}".format(
- arg=self.argument, val=value, length=self.max_length
- )
+ error = f"Invalid {self.argument}: {value}. {self.argument} cannot exceed length {self.max_length}"
raise ValueError(error)
return value
@@ -346,9 +344,7 @@ class DatetimeString:
try:
datetime.strptime(value, self.format)
except ValueError:
- error = "Invalid {arg}: {val}. {arg} must be conform to the format {format}".format(
- arg=self.argument, val=value, format=self.format
- )
+ error = f"Invalid {self.argument}: {value}. {self.argument} must be conform to the format {self.format}"
raise ValueError(error)
return value
diff --git a/api/services/data_source/provider_service.py b/api/services/data_source/provider_service.py
index 008dc846b31..81accea97de 100644
--- a/api/services/data_source/provider_service.py
+++ b/api/services/data_source/provider_service.py
@@ -925,8 +925,9 @@ class DatasourceProviderService:
user=user,
credential_query=credential_query,
)
- redirect_uri = "{}/console/api/oauth/plugin/{}/datasource/callback".format(
- dify_config.CONSOLE_API_URL, datasource_provider_id
+ redirect_uri = (
+ f"{dify_config.CONSOLE_API_URL}/console/api/oauth/plugin/"
+ f"{datasource_provider_id}/datasource/callback"
)
datasource_credentials.append(
{
diff --git a/api/tasks/annotation/batch_import_annotations_task.py b/api/tasks/annotation/batch_import_annotations_task.py
index 41656e1ab11..fd0827b6153 100644
--- a/api/tasks/annotation/batch_import_annotations_task.py
+++ b/api/tasks/annotation/batch_import_annotations_task.py
@@ -85,9 +85,7 @@ def batch_import_annotations_task(job_id: str, content_list: list[dict], app_id:
end_at = time.perf_counter()
logger.info(
click.style(
- "Build index successful for batch import annotation: {} latency: {}".format(
- job_id, end_at - start_at
- ),
+ f"Build index successful for batch import annotation: {job_id} latency: {end_at - start_at}",
fg="green",
)
)
diff --git a/api/tasks/clean_notion_document_task.py b/api/tasks/clean_notion_document_task.py
index 7e7d1a7718c..bedb3cb1541 100644
--- a/api/tasks/clean_notion_document_task.py
+++ b/api/tasks/clean_notion_document_task.py
@@ -71,9 +71,7 @@ def clean_notion_document_task(document_ids: list[str], dataset_id: str):
end_at = time.perf_counter()
logger.info(
click.style(
- "Clean document when import form notion document deleted end :: {} latency: {}".format(
- dataset_id, end_at - start_at
- ),
+ f"Clean document when import form notion document deleted end :: {dataset_id} latency: {end_at - start_at}",
fg="green",
)
)
diff --git a/api/tasks/deal_dataset_index_update_task.py b/api/tasks/deal_dataset_index_update_task.py
index c448e9be48a..5103e4ad494 100644
--- a/api/tasks/deal_dataset_index_update_task.py
+++ b/api/tasks/deal_dataset_index_update_task.py
@@ -24,7 +24,7 @@ def deal_dataset_index_update_task(dataset_id: str, action: str):
:param action: action
Usage: deal_dataset_index_update_task.delay(dataset_id, action)
"""
- logging.info(click.style("Start deal dataset index update: {}".format(dataset_id), fg="green"))
+ logging.info(click.style(f"Start deal dataset index update: {dataset_id}", fg="green"))
start_at = time.perf_counter()
with session_factory.create_session() as session:
@@ -212,7 +212,7 @@ def deal_dataset_index_update_task(dataset_id: str, action: str):
end_at = time.perf_counter()
logging.info(
click.style(
- "Deal dataset vector index: {} latency: {}".format(dataset_id, end_at - start_at),
+ f"Deal dataset vector index: {dataset_id} latency: {end_at - start_at}",
fg="green",
)
)
diff --git a/api/tasks/document_indexing_update_task.py b/api/tasks/document_indexing_update_task.py
index 2304529a243..bdb97e8e7e5 100644
--- a/api/tasks/document_indexing_update_task.py
+++ b/api/tasks/document_indexing_update_task.py
@@ -72,9 +72,8 @@ def document_indexing_update_task(dataset_id: str, document_id: str):
end_at = time.perf_counter()
logger.info(
click.style(
- "Cleaned document when document update data source or process rule: {} latency: {}".format(
- document_id, end_at - start_at
- ),
+ f"Cleaned document when document update data source or process rule: {document_id} "
+ f"latency: {end_at - start_at}",
fg="green",
)
)
diff --git a/api/tasks/mail_account_deletion_task.py b/api/tasks/mail_account_deletion_task.py
index ae42dff9073..da7257841ca 100644
--- a/api/tasks/mail_account_deletion_task.py
+++ b/api/tasks/mail_account_deletion_task.py
@@ -76,9 +76,7 @@ def send_account_deletion_verification_code(to: str, code: str, language: str =
end_at = time.perf_counter()
logger.info(
click.style(
- "Send account deletion verification code email to {} succeeded: latency: {}".format(
- to, end_at - start_at
- ),
+ f"Send account deletion verification code email to {to} succeeded: latency: {end_at - start_at}",
fg="green",
)
)