fix(api): lint errors in Rate Limiter + RAG services

- Remove unused imports (settings, uuid)
- Add 'from e' to exception raises (B904)
- Add strict=True to zip() (B905)
- Remove unused variable

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
OG T
2026-03-26 16:03:16 +08:00
parent bf32c4b1f2
commit e26ea526b1
3 changed files with 6 additions and 10 deletions

View File

@@ -17,8 +17,6 @@ AI Rate Limiter - Gemini API 用量閥值控制
import structlog
from src.core.config import settings
logger = structlog.get_logger(__name__)

View File

@@ -143,19 +143,19 @@ class OllamaEmbeddingService:
return embedding
except httpx.TimeoutException:
except httpx.TimeoutException as e:
logger.error("embedding_timeout", model=self._model, text_len=len(text))
raise EmbeddingError(f"Embedding timeout after {self._timeout}s")
raise EmbeddingError(f"Embedding timeout after {self._timeout}s") from e
except httpx.HTTPStatusError as e:
logger.error(
"embedding_http_error",
status=e.response.status_code,
model=self._model,
)
raise EmbeddingError(f"Ollama API error: {e.response.status_code}")
raise EmbeddingError(f"Ollama API error: {e.response.status_code}") from e
except Exception as e:
logger.error("embedding_error", error=str(e), model=self._model)
raise EmbeddingError(f"Embedding failed: {e}")
raise EmbeddingError(f"Embedding failed: {e}") from e
async def embed_batch(
self,

View File

@@ -16,14 +16,12 @@ Phase 13.2 #84 - Runbook RAG Tool
import hashlib
import struct
import uuid
from pathlib import Path
from typing import Protocol
import redis.asyncio as redis
import structlog
from src.core.config import settings
from src.services.embedding_service import IEmbeddingService, get_embedding_service
logger = structlog.get_logger(__name__)
@@ -311,7 +309,7 @@ class RAGService:
embeddings = await embedding_service.embed_batch(texts, concurrency=3)
# 儲存到 Redis
for chunk, embedding in zip(all_chunks, embeddings):
for chunk, embedding in zip(all_chunks, embeddings, strict=True):
await self._store_chunk(chunk, embedding)
total_chunks += 1
@@ -373,7 +371,7 @@ class RAGService:
parsed = []
i = 1
while i < len(results):
key = results[i]
# results[i] is the Redis key, results[i+1] is the fields
fields = results[i + 1] if i + 1 < len(results) else []
# 將 fields list 轉為 dict