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,9 @@
|
||||
"""Search torrents use case."""
|
||||
|
||||
import logging
|
||||
|
||||
from infrastructure.api.knaben import KnabenClient, KnabenNotFoundError, KnabenAPIError
|
||||
from infrastructure.api.knaben import KnabenAPIError, KnabenClient, KnabenNotFoundError
|
||||
|
||||
from .dto import SearchTorrentsResponse
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -10,85 +12,79 @@ logger = logging.getLogger(__name__)
|
||||
class SearchTorrentsUseCase:
|
||||
"""
|
||||
Use case for searching torrents.
|
||||
|
||||
|
||||
This orchestrates the Knaben API client to find torrents.
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, knaben_client: KnabenClient):
|
||||
"""
|
||||
Initialize use case.
|
||||
|
||||
|
||||
Args:
|
||||
knaben_client: Knaben API client
|
||||
"""
|
||||
self.knaben_client = knaben_client
|
||||
|
||||
|
||||
def execute(self, media_title: str, limit: int = 10) -> SearchTorrentsResponse:
|
||||
"""
|
||||
Search for torrents by media title.
|
||||
|
||||
|
||||
Args:
|
||||
media_title: Title of the media to search for
|
||||
limit: Maximum number of results
|
||||
|
||||
|
||||
Returns:
|
||||
SearchTorrentsResponse with torrent information or error
|
||||
"""
|
||||
try:
|
||||
# Search for torrents
|
||||
results = self.knaben_client.search(media_title, limit=limit)
|
||||
|
||||
|
||||
if not results:
|
||||
logger.info(f"No torrents found for '{media_title}'")
|
||||
return SearchTorrentsResponse(
|
||||
status="error",
|
||||
error="not_found",
|
||||
message=f"No torrents found for '{media_title}'"
|
||||
message=f"No torrents found for '{media_title}'",
|
||||
)
|
||||
|
||||
|
||||
# Convert to dict format
|
||||
torrents = []
|
||||
for torrent in results:
|
||||
torrents.append({
|
||||
"name": torrent.title,
|
||||
"size": torrent.size,
|
||||
"seeders": torrent.seeders,
|
||||
"leechers": torrent.leechers,
|
||||
"magnet": torrent.magnet,
|
||||
"info_hash": torrent.info_hash,
|
||||
"tracker": torrent.tracker,
|
||||
"upload_date": torrent.upload_date,
|
||||
"category": torrent.category
|
||||
})
|
||||
|
||||
torrents.append(
|
||||
{
|
||||
"name": torrent.title,
|
||||
"size": torrent.size,
|
||||
"seeders": torrent.seeders,
|
||||
"leechers": torrent.leechers,
|
||||
"magnet": torrent.magnet,
|
||||
"info_hash": torrent.info_hash,
|
||||
"tracker": torrent.tracker,
|
||||
"upload_date": torrent.upload_date,
|
||||
"category": torrent.category,
|
||||
}
|
||||
)
|
||||
|
||||
logger.info(f"Found {len(torrents)} torrents for '{media_title}'")
|
||||
|
||||
|
||||
return SearchTorrentsResponse(
|
||||
status="ok",
|
||||
torrents=torrents,
|
||||
count=len(torrents)
|
||||
status="ok", torrents=torrents, count=len(torrents)
|
||||
)
|
||||
|
||||
|
||||
except KnabenNotFoundError as e:
|
||||
logger.info(f"Torrents not found: {e}")
|
||||
return SearchTorrentsResponse(
|
||||
status="error",
|
||||
error="not_found",
|
||||
message=str(e)
|
||||
status="error", error="not_found", message=str(e)
|
||||
)
|
||||
|
||||
|
||||
except KnabenAPIError as e:
|
||||
logger.error(f"Knaben API error: {e}")
|
||||
return SearchTorrentsResponse(
|
||||
status="error",
|
||||
error="api_error",
|
||||
message=str(e)
|
||||
status="error", error="api_error", message=str(e)
|
||||
)
|
||||
|
||||
|
||||
except ValueError as e:
|
||||
logger.error(f"Validation error: {e}")
|
||||
return SearchTorrentsResponse(
|
||||
status="error",
|
||||
error="validation_failed",
|
||||
message=str(e)
|
||||
status="error", error="validation_failed", message=str(e)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user