cat-stack 2.5.1__tar.gz → 2.5.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cat_stack-2.5.1 → cat_stack-2.5.2}/PKG-INFO +6 -4
- {cat_stack-2.5.1 → cat_stack-2.5.2}/README.md +2 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/pyproject.toml +2 -2
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/__about__.py +1 -1
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/_providers.py +56 -4
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/image_functions.py +12 -13
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/pdf_functions.py +15 -15
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/text_functions_ensemble.py +25 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/.gitignore +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/LICENSE +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/cat_stack/__init__.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/__init__.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/_batch.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/_category_analysis.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/_chunked.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/_embeddings.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/_formatter.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/_pilot_test.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/_prompts.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/_review_ui.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/_tiebreaker.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/_utils.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/_web_fetch.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/_wrapper_helpers.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/calls/CoVe.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/calls/__init__.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/calls/image_CoVe.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/calls/image_stepback.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/calls/pdf_CoVe.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/calls/pdf_stepback.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/calls/stepback.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/calls/top_n.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/classify.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/collapse_themes.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/explore.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/extract.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/images/circle.png +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/images/cube.png +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/images/diamond.png +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/images/overlapping_pentagons.png +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/images/rectangles.png +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/model_reference_list.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/prompt_tune.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/summarize.py +0 -0
- {cat_stack-2.5.1 → cat_stack-2.5.2}/src/catstack/text_functions.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: cat-stack
|
|
3
|
-
Version: 2.5.
|
|
3
|
+
Version: 2.5.2
|
|
4
4
|
Summary: Domain-agnostic text, image, PDF, and DOCX classification engine powered by LLMs
|
|
5
5
|
Project-URL: Documentation, https://github.com/chrissoria/cat-stack#readme
|
|
6
6
|
Project-URL: Issues, https://github.com/chrissoria/cat-stack/issues
|
|
@@ -24,9 +24,9 @@ Requires-Dist: pandas
|
|
|
24
24
|
Requires-Dist: requests
|
|
25
25
|
Requires-Dist: tqdm
|
|
26
26
|
Provides-Extra: agent
|
|
27
|
-
Requires-Dist: cat-claws[claude]>=0.3.
|
|
27
|
+
Requires-Dist: cat-claws[claude]>=0.3.2; extra == 'agent'
|
|
28
28
|
Provides-Extra: codex-agent
|
|
29
|
-
Requires-Dist: cat-claws[codex]>=0.3.
|
|
29
|
+
Requires-Dist: cat-claws[codex]>=0.3.2; extra == 'codex-agent'
|
|
30
30
|
Provides-Extra: docx
|
|
31
31
|
Requires-Dist: python-docx>=1.0.0; extra == 'docx'
|
|
32
32
|
Provides-Extra: embeddings
|
|
@@ -241,6 +241,8 @@ All providers use the same `(model_name, provider, api_key)` tuple format. Provi
|
|
|
241
241
|
|
|
242
242
|
**Subscription backends (no API key).** Three `model_source` values authenticate through a chat subscription instead of a metered key — leave `api_key` unset: `"claude-agent"` (Claude subscription via the Agent SDK; `pip install "cat-stack[agent]"`), `"claude-code"` (the Claude Code CLI, if installed — no extra needed), and `"codex-agent"` (ChatGPT subscription; `pip install "cat-stack[codex-agent]"`). Classification, extraction, exploration, and summarization all route through them.
|
|
243
243
|
|
|
244
|
+
**Reproducibility note:** the same nominal model can behave differently across access routes. In a seed-matched benchmark (Claude Sonnet 5, temperature 0), extraction through the Agent SDK produced more varied label phrasings than the direct API (89% vs. 74% unique raw labels), while final consolidated taxonomies were equivalent. If raw label counts matter to your analysis, record the access route alongside the model version.
|
|
245
|
+
|
|
244
246
|
## Features
|
|
245
247
|
|
|
246
248
|
- **Automatic prompt optimization** (`prompt_tune`) — correct a small sample in a browser UI, and the system generates per-category instructions that improve accuracy
|
|
@@ -200,6 +200,8 @@ All providers use the same `(model_name, provider, api_key)` tuple format. Provi
|
|
|
200
200
|
|
|
201
201
|
**Subscription backends (no API key).** Three `model_source` values authenticate through a chat subscription instead of a metered key — leave `api_key` unset: `"claude-agent"` (Claude subscription via the Agent SDK; `pip install "cat-stack[agent]"`), `"claude-code"` (the Claude Code CLI, if installed — no extra needed), and `"codex-agent"` (ChatGPT subscription; `pip install "cat-stack[codex-agent]"`). Classification, extraction, exploration, and summarization all route through them.
|
|
202
202
|
|
|
203
|
+
**Reproducibility note:** the same nominal model can behave differently across access routes. In a seed-matched benchmark (Claude Sonnet 5, temperature 0), extraction through the Agent SDK produced more varied label phrasings than the direct API (89% vs. 74% unique raw labels), while final consolidated taxonomies were equivalent. If raw label counts matter to your analysis, record the access route alongside the model version.
|
|
204
|
+
|
|
203
205
|
## Features
|
|
204
206
|
|
|
205
207
|
- **Automatic prompt optimization** (`prompt_tune`) — correct a small sample in a browser UI, and the system generates per-category instructions that improve accuracy
|
|
@@ -42,8 +42,8 @@ embeddings = ["sentence-transformers>=2.2.0"]
|
|
|
42
42
|
# `agent` keeps its historical meaning (the Claude backend) so every shipped
|
|
43
43
|
# install hint stays true; `codex-agent` matches the provider string so the
|
|
44
44
|
# error-message hint is copy-pasteable.
|
|
45
|
-
agent = ["cat-claws[claude]>=0.3.
|
|
46
|
-
codex-agent = ["cat-claws[codex]>=0.3.
|
|
45
|
+
agent = ["cat-claws[claude]>=0.3.2"]
|
|
46
|
+
codex-agent = ["cat-claws[codex]>=0.3.2"]
|
|
47
47
|
|
|
48
48
|
[project.urls]
|
|
49
49
|
Documentation = "https://github.com/chrissoria/cat-stack#readme"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# SPDX-FileCopyrightText: 2025-present Christopher Soria <chrissoria@berkeley.edu>
|
|
2
2
|
#
|
|
3
3
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
4
|
-
__version__ = "2.5.
|
|
4
|
+
__version__ = "2.5.2"
|
|
5
5
|
__author__ = "Chris Soria"
|
|
6
6
|
__email__ = "chrissoria@berkeley.edu"
|
|
7
7
|
__title__ = "cat-stack"
|
|
@@ -735,8 +735,10 @@ PROVIDER_CONFIG = {
|
|
|
735
735
|
|
|
736
736
|
|
|
737
737
|
# Providers that route through complete() with no HTTP endpoint of their own
|
|
738
|
-
# (subscription logins / CLI). Features that build a direct HTTP request
|
|
739
|
-
#
|
|
738
|
+
# (subscription logins / CLI). Features that build a direct HTTP request can't
|
|
739
|
+
# use them — guard with a clear error, not a deep crash. (Images and PDF pages
|
|
740
|
+
# DO work on the cat-claws agent backends: they go through the adapters'
|
|
741
|
+
# images= argument, see _split_agent_content / _call_agent_image.)
|
|
740
742
|
_SUBSCRIPTION_PROVIDERS = ("claude-code", "claude-agent", "codex-agent")
|
|
741
743
|
|
|
742
744
|
# Agent-SDK backends routed through cat-claws: provider -> (adapter name,
|
|
@@ -748,6 +750,46 @@ _AGENT_BACKENDS = {
|
|
|
748
750
|
}
|
|
749
751
|
|
|
750
752
|
|
|
753
|
+
def _split_agent_content(content):
|
|
754
|
+
"""Split one message's content into (text, images) for the cat-claws
|
|
755
|
+
adapters.
|
|
756
|
+
|
|
757
|
+
Plain-string content is text only. Multimodal content is a list of blocks
|
|
758
|
+
in whichever provider shape the prompt builder produced (Anthropic
|
|
759
|
+
`image` + base64 `source`, OpenAI `image_url` data URL, Google
|
|
760
|
+
`inline_data`); text blocks are joined and image blocks become the
|
|
761
|
+
adapters' ``{"media_type", "data"}`` dicts. Unknown block types are
|
|
762
|
+
dropped rather than stringified into the prompt.
|
|
763
|
+
"""
|
|
764
|
+
if not isinstance(content, list):
|
|
765
|
+
return content, []
|
|
766
|
+
texts, images = [], []
|
|
767
|
+
for block in content:
|
|
768
|
+
if not isinstance(block, dict):
|
|
769
|
+
continue
|
|
770
|
+
kind = block.get("type")
|
|
771
|
+
if kind == "text":
|
|
772
|
+
texts.append(block.get("text", ""))
|
|
773
|
+
elif kind == "image":
|
|
774
|
+
src = block.get("source") or {}
|
|
775
|
+
if src.get("type") == "base64" and src.get("data"):
|
|
776
|
+
images.append({"media_type": src.get("media_type") or "image/png",
|
|
777
|
+
"data": src["data"]})
|
|
778
|
+
elif kind == "image_url":
|
|
779
|
+
url = (block.get("image_url") or {}).get("url", "")
|
|
780
|
+
if url.startswith("data:") and ";base64," in url:
|
|
781
|
+
header, data = url.split(",", 1)
|
|
782
|
+
images.append({"media_type": header[5:].split(";", 1)[0] or "image/png",
|
|
783
|
+
"data": data})
|
|
784
|
+
elif kind == "inline_data" and block.get("data"):
|
|
785
|
+
images.append({"media_type": block.get("mime_type") or "image/png",
|
|
786
|
+
"data": block["data"]})
|
|
787
|
+
for im in images: # the API wants image/jpeg, not image/jpg
|
|
788
|
+
if im["media_type"] == "image/jpg":
|
|
789
|
+
im["media_type"] = "image/jpeg"
|
|
790
|
+
return "\n\n".join(t for t in texts if t), images
|
|
791
|
+
|
|
792
|
+
|
|
751
793
|
def _require_http_provider(model_source, feature):
|
|
752
794
|
"""Raise a clear error when an HTTP-only feature is used with a
|
|
753
795
|
subscription/CLI provider (claude-code / claude-agent / codex-agent)."""
|
|
@@ -1272,17 +1314,26 @@ class UnifiedLLMClient:
|
|
|
1272
1314
|
)
|
|
1273
1315
|
import asyncio
|
|
1274
1316
|
|
|
1317
|
+
# Multimodal content (image summaries, rendered PDF pages) arrives as
|
|
1318
|
+
# a list of blocks: text goes to the prompt, images to the adapter's
|
|
1319
|
+
# `images=` argument (base.AgentAdapter.one_shot contract).
|
|
1275
1320
|
system_parts = []
|
|
1276
1321
|
user_parts = []
|
|
1322
|
+
images = []
|
|
1277
1323
|
for msg in messages:
|
|
1324
|
+
text, msg_images = _split_agent_content(msg["content"])
|
|
1278
1325
|
if msg["role"] == "system":
|
|
1279
|
-
system_parts.append(
|
|
1326
|
+
system_parts.append(text)
|
|
1280
1327
|
elif msg["role"] in ("user", "assistant"):
|
|
1281
|
-
user_parts.append(
|
|
1328
|
+
user_parts.append(text)
|
|
1329
|
+
images.extend(msg_images)
|
|
1282
1330
|
system_prompt = "\n\n".join(system_parts) if system_parts else None
|
|
1283
1331
|
user_prompt = "\n\n".join(user_parts)
|
|
1284
1332
|
|
|
1285
1333
|
adapter = get_adapter(adapter_name)
|
|
1334
|
+
# Only pass images when there are some, so text-only calls are
|
|
1335
|
+
# byte-identical to before.
|
|
1336
|
+
image_kwargs = {"images": images} if images else {}
|
|
1286
1337
|
try:
|
|
1287
1338
|
return asyncio.run(
|
|
1288
1339
|
adapter.one_shot(
|
|
@@ -1290,6 +1341,7 @@ class UnifiedLLMClient:
|
|
|
1290
1341
|
system_prompt=system_prompt,
|
|
1291
1342
|
model=self.model,
|
|
1292
1343
|
thinking_budget=thinking_budget or 0,
|
|
1344
|
+
**image_kwargs,
|
|
1293
1345
|
)
|
|
1294
1346
|
)
|
|
1295
1347
|
except Exception as e:
|
|
@@ -154,12 +154,6 @@ def image_multi_class(
|
|
|
154
154
|
"(the text-only CLI shim). Use model_source='claude-agent' (the cat-claws "
|
|
155
155
|
"subscription backend) or an API-key provider."
|
|
156
156
|
)
|
|
157
|
-
if model_source == "codex-agent":
|
|
158
|
-
raise ValueError(
|
|
159
|
-
"Image classification is not yet supported with "
|
|
160
|
-
"model_source='codex-agent'. Use model_source='claude-agent' (the "
|
|
161
|
-
"multimodal subscription backend) or an API-key provider."
|
|
162
|
-
)
|
|
163
157
|
|
|
164
158
|
image_files = _load_image_files(image_input)
|
|
165
159
|
|
|
@@ -677,15 +671,18 @@ Provide the final categorization in the same JSON format:"""
|
|
|
677
671
|
|
|
678
672
|
return """{"1":"e"}""", "Max retries exceeded"
|
|
679
673
|
|
|
680
|
-
def
|
|
681
|
-
"""Image classification via
|
|
682
|
-
subscription, no API key).
|
|
674
|
+
def _call_agent_image(base_text, encoded, media_type):
|
|
675
|
+
"""Image classification via a cat-claws multimodal adapter
|
|
676
|
+
(claude-agent or codex-agent: subscription login, no API key).
|
|
677
|
+
Returns (reply, error) like _call_anthropic."""
|
|
678
|
+
from ._providers import _AGENT_BACKENDS
|
|
679
|
+
adapter_name, install_hint = _AGENT_BACKENDS[model_source]
|
|
683
680
|
try:
|
|
684
681
|
from catclaws._adapters import get_adapter
|
|
685
682
|
except ImportError:
|
|
686
|
-
return None,
|
|
683
|
+
return None, f"cat-claws is not installed. Run: {install_hint}"
|
|
687
684
|
import asyncio
|
|
688
|
-
adapter = get_adapter(
|
|
685
|
+
adapter = get_adapter(adapter_name)
|
|
689
686
|
_system = ("You are an image classification engine. Follow the user's "
|
|
690
687
|
"instructions exactly and reply with only what they ask for.")
|
|
691
688
|
try:
|
|
@@ -738,9 +735,11 @@ Provide the final categorization in the same JSON format:"""
|
|
|
738
735
|
image_content = {"type": "image_url", "image_url": {"url": encoded_image, "detail": "high"}}
|
|
739
736
|
return _call_mistral(prompt, step2_prompt, step3_prompt, step4_prompt, image_content)
|
|
740
737
|
|
|
741
|
-
elif model_source
|
|
738
|
+
elif model_source in ("claude-agent", "codex-agent"):
|
|
742
739
|
media_type = f"image/{ext}" if ext else "image/jpeg"
|
|
743
|
-
|
|
740
|
+
if media_type == "image/jpg":
|
|
741
|
+
media_type = "image/jpeg"
|
|
742
|
+
return _call_agent_image(base_prompt_text, encoded, media_type)
|
|
744
743
|
|
|
745
744
|
else:
|
|
746
745
|
raise ValueError("Unknown source! Choose from OpenAI, Anthropic, Perplexity, Google, xAI, Huggingface, or Mistral")
|
|
@@ -399,12 +399,6 @@ def pdf_multi_class(
|
|
|
399
399
|
"(the text-only CLI shim). Use model_source='claude-agent' (the cat-claws "
|
|
400
400
|
"subscription backend) or an API-key provider."
|
|
401
401
|
)
|
|
402
|
-
if model_source == "codex-agent":
|
|
403
|
-
raise ValueError(
|
|
404
|
-
"PDF classification is not yet supported with "
|
|
405
|
-
"model_source='codex-agent'. Use model_source='claude-agent' (the "
|
|
406
|
-
"multimodal subscription backend) or an API-key provider."
|
|
407
|
-
)
|
|
408
402
|
|
|
409
403
|
# Providers with native PDF support (only used in image/both modes)
|
|
410
404
|
native_pdf_providers = {"anthropic", "google"}
|
|
@@ -1192,23 +1186,27 @@ Provide the final categorization in the same JSON format:"""
|
|
|
1192
1186
|
|
|
1193
1187
|
return """{"1":"e"}""", "Max retries exceeded"
|
|
1194
1188
|
|
|
1195
|
-
def
|
|
1196
|
-
"""PDF-page classification via
|
|
1197
|
-
|
|
1198
|
-
|
|
1189
|
+
def _call_agent_pdf(base_text, encoded_image):
|
|
1190
|
+
"""PDF-page classification via a cat-claws adapter (claude-agent or
|
|
1191
|
+
codex-agent: subscription login, no API key). The page is rendered to
|
|
1192
|
+
an image (PDF-as-images); encoded_image=None sends text only (mode
|
|
1193
|
+
"text"). Returns (reply, error)."""
|
|
1194
|
+
from ._providers import _AGENT_BACKENDS
|
|
1195
|
+
adapter_name, install_hint = _AGENT_BACKENDS[model_source]
|
|
1199
1196
|
try:
|
|
1200
1197
|
from catclaws._adapters import get_adapter
|
|
1201
1198
|
except ImportError:
|
|
1202
|
-
return None,
|
|
1199
|
+
return None, f"cat-claws is not installed. Run: {install_hint}"
|
|
1203
1200
|
import asyncio
|
|
1204
|
-
adapter = get_adapter(
|
|
1201
|
+
adapter = get_adapter(adapter_name)
|
|
1205
1202
|
_system = ("You are a document-page classification engine. Follow the "
|
|
1206
1203
|
"user's instructions exactly and reply with only what they ask for.")
|
|
1207
1204
|
try:
|
|
1208
1205
|
reply, error = asyncio.run(adapter.one_shot(
|
|
1209
1206
|
base_text, system_prompt=_system, model=user_model,
|
|
1210
1207
|
thinking_budget=thinking_budget or 0,
|
|
1211
|
-
images
|
|
1208
|
+
**({"images": [{"media_type": "image/png", "data": encoded_image}]}
|
|
1209
|
+
if encoded_image else {}),
|
|
1212
1210
|
))
|
|
1213
1211
|
return (None, error) if error else (reply, None)
|
|
1214
1212
|
except Exception as e:
|
|
@@ -1244,6 +1242,8 @@ Provide the final categorization in the same JSON format:"""
|
|
|
1244
1242
|
return _call_openai_text_only(base_prompt_text, step2_prompt, step3_prompt, step4_prompt)
|
|
1245
1243
|
elif model_source == "mistral":
|
|
1246
1244
|
return _call_mistral_text_only(base_prompt_text, step2_prompt, step3_prompt, step4_prompt)
|
|
1245
|
+
elif model_source in ("claude-agent", "codex-agent"):
|
|
1246
|
+
return _call_agent_pdf(base_prompt_text, None)
|
|
1247
1247
|
else:
|
|
1248
1248
|
raise ValueError(f"Unknown source! Choose from OpenAI, Anthropic, Perplexity, Google, xAI, Huggingface, or Mistral")
|
|
1249
1249
|
|
|
@@ -1293,12 +1293,12 @@ Provide the final categorization in the same JSON format:"""
|
|
|
1293
1293
|
prompt_data = _build_prompt_google_pdf(encoded_pdf, base_prompt_text)
|
|
1294
1294
|
return _call_google(prompt_data, step2_prompt, step3_prompt, step4_prompt, base_prompt_text)
|
|
1295
1295
|
|
|
1296
|
-
elif model_source
|
|
1296
|
+
elif model_source in ("claude-agent", "codex-agent"):
|
|
1297
1297
|
image_bytes, is_valid = _extract_page_as_image_bytes(pdf_path, page_index)
|
|
1298
1298
|
if not is_valid:
|
|
1299
1299
|
return None, "Failed to render PDF page to image"
|
|
1300
1300
|
encoded_image = _encode_bytes_to_base64(image_bytes)
|
|
1301
|
-
return
|
|
1301
|
+
return _call_agent_pdf(base_prompt_text, encoded_image)
|
|
1302
1302
|
|
|
1303
1303
|
# Handle providers requiring image conversion
|
|
1304
1304
|
else:
|
|
@@ -3863,6 +3863,17 @@ multi_class_ensemble = classify_ensemble
|
|
|
3863
3863
|
# Summarization helpers
|
|
3864
3864
|
# =============================================================================
|
|
3865
3865
|
|
|
3866
|
+
def _format_item_errors(errors: dict, multi_model: bool) -> str:
|
|
3867
|
+
"""One row's failure reasons for the `error_message` column: the bare
|
|
3868
|
+
message for a single model, "model: message" pairs for an ensemble.
|
|
3869
|
+
Empty string when the row had no errors."""
|
|
3870
|
+
if not errors:
|
|
3871
|
+
return ""
|
|
3872
|
+
if not multi_model:
|
|
3873
|
+
return "; ".join(str(e) for e in errors.values())
|
|
3874
|
+
return "; ".join(f"{m}: {e}" for m, e in errors.items())
|
|
3875
|
+
|
|
3876
|
+
|
|
3866
3877
|
def _save_partial_summarize_results(all_results, model_configs, model_names, is_pdf_mode, filename, save_directory):
|
|
3867
3878
|
"""Save partial summarization results to CSV for safety/incremental saves."""
|
|
3868
3879
|
rows = []
|
|
@@ -3895,6 +3906,7 @@ def _save_partial_summarize_results(all_results, model_configs, model_names, is_
|
|
|
3895
3906
|
) else "partial"
|
|
3896
3907
|
else:
|
|
3897
3908
|
row["processing_status"] = "success"
|
|
3909
|
+
row["error_message"] = _format_item_errors(entry["errors"], len(model_configs) > 1)
|
|
3898
3910
|
|
|
3899
3911
|
rows.append(row)
|
|
3900
3912
|
|
|
@@ -4511,6 +4523,9 @@ def summarize_ensemble(
|
|
|
4511
4523
|
|
|
4512
4524
|
if error and error != "skipped":
|
|
4513
4525
|
still_failed.append((idx, model_name))
|
|
4526
|
+
# Keep the latest reason so the output reports what the
|
|
4527
|
+
# final attempt actually hit.
|
|
4528
|
+
all_results[idx]["errors"][model_name] = error
|
|
4514
4529
|
else:
|
|
4515
4530
|
# Update the stored result
|
|
4516
4531
|
all_results[idx]["model_results"][model_name] = json_result
|
|
@@ -4631,10 +4646,20 @@ def summarize_ensemble(
|
|
|
4631
4646
|
else:
|
|
4632
4647
|
row["processing_status"] = "success"
|
|
4633
4648
|
|
|
4649
|
+
# Why a row failed: previously collected per item but never written
|
|
4650
|
+
# out, so failures were silent (status "error", no reason).
|
|
4651
|
+
row["error_message"] = _format_item_errors(entry["errors"], len(model_configs) > 1)
|
|
4652
|
+
|
|
4634
4653
|
rows.append(row)
|
|
4635
4654
|
|
|
4636
4655
|
df = pd.DataFrame(rows)
|
|
4637
4656
|
|
|
4657
|
+
n_failed = int((df["error_message"] != "").sum()) if "error_message" in df else 0
|
|
4658
|
+
if n_failed:
|
|
4659
|
+
first = df.loc[df["error_message"] != "", "error_message"].iloc[0]
|
|
4660
|
+
print(f"\n[CatLLM] WARNING: {n_failed} of {len(df)} item(s) had errors "
|
|
4661
|
+
f"(see the error_message column). First error: {first}")
|
|
4662
|
+
|
|
4638
4663
|
# Save to file if requested
|
|
4639
4664
|
if filename:
|
|
4640
4665
|
save_path = os.path.join(save_directory, filename) if save_directory else filename
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|