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("• ", style="white")
|
||||||
error_text.append("LLM_API_KEY", style="bold cyan")
|
error_text.append("LLM_API_KEY", style="bold cyan")
|
||||||
error_text.append(
|
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",
|
style="white",
|
||||||
)
|
)
|
||||||
elif var == "LLM_API_BASE":
|
elif var == "LLM_API_BASE":
|
||||||
@@ -123,7 +124,8 @@ def validate_environment() -> None: # noqa: PLR0912, PLR0915
|
|||||||
for var in missing_optional_vars:
|
for var in missing_optional_vars:
|
||||||
if var == "LLM_API_KEY":
|
if var == "LLM_API_KEY":
|
||||||
error_text.append(
|
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",
|
style="dim white",
|
||||||
)
|
)
|
||||||
elif var == "LLM_API_BASE":
|
elif var == "LLM_API_BASE":
|
||||||
|
|||||||
@@ -392,26 +392,27 @@ class LLM:
|
|||||||
if not self.config.model_name:
|
if not self.config.model_name:
|
||||||
return False
|
return False
|
||||||
try:
|
try:
|
||||||
return supports_vision(model=self.config.model_name)
|
return bool(supports_vision(model=self.config.model_name))
|
||||||
except Exception: # noqa: BLE001
|
except Exception: # noqa: BLE001
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _filter_images_from_messages(
|
def _filter_images_from_messages(self, messages: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||||
self, messages: list[dict[str, Any]]
|
|
||||||
) -> list[dict[str, Any]]:
|
|
||||||
filtered_messages = []
|
filtered_messages = []
|
||||||
for msg in messages:
|
for msg in messages:
|
||||||
content = msg.get("content")
|
content = msg.get("content")
|
||||||
|
updated_msg = msg
|
||||||
if isinstance(content, list):
|
if isinstance(content, list):
|
||||||
filtered_content = []
|
filtered_content = []
|
||||||
for item in content:
|
for item in content:
|
||||||
if isinstance(item, dict):
|
if isinstance(item, dict):
|
||||||
if item.get("type") == "image_url":
|
if item.get("type") == "image_url":
|
||||||
filtered_content.append({
|
filtered_content.append(
|
||||||
"type": "text",
|
{
|
||||||
"text": "[Screenshot removed - model does not support vision. "
|
"type": "text",
|
||||||
"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:
|
else:
|
||||||
filtered_content.append(item)
|
filtered_content.append(item)
|
||||||
else:
|
else:
|
||||||
@@ -421,13 +422,17 @@ class LLM:
|
|||||||
item.get("text", "") if isinstance(item, dict) else str(item)
|
item.get("text", "") if isinstance(item, dict) else str(item)
|
||||||
for item in filtered_content
|
for item in filtered_content
|
||||||
]
|
]
|
||||||
if all(isinstance(item, dict) and item.get("type") == "text" for item in filtered_content):
|
all_text = all(
|
||||||
msg = {**msg, "content": "\n".join(text_parts)}
|
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:
|
else:
|
||||||
msg = {**msg, "content": filtered_content}
|
updated_msg = {**msg, "content": filtered_content}
|
||||||
else:
|
else:
|
||||||
msg = {**msg, "content": ""}
|
updated_msg = {**msg, "content": ""}
|
||||||
filtered_messages.append(msg)
|
filtered_messages.append(updated_msg)
|
||||||
return filtered_messages
|
return filtered_messages
|
||||||
|
|
||||||
async def _make_request(
|
async def _make_request(
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ class DockerRuntime(AbstractRuntime):
|
|||||||
all=True, filters={"label": f"strix-scan-id={scan_id}"}
|
all=True, filters={"label": f"strix-scan-id={scan_id}"}
|
||||||
)
|
)
|
||||||
if containers:
|
if containers:
|
||||||
container = cast("Container", containers[0])
|
container = containers[0]
|
||||||
if container.status != "running":
|
if container.status != "running":
|
||||||
container.start()
|
container.start()
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|||||||
Reference in New Issue
Block a user