chore: apply pep8-naming rules for naming convention (#8261)

This commit is contained in:
Bowen Liang
2024-09-11 16:40:52 +08:00
committed by GitHub
parent 53f37a6704
commit 292220c596
95 changed files with 287 additions and 258 deletions

View File

@@ -69,7 +69,7 @@ class DallE3Tool(BuiltinTool):
self.create_blob_message(
blob=b64decode(image.b64_json),
meta={"mime_type": "image/png"},
save_as=self.VARIABLE_KEY.IMAGE.value,
save_as=self.VariableKey.IMAGE.value,
)
)
result.append(self.create_text_message(f"\nGenerate image source to Seed ID: {seed_id}"))

View File

@@ -59,7 +59,7 @@ class DallE2Tool(BuiltinTool):
self.create_blob_message(
blob=b64decode(image.b64_json),
meta={"mime_type": "image/png"},
save_as=self.VARIABLE_KEY.IMAGE.value,
save_as=self.VariableKey.IMAGE.value,
)
)

View File

@@ -66,7 +66,7 @@ class DallE3Tool(BuiltinTool):
for image in response.data:
mime_type, blob_image = DallE3Tool._decode_image(image.b64_json)
blob_message = self.create_blob_message(
blob=blob_image, meta={"mime_type": mime_type}, save_as=self.VARIABLE_KEY.IMAGE.value
blob=blob_image, meta={"mime_type": mime_type}, save_as=self.VariableKey.IMAGE.value
)
result.append(blob_message)
return result

View File

@@ -34,7 +34,7 @@ class NovitaAiCreateTileTool(BuiltinTool):
self.create_blob_message(
blob=b64decode(client_result.image_file),
meta={"mime_type": f"image/{client_result.image_type}"},
save_as=self.VARIABLE_KEY.IMAGE.value,
save_as=self.VariableKey.IMAGE.value,
)
)

View File

@@ -40,7 +40,7 @@ class NovitaAiTxt2ImgTool(BuiltinTool, NovitaAiToolBase):
self.create_blob_message(
blob=b64decode(image_encoded),
meta={"mime_type": f"image/{image.image_type}"},
save_as=self.VARIABLE_KEY.IMAGE.value,
save_as=self.VariableKey.IMAGE.value,
)
)

View File

@@ -46,7 +46,7 @@ class QRCodeGeneratorTool(BuiltinTool):
image = self._generate_qrcode(content, border, error_correction)
image_bytes = self._image_to_byte_array(image)
return self.create_blob_message(
blob=image_bytes, meta={"mime_type": "image/png"}, save_as=self.VARIABLE_KEY.IMAGE.value
blob=image_bytes, meta={"mime_type": "image/png"}, save_as=self.VariableKey.IMAGE.value
)
except Exception:
logging.exception(f"Failed to generate QR code for content: {content}")

View File

@@ -32,5 +32,5 @@ class FluxTool(BuiltinTool):
res = response.json()
result = [self.create_json_message(res)]
for image in res.get("images", []):
result.append(self.create_image_message(image=image.get("url"), save_as=self.VARIABLE_KEY.IMAGE.value))
result.append(self.create_image_message(image=image.get("url"), save_as=self.VariableKey.IMAGE.value))
return result

View File

@@ -41,5 +41,5 @@ class StableDiffusionTool(BuiltinTool):
res = response.json()
result = [self.create_json_message(res)]
for image in res.get("images", []):
result.append(self.create_image_message(image=image.get("url"), save_as=self.VARIABLE_KEY.IMAGE.value))
result.append(self.create_image_message(image=image.get("url"), save_as=self.VariableKey.IMAGE.value))
return result

View File

