Skip to content

Commit 115bae1

Browse files
Merge pull request #115 from djarecka/pre-commit_fix_new
Pre commit fix
2 parents 4a4bc89 + c8c9884 commit 115bae1

84 files changed

Lines changed: 3420 additions & 3155 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env_example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ CREWAI_DISABLE_TRACING=true
1010
CREWAI_TELEMETRY=false
1111
OTEL_SDK_DISABLED=true
1212
ENABLE_HUMAN_FEEDBACK=false
13-
ENABLE_CREW_MEMORY=false
13+
ENABLE_CREW_MEMORY=false

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,5 @@ jobs:
134134
shell: bash
135135
- name: Run pre-commit
136136
run: |
137-
poetry run pre-commit run --all-files
137+
poetry run pre-commit run --all-files --show-diff-on-failure
138138
shell: bash

.pre-commit-config.yaml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
fail_fast: false
22

3+
_exclude_default: &exclude_default \.(pdf|svg|png|jpg|jpeg|zip|json)$|^evaluation/(?!.*\.(md|yaml|py)$).*$
4+
_exclude_codespell: &exclude_codespell \.(pdf|svg|png|jpg|jpeg|zip|json)$|^evaluation/(?!.*\.(md|yaml)$).*$
5+
36
repos:
47
- repo: https://github.com/python-poetry/poetry
58
rev: 2.1.3
@@ -12,19 +15,11 @@ repos:
1215
- id: ruff
1316
- id: ruff-format
1417

15-
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
16-
rev: v2.13.0
18+
- repo: https://github.com/ComPWA/taplo-pre-commit
19+
rev: v0.9.3
1720
hooks:
18-
- id: pretty-format-yaml
19-
args:
20-
- --autofix
21-
- --indent=2
22-
- id: pretty-format-toml
21+
- id: taplo-format
2322
exclude: ^poetry.lock$
24-
args:
25-
- --autofix
26-
- --indent=2
27-
- --no-sort
2823

2924
- repo: https://github.com/pre-commit/pre-commit-hooks
3025
rev: v4.6.0
@@ -33,15 +28,19 @@ repos:
3328
args: [--maxkb=15000]
3429
- id: check-case-conflict
3530
- id: end-of-file-fixer
31+
exclude: *exclude_default
3632
- id: trailing-whitespace
37-
- id: pretty-format-json
38-
args:
39-
- --autofix
40-
- --indent=4
41-
- --no-sort-keys
33+
exclude: *exclude_default
34+
# removing checks for json since they are mostly results (we can think about it later)
35+
# - id: pretty-format-json
36+
# args:
37+
# - --autofix
38+
# - --indent=4
39+
# - --no-sort-keys
4240
- id: check-merge-conflict
4341
- id: check-yaml
44-
- id: check-json
42+
# removing checks for json since they are mostly results (we can think about it later)
43+
# - id: check-json
4544
- id: check-toml
4645
- id: detect-private-key
4746
- id: name-tests-test
@@ -50,8 +49,9 @@ repos:
5049
rev: v2.3.0
5150
hooks:
5251
- id: codespell
52+
exclude: *exclude_codespell
5353
args:
54-
- --skip=poetry.lock,docs_style/pdoc-theme/syntax-highlighting.css,*.cha,*.ipynb,example/sample_metadata.csv,evaluation/benchmark,evaluation/pdf2reproschema/old,evaluation/ner/old,evaluation/pdf2reproschema/old/evaluation
54+
- --skip=poetry.lock,docs_style/pdoc-theme/syntax-highlighting.css,*.cha
5555
- --ignore-words-list=SIE,sie
5656

5757
- repo: https://github.com/hija/clean-dotenv

