File size: 732 Bytes
454a778 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | from typing import Optional
from .config import EXPERIMENTAL_CONFIDENCE_THRESHOLD, FLAGS_ENABLED
EXPERIMENTAL_PREFIX = "[EXPERIMENTAL]"
UNCERTAIN_PREFIX = "[UNCERTAIN]"
def flag_response(response: str, confidence: float, is_experimental_code: bool = False) -> str:
if not FLAGS_ENABLED:
return response
prefix = ""
if is_experimental_code:
prefix = EXPERIMENTAL_PREFIX
elif confidence < EXPERIMENTAL_CONFIDENCE_THRESHOLD:
prefix = UNCERTAIN_PREFIX
if prefix and not response.startswith(prefix):
return f"{prefix} {response}"
return response
def is_flagged(response: str) -> bool:
return response.startswith(EXPERIMENTAL_PREFIX) or response.startswith(UNCERTAIN_PREFIX)
|