|
| 1 | +"""Citation type definitions for the SDK. |
| 2 | +
|
| 3 | +These types are modeled after the Bedrock API. |
| 4 | +""" |
| 5 | + |
| 6 | +from typing import List, Union |
| 7 | + |
| 8 | +from typing_extensions import TypedDict |
| 9 | + |
| 10 | + |
| 11 | +class CitationsConfig(TypedDict): |
| 12 | + """Configuration for enabling citations on documents. |
| 13 | +
|
| 14 | + Attributes: |
| 15 | + enabled: Whether citations are enabled for this document. |
| 16 | + """ |
| 17 | + |
| 18 | + enabled: bool |
| 19 | + |
| 20 | + |
| 21 | +class DocumentCharLocation(TypedDict, total=False): |
| 22 | + """Specifies a character-level location within a document. |
| 23 | +
|
| 24 | + Provides precise positioning information for cited content using |
| 25 | + start and end character indices. |
| 26 | +
|
| 27 | + Attributes: |
| 28 | + documentIndex: The index of the document within the array of documents |
| 29 | + provided in the request. Minimum value of 0. |
| 30 | + start: The starting character position of the cited content within |
| 31 | + the document. Minimum value of 0. |
| 32 | + end: The ending character position of the cited content within |
| 33 | + the document. Minimum value of 0. |
| 34 | + """ |
| 35 | + |
| 36 | + documentIndex: int |
| 37 | + start: int |
| 38 | + end: int |
| 39 | + |
| 40 | + |
| 41 | +class DocumentChunkLocation(TypedDict, total=False): |
| 42 | + """Specifies a chunk-level location within a document. |
| 43 | +
|
| 44 | + Provides positioning information for cited content using logical |
| 45 | + document segments or chunks. |
| 46 | +
|
| 47 | + Attributes: |
| 48 | + documentIndex: The index of the document within the array of documents |
| 49 | + provided in the request. Minimum value of 0. |
| 50 | + start: The starting chunk identifier or index of the cited content |
| 51 | + within the document. Minimum value of 0. |
| 52 | + end: The ending chunk identifier or index of the cited content |
| 53 | + within the document. Minimum value of 0. |
| 54 | + """ |
| 55 | + |
| 56 | + documentIndex: int |
| 57 | + start: int |
| 58 | + end: int |
| 59 | + |
| 60 | + |
| 61 | +class DocumentPageLocation(TypedDict, total=False): |
| 62 | + """Specifies a page-level location within a document. |
| 63 | +
|
| 64 | + Provides positioning information for cited content using page numbers. |
| 65 | +
|
| 66 | + Attributes: |
| 67 | + documentIndex: The index of the document within the array of documents |
| 68 | + provided in the request. Minimum value of 0. |
| 69 | + start: The starting page number of the cited content within |
| 70 | + the document. Minimum value of 0. |
| 71 | + end: The ending page number of the cited content within |
| 72 | + the document. Minimum value of 0. |
| 73 | + """ |
| 74 | + |
| 75 | + documentIndex: int |
| 76 | + start: int |
| 77 | + end: int |
| 78 | + |
| 79 | + |
| 80 | +# Union type for citation locations |
| 81 | +CitationLocation = Union[DocumentCharLocation, DocumentChunkLocation, DocumentPageLocation] |
| 82 | + |
| 83 | + |
| 84 | +class CitationSourceContent(TypedDict, total=False): |
| 85 | + """Contains the actual text content from a source document. |
| 86 | +
|
| 87 | + Contains the actual text content from a source document that is being |
| 88 | + cited or referenced in the model's response. |
| 89 | +
|
| 90 | + Note: |
| 91 | + This is a UNION type, so only one of the members can be specified. |
| 92 | +
|
| 93 | + Attributes: |
| 94 | + text: The text content from the source document that is being cited. |
| 95 | + """ |
| 96 | + |
| 97 | + text: str |
| 98 | + |
| 99 | + |
| 100 | +class CitationGeneratedContent(TypedDict, total=False): |
| 101 | + """Contains the generated text content that corresponds to a citation. |
| 102 | +
|
| 103 | + Contains the generated text content that corresponds to or is supported |
| 104 | + by a citation from a source document. |
| 105 | +
|
| 106 | + Note: |
| 107 | + This is a UNION type, so only one of the members can be specified. |
| 108 | +
|
| 109 | + Attributes: |
| 110 | + text: The text content that was generated by the model and is |
| 111 | + supported by the associated citation. |
| 112 | + """ |
| 113 | + |
| 114 | + text: str |
| 115 | + |
| 116 | + |
| 117 | +class Citation(TypedDict, total=False): |
| 118 | + """Contains information about a citation that references a source document. |
| 119 | +
|
| 120 | + Citations provide traceability between the model's generated response |
| 121 | + and the source documents that informed that response. |
| 122 | +
|
| 123 | + Attributes: |
| 124 | + location: The precise location within the source document where the |
| 125 | + cited content can be found, including character positions, page |
| 126 | + numbers, or chunk identifiers. |
| 127 | + sourceContent: The specific content from the source document that was |
| 128 | + referenced or cited in the generated response. |
| 129 | + title: The title or identifier of the source document being cited. |
| 130 | + """ |
| 131 | + |
| 132 | + location: CitationLocation |
| 133 | + sourceContent: List[CitationSourceContent] |
| 134 | + title: str |
| 135 | + |
| 136 | + |
| 137 | +class CitationsContentBlock(TypedDict, total=False): |
| 138 | + """A content block containing generated text and associated citations. |
| 139 | +
|
| 140 | + This block type is returned when document citations are enabled, providing |
| 141 | + traceability between the generated content and the source documents that |
| 142 | + informed the response. |
| 143 | +
|
| 144 | + Attributes: |
| 145 | + citations: An array of citations that reference the source documents |
| 146 | + used to generate the associated content. |
| 147 | + content: The generated content that is supported by the associated |
| 148 | + citations. |
| 149 | + """ |
| 150 | + |
| 151 | + citations: List[Citation] |
| 152 | + content: List[CitationGeneratedContent] |
0 commit comments