feat(backend): integrate document deletion and grounded speech providers
Enable replay-safe document deletion and public deployment model identifiers with the forward voice-model schema revision. Add GapGPT dialogue and ElevenLabs speech routing, strict extractive grounding, ten-source retrieval and regression coverage. Validation: 199 targeted provider-free tests passed. The full provider-free run stalled and was interrupted; PostgreSQL acceptance was not run because TEST_DATABASE_URL is unset.
This commit is contained in:
@@ -3,6 +3,7 @@ from array import array
|
||||
from contextlib import ExitStack, contextmanager
|
||||
from dataclasses import asdict
|
||||
import json
|
||||
import re
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field, ValidationError, field_validator
|
||||
@@ -75,12 +76,28 @@ def sql_error(exc):
|
||||
and exc.connection_invalidated)))
|
||||
|
||||
|
||||
def clean_search_query(text: str) -> str:
|
||||
cleaned = text
|
||||
patterns = [
|
||||
r"شرکت\s+شهرک[\s]*های\s+صنعتی\s+(?:استان\s+)?اصفهان",
|
||||
r"شهرک[\s]*های\s+صنعتی\s+(?:استان\s+)?اصفهان",
|
||||
r"شرکت\s+شهرک[\s]*های\s+صنعتی",
|
||||
]
|
||||
for pat in patterns:
|
||||
sub = re.sub(pat, "", cleaned, flags=re.IGNORECASE).strip()
|
||||
sub = re.sub(r"^(در|از|به|برای)\s+", "", sub).strip()
|
||||
sub = re.sub(r"\s+(در|از|به|برای)$", "", sub).strip()
|
||||
if len(sub) >= 3:
|
||||
cleaned = sub
|
||||
return re.sub(r"\s+", " ", cleaned).strip()
|
||||
|
||||
|
||||
class SearchInput(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid", strict=True)
|
||||
query: str = Field(
|
||||
min_length=1,
|
||||
max_length=2000,
|
||||
description="Clean, concise search terms or entity names only (e.g. 'آقای دانش' or 'معاون برنامه ریزی'). Do NOT include conversational filler, meta-narration, or 'کاربر میپرسد'."
|
||||
description="Clean, concise search terms or entity names only (e.g. 'آقای دانش' or 'معاون برنامه ریزی'). Do NOT include conversational filler, meta-narration, or 'کاربر میپرسد'. Never append 'شهرکهای صنعتی اصفهان' or expand 'شرکت'."
|
||||
)
|
||||
context: str | None = Field(
|
||||
default=None,
|
||||
@@ -93,8 +110,10 @@ class SearchInput(BaseModel):
|
||||
def database_text(cls, value, info):
|
||||
if value is not None:
|
||||
validate_database_string(value)
|
||||
if info.field_name == "query" and not value.strip():
|
||||
raise ValueError("Search text cannot be blank")
|
||||
if info.field_name == "query":
|
||||
value = clean_search_query(value)
|
||||
if not value.strip():
|
||||
raise ValueError("Search text cannot be blank")
|
||||
return value
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user