Abid Ali Awan Codex commited on
Commit
edc8d43
Β·
1 Parent(s): f619a9b

Consolidate trace tooling under traces package

Browse files
README.md CHANGED
@@ -139,15 +139,15 @@ the shard pending for a later retry and do not affect scam analysis.
139
  Operator commands:
140
 
141
  ```bash
142
- python scripts/seed_trace_dataset.py
143
- python scripts/validate_traces.py data/trace_samples.jsonl
144
- python scripts/create_trace_dataset.py --dry-run
145
- python scripts/create_trace_dataset.py
146
- python scripts/export_pending_traces.py --dry-run
147
- python scripts/upload_trace_shards.py --dry-run
148
  ```
149
 
150
- See [the dataset card](docs/trace_dataset_card.md) for the schema, privacy
151
  policy, provenance, and limitations.
152
 
153
  ## Hugging Face Spaces
@@ -182,14 +182,17 @@ docs/
182
  model_experiment_notes.md
183
  data/
184
  example_assessments.json
185
- trace_samples.jsonl
186
  traces/
187
- scripts/
188
- create_trace_dataset.py
189
- seed_trace_dataset.py
190
- validate_traces.py
191
- export_pending_traces.py
192
- upload_trace_shards.py
 
 
 
 
193
  static/
194
  index.html
195
  styles.css
 
139
  Operator commands:
140
 
141
  ```bash
142
+ python -m traces.scripts.seed_trace_dataset
143
+ python -m traces.scripts.validate_traces
144
+ python -m traces.scripts.create_trace_dataset --dry-run
145
+ python -m traces.scripts.create_trace_dataset
146
+ python -m traces.scripts.export_pending_traces --dry-run
147
+ python -m traces.scripts.upload_trace_shards --dry-run
148
  ```
149
 
150
+ See [the dataset card](traces/dataset_card.md) for the schema, privacy
151
  policy, provenance, and limitations.
152
 
153
  ## Hugging Face Spaces
 
182
  model_experiment_notes.md
183
  data/
184
  example_assessments.json
 
185
  traces/
186
+ runtime.py
187
+ dataset_card.md
188
+ data/
189
+ trace_samples.jsonl
190
+ scripts/
191
+ create_trace_dataset.py
192
+ seed_trace_dataset.py
193
+ validate_traces.py
194
+ export_pending_traces.py
195
+ upload_trace_shards.py
196
  static/
197
  index.html
198
  styles.css
app.py CHANGED
@@ -15,7 +15,7 @@ from fastapi.responses import FileResponse
15
  from fastapi.staticfiles import StaticFiles
16
  from gradio import Server
17
  from openai import APIConnectionError, APIStatusError, APITimeoutError, OpenAI
18
- from trace_runtime import queue_trace, start_trace_worker, trace_status
19
 
20
  ROOT = Path(__file__).resolve().parent
21
  STATIC_DIR = ROOT / "static"
 
15
  from fastapi.staticfiles import StaticFiles
16
  from gradio import Server
17
  from openai import APIConnectionError, APIStatusError, APITimeoutError, OpenAI
18
+ from traces.runtime import queue_trace, start_trace_worker, trace_status
19
 
20
  ROOT = Path(__file__).resolve().parent
21
  STATIC_DIR = ROOT / "static"
scripts/__init__.py DELETED
@@ -1 +0,0 @@
1
- """Trace dataset administration scripts."""
 
 
tests/test_tracing.py CHANGED
@@ -14,7 +14,7 @@ import httpx
14
  from openai import APIStatusError, APITimeoutError
15
 
16
  import app
17
- import trace_runtime
18
 
19
 
20
  class TraceTests(unittest.TestCase):
@@ -281,7 +281,7 @@ class TraceTests(unittest.TestCase):
281
  ), patch.dict("os.environ", {"HF_TOKEN": "test-token"}), patch(
282
  "huggingface_hub.HfApi.upload_file",
283
  side_effect=RuntimeError("offline"),
284
- ), patch("trace_runtime.time.sleep"):
285
  publisher._persist_batch([self.sample_record()])
286
  publisher._upload_pending()