CHANGE_LOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The current version implements the following specialized tool (see figure) for N
88
![](docs/design_docs/ner_tool.png)
99
### 2. Implements the specialized concept mapping tool, `Concept Mapping tool`, avoiding the need for manually maintaining the ontology database.
1010
- The concept mapping tool implements features such as throttling (see default values below), i.e., minimum seconds between BioPortal requests (throttle; lower = faster, higher 429 risk). This done to take into account the rate limit of the bioportal.
11-
11+
1212
| Variable | Where used | Default | Description |
1313
|----------|------------|---------|-------------|
1414
| `BIOPORTAL_API_KEY` | `conceptmappingtool.py` || **Required** for ConceptMappingTool. Used in Authorization header. |
@@ -17,7 +17,7 @@ The current version implements the following specialized tool (see figure) for N
1717
| `MAX_CONCEPT_MAPPING_RESULTS` | `conceptmappingtool.py` | `1` | Top-N results per concept (1–50). |
1818
| `CONCEPT_MAPPING_CACHE_SIZE` | `conceptmappingtool.py` | `2000` | Max in-memory cache entries for concept mapping. |
1919
| `CONCEPT_MAPPING_MAX_TERMS` | `postprocessing.py` || Optional cap on how many unique terms are mapped in batch (rest get null). |
20-
20+
2121
- To avoid the continuous API call, it implements the inmemory caching (to be replaced with new caching mechanism), i.e., `_CONCEPT_MAPPING_CACHE` (dict). The cache size is default `2000` set with `CONCEPT_MAPPING_CACHE_SIZE`. The FIFO-style cache eviction is applied, i.e., when the cache is full, one oldest entry is removed before inserting a new one. The lookup is done using `_map_single_concept()` before making an API call.
2222
### 3. Implements automatic task detection
2323
This version of **`StructSense`** introduces automatic task detection to support accurate task-to-tool mapping, enabling agents to invoke the most relevant tools for a given task.
@@ -30,7 +30,7 @@ The implementation combines an **LLM-based classifier** with a **heuristic fallb
3030
| `"structured extraction"` or `"structured_extraction"` | `structured_extraction` |
3131
| Otherwise | `extraction` |
3232

33-
Task detection is executed **once per stage** at the point where tools and post-processing are selected (e.g., `information_extraction_task`).
33+
Task detection is executed **once per stage** at the point where tools and post-processing are selected (e.g., `information_extraction_task`).
3434
In the full pipeline, the **first stage’s task type** determines the post-processing key and the default result shape. While each stage may theoretically define its own task type, the initial stage serves as the canonical reference for downstream processing.
3535

3636
### 4. Fixed chunking behavior

DEVELOPER.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
# StructSense Information for Developer
1+
# StructSense Information for Developer
22

33
This document provides the overview of the major **StructSense** component and flow.
44

55
## Key Functions
66

77
### Pipeline entry and flow
8-
- **`StructSenseFlow.information_extraction_task()`** (`app.py`)
8+
- **`StructSenseFlow.information_extraction_task()`** (`app.py`)
99
Main entry: runs extraction → alignment → judge → humanfeedback in order; builds `final`, injects `aligned_resources` for resource task, calls `promote_canonical_resources_for_resource_task`, handles skip end concept mapping and provenance.
10-
- **`StructSenseFlow.run_agent_task()`** (`app.py`)
10+
- **`StructSenseFlow.run_agent_task()`** (`app.py`)
1111
Runs one agent–task pair (with optional chunking). Used by the pipeline for each stage and by CLI `run-agent`. Passes `pick_richest_alignment` for resource alignment so multiple alignment blobs are returned for merge.
12-
- **`StructSenseFlow._get_detected_task_type()`** (`app.py`)
12+
- **`StructSenseFlow._get_detected_task_type()`** (`app.py`)
1313
Returns `"ner"`, `"resource"`, `"structured_extraction"`, or `"extraction"` from task config (LLM or heuristic). Drives post-processor, merger, and whether alignment blobs are extracted for merge.
1414
### Crew run and parsing
1515

16-
- **`run_crew_extraction()` / `run_crew_extraction_async()`** (`crew_utils.py`)
16+
- **`run_crew_extraction()` / `run_crew_extraction_async()`** (`crew_utils.py`)
1717
Generic crew runner: no-chunk path (single run) or chunked path. No-chunk path can return multiple results when alignment returns multiple blobs (`pick_richest_alignment` + `_parse_crew_output_alignment_blobs`).
1818

19-
- **`_run_crew_on_retry()` / `_run_crew_on_retry_async()`** (`crew_utils.py`)
19+
- **`_run_crew_on_retry()` / `_run_crew_on_retry_async()`** (`crew_utils.py`)
2020
One (or two on retry) crew kickoff; parse string output via `_parse_raw_string``_parse_crew_output_alignment_blobs` (if alignment resource) or `_parse_crew_output_string`.
2121

22-
- **`_parse_crew_output_alignment_blobs(s)`** (`crew_utils.py`)
22+
- **`_parse_crew_output_alignment_blobs(s)`** (`crew_utils.py`)
2323
Extracts all top-level JSON blobs with `aligned_resources` and returns a list (2+) or single dict so the app can merge them in postprocessing.
2424

25-
- **`_extract_all_json_blobs(s)`** (`crew_utils.py`)
25+
- **`_extract_all_json_blobs(s)`** (`crew_utils.py`)
2626
Brace-matching extraction of every `{...}` in a string; used to get multiple alignment blocks from one LLM response.
2727

2828
The other functions include tool registration and invocation and merging results.
2929

30-
## Module Overview
30+
## Module Overview
3131

3232
- **`src/structsense/app.py`**: Main entry point for **StructSense**, responsible for initializing the pipeline and orchestrating agent execution.
3333
- **`src/structsense/cli.py`**: Defines and handles command-line interface (CLI) options for running **StructSense**.
@@ -52,7 +52,7 @@ The other functions include tool registration and invocation and merging results
5252
Tools are attached **per stage (agent) and per task type**. The flow is:
5353
- **Task type** is detected from the extractor task description (`task_detection.py`).
5454
- **Tool names** for that (agent_key, task_type) come from `task_tools.py` (generic + task-specific).
55-
- **Tool names** are resolved to **CrewAI tool instances** in `_resolve_tool()` in `task_tools.py`.
55+
- **Tool names** are resolved to **CrewAI tool instances** in `_resolve_tool()` in `task_tools.py`.
5656
- The agent is built with those tools; CrewAI runs the agent and the LLM can **call** the tools during execution.
5757

5858
### Steps to Add a New Tool
@@ -67,7 +67,7 @@ Tools are attached **per stage (agent) and per task type**. The flow is:
6767
- To add a new tool, update `_resolve_tool(name, ...)` in `src/utils/task_tools.py` to map the tool name to its corresponding function or instantiated class.
6868

