Spaces:
Running
Running
File size: 1,240 Bytes
c2ea5ed ea56a51 c2ea5ed ea56a51 c2ea5ed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
from pydantic import BaseModel, Field
from typing import Optional
class ContentReference(BaseModel):
"""
Reference to content location in the original trace using line numbers and character positions.
"""
line_start: Optional[int] = Field(None,
description="""Starting line number where the content begins (1-based indexing from <L1>, <L2>... markers)."""
)
line_end: Optional[int] = Field(None,
description="""Ending line number where content ends (1-based indexing from <L1>, <L2>... markers)."""
)
def validate_line_range(self) -> bool:
"""Validate that line_end >= line_start"""
return self.line_end >= self.line_start
def get_line_count(self) -> int:
"""Get the number of lines this reference spans"""
return self.line_end - self.line_start + 1
def is_single_line(self) -> bool:
"""Check if this reference is within a single line"""
return self.line_start == self.line_end
def __str__(self) -> str:
"""String representation for debugging"""
if self.is_single_line():
return f"Line {self.line_start}"
else:
return f"Lines {self.line_start}-{self.line_end}" |