Improve validation for space str
CI / lint_and_test (push) Successful in 2m29s
Details
CI / lint_and_test (push) Successful in 2m29s
Details
This commit is contained in:
parent
855bf35454
commit
d32beef6af
|
@ -109,7 +109,7 @@ docker compose up --build
|
||||||
```
|
```
|
||||||
|
|
||||||
### 4. Загрузка базы знаний
|
### 4. Загрузка базы знаний
|
||||||
|
Полоджите файлы/папку с md в data/, а после выполните запрос
|
||||||
```bash
|
```bash
|
||||||
curl -X POST "http://localhost:8000/api/v1/admin/ingest" \
|
curl -X POST "http://localhost:8000/api/v1/admin/ingest" \
|
||||||
-H "Authorization: Bearer your_admin_token"
|
-H "Authorization: Bearer your_admin_token"
|
||||||
|
|
|
@ -12,19 +12,6 @@ def input_validation_node(state: EmailGenerationState) -> EmailGenerationState:
|
||||||
return state
|
return state
|
||||||
|
|
||||||
lead_input = LeadInput(**raw_input)
|
lead_input = LeadInput(**raw_input)
|
||||||
|
|
||||||
if not lead_input.contact.strip():
|
|
||||||
raise ValidationError("Contact cannot be empty")
|
|
||||||
|
|
||||||
if not lead_input.position.strip():
|
|
||||||
raise ValidationError("Position cannot be empty")
|
|
||||||
|
|
||||||
if not lead_input.company_name.strip():
|
|
||||||
raise ValidationError("Company name cannot be empty")
|
|
||||||
|
|
||||||
if not lead_input.segment.strip():
|
|
||||||
raise ValidationError("Segment cannot be empty")
|
|
||||||
|
|
||||||
lead_model = LeadModel.from_input(lead_input)
|
lead_model = LeadModel.from_input(lead_input)
|
||||||
|
|
||||||
state["lead_input"] = lead_input
|
state["lead_input"] = lead_input
|
||||||
|
|
|
@ -1,18 +1,34 @@
|
||||||
from typing import Literal, Optional
|
from typing import Literal, Optional
|
||||||
from pydantic import BaseModel, ConfigDict, EmailStr, Field
|
from pydantic import BaseModel, ConfigDict, EmailStr, Field, field_validator
|
||||||
|
|
||||||
|
|
||||||
class LeadInput(BaseModel):
|
class LeadInput(BaseModel):
|
||||||
contact: str = Field(min_length=1, max_length=100)
|
contact: str = Field(max_length=100)
|
||||||
position: str = Field(min_length=1, max_length=100)
|
position: str = Field(max_length=100)
|
||||||
company_name: str = Field(min_length=1, max_length=100)
|
company_name: str = Field(max_length=100)
|
||||||
segment: str = Field(min_length=1, max_length=100)
|
segment: str = Field(max_length=100)
|
||||||
email: Optional[EmailStr] = None
|
email: Optional[EmailStr] = None
|
||||||
locale: Literal["ru", "en"] = "ru"
|
locale: Literal["ru", "en"] = "ru"
|
||||||
notes: Optional[str] = Field(default=None, max_length=500)
|
notes: Optional[str] = Field(default=None, max_length=500)
|
||||||
|
|
||||||
model_config = ConfigDict(populate_by_name=True)
|
model_config = ConfigDict(populate_by_name=True)
|
||||||
|
|
||||||
|
@field_validator("contact", "position", "company_name", "segment")
|
||||||
|
@classmethod
|
||||||
|
def validate_required_fields(cls, v: str) -> str:
|
||||||
|
if not v or not v.strip():
|
||||||
|
raise ValueError("Field cannot be empty or contain only whitespace")
|
||||||
|
return v.strip()
|
||||||
|
|
||||||
|
@field_validator("notes")
|
||||||
|
@classmethod
|
||||||
|
def validate_notes(cls, v: Optional[str]) -> Optional[str]:
|
||||||
|
if v is None:
|
||||||
|
return None
|
||||||
|
if not v.strip():
|
||||||
|
return None
|
||||||
|
return v.strip()
|
||||||
|
|
||||||
|
|
||||||
class LeadModel(BaseModel):
|
class LeadModel(BaseModel):
|
||||||
contact_name: str
|
contact_name: str
|
||||||
|
|
Loading…
Reference in New Issue