feat: security(CORS/API key), OpenAI-compatible endpoint, Paperless hook indexing; .env support
This commit is contained in:
19
server/utils.py
Normal file
19
server/utils.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import List
|
||||
|
||||
|
||||
def chunk_text(text: str, max_chars: int = 1200, overlap: int = 200) -> List[str]:
|
||||
chunks: List[str] = []
|
||||
start = 0
|
||||
n = len(text)
|
||||
while start < n:
|
||||
end = min(start + max_chars, n)
|
||||
chunk = text[start:end].strip()
|
||||
if chunk:
|
||||
chunks.append(chunk)
|
||||
if end == n:
|
||||
break
|
||||
start = max(0, end - overlap)
|
||||
return chunks
|
||||
|
||||
Reference in New Issue
Block a user