open-notebook/open_notebook/utils/__init__.py
Luis Novo 11ca9c138c
refactor(api): single context-building implementation (#1079)
Consolidate the three copies of context assembly into
open_notebook/utils/context_builder.py:

- POST /api/chat/context now delegates to build_notebook_context()
  (same request/response shapes, same string-matching config semantics)
- The source-chat graph now calls build_source_context() instead of the
  495-line generalized ContextBuilder class, which had exactly one
  caller and whose notebook/notes/priority-config flexibility was dead
- POST /api/notebooks/{notebook_id}/context removed: it duplicated
  /api/chat/context with a slightly different envelope and had zero
  callers (frontend, docs, tests)

Behavior is pinned by new characterization tests written before the
refactor (tests/test_context_endpoint_characterization.py) plus unit
tests for build_source_context.
2026-07-11 19:55:46 -03:00

72 lines
1.8 KiB
Python

"""
Utils package for Open Notebook.
To avoid circular imports, import functions directly:
- from open_notebook.utils.context_builder import build_notebook_context, build_source_context
- from open_notebook.utils import token_count, compare_versions
- from open_notebook.utils.chunking import chunk_text, detect_content_type, ContentType
- from open_notebook.utils.embedding import generate_embedding, generate_embeddings
- from open_notebook.utils.encryption import encrypt_value, decrypt_value
"""
from .chunking import (
CHUNK_SIZE,
ContentType,
chunk_text,
detect_content_type,
detect_content_type_from_extension,
detect_content_type_from_heuristics,
)
from .embedding import (
generate_embedding,
generate_embeddings,
mean_pool_embeddings,
)
from .encryption import (
decrypt_value,
encrypt_value,
)
from .model_utils import full_model_dump
from .text_utils import (
clean_thinking_content,
parse_thinking_content,
remove_non_ascii,
remove_non_printable,
)
from .token_utils import token_cost, token_count
from .version_utils import (
compare_versions,
get_installed_version,
get_version_from_github,
)
__all__ = [
# Chunking
"CHUNK_SIZE",
"ContentType",
"chunk_text",
"detect_content_type",
"detect_content_type_from_extension",
"detect_content_type_from_heuristics",
# Embedding
"generate_embedding",
"generate_embeddings",
"mean_pool_embeddings",
# Text utils
"remove_non_ascii",
"remove_non_printable",
"parse_thinking_content",
"clean_thinking_content",
# Token utils
"token_count",
"token_cost",
# Version utils
"compare_versions",
"get_installed_version",
"get_version_from_github",
# Encryption utils
"decrypt_value",
"encrypt_value",
# Model utils
"full_model_dump",
]