Skip to content

Commit c9310f1

Browse files
CopilotMte90
andcommitted
Clean up redundant config and comments
- Remove duplicate config settings (EMBEDDING_API_URL, EMBEDDING_API_KEY, EMBEDDING_MODEL_NAME) - EmbeddingClient now uses CFG values directly for api_url, api_key, and model - Remove unnecessary comments in analyzer.py - Keep only timeout, retries, and backoff as environment-configurable overrides Co-authored-by: Mte90 <403283+Mte90@users.noreply.github.com>
1 parent e73edcd commit c9310f1

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

ai/analyzer.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,9 @@ def _get_embedding_with_semaphore(semaphore: threading.Semaphore, text: str, fil
6767
"""
6868
Wrapper to acquire semaphore inside executor task to avoid deadlock.
6969
The semaphore is acquired in the worker thread, not the main thread.
70-
Now uses EmbeddingClient for better logging and error handling.
7170
"""
7271
semaphore.acquire()
7372
try:
74-
# Use the embedding client with enhanced logging
7573
return _embedding_client.embed_text(text, file_path=file_path, chunk_index=chunk_index)
7674
finally:
7775
semaphore.release()

ai/openai.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@
2121
# Embedding client logger
2222
_embedding_logger = logging.getLogger("ai.analyzer.embedding")
2323

24-
# Embedding client configuration (can override via environment)
25-
EMBEDDING_API_URL = os.getenv("PICOCODE_EMBEDDING_URL", CFG.get("api_url", "https://example.com/v1/embeddings"))
26-
EMBEDDING_API_KEY = os.getenv("PICOCODE_EMBEDDING_API_KEY", CFG.get("api_key", ""))
24+
# Embedding client configuration (uses CFG values, can override specific ones via environment)
2725
DEFAULT_TIMEOUT = float(os.getenv("PICOCODE_EMBEDDING_TIMEOUT", "30")) # seconds per request
2826
MAX_RETRIES = int(os.getenv("PICOCODE_EMBEDDING_RETRIES", "2"))
2927
BACKOFF_FACTOR = float(os.getenv("PICOCODE_EMBEDDING_BACKOFF", "1.5"))
30-
EMBEDDING_MODEL_NAME = os.getenv("PICOCODE_EMBEDDING_MODEL", DEFAULT_EMBEDDING_MODEL or "text-embedding-3-small")
3128

3229
# Optionally enable requests debug logging by setting PICOCODE_HTTP_DEBUG=true
3330
if os.getenv("PICOCODE_HTTP_DEBUG", "").lower() in ("1", "true", "yes"):
@@ -132,21 +129,21 @@ class EmbeddingClient:
132129
Provides better debugging for embedding API failures.
133130
"""
134131
def __init__(self,
135-
api_url: str = EMBEDDING_API_URL,
136-
api_key: str = EMBEDDING_API_KEY,
137-
model: str = EMBEDDING_MODEL_NAME,
132+
api_url: Optional[str] = None,
133+
api_key: Optional[str] = None,
134+
model: Optional[str] = None,
138135
timeout: float = DEFAULT_TIMEOUT,
139136
max_retries: int = MAX_RETRIES,
140137
backoff: float = BACKOFF_FACTOR):
141-
self.api_url = api_url
142-
self.api_key = api_key
143-
self.model = model
138+
self.api_url = api_url or CFG.get("api_url")
139+
self.api_key = api_key or CFG.get("api_key")
140+
self.model = model or DEFAULT_EMBEDDING_MODEL or "text-embedding-3-small"
144141
self.timeout = timeout
145142
self.max_retries = max_retries
146143
self.backoff = backoff
147144
self.session = requests.Session()
148-
if api_key:
149-
self.session.headers.update({"Authorization": f"Bearer {api_key}"})
145+
if self.api_key:
146+
self.session.headers.update({"Authorization": f"Bearer {self.api_key}"})
150147
self.session.headers.update({"Content-Type": "application/json"})
151148

152149
def _log_request_start(self, request_id: str, file_path: str, chunk_index: int, chunk_len: int):

0 commit comments

Comments
 (0)