chore: refurbish Python code by applying refurb linter rules (#8296)

This commit is contained in:
Bowen Liang
2024-09-12 15:50:49 +08:00
committed by GitHub
parent c69f5b07ba
commit 40fb4d16ef
105 changed files with 220 additions and 276 deletions

View File

@@ -1,4 +1,5 @@
import json
import operator
from typing import Any, Union
import boto3
@@ -71,7 +72,7 @@ class SageMakerReRankTool(BuiltinTool):
candidate_docs[idx]["score"] = scores[idx]
line = 8
sorted_candidate_docs = sorted(candidate_docs, key=lambda x: x["score"], reverse=True)
sorted_candidate_docs = sorted(candidate_docs, key=operator.itemgetter("score"), reverse=True)
line = 9
return [self.create_json_message(res) for res in sorted_candidate_docs[: self.topk]]

View File

@@ -115,7 +115,7 @@ class GetWorksheetFieldsTool(BuiltinTool):
fields.append(field)
fields_list.append(
f"|{field['id']}|{field['name']}|{field['type']}|{field['typeId']}|{field['description']}"
f"|{field['options'] if field['options'] else ''}|"
f"|{field['options'] or ''}|"
)
fields.append(

View File

@@ -130,7 +130,7 @@ class GetWorksheetPivotDataTool(BuiltinTool):
# ]
rows = []
for row in data["data"]:
row_data = row["rows"] if row["rows"] else {}
row_data = row["rows"] or {}
row_data.update(row["columns"])
row_data.update(row["values"])
rows.append(row_data)

View File

@@ -113,7 +113,7 @@ class ListWorksheetRecordsTool(BuiltinTool):
result_text = f"Found {result['total']} rows in worksheet \"{worksheet_name}\"."
if result["total"] > 0:
result_text += (
f" The following are {result['total'] if result['total'] < limit else limit}"
f" The following are {min(limit, result['total'])}"
f" pieces of data presented in a table format:\n\n{table_header}"
)
for row in rows:

View File

@@ -37,7 +37,7 @@ class SearchAPI:
return {
"engine": "youtube_transcripts",
"video_id": video_id,
"lang": language if language else "en",
"lang": language or "en",
**{key: value for key, value in kwargs.items() if value not in [None, ""]},
}