287
  self.assertEqual(len(list(Path(directory).glob("*.jsonl"))), 1)
 
14
  from openai import APIStatusError, APITimeoutError
15
 
16
  import app
17
+ from traces import runtime as trace_runtime
18
 
19
 
20
  class TraceTests(unittest.TestCase):
 
281
  ), patch.dict("os.environ", {"HF_TOKEN": "test-token"}), patch(
282
  "huggingface_hub.HfApi.upload_file",
283
  side_effect=RuntimeError("offline"),
284
+ ), patch("traces.runtime.time.sleep"):
285
  publisher._persist_batch([self.sample_record()])
286
  publisher._upload_pending()
287
  self.assertEqual(len(list(Path(directory).glob("*.jsonl"))), 1)
traces/.gitkeep DELETED
@@ -1 +0,0 @@
1
-
 
 
traces/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ """Deterministic privacy-safe tracing for the application."""
{data β†’ traces/data}/trace_samples.jsonl RENAMED
File without changes
docs/trace_dataset_card.md β†’ traces/dataset_card.md RENAMED
File without changes
trace_runtime.py β†’ traces/runtime.py RENAMED
@@ -13,7 +13,7 @@ from datetime import datetime, timezone
13
  from pathlib import Path
14
  from typing import Any
15
 
16
- ROOT = Path(__file__).resolve().parent
17
  TRACE_ROOT = Path(os.getenv("TRACE_DIR", ROOT / "traces"))
18
  PENDING_DIR = TRACE_ROOT / "pending"
