Skip to content

Commit ce2b574

Browse files
committed
fix(text): resolve missing Span import for structured output
- Add lazy import function for Span class to handle runtime usage - Fix NameError in multi-chunk structured output processing - Maintain TYPE_CHECKING imports for development experience - All benchmark tests now passing including structured output - Resolves issue where Span was only available during type checking
1 parent 97c61d8 commit ce2b574

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

datafog/services/text_service.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@
1010

1111
if TYPE_CHECKING:
1212
from datafog.processing.text_processing.regex_annotator.regex_annotator import Span
13+
else:
14+
# Runtime import for Span when needed
15+
Span = None
16+
17+
18+
def _get_span_class():
19+
"""Lazily import Span class when needed."""
20+
global Span
21+
if Span is None:
22+
from datafog.processing.text_processing.regex_annotator.regex_annotator import (
23+
Span,
24+
)
25+
return Span
1326

1427

1528
class TextService:
@@ -172,7 +185,8 @@ def annotate_text_sync(
172185
chunk_spans = self.annotate_text_sync(chunk, structured=True)
173186
# Adjust span positions to account for chunk offset
174187
for span in chunk_spans:
175-
adjusted_span = Span(
188+
SpanClass = _get_span_class()
189+
adjusted_span = SpanClass(
176190
start=span.start + current_offset,
177191
end=span.end + current_offset,
178192
text=span.text,

0 commit comments

Comments
 (0)