mirror of
https://github.com/hanzoai/python-sdk.git
synced 2026-10-23 20:23:00 +00:00
Fix litellm deprecation warning in hanzo-mcp
- Add warning filter to suppress "There is no current event loop" deprecation - Applied to both __init__.py and server.py to catch early imports - Also includes auto-formatting updates from formatter
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
|
||||
# Configure FastMCP logging globally for stdio transport
|
||||
import os
|
||||
import warnings
|
||||
|
||||
# Suppress litellm deprecation warnings about event loop
|
||||
warnings.filterwarnings("ignore", message="There is no current event loop", category=DeprecationWarning)
|
||||
|
||||
if os.environ.get("HANZO_MCP_TRANSPORT") == "stdio":
|
||||
try:
|
||||
|
||||
@@ -4,9 +4,11 @@ import atexit
|
||||
import signal
|
||||
import logging
|
||||
import threading
|
||||
import warnings
|
||||
from typing import Literal, cast, final
|
||||
|
||||
# No need for warning suppression here as it's handled in the imports
|
||||
# Suppress litellm deprecation warnings about event loop
|
||||
warnings.filterwarnings("ignore", message="There is no current event loop", category=DeprecationWarning)
|
||||
|
||||
try:
|
||||
from fastmcp import FastMCP
|
||||
|
||||
@@ -5,14 +5,14 @@ from typing import Any, Dict, List, Optional
|
||||
|
||||
class PaginatedResponseWrapper:
|
||||
"""Wrapper class for paginated responses to support tests."""
|
||||
|
||||
|
||||
def __init__(self, items=None, next_cursor=None, has_more=False, total_items=None):
|
||||
"""Initialize paginated response."""
|
||||
self.items = items or []
|
||||
self.next_cursor = next_cursor
|
||||
self.has_more = has_more
|
||||
self.total_items = total_items or len(self.items)
|
||||
|
||||
|
||||
def to_json(self) -> Dict[str, Any]:
|
||||
"""Convert to JSON-serializable dict."""
|
||||
return {
|
||||
@@ -20,12 +20,12 @@ class PaginatedResponseWrapper:
|
||||
"_meta": {
|
||||
"next_cursor": self.next_cursor,
|
||||
"has_more": self.has_more,
|
||||
"total_items": self.total_items
|
||||
}
|
||||
"total_items": self.total_items,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
# Export a convenience constructor
|
||||
def PaginatedResponse(items=None, next_cursor=None, has_more=False, total_items=None):
|
||||
"""Create a paginated response for testing."""
|
||||
return PaginatedResponseWrapper(items, next_cursor, has_more, total_items)
|
||||
return PaginatedResponseWrapper(items, next_cursor, has_more, total_items)
|
||||
|
||||
@@ -11,6 +11,7 @@ from mcp.server.fastmcp import FastMCP
|
||||
from hanzo_mcp.tools.common.truncate import truncate_response
|
||||
from hanzo_mcp.tools.common.tool_list import ToolListTool
|
||||
from hanzo_mcp.tools.common.fastmcp_pagination import FastMCPPaginator
|
||||
|
||||
try:
|
||||
# Try to import test helper version first
|
||||
from hanzo_mcp.tools.common.test_helpers import PaginatedResponse
|
||||
@@ -136,10 +137,7 @@ class TestPaginationSystem:
|
||||
|
||||
# Create paginated response using wrapper
|
||||
response = PaginatedResponse(
|
||||
items=items[:10],
|
||||
next_cursor="cursor_10",
|
||||
has_more=True,
|
||||
total_items=100
|
||||
items=items[:10], next_cursor="cursor_10", has_more=True, total_items=100
|
||||
)
|
||||
|
||||
# Check response attributes
|
||||
@@ -147,7 +145,7 @@ class TestPaginationSystem:
|
||||
assert response.next_cursor == "cursor_10"
|
||||
assert response.has_more is True
|
||||
assert response.total_items == 100
|
||||
|
||||
|
||||
# Test JSON serialization
|
||||
json_data = response.to_json()
|
||||
assert json_data["items"] == items[:10]
|
||||
@@ -159,19 +157,21 @@ class TestPaginationSystem:
|
||||
|
||||
# Test paginating a list
|
||||
items = [f"item_{i}" for i in range(100)]
|
||||
|
||||
|
||||
# Get first page
|
||||
result = paginator.paginate_list(items, cursor=None, page_size=10)
|
||||
|
||||
|
||||
assert result is not None
|
||||
assert "items" in result
|
||||
assert len(result["items"]) == 10
|
||||
assert result["items"][0] == "item_0"
|
||||
|
||||
|
||||
# Check if there's a next cursor
|
||||
if "nextCursor" in result:
|
||||
# Get next page using cursor
|
||||
next_result = paginator.paginate_list(items, cursor=result["nextCursor"], page_size=10)
|
||||
next_result = paginator.paginate_list(
|
||||
items, cursor=result["nextCursor"], page_size=10
|
||||
)
|
||||
assert next_result is not None
|
||||
assert "items" in next_result
|
||||
|
||||
|
||||
@@ -18,7 +18,11 @@ from .distributed_network import (
|
||||
create_distributed_network,
|
||||
)
|
||||
|
||||
from .local_network import create_local_agent, create_local_distributed_network, check_local_llm_status
|
||||
from .local_network import (
|
||||
create_local_agent,
|
||||
create_local_distributed_network,
|
||||
check_local_llm_status,
|
||||
)
|
||||
|
||||
# Import LLM providers
|
||||
from .llm import HanzoNetProvider, LocalLLMProvider, OllamaProvider, MLXProvider
|
||||
|
||||
@@ -7,14 +7,14 @@ from typing import Optional
|
||||
@dataclass
|
||||
class DeviceCapabilities:
|
||||
"""Represents the capabilities of a device in the network."""
|
||||
|
||||
|
||||
cpu_cores: int = 1
|
||||
memory_gb: float = 1.0
|
||||
gpu_available: bool = False
|
||||
gpu_memory_gb: Optional[float] = None
|
||||
network_bandwidth_mbps: float = 100.0
|
||||
storage_gb: float = 10.0
|
||||
|
||||
|
||||
def __post_init__(self):
|
||||
"""Validate capabilities after initialization."""
|
||||
if self.cpu_cores < 1:
|
||||
@@ -27,7 +27,7 @@ class DeviceCapabilities:
|
||||
raise ValueError("Network bandwidth must be positive")
|
||||
if self.storage_gb <= 0:
|
||||
raise ValueError("Storage must be positive")
|
||||
|
||||
|
||||
def to_dict(self) -> dict:
|
||||
"""Convert capabilities to dictionary."""
|
||||
return {
|
||||
@@ -38,7 +38,7 @@ class DeviceCapabilities:
|
||||
"network_bandwidth_mbps": self.network_bandwidth_mbps,
|
||||
"storage_gb": self.storage_gb,
|
||||
}
|
||||
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict) -> "DeviceCapabilities":
|
||||
"""Create capabilities from dictionary."""
|
||||
@@ -50,8 +50,13 @@ class DeviceCapabilities:
|
||||
network_bandwidth_mbps=data.get("network_bandwidth_mbps", 100.0),
|
||||
storage_gb=data.get("storage_gb", 10.0),
|
||||
)
|
||||
|
||||
def can_handle_workload(self, required_memory_gb: float, required_cpu_cores: int = 1, requires_gpu: bool = False) -> bool:
|
||||
|
||||
def can_handle_workload(
|
||||
self,
|
||||
required_memory_gb: float,
|
||||
required_cpu_cores: int = 1,
|
||||
requires_gpu: bool = False,
|
||||
) -> bool:
|
||||
"""Check if this device can handle a given workload."""
|
||||
if self.memory_gb < required_memory_gb:
|
||||
return False
|
||||
@@ -59,4 +64,4 @@ class DeviceCapabilities:
|
||||
return False
|
||||
if requires_gpu and not self.gpu_available:
|
||||
return False
|
||||
return True
|
||||
return True
|
||||
|
||||
@@ -5,6 +5,7 @@ from typing import Any, Dict, List, Optional
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from ..core.state import NetworkState
|
||||
|
||||
# Commenting out missing imports - need to implement these
|
||||
# from .inference.inference_engine import get_inference_engine
|
||||
# from .inference.shard import Shard
|
||||
@@ -13,6 +14,7 @@ from ..core.state import NetworkState
|
||||
# Define Message locally for now
|
||||
from typing import TypedDict
|
||||
|
||||
|
||||
class Message(TypedDict):
|
||||
role: str
|
||||
content: str
|
||||
@@ -62,7 +64,7 @@ class HanzoNetProvider(LocalLLMProvider):
|
||||
# Dummy implementation for testing
|
||||
if self.engine is None:
|
||||
self.engine = {"type": self.engine_type, "model": model}
|
||||
|
||||
|
||||
# Update model if needed
|
||||
if self.current_shard is None or self.current_shard != model:
|
||||
self.current_shard = model
|
||||
|
||||
Reference in New Issue
Block a user