mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-11 00:58:30 +00:00
Fix linting and type-checking issues
- Fix whitespace in docstring blank lines (ruff W293) - Add null check before calling _validate_base_url to fix mypy type error - Ensure url_to_validate is not None before validation Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
@@ -1196,11 +1196,11 @@ class LLM(BaseLLM):
|
|||||||
f"The model {self.model} does not support response_format for provider '{provider}'. "
|
f"The model {self.model} does not support response_format for provider '{provider}'. "
|
||||||
"Please remove response_format or use a supported model."
|
"Please remove response_format or use a supported model."
|
||||||
)
|
)
|
||||||
|
|
||||||
# Validate base_url for Ollama connections
|
# Validate base_url for Ollama connections
|
||||||
if "ollama" in self.model.lower() and (self.base_url or self.api_base):
|
if "ollama" in self.model.lower() and (self.base_url or self.api_base):
|
||||||
url_to_validate = self.base_url or self.api_base
|
url_to_validate = self.base_url or self.api_base
|
||||||
if not self._validate_base_url(url_to_validate):
|
if url_to_validate and not self._validate_base_url(url_to_validate):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Invalid Ollama base_url: '{url_to_validate}'. "
|
f"Invalid Ollama base_url: '{url_to_validate}'. "
|
||||||
"Please check that the URL format is correct and the IP address is valid. "
|
"Please check that the URL format is correct and the IP address is valid. "
|
||||||
@@ -1209,27 +1209,27 @@ class LLM(BaseLLM):
|
|||||||
|
|
||||||
def _validate_base_url(self, url: str) -> bool:
|
def _validate_base_url(self, url: str) -> bool:
|
||||||
"""Validate base_url format and IP address for Ollama connections.
|
"""Validate base_url format and IP address for Ollama connections.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
url: The base URL to validate
|
url: The base URL to validate
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
bool: True if URL is valid, False otherwise
|
bool: True if URL is valid, False otherwise
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
from urllib.parse import urlparse
|
|
||||||
import ipaddress
|
import ipaddress
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
result = urlparse(url)
|
result = urlparse(url)
|
||||||
|
|
||||||
if not all([result.scheme in ("http", "https"), result.netloc]):
|
if not all([result.scheme in ("http", "https"), result.netloc]):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Extract hostname/IP from netloc (remove port if present)
|
# Extract hostname/IP from netloc (remove port if present)
|
||||||
hostname = result.hostname
|
hostname = result.hostname
|
||||||
if not hostname:
|
if not hostname:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Check if it looks like an IP address first
|
# Check if it looks like an IP address first
|
||||||
if all(part.isdigit() for part in hostname.split('.')) and len(hostname.split('.')) == 4:
|
if all(part.isdigit() for part in hostname.split('.')) and len(hostname.split('.')) == 4:
|
||||||
try:
|
try:
|
||||||
@@ -1243,7 +1243,7 @@ class LLM(BaseLLM):
|
|||||||
if "." in hostname and all(c.isalnum() or c in ".-" for c in hostname):
|
if "." in hostname and all(c.isalnum() or c in ".-" for c in hostname):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user