@@ -15,16 +15,16 @@ from core.tools.entities.tool_entities import ToolInvokeMessage
from core.tools.tool.builtin_tool import BuiltinTool
class AssembleHeaderException(Exception):
class AssembleHeaderError(Exception):
def __init__(self, msg):
self.message = msg
class Url:
def __init__(this, host, path, schema):
this.host = host
this.path = path
this.schema = schema
def __init__(self, host, path, schema):
self.host = host
self.path = path
self.schema = schema
# calculate sha256 and encode to base64
@@ -41,7 +41,7 @@ def parse_url(request_url):
schema = request_url[: stidx + 3]
edidx = host.index("/")
if edidx <= 0:
raise AssembleHeaderException("invalid request url:" + request_url)
raise AssembleHeaderError("invalid request url:" + request_url)
path = host[edidx:]
host = host[:edidx]
u = Url(host, path, schema)
@@ -115,7 +115,7 @@ class SparkImgGeneratorTool(BuiltinTool):
self.create_blob_message(
blob=b64decode(image["base64_image"]),
meta={"mime_type": "image/png"},
save_as=self.VARIABLE_KEY.IMAGE.value,
save_as=self.VariableKey.IMAGE.value,
)
)
return result

View File

@@ -52,5 +52,5 @@ class StableDiffusionTool(BuiltinTool, BaseStabilityAuthorization):
raise Exception(response.text)
return self.create_blob_message(
blob=response.content, meta={"mime_type": "image/png"}, save_as=self.VARIABLE_KEY.IMAGE.value
blob=response.content, meta={"mime_type": "image/png"}, save_as=self.VariableKey.IMAGE.value
)

View File

@@ -260,7 +260,7 @@ class StableDiffusionTool(BuiltinTool):
image = response.json()["images"][0]
return self.create_blob_message(
blob=b64decode(image), meta={"mime_type": "image/png"}, save_as=self.VARIABLE_KEY.IMAGE.value
blob=b64decode(image), meta={"mime_type": "image/png"}, save_as=self.VariableKey.IMAGE.value
)
except Exception as e:
@@ -294,7 +294,7 @@ class StableDiffusionTool(BuiltinTool):
image = response.json()["images"][0]
return self.create_blob_message(
blob=b64decode(image), meta={"mime_type": "image/png"}, save_as=self.VARIABLE_KEY.IMAGE.value
blob=b64decode(image), meta={"mime_type": "image/png"}, save_as=self.VariableKey.IMAGE.value
)
except Exception as e:

View File

@@ -45,5 +45,5 @@ class PoiSearchTool(BuiltinTool):
).content
return self.create_blob_message(
blob=result, meta={"mime_type": "image/png"}, save_as=self.VARIABLE_KEY.IMAGE.value
blob=result, meta={"mime_type": "image/png"}, save_as=self.VariableKey.IMAGE.value
)

View File

@@ -32,7 +32,7 @@ class VectorizerTool(BuiltinTool):
if image_id.startswith("__test_"):
image_binary = b64decode(VECTORIZER_ICON_PNG)
else:
image_binary = self.get_variable_file(self.VARIABLE_KEY.IMAGE)
image_binary = self.get_variable_file(self.VariableKey.IMAGE)
if not image_binary:
return self.create_text_message("Image not found, please request user to generate image firstly.")

View File

@@ -63,7 +63,7 @@ class Tool(BaseModel, ABC):
def __init__(self, **data: Any):
super().__init__(**data)
class VARIABLE_KEY(Enum):
class VariableKey(Enum):
IMAGE = "image"
def fork_tool_runtime(self, runtime: dict[str, Any]) -> "Tool":
@@ -142,7 +142,7 @@ class Tool(BaseModel, ABC):
if not self.variables:
return None
return self.get_variable(self.VARIABLE_KEY.IMAGE)
return self.get_variable(self.VariableKey.IMAGE)
def get_variable_file(self, name: Union[str, Enum]) -> Optional[bytes]:
"""
@@ -189,7 +189,7 @@ class Tool(BaseModel, ABC):
result = []
for variable in self.variables.pool:
if variable.name.startswith(self.VARIABLE_KEY.IMAGE.value):
if variable.name.startswith(self.VariableKey.IMAGE.value):
result.append(variable)
return result