|
| 1 | +from enum import Enum |
| 2 | +from typing import List, Optional, Union |
| 3 | +from pydantic import BaseModel, Field, RootModel, ConfigDict |
| 4 | +from guardrails.classes.validation_outcome import ValidationOutcome |
| 5 | + |
| 6 | + |
| 7 | +class Evidence(BaseModel): |
| 8 | + source: str = Field( |
| 9 | + title="Source", |
| 10 | + example="https://en.wikipedia.org/wiki/IBM", |
| 11 | + description="Source of the evidence, it can be url of the evidence etc", |
| 12 | + ) |
| 13 | + |
| 14 | + |
| 15 | +class EvidenceType(str, Enum): |
| 16 | + url = "url" |
| 17 | + title = "title" |
| 18 | + |
| 19 | + |
| 20 | +class EvidenceObj(BaseModel): |
| 21 | + type: EvidenceType = Field( |
| 22 | + title="EvidenceType", |
| 23 | + example="url", |
| 24 | + description="Type field signifying the type of evidence provided. Example url, title etc", |
| 25 | + ) |
| 26 | + evidence: Evidence = Field( |
| 27 | + description="Evidence object, currently only containing source, but in future can contain other optional arguments like id, etc", |
| 28 | + ) |
| 29 | + |
| 30 | + |
| 31 | +class ContentAnalysisHttpRequest(BaseModel): |
| 32 | + contents: List[str] = Field( |
| 33 | + min_length=1, |
| 34 | + title="Contents", |
| 35 | + description="Field allowing users to provide list of texts for analysis. Note, results of this endpoint will contain analysis / detection of each of the provided text in the order they are present in the contents object.", |
| 36 | + example=[ "My email address is [email protected] and [email protected]"], |
| 37 | + ) |
| 38 | + |
| 39 | + |
| 40 | +class ContentAnalysisResponse(BaseModel): |
| 41 | + model_config = ConfigDict(arbitrary_types_allowed=True) |
| 42 | + start: int = Field(example=14) |
| 43 | + end: int = Field(example=26) |
| 44 | + detection_type: str = Field(example="detection_type") |
| 45 | + text: str = Field( |
| 46 | + example="My email address is [email protected] and [email protected]" |
| 47 | + ) |
| 48 | + validation_result: Union[Exception, ValidationOutcome] |
| 49 | + evidences: Optional[List[EvidenceObj]] = Field( |
| 50 | + description="Optional field providing evidences for the provided detection", |
| 51 | + default=[], |
| 52 | + ) |
| 53 | + |
| 54 | + |
| 55 | +class ContentsAnalysisResponse(RootModel): |
| 56 | + root: List[List[ContentAnalysisResponse]] = Field( |
| 57 | + title="Response Text Content Analysis Unary Handler Api V1 Text Content Post" |
| 58 | + ) |
| 59 | + |
| 60 | + |
| 61 | +class Error(BaseModel): |
| 62 | + code: int |
| 63 | + message: str |
0 commit comments