From 1edd8eda01a631965bd045bb30e7c33bee1b9b99 Mon Sep 17 00:00:00 2001 From: 0xallam Date: Sun, 7 Dec 2025 17:54:32 +0200 Subject: [PATCH] fix: lint errors and code style improvements --- strix/interface/main.py | 6 ++++-- strix/llm/llm.py | 33 +++++++++++++++++++-------------- strix/runtime/docker_runtime.py | 2 +- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/strix/interface/main.py b/strix/interface/main.py index 54f2941..6d48227 100644 --- a/strix/interface/main.py +++ b/strix/interface/main.py @@ -98,7 +98,8 @@ def validate_environment() -> None: # noqa: PLR0912, PLR0915 error_text.append("• ", style="white") error_text.append("LLM_API_KEY", style="bold cyan") error_text.append( - " - API key for the LLM provider (not needed for local models, Vertex AI, AWS, etc.)\n", + " - API key for the LLM provider " + "(not needed for local models, Vertex AI, AWS, etc.)\n", style="white", ) elif var == "LLM_API_BASE": @@ -123,7 +124,8 @@ def validate_environment() -> None: # noqa: PLR0912, PLR0915 for var in missing_optional_vars: if var == "LLM_API_KEY": error_text.append( - "export LLM_API_KEY='your-api-key-here' # not needed for local models, Vertex AI, AWS, etc.\n", + "export LLM_API_KEY='your-api-key-here' " + "# not needed for local models, Vertex AI, AWS, etc.\n", style="dim white", ) elif var == "LLM_API_BASE": diff --git a/strix/llm/llm.py b/strix/llm/llm.py index 6ea6776..50e0003 100644 --- a/strix/llm/llm.py +++ b/strix/llm/llm.py @@ -392,26 +392,27 @@ class LLM: if not self.config.model_name: return False try: - return supports_vision(model=self.config.model_name) + return bool(supports_vision(model=self.config.model_name)) except Exception: # noqa: BLE001 return False - def _filter_images_from_messages( - self, messages: list[dict[str, Any]] - ) -> list[dict[str, Any]]: + def _filter_images_from_messages(self, messages: list[dict[str, Any]]) -> list[dict[str, Any]]: filtered_messages = [] for msg in messages: content = msg.get("content") + updated_msg = msg if isinstance(content, list): filtered_content = [] for item in content: if isinstance(item, dict): if item.get("type") == "image_url": - filtered_content.append({ - "type": "text", - "text": "[Screenshot removed - model does not support vision. " - "Use view_source or execute_js to interact with the page instead.]", - }) + filtered_content.append( + { + "type": "text", + "text": "[Screenshot removed - model does not support " + "vision. Use view_source or execute_js instead.]", + } + ) else: filtered_content.append(item) else: @@ -421,13 +422,17 @@ class LLM: item.get("text", "") if isinstance(item, dict) else str(item) for item in filtered_content ] - if all(isinstance(item, dict) and item.get("type") == "text" for item in filtered_content): - msg = {**msg, "content": "\n".join(text_parts)} + all_text = all( + isinstance(item, dict) and item.get("type") == "text" + for item in filtered_content + ) + if all_text: + updated_msg = {**msg, "content": "\n".join(text_parts)} else: - msg = {**msg, "content": filtered_content} + updated_msg = {**msg, "content": filtered_content} else: - msg = {**msg, "content": ""} - filtered_messages.append(msg) + updated_msg = {**msg, "content": ""} + filtered_messages.append(updated_msg) return filtered_messages async def _make_request( diff --git a/strix/runtime/docker_runtime.py b/strix/runtime/docker_runtime.py index 63cb7a0..7ba04f8 100644 --- a/strix/runtime/docker_runtime.py +++ b/strix/runtime/docker_runtime.py @@ -203,7 +203,7 @@ class DockerRuntime(AbstractRuntime): all=True, filters={"label": f"strix-scan-id={scan_id}"} ) if containers: - container = cast("Container", containers[0]) + container = containers[0] if container.status != "running": container.start() time.sleep(2)