mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
fix(backend/store): deduplicate missing API key error logs
Only log "openai_internal_api_key not set" error once per process instead of on every embedding generation attempt. Reduces log spam when processing batch operations without an API key configured.
This commit is contained in:
@@ -21,6 +21,8 @@ from backend.util.json import dumps
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Track if we've already logged the missing API key error
|
||||
_missing_api_key_logged = False
|
||||
|
||||
# OpenAI embedding model configuration
|
||||
EMBEDDING_MODEL = "text-embedding-3-small"
|
||||
@@ -70,10 +72,17 @@ async def generate_embedding(text: str) -> list[float] | None:
|
||||
Returns None if embedding generation fails.
|
||||
Fail-fast: no retries to maintain consistency with approval flow.
|
||||
"""
|
||||
global _missing_api_key_logged
|
||||
|
||||
try:
|
||||
client = get_openai_client()
|
||||
if not client:
|
||||
logger.error("openai_internal_api_key not set, cannot generate embedding")
|
||||
if not _missing_api_key_logged:
|
||||
logger.error(
|
||||
"openai_internal_api_key not set, cannot generate embeddings. "
|
||||
"This message will only be shown once."
|
||||
)
|
||||
_missing_api_key_logged = True
|
||||
return None
|
||||
|
||||
# Truncate text to token limit using tiktoken
|
||||
|
||||
Reference in New Issue
Block a user