added neutralization option to indexing new connections

This commit is contained in:
Ida 2026-04-29 14:16:52 +02:00
parent 93cb6939dc
commit 4a840e9e6e

View file

@ -164,12 +164,29 @@ class AiService:
# SPEECH_TEAMS: Dedicated pipeline, bypasses standard model selection # SPEECH_TEAMS: Dedicated pipeline, bypasses standard model selection
if request.options and request.options.operationType == OperationTypeEnum.SPEECH_TEAMS: if request.options and request.options.operationType == OperationTypeEnum.SPEECH_TEAMS:
return await self._handleSpeechTeams(request) return await self._handleSpeechTeams(request)
# FAIL-SAFE: Pre-flight billing validation (like 0 CHF credit card check) _opType = request.options.operationType if request.options else None
self._preflightBillingCheck() _isNeutralizationCall = _opType in (
OperationTypeEnum.NEUTRALIZATION_TEXT,
# Balance & provider permission checks OperationTypeEnum.NEUTRALIZATION_IMAGE,
await self._checkBillingBeforeAiCall() )
if not _isNeutralizationCall:
# FAIL-SAFE: Pre-flight billing validation (like 0 CHF credit card check)
self._preflightBillingCheck()
# Balance & provider permission checks
await self._checkBillingBeforeAiCall()
else:
# Neutralization calls are system-level operations (connector anonymization).
# They run without a mandate context (e.g. personal-scope connections) and
# are billed the same way as embedding calls: best-effort, skipped when no
# billing settings exist for an empty mandate.
logger.debug(
"callAi: skipping billing preflight for neutralization call "
"(operationType=%s, user=%s)",
_opType,
getattr(getattr(self.services, 'user', None), 'id', 'unknown'),
)
# Calculate effective allowedProviders: RBAC ∩ Workflow # Calculate effective allowedProviders: RBAC ∩ Workflow
effectiveProviders = self._calculateEffectiveProviders() effectiveProviders = self._calculateEffectiveProviders()
@ -218,8 +235,15 @@ class AiService:
Rehydration happens on the final AiCallResponse (not on individual str deltas). Rehydration happens on the final AiCallResponse (not on individual str deltas).
""" """
await self.ensureAiObjectsInitialized() await self.ensureAiObjectsInitialized()
self._preflightBillingCheck()
await self._checkBillingBeforeAiCall() _streamOpType = request.options.operationType if request.options else None
_isNeutralizationStream = _streamOpType in (
OperationTypeEnum.NEUTRALIZATION_TEXT,
OperationTypeEnum.NEUTRALIZATION_IMAGE,
)
if not _isNeutralizationStream:
self._preflightBillingCheck()
await self._checkBillingBeforeAiCall()
effectiveProviders = self._calculateEffectiveProviders() effectiveProviders = self._calculateEffectiveProviders()
if effectiveProviders and request.options: if effectiveProviders and request.options: