feat!: migrate to OpenAI native tool calls and fix circular deps (#fuck-gemini)
- Fix circular dependencies in agent/tools - Migrate from custom JSON to OpenAI tool calls format - Add async streaming (step_stream, complete_stream) - Simplify prompt system and remove token counting - Add 5 new API endpoints (/health, /v1/models, /api/memory/*) - Add 3 new tools (get_torrent_by_index, add_torrent_by_index, set_language) - Fix all 500 tests and add coverage config (80% threshold) - Add comprehensive docs (README, pytest guide) BREAKING: LLM interface changed, memory injection via get_memory()
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
"""Add torrent use case."""
|
||||
|
||||
import logging
|
||||
|
||||
from infrastructure.api.qbittorrent import QBittorrentClient, QBittorrentAuthError, QBittorrentAPIError
|
||||
from infrastructure.api.qbittorrent import (
|
||||
QBittorrentAPIError,
|
||||
QBittorrentAuthError,
|
||||
QBittorrentClient,
|
||||
)
|
||||
|
||||
from .dto import AddTorrentResponse
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -10,26 +16,26 @@ logger = logging.getLogger(__name__)
|
||||
class AddTorrentUseCase:
|
||||
"""
|
||||
Use case for adding a torrent to qBittorrent.
|
||||
|
||||
|
||||
This orchestrates the qBittorrent API client to add torrents.
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, qbittorrent_client: QBittorrentClient):
|
||||
"""
|
||||
Initialize use case.
|
||||
|
||||
|
||||
Args:
|
||||
qbittorrent_client: qBittorrent API client
|
||||
"""
|
||||
self.qbittorrent_client = qbittorrent_client
|
||||
|
||||
|
||||
def execute(self, magnet_link: str) -> AddTorrentResponse:
|
||||
"""
|
||||
Add a torrent to qBittorrent using a magnet link.
|
||||
|
||||
|
||||
Args:
|
||||
magnet_link: Magnet link of the torrent to add
|
||||
|
||||
|
||||
Returns:
|
||||
AddTorrentResponse with success or error information
|
||||
"""
|
||||
@@ -37,49 +43,42 @@ class AddTorrentUseCase:
|
||||
# Validate magnet link
|
||||
if not magnet_link or not isinstance(magnet_link, str):
|
||||
raise ValueError("Magnet link must be a non-empty string")
|
||||
|
||||
|
||||
if not magnet_link.startswith("magnet:"):
|
||||
raise ValueError("Invalid magnet link format")
|
||||
|
||||
|
||||
logger.info("Adding torrent to qBittorrent")
|
||||
|
||||
|
||||
# Add torrent to qBittorrent
|
||||
success = self.qbittorrent_client.add_torrent(magnet_link)
|
||||
|
||||
|
||||
if success:
|
||||
logger.info("Torrent added successfully to qBittorrent")
|
||||
return AddTorrentResponse(
|
||||
status="ok",
|
||||
message="Torrent added successfully to qBittorrent"
|
||||
status="ok", message="Torrent added successfully to qBittorrent"
|
||||
)
|
||||
else:
|
||||
logger.warning("Failed to add torrent to qBittorrent")
|
||||
return AddTorrentResponse(
|
||||
status="error",
|
||||
error="add_failed",
|
||||
message="Failed to add torrent to qBittorrent"
|
||||
message="Failed to add torrent to qBittorrent",
|
||||
)
|
||||
|
||||
|
||||
except QBittorrentAuthError as e:
|
||||
logger.error(f"qBittorrent authentication error: {e}")
|
||||
return AddTorrentResponse(
|
||||
status="error",
|
||||
error="authentication_failed",
|
||||
message="Failed to authenticate with qBittorrent"
|
||||
message="Failed to authenticate with qBittorrent",
|
||||
)
|
||||
|
||||
|
||||
except QBittorrentAPIError as e:
|
||||
logger.error(f"qBittorrent API error: {e}")
|
||||
return AddTorrentResponse(
|
||||
status="error",
|
||||
error="api_error",
|
||||
message=str(e)
|
||||
)
|
||||
|
||||
return AddTorrentResponse(status="error", error="api_error", message=str(e))
|
||||
|
||||
except ValueError as e:
|
||||
logger.error(f"Validation error: {e}")
|
||||
return AddTorrentResponse(
|
||||
status="error",
|
||||
error="validation_failed",
|
||||
message=str(e)
|
||||
status="error", error="validation_failed", message=str(e)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user