fix: lint errors and code style improvements
This commit is contained in:
@@ -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":
|
||||
|
||||
@@ -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({
|
||||
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.]",
|
||||
})
|
||||
"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(
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user