Skip to content

Commit c01d724

Browse files
committedMar 21, 2025
- fixed bindings for determining engine token support
1 parent 4ae9c8d commit c01d724

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed
 

‎src/hierarchical.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def __init__(
164164
else:
165165
self.tokenizer = tokenizer
166166
self.chunker = chunker
167-
167+
168168
# Content type is unknown at initialization
169169
self.document_type = None
170170

@@ -253,11 +253,11 @@ def static_context(self):
253253
def _compute_required_tokens(self):
254254
pass
255255

256-
@bind(engine="neurosymbolic", property="api_max_context_tokens")(lambda: 0)
256+
@bind(engine="neurosymbolic", property="max_context_tokens")
257257
def _max_context_tokens(_):
258258
pass
259259

260-
@bind(engine="neurosymbolic", property="api_max_response_tokens")(lambda: 0)
260+
@bind(engine="neurosymbolic", property="max_response_tokens")
261261
def _max_response_tokens(_):
262262
pass
263263

@@ -311,7 +311,7 @@ async def summarize_chunk(chunk):
311311
chunk,
312312
preview=False,
313313
response_format={"type": "json_object"},
314-
**kwargs
314+
**kwargs,
315315
)
316316
return await loop.run_in_executor(None, forward_fn)
317317

@@ -419,7 +419,7 @@ def forward(self, **kwargs) -> Summary:
419419
data = self.content
420420
doc_type = None
421421

422-
while summary_token_count > self.max_output_tokens:
422+
while summary_token_count > self.max_output_tokens:
423423
logger.debug("Chunking content...")
424424
chunks = self.chunk_by_token_count(str(data), chunk_size)
425425
if doc_type is None:
@@ -444,8 +444,6 @@ def forward(self, **kwargs) -> Summary:
444444
if hasattr(res, "type"):
445445
res.type = doc_type
446446

447-
# collect and return results
448-
return res
449447
else:
450448
logger.debug("Content is within token limit, processing in one go...")
451449
logger.debug("Determining document type and language...")
@@ -463,4 +461,9 @@ def forward(self, **kwargs) -> Summary:
463461
)
464462
res.type = doc_type
465463

464+
# log compression ratio
465+
result_tokens = self.compute_required_tokens(res, count_context=False)
466+
logger.debug(
467+
f"Compression ratio: {total_tokens} -> {result_tokens} ({ result_tokens/total_tokens:.2f})"
468+
)
466469
return res

0 commit comments

Comments
 (0)
Please sign in to comment.