19
  DATASET_REPO = os.getenv(
 
13
  from pathlib import Path
14
  from typing import Any
15
 
16
+ ROOT = Path(__file__).resolve().parents[1]
17
  TRACE_ROOT = Path(os.getenv("TRACE_DIR", ROOT / "traces"))
18
  PENDING_DIR = TRACE_ROOT / "pending"
19
  DATASET_REPO = os.getenv(
traces/scripts/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ """Trace dataset administration commands."""
{scripts β†’ traces/scripts}/create_trace_dataset.py RENAMED
@@ -8,7 +8,8 @@ from pathlib import Path
8
 
9
  from huggingface_hub import HfApi
10
 
11
- ROOT = Path(__file__).resolve().parents[1]
 
12
  DEFAULT_REPO = "build-small-hackathon/pakistan-notice-helper-traces"
13
 
14
 
@@ -21,8 +22,8 @@ def main() -> int:
21
  parser.add_argument("--dry-run", action="store_true")
22
  args = parser.parse_args()
23
  files = {
24
- ROOT / "docs" / "trace_dataset_card.md": "README.md",
25
- ROOT / "data" / "trace_samples.jsonl": "data/seed/trace_samples.jsonl",
26
  }
27
  if args.dry_run:
28
  print(f"Would create public dataset: {args.repo_id}")
 
8
 
9
  from huggingface_hub import HfApi
10
 
11
+ ROOT = Path(__file__).resolve().parents[2]
12
+ TRACE_DIR = Path(__file__).resolve().parents[1]
13
  DEFAULT_REPO = "build-small-hackathon/pakistan-notice-helper-traces"
14
 
15
 
 
22
  parser.add_argument("--dry-run", action="store_true")
23
  args = parser.parse_args()
24
  files = {
25
+ TRACE_DIR / "dataset_card.md": "README.md",
26
+ TRACE_DIR / "data" / "trace_samples.jsonl": "data/seed/trace_samples.jsonl",
27
  }
28
  if args.dry_run:
29
  print(f"Would create public dataset: {args.repo_id}")
{scripts β†’ traces/scripts}/export_pending_traces.py RENAMED
@@ -7,10 +7,10 @@ import json
7
  import sys
8
  from pathlib import Path
9
 
10
- ROOT = Path(__file__).resolve().parents[1]
11
  sys.path.insert(0, str(ROOT))
12
 
13
- from trace_runtime import PENDING_DIR, validate_trace
14
 
15
 
16
  def main() -> int:
 
7
  import sys
8
  from pathlib import Path
9
 
10
+ ROOT = Path(__file__).resolve().parents[2]
11
  sys.path.insert(0, str(ROOT))
12
 
13
+ from traces.runtime import PENDING_DIR, validate_trace
14
 
15
 
16
  def main() -> int:
{scripts β†’ traces/scripts}/seed_trace_dataset.py RENAMED
@@ -7,10 +7,11 @@ import json
7
  import sys
8
  from pathlib import Path
9
 
10
- ROOT = Path(__file__).resolve().parents[1]
 
11
  sys.path.insert(0, str(ROOT))
12
 
13
- from trace_runtime import PIPELINE_STEPS, build_trace_record, validate_trace
14
 
15
  TEXT_EXAMPLES = {
16
  "text-courier": (
@@ -84,7 +85,7 @@ def main() -> int:
84
  parser.add_argument(
85
  "--output",
86
  type=Path,
87
- default=ROOT / "data" / "trace_samples.jsonl",
88
  )
89
  parser.add_argument("--dry-run", action="store_true")
90
  args = parser.parse_args()
 
7
  import sys
8
  from pathlib import Path
9
 
10
+ ROOT = Path(__file__).resolve().parents[2]
11
+ TRACE_DIR = Path(__file__).resolve().parents[1]
12
  sys.path.insert(0, str(ROOT))
13
 
14
+ from traces.runtime import PIPELINE_STEPS, build_trace_record, validate_trace
15
 
16
  TEXT_EXAMPLES = {
17
  "text-courier": (
 
85
  parser.add_argument(
86
  "--output",
87
  type=Path,
88
+ default=TRACE_DIR / "data" / "trace_samples.jsonl",
89
  )
90
  parser.add_argument("--dry-run", action="store_true")
91
  args = parser.parse_args()
{scripts β†’ traces/scripts}/upload_trace_shards.py RENAMED
@@ -10,11 +10,11 @@ from pathlib import Path
10
 
11
  from huggingface_hub import HfApi
12
 
13
- ROOT = Path(__file__).resolve().parents[1]
14
  sys.path.insert(0, str(ROOT))
15
 
16
- from scripts.validate_traces import validate_file
17
- from trace_runtime import DATASET_REPO, PENDING_DIR
18
 
19
 
20
  def main() -> int:
 
10
 
11
  from huggingface_hub import HfApi
12
 
13
+ ROOT = Path(__file__).resolve().parents[2]
14
  sys.path.insert(0, str(ROOT))
15
 
16
+ from traces.runtime import DATASET_REPO, PENDING_DIR
17
+ from traces.scripts.validate_traces import validate_file
18
 
19
 
20
  def main() -> int:
{scripts β†’ traces/scripts}/validate_traces.py RENAMED
@@ -7,10 +7,11 @@ import json
7
  import sys
8
  from pathlib import Path
9
 
10
- ROOT = Path(__file__).resolve().parents[1]
 
11
  sys.path.insert(0, str(ROOT))
12
 
13
- from trace_runtime import validate_trace
14
 
15
 
16
  def validate_file(path: Path) -> tuple[int, list[str]]:
@@ -37,7 +38,7 @@ def main() -> int:
37
  parser = argparse.ArgumentParser(description=__doc__)
38
  parser.add_argument("paths", nargs="*", type=Path)
39
  args = parser.parse_args()
40
- paths = args.paths or [ROOT / "data" / "trace_samples.jsonl"]
41
  total = 0
42
  all_errors: list[str] = []
43
  for path in paths:
 
7
  import sys
8
  from pathlib import Path
9
 
10
+ ROOT = Path(__file__).resolve().parents[2]
11
+ TRACE_DIR = Path(__file__).resolve().parents[1]
12
  sys.path.insert(0, str(ROOT))
13
 
14
+ from traces.runtime import validate_trace
15
 
16
 
17
  def validate_file(path: Path) -> tuple[int, list[str]]:
 
38
  parser = argparse.ArgumentParser(description=__doc__)
39
  parser.add_argument("paths", nargs="*", type=Path)
40
  args = parser.parse_args()
41
+ paths = args.paths or [TRACE_DIR / "data" / "trace_samples.jsonl"]
42
  total = 0
43
  all_errors: list[str] = []
44
  for path in paths: