Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: apply ruff E501 line-too-long linter rule #8275

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
update
  • Loading branch information
bowenliang123 committed Sep 12, 2024
commit c9cfb445895e633e7ca4add711731eea68222929
3 changes: 2 additions & 1 deletion api/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@ def migrate_knowledge_vector_database():
try:
click.echo(
click.style(
f"Start to created vector index with {len(documents)} documents of {segments_count} segments for dataset {dataset.id}.",
f"Start to created vector index with {len(documents)} documents of {segments_count}"
f" segments for dataset {dataset.id}.",
fg="green",
)
)
Expand Down
9 changes: 6 additions & 3 deletions api/controllers/console/app/statistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def get(self, app_model):
args = parser.parse_args()

sql_query = """
SELECT date(DATE_TRUNC('day', created_at AT TIME ZONE 'UTC' AT TIME ZONE :tz )) AS date, count(*) AS message_count
SELECT date(DATE_TRUNC('day', created_at AT TIME ZONE 'UTC' AT TIME ZONE :tz )) AS date,
count(*) AS message_count
FROM messages where app_id = :app_id
"""
arg_dict = {"tz": account.timezone, "app_id": app_model.id}
Expand Down Expand Up @@ -84,7 +85,8 @@ def get(self, app_model):
args = parser.parse_args()

sql_query = """
SELECT date(DATE_TRUNC('day', created_at AT TIME ZONE 'UTC' AT TIME ZONE :tz )) AS date, count(distinct messages.conversation_id) AS conversation_count
SELECT date(DATE_TRUNC('day', created_at AT TIME ZONE 'UTC' AT TIME ZONE :tz )) AS date,
count(distinct messages.conversation_id) AS conversation_count
FROM messages where app_id = :app_id
"""
arg_dict = {"tz": account.timezone, "app_id": app_model.id}
Expand Down Expand Up @@ -138,7 +140,8 @@ def get(self, app_model):
args = parser.parse_args()

sql_query = """
SELECT date(DATE_TRUNC('day', created_at AT TIME ZONE 'UTC' AT TIME ZONE :tz )) AS date, count(distinct messages.from_end_user_id) AS terminal_count
SELECT date(DATE_TRUNC('day', created_at AT TIME ZONE 'UTC' AT TIME ZONE :tz )) AS date,
count(distinct messages.from_end_user_id) AS terminal_count
FROM messages where app_id = :app_id
"""
arg_dict = {"tz": account.timezone, "app_id": app_model.id}
Expand Down
3 changes: 2 additions & 1 deletion api/controllers/console/app/workflow_statistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def get(self, app_model):
args = parser.parse_args()

sql_query = """
SELECT date(DATE_TRUNC('day', created_at AT TIME ZONE 'UTC' AT TIME ZONE :tz )) AS date, count(distinct workflow_runs.created_by) AS terminal_count
SELECT date(DATE_TRUNC('day', created_at AT TIME ZONE 'UTC' AT TIME ZONE :tz )) AS date,
count(distinct workflow_runs.created_by) AS terminal_count
FROM workflow_runs
WHERE app_id = :app_id
AND triggered_from = :triggered_from
Expand Down
3 changes: 2 additions & 1 deletion api/controllers/console/wraps.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def decorated(*args, **kwargs):
elif resource == "vector_space" and 0 < vector_space.limit <= vector_space.size:
abort(403, "The capacity of the vector space has reached the limit of your subscription.")
elif resource == "documents" and 0 < documents_upload_quota.limit <= documents_upload_quota.size:
# The api of file upload is used in the multiple places, so we need to check the source of the request from datasets
# The api of file upload is used in the multiple places,
# so we need to check the source of the request from datasets
source = request.args.get("source")
if source == "datasets":
abort(403, "The number of documents has reached the limit of your subscription.")
Expand Down
3 changes: 2 additions & 1 deletion api/controllers/web/wraps.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def _validate_web_sso_token(decoded, system_features, app_code):
if not source or source != "sso":
raise WebSSOAuthRequiredError()

# Check if SSO is not enforced for web, and if the token source is SSO, raise an error and redirect to normal passport login
# Check if SSO is not enforced for web, and if the token source is SSO,
# raise an error and redirect to normal passport login
if not system_features.sso_enforced_for_web or not app_web_sso_enabled:
source = decoded.get("token_source")
if source and source == "sso":
Expand Down
6 changes: 4 additions & 2 deletions api/core/agent/prompt/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
{{historic_messages}}
Question: {{query}}
{{agent_scratchpad}}
Thought:"""
Thought:""" # noqa: E501


ENGLISH_REACT_COMPLETION_AGENT_SCRATCHPAD_TEMPLATES = """Observation: {{observation}}
Thought:"""
Expand Down Expand Up @@ -86,7 +87,8 @@
```

Begin! Reminder to ALWAYS respond with a valid json blob of a single action. Use tools if necessary. Respond directly if appropriate. Format is Action:```$JSON_BLOB```then Observation:.
"""
""" # noqa: E501


ENGLISH_REACT_CHAT_AGENT_SCRATCHPAD_TEMPLATES = ""

Expand Down
15 changes: 10 additions & 5 deletions api/core/app/apps/workflow_logging_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ def on_workflow_node_execute_succeeded(self, event: NodeRunSucceededEvent) -> No
if route_node_state.node_run_result:
node_run_result = route_node_state.node_run_result
self.print_text(
f"Inputs: {jsonable_encoder(node_run_result.inputs) if node_run_result.inputs else ''}", color="green"
f"Inputs: " f"{jsonable_encoder(node_run_result.inputs) if node_run_result.inputs else ''}",
color="green",
)
self.print_text(
f"Process Data: {jsonable_encoder(node_run_result.process_data) if node_run_result.process_data else ''}",
f"Process Data: "
f"{jsonable_encoder(node_run_result.process_data) if node_run_result.process_data else ''}",
color="green",
)
self.print_text(
Expand All @@ -114,14 +116,17 @@ def on_workflow_node_execute_failed(self, event: NodeRunFailedEvent) -> None:
node_run_result = route_node_state.node_run_result
self.print_text(f"Error: {node_run_result.error}", color="red")
self.print_text(
f"Inputs: {jsonable_encoder(node_run_result.inputs) if node_run_result.inputs else ''}", color="red"
f"Inputs: " f"" f"{jsonable_encoder(node_run_result.inputs) if node_run_result.inputs else ''}",
color="red",
)
self.print_text(
f"Process Data: {jsonable_encoder(node_run_result.process_data) if node_run_result.process_data else ''}",
f"Process Data: "
f"{jsonable_encoder(node_run_result.process_data) if node_run_result.process_data else ''}",
color="red",
)
self.print_text(
f"Outputs: {jsonable_encoder(node_run_result.outputs) if node_run_result.outputs else ''}", color="red"
f"Outputs: " f"{jsonable_encoder(node_run_result.outputs) if node_run_result.outputs else ''}",
color="red",
)

def on_node_text_chunk(self, event: NodeRunStreamChunkEvent) -> None:
Expand Down
3 changes: 2 additions & 1 deletion api/core/file/message_file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ def _to_file_obj(self, file: Union[dict, MessageFile], file_extra_config: FileEx
def _check_image_remote_url(self, url):
try:
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)"
" Chrome/91.0.4472.124 Safari/537.36"
}

def is_s3_presigned_url(url):
Expand Down
3 changes: 2 additions & 1 deletion api/core/helper/code_executor/code_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ def execute_code(cls, language: CodeLanguage, preload: str, code: str) -> str:
raise CodeExecutionError("Code execution service is unavailable")
elif response.status_code != 200:
raise Exception(
f"Failed to execute code, got status code {response.status_code}, please check if the sandbox service is running"
f"Failed to execute code, got status code {response.status_code},"
f" please check if the sandbox service is running"
)
except CodeExecutionError as e:
raise e
Expand Down
5 changes: 4 additions & 1 deletion api/core/helper/tool_parameter_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ class ToolParameterCache:
def __init__(
self, tenant_id: str, provider: str, tool_name: str, cache_type: ToolParameterCacheType, identity_id: str
):
self.cache_key = f"{cache_type.value}_secret:tenant_id:{tenant_id}:provider:{provider}:tool_name:{tool_name}:identity_id:{identity_id}"
self.cache_key = (
f"{cache_type.value}_secret:tenant_id:{tenant_id}:provider:{provider}:tool_name:{tool_name}"
f":identity_id:{identity_id}"
)

def get(self) -> Optional[dict]:
"""
Expand Down
19 changes: 11 additions & 8 deletions api/core/llm_generator/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,27 @@
}

User Input:
"""
""" # noqa: E501

SUGGESTED_QUESTIONS_AFTER_ANSWER_INSTRUCTION_PROMPT = (
"Please help me predict the three most likely questions that human would ask, "
"and keeping each question under 20 characters.\n"
"MAKE SURE your output is the SAME language as the Assistant's latest response(if the main response is written in Chinese, then the language of your output must be using Chinese.)!\n"
"MAKE SURE your output is the SAME language as the Assistant's latest response"
"(if the main response is written in Chinese, then the language of your output must be using Chinese.)!\n"
"The output must be an array in JSON format following the specified schema:\n"
'["question1","question2","question3"]\n'
)

GENERATOR_QA_PROMPT = (
"<Task> The user will send a long text. Generate a Question and Answer pairs only using the knowledge in the long text. Please think step by step."
"<Task> The user will send a long text. Generate a Question and Answer pairs only using the knowledge"
" in the long text. Please think step by step."
"Step 1: Understand and summarize the main content of this text.\n"
"Step 2: What key information or concepts are mentioned in this text?\n"
"Step 3: Decompose or combine multiple pieces of information and concepts.\n"
"Step 4: Generate questions and answers based on these key information and concepts.\n"
"<Constraints> The questions should be clear and detailed, and the answers should be detailed and complete. "
"You must answer in {language}, in a style that is clear and detailed in {language}. No language other than {language} should be used. \n"
"You must answer in {language}, in a style that is clear and detailed in {language}."
" No language other than {language} should be used. \n"
"<Format> Use the following format: Q1:\nA1:\nQ2:\nA2:...\n"
"<QA Pairs>"
)
Expand All @@ -94,7 +97,7 @@
- Use the same language as task description.
- Output in ``` xml ``` and start with <instruction>
Please generate the full prompt template with at least 300 words and output only the prompt template.
"""
""" # noqa: E501

RULE_CONFIG_PROMPT_GENERATE_TEMPLATE = """
Here is a task description for which I would like you to create a high-quality prompt template for:
Expand All @@ -109,7 +112,7 @@
- Use the same language as task description.
- Output in ``` xml ``` and start with <instruction>
Please generate the full prompt template and output only the prompt template.
"""
""" # noqa: E501

RULE_CONFIG_PARAMETER_GENERATE_TEMPLATE = """
I need to extract the following information from the input text. The <information to be extracted> tag specifies the 'type', 'description' and 'required' of the information to be extracted.
Expand All @@ -134,7 +137,7 @@

### Answer
I should always output a valid list. Output nothing other than the list of variable_name. Output an empty list if there is no variable name in input text.
"""
""" # noqa: E501

RULE_CONFIG_STATEMENT_GENERATE_TEMPLATE = """
<instruction>
Expand All @@ -150,4 +153,4 @@
Here is the task description: {{INPUT_TEXT}}

You just need to generate the output
"""
""" # noqa: E501
16 changes: 11 additions & 5 deletions api/core/model_runtime/entities/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
},
"type": "float",
"help": {
"en_US": "Controls randomness. Lower temperature results in less random completions. As the temperature approaches zero, the model will become deterministic and repetitive. Higher temperature results in more random completions.",
"zh_Hans": "温度控制随机性。较低的温度会导致较少的随机完成。随着温度接近零,模型将变得确定性和重复性。较高的温度会导致更多的随机完成。",
"en_US": "Controls randomness. Lower temperature results in less random completions."
" As the temperature approaches zero, the model will become deterministic and repetitive."
" Higher temperature results in more random completions.",
"zh_Hans": "温度控制随机性。较低的温度会导致较少的随机完成。随着温度接近零,模型将变得确定性和重复性。"
"较高的温度会导致更多的随机完成。",
},
"required": False,
"default": 0.0,
Expand All @@ -24,7 +27,8 @@
},
"type": "float",
"help": {
"en_US": "Controls diversity via nucleus sampling: 0.5 means half of all likelihood-weighted options are considered.",
"en_US": "Controls diversity via nucleus sampling: 0.5 means half of all likelihood-weighted options"
" are considered.",
"zh_Hans": "通过核心采样控制多样性:0.5表示考虑了一半的所有可能性加权选项。",
},
"required": False,
Expand Down Expand Up @@ -88,7 +92,8 @@
},
"type": "int",
"help": {
"en_US": "Specifies the upper limit on the length of generated results. If the generated results are truncated, you can increase this parameter.",
"en_US": "Specifies the upper limit on the length of generated results."
" If the generated results are truncated, you can increase this parameter.",
"zh_Hans": "指定生成结果长度的上限。如果生成结果截断,可以调大该参数。",
},
"required": False,
Expand All @@ -104,7 +109,8 @@
},
"type": "string",
"help": {
"en_US": "Set a response format, ensure the output from llm is a valid code block as possible, such as JSON, XML, etc.",
"en_US": "Set a response format, ensure the output from llm is a valid code block as possible,"
" such as JSON, XML, etc.",
"zh_Hans": "设置一个返回格式,确保llm的输出尽可能是有效的代码块,如JSON、XML等",
},
"required": False,
Expand Down
4 changes: 3 additions & 1 deletion api/core/model_runtime/model_providers/__base/ai_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ def _transform_invoke_error(self, error: Exception) -> InvokeError:
if isinstance(error, tuple(model_errors)):
if invoke_error == InvokeAuthorizationError:
return invoke_error(
description=f"[{provider_name}] Incorrect model credentials provided, please check and try again. "
description=(
f"[{provider_name}] Incorrect model credentials provided, please check and try again."
)
)

return invoke_error(description=f"[{provider_name}] {invoke_error.description}, {str(error)}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def _code_block_mode_wrapper(
<instructions>
{{instructions}}
</instructions>
"""
""" # noqa: E501

code_block = model_parameters.get("response_format", "")
if not code_block:
Expand Down Expand Up @@ -830,7 +830,8 @@ def _validate_and_filter_model_parameters(self, model: str, model_parameters: di
else:
if parameter_value != round(parameter_value, parameter_rule.precision):
raise ValueError(
f"Model Parameter {parameter_name} should be round to {parameter_rule.precision} decimal places."
f"Model Parameter {parameter_name} should be round to {parameter_rule.precision}"
f" decimal places."
)

# validate parameter value range
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<instructions>
{{instructions}}
</instructions>
"""
""" # noqa: E501


class AnthropicLargeLanguageModel(LargeLanguageModel):
Expand Down
Loading
Loading