refactor(input): bake codex cli runtime
This commit is contained in:
@@ -15,7 +15,9 @@ RUN apt-get update \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN npm install --location=global codex-cli || true
|
||||
# Install the official Codex CLI so the container can invoke `codex prompt`.
|
||||
# The CLI expects credentials/configuration from the mounted ~/.codex directory.
|
||||
RUN npm install --location=global @openai/codex
|
||||
|
||||
RUN groupadd -r codex && \
|
||||
useradd -r -m -g codex -s /bin/bash codex
|
||||
|
||||
@@ -12,8 +12,6 @@ services:
|
||||
PGID: "${LOCAL_GID:-1000}"
|
||||
POLL_INTERVAL_SECONDS: "${POLL_INTERVAL_SECONDS:-5}"
|
||||
CODEX_TIMEOUT_SECONDS: "${CODEX_TIMEOUT_SECONDS:-600}"
|
||||
CODEX_COMMAND_TEMPLATE: "${CODEX_COMMAND_TEMPLATE:-codex prompt --input {prompt} --output {output} --format markdown}"
|
||||
CODEX_NORMALIZER_COMMAND_TEMPLATE: "${CODEX_NORMALIZER_COMMAND_TEMPLATE:-codex prompt --input {prompt} --output {output} --format markdown}"
|
||||
volumes:
|
||||
- ../ForCustomizing/inbox:/workspace/inbox
|
||||
- ../ForCustomizing/outbox:/workspace/outbox
|
||||
@@ -22,3 +20,4 @@ services:
|
||||
- ../resume:/workspace/resume:ro
|
||||
- ../templates:/templates:ro
|
||||
- ${CODEX_CONFIG_DIR:-/workspace/.codex}:/home/codex/.codex
|
||||
- /etc/localtime:/etc/localtime:ro
|
||||
|
||||
@@ -13,7 +13,6 @@ from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os
|
||||
import shlex
|
||||
import shutil
|
||||
import subprocess
|
||||
import time
|
||||
@@ -32,17 +31,9 @@ TEMPLATES_DIR = Path("/templates")
|
||||
TEMPLATE_CACHE = Path("/tmp/templates")
|
||||
PROMPT_TEMPLATE = TEMPLATES_DIR / "ResumeCustomizerPrompt.md"
|
||||
PROMPT_TEMPLATE_EXAMPLE = TEMPLATES_DIR / "ResumeCustomizerPrompt.md.example"
|
||||
NORMALIZER_TEMPLATE = Path('/app/JobDescriptionNormalizerPrompt.md')
|
||||
NORMALIZER_TEMPLATE = Path("/app/JobDescriptionNormalizerPrompt.md")
|
||||
|
||||
POLL_INTERVAL_SECONDS = int(os.environ.get("POLL_INTERVAL_SECONDS", "5"))
|
||||
CODEX_COMMAND_TEMPLATE = os.environ.get(
|
||||
"CODEX_COMMAND_TEMPLATE",
|
||||
"codex prompt --input {prompt} --output {output} --format markdown",
|
||||
)
|
||||
CODEX_NORMALIZER_COMMAND_TEMPLATE = os.environ.get(
|
||||
"CODEX_NORMALIZER_COMMAND_TEMPLATE",
|
||||
CODEX_COMMAND_TEMPLATE,
|
||||
)
|
||||
CODEX_TIMEOUT_SECONDS = int(os.environ.get("CODEX_TIMEOUT_SECONDS", "600"))
|
||||
|
||||
RESOLVED_PROMPT_TEMPLATE: Path | None = None
|
||||
@@ -193,20 +184,19 @@ def slugify(component: str) -> str:
|
||||
return "-".join(parts)
|
||||
|
||||
|
||||
def run_codex(prompt_path: Path, output_path: Path, command_template: str) -> None:
|
||||
"""Execute the Codex CLI using the provided command template."""
|
||||
command_text = command_template.format(
|
||||
prompt=str(prompt_path),
|
||||
output=str(output_path),
|
||||
)
|
||||
logging.info("Running Codex CLI command: %s", command_text)
|
||||
|
||||
try:
|
||||
command = shlex.split(command_text)
|
||||
except ValueError as exc:
|
||||
raise FatalConfigurationError(
|
||||
f"Unable to parse Codex command template into arguments: {exc}"
|
||||
) from exc
|
||||
def run_codex(prompt_path: Path, output_path: Path) -> None:
|
||||
"""Execute the Codex CLI."""
|
||||
command = [
|
||||
"codex",
|
||||
"prompt",
|
||||
"--input",
|
||||
str(prompt_path),
|
||||
"--output",
|
||||
str(output_path),
|
||||
"--format",
|
||||
"markdown",
|
||||
]
|
||||
logging.info("Running Codex CLI command: %s", " ".join(command))
|
||||
|
||||
try:
|
||||
subprocess.run(
|
||||
@@ -217,7 +207,7 @@ def run_codex(prompt_path: Path, output_path: Path, command_template: str) -> No
|
||||
)
|
||||
except FileNotFoundError as exc:
|
||||
raise FatalConfigurationError(
|
||||
f"Executable not found while running Codex CLI command: {command[0]}"
|
||||
"Codex CLI executable 'codex' not found in PATH"
|
||||
) from exc
|
||||
except subprocess.TimeoutExpired as exc:
|
||||
raise RuntimeError("Codex CLI timed out") from exc
|
||||
@@ -301,7 +291,7 @@ def normalize_job_description(job_file: Path) -> NormalizedJobDescription:
|
||||
prompt_path.write_text(prompt_text, encoding="utf-8")
|
||||
|
||||
output_path = tmp_dir / "normalize_output.md"
|
||||
run_codex(prompt_path, output_path, CODEX_NORMALIZER_COMMAND_TEMPLATE)
|
||||
run_codex(prompt_path, output_path)
|
||||
normalized_text = output_path.read_text(encoding="utf-8").strip()
|
||||
|
||||
return parse_normalized_output(normalized_text)
|
||||
@@ -356,7 +346,7 @@ def process_job(job_file: Path) -> None:
|
||||
prompt_path.write_text(prompt_text, encoding="utf-8")
|
||||
|
||||
output_path = tmp_dir / "codex_output.md"
|
||||
run_codex(prompt_path, output_path, CODEX_COMMAND_TEMPLATE)
|
||||
run_codex(prompt_path, output_path)
|
||||
|
||||
generated_output = out_dir / output_filename
|
||||
counter = 1
|
||||
|
||||
Reference in New Issue
Block a user