6969
**Example (function tool):**
70-
70+
7171
```python
7272
# In task_tools.py _resolve_tool()
7373
if name == "your_new_tool":
@@ -112,13 +112,13 @@ The pipeline detects **task type** from the extractor task description (LLM or h
112112

113113
Tools are resolved **per stage (agent) and task type** so different agents and tasks can use different tools.
114114

115-
- **Stage (agent)**
115+
- **Stage (agent)**
116116
Only the **extractor** stage receives tools by default; **alignment**, **judge**, and **human_feedback** use no tools (LLM-only).
117117

118-
- **Generic tools**
118+
- **Generic tools**
119119
An agent can have **generic** tools that apply to **all** task types (e.g. a shared search or lookup). Configured in `GENERIC_TOOLS_BY_STAGE` in `src/utils/task_tools.py`.
120120

121-
- **Task-specific tools**
121+
- **Task-specific tools**
122122
Task types (e.g. `ner`, `keyphrase_extraction`) get additional tools (e.g. `extract_ner_terms`). Configured in `TOOLS_BY_TASK_TYPE` (in `task_detection`) for the extractor and in `TOOLS_BY_STAGE_AND_TASK` for other agents.
123123

124124
**Current mapping:**

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ If you find this work useful or build upon it, please consider citing:
3131
- [Python](#python)
3232
- [Configuration](#configuration)
3333
- [Config file structure](#config-file-structure)
34-
- [Task types](#task-types)
34+
- [Task types](#task-types)
3535
- [Pipeline Options](#pipeline-options)
3636
- [Skip pipeline stages](#skip-pipeline-stages)
3737
- [Alignment options](#alignment-options)
@@ -67,7 +67,7 @@ The figure below illustrates the overall architecture of **StructSense**.
6767

6868
<img width="2571" height="823" alt="with_arch_search-with_search_api drawio (1)" src="https://github.com/user-attachments/assets/8f652c10-4301-4193-b1c8-f750229f972c" />
6969

70-
StructSense integrates a local concept mapping service, which can also be used independently. The service is available here:
70+
StructSense integrates a local concept mapping service, which can also be used independently. The service is available here:
7171
- https://github.com/sensein/search_hybrid
7272

7373
---
@@ -145,7 +145,7 @@ with open("result.json", "w") as f:
145145
## Advanced Usage
146146

147147
### Using CLI
148-
148+
149149
#### Full pipeline
150150

151151
Runs extraction → alignment → judge → optional human feedback and returns the final structured result.
@@ -558,7 +558,7 @@ flow = StructSenseFlow(..., skip_judge_llm=True)
558558
|---|---|
559559
| `False` / `None` (default) | Run judge |
560560
| `True` | No LLM call — all entities receive `judge_score=1.0`, `remarks="auto-approved"` |
561-
561+
562562
#### Run the custom judge agent or through CrewAI (`direct_judge_api`)
563563

564564
When `direct_judge_api=True` (default), the judge LLM is still used, but it does **not** run through the CrewAI agent loop. Instead, StructSense uses a custom implementation that calls the LLM directly through `AsyncOpenAI` in parallel batches with retry support.
@@ -620,7 +620,7 @@ You can preload multiple stages. `--source` / `--source_text` is still required
620620
*Preloading multiple stages:*
621621

622622
```bash
623-
structsense-cli extract --env_file=.env --save_file=output.json --chunk_size=2000 --max_workers=8 --enable_chunking --config=some-config.yaml --source=vitpose.pdf --preload_stage extraction_task:00_extractor_agent_extraction_task.json --preload_stage alignment_task:01_alignment_agent_alignment_task.json --api_key=sk-or-v
623+
structsense-cli extract --env_file=.env --save_file=output.json --chunk_size=2000 --max_workers=8 --enable_chunking --config=some-config.yaml --source=vitpose.pdf --preload_stage extraction_task:00_extractor_agent_extraction_task.json --preload_stage alignment_task:01_alignment_agent_alignment_task.json --api_key=sk-or-v
624624
```
625625
---
626626

@@ -649,7 +649,7 @@ LOCAL_CONCEPT_MAPPING_URL=http://localhost:8000
649649
| `LOCAL_CONCEPT_MAPPING_TIMEOUT` | `30` | Request timeout in seconds |
650650
| `MAX_CONCEPT_MAPPING_RESULTS` | `1` | Results per term (1–20) |
651651

652-
652+
653653
### BioPortal
654654

655655
Uses the [BioPortal](https://bioportal.bioontology.org/) REST API for ontology lookup with automatic ontology detection.

config_template/.env_example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ CREWAI_DISABLE_TRACING=true
1010
CREWAI_TELEMETRY=false
1111
OTEL_SDK_DISABLED=true
1212
ENABLE_HUMAN_FEEDBACK=false
13-
ENABLE_CREW_MEMORY=false
13+
ENABLE_CREW_MEMORY=false

config_template/config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ task_config:
5858
5959
expected_output: >
6060
output format: json
61-
Example output:
61+
Example output:
6262
"extracted_terms":{
6363
#data
6464
}
@@ -76,7 +76,7 @@ task_config:
7676
expected_output: >
7777
output format: json
7878
79-
Example output:
79+
Example output:
8080
"aligned_terms":{
8181
#data
8282
}
@@ -116,7 +116,7 @@ task_config:
116116
expected_output: >
117117
output format: json
118118
119-
Example output:
119+
Example output:
120120
"judged_terms":{
121121
#data
122122
}

config_template/ner-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,3 @@ embedder_config:
8080
config:
8181
api_base: http://localhost:11434
8282
model: nomic-embed-text
83-

0 commit comments

Comments
 (0)