Skip to content

Commit c3e9c22

Browse files
authored
Merge branch 'main' into async
2 parents c0a9695 + 1964907 commit c3e9c22

File tree

19 files changed

+222
-36
lines changed

19 files changed

+222
-36
lines changed

.devcontainer/devcontainer.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-dockerfile
3+
{
4+
"name": "ADT Press",
5+
"build": {
6+
// Sets the run context to one level up instead of the .devcontainer folder.
7+
"context": "..",
8+
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
9+
"dockerfile": "../Dockerfile"
10+
}
11+
}

.dockerignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
__pycache__/
2+
*.pyc
3+
*.pyo
4+
*.pyd
5+
*.db
6+
*.sqlite3
7+
.env
8+
.venv
9+
.git
10+
.gitignore
11+
tests/
12+
# Removed exclusion of README.md

.github/workflows/deploy.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ jobs:
3030
- name: Install uv
3131
uses: astral-sh/setup-uv@v6
3232

33+
- name: Update lockfile
34+
run: uv lock
35+
3336
- name: Install the project
3437
run: uv sync --locked --all-extras --dev
3538

.github/workflows/mypy.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: MyPy
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Setup Graphviz
21+
uses: ts-graphviz/setup-graphviz@v2
22+
23+
- name: Install uv
24+
uses: astral-sh/setup-uv@v6
25+
26+
- name: Update lockfile
27+
run: uv lock
28+
29+
- name: Install the project
30+
run: uv sync --locked --all-extras --dev
31+
32+
- name: Run mypy
33+
run: uv run mypy adt-press.py

.github/workflows/preview.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ jobs:
3636
- name: Install uv
3737
uses: astral-sh/setup-uv@v6
3838

39+
- name: Update lockfile
40+
run: uv lock
41+
3942
- name: Install the project
4043
run: uv sync --locked --all-extras --dev
4144

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ jobs:
2323
- name: Install uv
2424
uses: astral-sh/setup-uv@v6
2525

26+
- name: Update lockfile
27+
run: uv lock
28+
2629
- name: Install the project
2730
run: uv sync --locked --all-extras --dev
2831

Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM python:3.13-slim
2+
3+
# Set work directory
4+
WORKDIR /app
5+
6+
# Install system dependencies for graphviz and opencv
7+
RUN apt-get update && apt-get install -y \
8+
graphviz \
9+
libgl1 \
10+
&& rm -rf /var/lib/apt/lists/*
11+
12+
# Install uv
13+
RUN pip install --upgrade pip && pip install uv
14+
15+
# Copy project files
16+
COPY . .
17+
18+
# Sync and install dependencies using uv
19+
RUN uv sync
20+
21+
# Pre-create the .venv by running a dummy command
22+
RUN uv run -- python -c "import sys; print('venv ready:', sys.prefix)"
23+
24+
# Set default command (adjust as needed)
25+
CMD ["python"]

README.md

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ The [sample report](https://unicef.github.io/adt-press/) can help in better unde
2323

2424
- Python 3.13 or higher
2525
- UV package manager (recommended)
26+
- **You must set the environment variable `OPENAI_API_KEY` with your OpenAI API key for the application to work.**
2627

2728
## Installation
2829

@@ -111,4 +112,67 @@ uv run pytest
111112
- `config/`: Configuration files
112113
- `prompts/`: LLM prompt templates
113114
- `templates/`: HTML templates
114-
- `tests/`: Test files
115+
- `tests/`: Test files
116+
117+
## Docker
118+
119+
Build the image:
120+
121+
```bash
122+
docker build -t adt-press .
123+
```
124+
125+
Run the container:
126+
127+
```bash
128+
docker run --rm adt-press
129+
```
130+
131+
To run a specific command inside the container (for example, to execute `uv run adt-press.py` with a PDF file):
132+
133+
```bash
134+
docker run --rm adt-press uv run adt-press.py pdf_path=/data/yourfile.pdf
135+
```
136+
137+
Replace `/data/yourfile.pdf` with the path to your PDF file inside the container.
138+
139+
---
140+
141+
#### VS Code: "Reopen in Container"
142+
143+
If you use Visual Studio Code, you can take advantage of the **"Reopen in Container"** feature for a full-featured development environment inside Docker.
144+
This allows you to edit, run, and debug your code directly within the container.
145+
146+
To use this, add a `.devcontainer` configuration to your project and select "Reopen in Container" from the VS Code command palette.
147+
You will need to have the **Dev Containers** extension installed in VS Code to use this feature.
148+
149+
---
150+
151+
**Note:**
152+
The folder `.devcontainer` needs to be in the root of your project, containing a `devcontainer.json` file with the following content:
153+
154+
```json
155+
{
156+
"name": "ADT Press",
157+
"build": {
158+
// Sets the run context to one level up instead of the .devcontainer folder.
159+
"context": "..",
160+
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
161+
"dockerfile": "../Dockerfile"
162+
}
163+
}
164+
```
165+
166+
---
167+
168+
**Environment Variable Required**
169+
170+
> **Note:**
171+
> You must set the environment variable `OPENAI_API_KEY` with your OpenAI API key for the application to work.
172+
>
173+
> - When running the Dockerized version, you need to set the `OPENAI_API_KEY` variable every time you run the container.
174+
> For example:
175+
> ```bash
176+
> docker run --rm -e OPENAI_API_KEY=your-key-here adt-press
177+
> ```
178+
> - When using VS Code "Reopen in Container", you can add the variable to your `.env` file or set it in the container terminal before running your scripts.

adt-press.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import structlog
55
from hamilton import driver, registry, telemetry
66
from hamilton.lifecycle import NodeExecutionHook
7-
from omegaconf import OmegaConf
7+
from omegaconf import DictConfig, OmegaConf
88

99
from adt_press.nodes import config_nodes, pdf_nodes, report_nodes
1010

@@ -55,7 +55,7 @@ def run_after_node_execution(
5555
def main() -> None:
5656
cli_config = OmegaConf.from_cli()
5757
file_config = OmegaConf.load("config/config.yaml")
58-
config = OmegaConf.merge(file_config, cli_config)
58+
config = DictConfig(OmegaConf.merge(file_config, cli_config))
5959
print(OmegaConf.to_yaml(config))
6060

6161
cache_args = {"recompute": True} if config.get("clear_cache", False) else {}

adt_press/llm/image_caption.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from .prompt import PromptConfig
1111

1212

13-
class ImageCaptionResponse(BaseModel):
13+
class CaptionResponse(BaseModel):
1414
caption: ImageCaption
1515

1616

@@ -31,9 +31,9 @@ async def get_image_caption(config: PromptConfig, page: Page, image: Image, lang
3131

3232
prompt = Prompt(template_content)
3333
client = instructor.from_litellm(acompletion)
34-
response = await client.chat.completions.create(
34+
response: CaptionResponse = await client.chat.completions.create(
3535
model=config.model,
36-
response_model=ImageCaptionResponse,
36+
response_model=CaptionResponse,
3737
messages=[m.model_dump(exclude_none=True) for m in prompt.chat_messages(context)],
3838
max_retries=3,
3939
)

0 commit comments

Comments
 (0)