|
| 1 | +# Copyright (c) 2025, Salesforce, Inc. |
| 2 | +# SPDX-License-Identifier: Apache-2 |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +""" |
| 17 | +Pydantic models for byoc-function-proto (uds_chunking.proto) |
| 18 | +Auto-generated - validation rules from buf.validate |
| 19 | +""" |
| 20 | + |
| 21 | +from typing import ( |
| 22 | + Any, |
| 23 | + Dict, |
| 24 | + List, |
| 25 | + Literal, |
| 26 | +) |
| 27 | + |
| 28 | +from pydantic import BaseModel, Field |
| 29 | + |
| 30 | + |
| 31 | +class DocElement(BaseModel): |
| 32 | + """Document element to be chunked""" |
| 33 | + |
| 34 | + text: str = Field(..., description="Text content to be chunked") |
| 35 | + metadata: Dict[str, Any] = Field( |
| 36 | + default_factory=dict, description="Source document metadata" |
| 37 | + ) |
| 38 | + |
| 39 | + |
| 40 | +class ChunkOutput(BaseModel): |
| 41 | + """Output chunk from the chunking process""" |
| 42 | + |
| 43 | + chunk_id: str = Field(..., description="UUID for this chunk") |
| 44 | + chunk_type: str = Field(..., description="Type: 'text'") |
| 45 | + text: str = Field(..., description="Chunk text content") |
| 46 | + seq_no: int = Field(..., description="Sequential chunk number (1-based)") |
| 47 | + metadata: Dict[str, str] = Field( |
| 48 | + default_factory=dict, description="Metadata from source (DMO fields)" |
| 49 | + ) |
| 50 | + tag_metadata: Dict[str, Any] = Field( |
| 51 | + default_factory=dict, description="Additional tags" |
| 52 | + ) |
| 53 | + citations: Dict[str, Any] = Field( |
| 54 | + default_factory=dict, description="Citation information" |
| 55 | + ) |
| 56 | + |
| 57 | + |
| 58 | +class StatusResponse(BaseModel): |
| 59 | + """Status response for operation""" |
| 60 | + |
| 61 | + status_type: str = Field(..., description="'success' or 'error'") |
| 62 | + status_message: str = Field(..., description="Human-readable status") |
| 63 | + |
| 64 | + |
| 65 | +class UdsChunkingV1BatchRequest(BaseModel): |
| 66 | + """Batch request for UDS chunking""" |
| 67 | + |
| 68 | + version: Literal["v1"] = Field( |
| 69 | + default="v1", description="API version, must be 'v1'" |
| 70 | + ) |
| 71 | + input: List[DocElement] = Field( |
| 72 | + ..., min_length=1, description="List of documents (min 1)" |
| 73 | + ) |
| 74 | + max_characters: int = Field(..., description="Max chars per chunk (default: 100)") |
| 75 | + additional_params: Dict[str, Any] = Field( |
| 76 | + default_factory=dict, description="Future extension point" |
| 77 | + ) |
| 78 | + |
| 79 | + |
| 80 | +class UdsChunkingV1BatchResponse(BaseModel): |
| 81 | + """Batch response for UDS chunking""" |
| 82 | + |
| 83 | + version: Literal["v1"] = Field( |
| 84 | + default="v1", description="API version, must be 'v1'" |
| 85 | + ) |
| 86 | + output: List[ChunkOutput] = Field( |
| 87 | + default_factory=list, description="Flat list of chunks from all docs" |
| 88 | + ) |
| 89 | + status: StatusResponse = Field(..., description="Overall operation status") |
0 commit comments