corethink 1.0.4__tar.gz → 1.0.6__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.
- {corethink-1.0.4 → corethink-1.0.6}/PKG-INFO +15 -2
- {corethink-1.0.4 → corethink-1.0.6}/README.md +14 -1
- {corethink-1.0.4 → corethink-1.0.6}/pyproject.toml +1 -1
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/_version.py +1 -1
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/commands/env.py +252 -5
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/commands/hub.py +1 -1
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/commands/train.py +2 -2
- corethink-1.0.6/src/corethink/env_import.py +1534 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink.egg-info/PKG-INFO +15 -2
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink.egg-info/SOURCES.txt +2 -0
- {corethink-1.0.4 → corethink-1.0.6}/tests/test_env.py +2 -2
- corethink-1.0.6/tests/test_env_import.py +480 -0
- {corethink-1.0.4 → corethink-1.0.6}/tests/test_hub.py +2 -2
- {corethink-1.0.4 → corethink-1.0.6}/tests/test_train.py +15 -6
- {corethink-1.0.4 → corethink-1.0.6}/setup.cfg +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/__init__.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/__main__.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/account.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/cli.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/client.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/commands/__init__.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/commands/admin.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/commands/api.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/commands/archive.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/commands/auth.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/commands/billing.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/commands/capture.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/commands/connection.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/commands/endpoint.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/commands/library.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/commands/models.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/commands/workspace.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/config.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/context.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/env_template.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/environment_http_store.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/experiment_cli.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/hosted_profiles.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/hosted_rl.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/hosted_rl_archive.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/hosted_rl_attribution.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/hosted_rl_billing.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/hosted_rl_state.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/jobs_cli.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/main.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/output.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/py.typed +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/rl_cli.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/rl_inspect.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/rl_playground.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/rl_reassessment.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/rl_settings.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/sdk.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink/settings.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink.egg-info/dependency_links.txt +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink.egg-info/entry_points.txt +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink.egg-info/requires.txt +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/src/corethink.egg-info/top_level.txt +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/tests/test_admin.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/tests/test_archive.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/tests/test_auth.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/tests/test_billing.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/tests/test_capture.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/tests/test_connection.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/tests/test_endpoint.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/tests/test_library.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/tests/test_main_json.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/tests/test_models.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/tests/test_version.py +0 -0
- {corethink-1.0.4 → corethink-1.0.6}/tests/test_workspace.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: corethink
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.6
|
|
4
4
|
Summary: The CoreThink Workbench from your terminal: environments, training, endpoints and more.
|
|
5
5
|
Author-email: CoreThink <support@corethink.ai>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -75,7 +75,7 @@ Every command has `--help`, and `corethink --help` lists them all.
|
|
|
75
75
|
| --- | --- |
|
|
76
76
|
| Account | `login`, `logout`, `whoami`, `token`, `profile` |
|
|
77
77
|
| Workspaces and team | `workspace` (list, use, create, members, invite, roles, audit, credit) |
|
|
78
|
-
| Environments | `env` (init, create, check, show, versions, pull, push, archive), `capture` (live traffic → tasks) |
|
|
78
|
+
| Environments | `env` (init, import, create, check, show, versions, pull, push, archive), `capture` (live traffic → tasks) |
|
|
79
79
|
| Connections | `connection` (HTTP/OpenAPI, MCP, databases, your own code; secrets, tests, health) |
|
|
80
80
|
| Hub and library | `hub` (starters), `library` (every step training has learned) |
|
|
81
81
|
| Training | `train` (start in Automatic or Advanced mode, `--from` an earlier run, test the base model, settings, estimate, list, show, watch, curve, tasks, logs, cancel, resume, archive), `models` |
|
|
@@ -85,6 +85,19 @@ Every command has `--help`, and `corethink --help` lists them all.
|
|
|
85
85
|
| Admins | `admin` (CoreThink staff only) |
|
|
86
86
|
| Anything else | `corethink api GET /api/v1/...` calls any Workbench API route |
|
|
87
87
|
|
|
88
|
+
### Your own data
|
|
89
|
+
|
|
90
|
+
`corethink env import` turns data in another shape into an environment's files: chat logs (OpenAI or Anthropic
|
|
91
|
+
messages with tool calls, request and response logs, ShareGPT), tables of tasks with an answer column (CSV, TSV,
|
|
92
|
+
.xlsx, JSON Lines, a JSON array) and folders of text files such as support tickets. It writes `IMPORT.md` beside them
|
|
93
|
+
with what was guessed. When the shape is not clear, a small sample (at most 20 records, long text cut) is sent to an
|
|
94
|
+
AI model to map it, after you agree; `--no-ai` never sends one.
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
corethink env import support-chats.jsonl --name "Support chat" # writes support-chats-environment/
|
|
98
|
+
corethink env create support-chats-environment
|
|
99
|
+
```
|
|
100
|
+
|
|
88
101
|
### Training modes and hyperparameters
|
|
89
102
|
|
|
90
103
|
`corethink train start ENV` uses **Automatic** mode: recommended settings, and you set the spending limit. For
|
|
@@ -45,7 +45,7 @@ Every command has `--help`, and `corethink --help` lists them all.
|
|
|
45
45
|
| --- | --- |
|
|
46
46
|
| Account | `login`, `logout`, `whoami`, `token`, `profile` |
|
|
47
47
|
| Workspaces and team | `workspace` (list, use, create, members, invite, roles, audit, credit) |
|
|
48
|
-
| Environments | `env` (init, create, check, show, versions, pull, push, archive), `capture` (live traffic → tasks) |
|
|
48
|
+
| Environments | `env` (init, import, create, check, show, versions, pull, push, archive), `capture` (live traffic → tasks) |
|
|
49
49
|
| Connections | `connection` (HTTP/OpenAPI, MCP, databases, your own code; secrets, tests, health) |
|
|
50
50
|
| Hub and library | `hub` (starters), `library` (every step training has learned) |
|
|
51
51
|
| Training | `train` (start in Automatic or Advanced mode, `--from` an earlier run, test the base model, settings, estimate, list, show, watch, curve, tasks, logs, cancel, resume, archive), `models` |
|
|
@@ -55,6 +55,19 @@ Every command has `--help`, and `corethink --help` lists them all.
|
|
|
55
55
|
| Admins | `admin` (CoreThink staff only) |
|
|
56
56
|
| Anything else | `corethink api GET /api/v1/...` calls any Workbench API route |
|
|
57
57
|
|
|
58
|
+
### Your own data
|
|
59
|
+
|
|
60
|
+
`corethink env import` turns data in another shape into an environment's files: chat logs (OpenAI or Anthropic
|
|
61
|
+
messages with tool calls, request and response logs, ShareGPT), tables of tasks with an answer column (CSV, TSV,
|
|
62
|
+
.xlsx, JSON Lines, a JSON array) and folders of text files such as support tickets. It writes `IMPORT.md` beside them
|
|
63
|
+
with what was guessed. When the shape is not clear, a small sample (at most 20 records, long text cut) is sent to an
|
|
64
|
+
AI model to map it, after you agree; `--no-ai` never sends one.
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
corethink env import support-chats.jsonl --name "Support chat" # writes support-chats-environment/
|
|
68
|
+
corethink env create support-chats-environment
|
|
69
|
+
```
|
|
70
|
+
|
|
58
71
|
### Training modes and hyperparameters
|
|
59
72
|
|
|
60
73
|
`corethink train start ENV` uses **Automatic** mode: recommended settings, and you set the spending limit. For
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "corethink"
|
|
7
|
-
version = "1.0.
|
|
7
|
+
version = "1.0.6"
|
|
8
8
|
description = "The CoreThink Workbench from your terminal: environments, training, endpoints and more."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -32,8 +32,9 @@ import typer
|
|
|
32
32
|
from rich.progress import BarColumn, DownloadColumn, Progress, TextColumn, TransferSpeedColumn
|
|
33
33
|
from rich.text import Text
|
|
34
34
|
|
|
35
|
+
from corethink import env_import as importer
|
|
35
36
|
from corethink import output as ui
|
|
36
|
-
from corethink.client import ApiError
|
|
37
|
+
from corethink.client import ApiError, NotSignedIn
|
|
37
38
|
from corethink.context import client, state
|
|
38
39
|
|
|
39
40
|
BASE = "/api/v1/harnesses"
|
|
@@ -49,8 +50,9 @@ A typical flow: `corethink env init` writes an example to edit, `corethink env c
|
|
|
49
50
|
without saving anything, and `corethink env create` saves them as v1. Then `corethink train test` scores
|
|
50
51
|
the base model on it, and `corethink train start` trains a program. To change it later,
|
|
51
52
|
`corethink env pull` the files, edit them, and `corethink env push` them back; `corethink env edit`
|
|
52
|
-
changes one file in your editor.
|
|
53
|
-
`corethink
|
|
53
|
+
changes one file in your editor. Data in another shape (chat logs, a spreadsheet of tasks, support
|
|
54
|
+
tickets) becomes these files with `corethink env import`. You can also start from a Hub program instead
|
|
55
|
+
of your own files: `corethink hub start`.
|
|
54
56
|
|
|
55
57
|
Every save makes a new version with the same ID; earlier versions stay, and each run says which version
|
|
56
58
|
it used. Part of the tasks is held back as the eval split: no run trains on them, and the final check is
|
|
@@ -271,7 +273,7 @@ def gain_text(best: dict[str, Any] | None) -> Text | str:
|
|
|
271
273
|
if not best:
|
|
272
274
|
return "—"
|
|
273
275
|
style = "green" if best["passed"] and best["delta"] > 0 else "dim"
|
|
274
|
-
return Text(f"{ui.points(best['delta'])}
|
|
276
|
+
return Text(f"{ui.points(best['delta'])} pts", style=style)
|
|
275
277
|
|
|
276
278
|
|
|
277
279
|
def _runs_of(jobs: list[dict[str, Any]] | None, meta: dict[str, Any]) -> list[dict[str, Any]]:
|
|
@@ -947,7 +949,7 @@ def env_show(
|
|
|
947
949
|
),
|
|
948
950
|
(
|
|
949
951
|
"Best gain",
|
|
950
|
-
Text(f"{ui.points(best['delta'])}
|
|
952
|
+
Text(f"{ui.points(best['delta'])} pts over the base model")
|
|
951
953
|
+ Text(
|
|
952
954
|
" · passed its final check" if best["passed"] else " · did not pass its final check",
|
|
953
955
|
style="dim",
|
|
@@ -1309,6 +1311,251 @@ STARTER_FILES = {
|
|
|
1309
1311
|
),
|
|
1310
1312
|
}
|
|
1311
1313
|
|
|
1314
|
+
# ---- `env import`: local data in another shape, as an environment's files (env_import.py) ---------------------------------
|
|
1315
|
+
|
|
1316
|
+
# the most a model's mapping is held at from the credit (companion/importDraft.ts DRAFT_HOLD_USD); its real cost is charged
|
|
1317
|
+
DRAFT_HOLD_USD = 0.25
|
|
1318
|
+
IMPORT_OUTPUTS = (USECASE, SCENARIOS, TRACES, "IMPORT.md", ".import-mapping.json", ".import-sample.json")
|
|
1319
|
+
|
|
1320
|
+
|
|
1321
|
+
def _import_folder(paths: list[Path]) -> Path:
|
|
1322
|
+
first = paths[0].resolve()
|
|
1323
|
+
stem = first.name if first.is_dir() else first.stem
|
|
1324
|
+
return Path(f"{re.sub(r'[^a-z0-9]+', '-', stem.lower()).strip('-') or 'imported'}-environment")
|
|
1325
|
+
|
|
1326
|
+
|
|
1327
|
+
def _draft_import(summary: dict[str, Any], detected: Any, previous: dict[str, Any] | None = None) -> dict[str, Any]:
|
|
1328
|
+
"""A model's mapping for the sample (companion/importDraft.ts): {mapping, usecase, notes, costUsd}."""
|
|
1329
|
+
body: dict[str, Any] = {
|
|
1330
|
+
**summary,
|
|
1331
|
+
"detected": (detected.label + (f": {detected.why}" if detected.why else ""))[:300],
|
|
1332
|
+
}
|
|
1333
|
+
if previous:
|
|
1334
|
+
body["previous"] = previous
|
|
1335
|
+
return client().post(f"{BASE}/usecases:draft-import", body) or {}
|
|
1336
|
+
|
|
1337
|
+
|
|
1338
|
+
def _write_import(folder: Path, built: Any, notes: str, mapping: dict[str, Any]) -> list[str]:
|
|
1339
|
+
folder.mkdir(parents=True, exist_ok=True)
|
|
1340
|
+
texts = {
|
|
1341
|
+
USECASE: json.dumps(built.usecase, indent=2, ensure_ascii=False) + "\n",
|
|
1342
|
+
SCENARIOS: importer.jsonl(built.scenarios),
|
|
1343
|
+
**({TRACES: importer.jsonl(built.traces)} if built.traces else {}),
|
|
1344
|
+
"IMPORT.md": notes,
|
|
1345
|
+
".import-mapping.json": json.dumps(mapping, indent=2, ensure_ascii=False) + "\n",
|
|
1346
|
+
}
|
|
1347
|
+
if not built.traces and (folder / TRACES).exists():
|
|
1348
|
+
# a traces.jsonl of an earlier import would be created with these tasks
|
|
1349
|
+
(folder / TRACES).unlink()
|
|
1350
|
+
for name, text in texts.items():
|
|
1351
|
+
(folder / name).write_text(text, encoding="utf-8")
|
|
1352
|
+
return [str(folder / name) for name in texts if not name.startswith(".")]
|
|
1353
|
+
|
|
1354
|
+
|
|
1355
|
+
def _check_import(folder: Path) -> dict[str, Any] | None:
|
|
1356
|
+
"""The check `env check` makes (on the Workbench, nothing saved), or None when not signed in."""
|
|
1357
|
+
try:
|
|
1358
|
+
files = collect([folder])
|
|
1359
|
+
body, staged = send_files(files)
|
|
1360
|
+
try:
|
|
1361
|
+
return client().post(f"{BASE}/usecases:check", body)
|
|
1362
|
+
finally:
|
|
1363
|
+
discard_upload(staged)
|
|
1364
|
+
except NotSignedIn:
|
|
1365
|
+
ui.warn(f"Not signed in, so the files were not checked. Sign in, then: corethink env check {folder}")
|
|
1366
|
+
return None
|
|
1367
|
+
|
|
1368
|
+
|
|
1369
|
+
def _errors_of(check: dict[str, Any] | None) -> list[str]:
|
|
1370
|
+
return [
|
|
1371
|
+
f"{p.get('where')}: {p.get('message')}"
|
|
1372
|
+
for p in (check or {}).get("problems") or []
|
|
1373
|
+
if p.get("severity") == "error"
|
|
1374
|
+
]
|
|
1375
|
+
|
|
1376
|
+
|
|
1377
|
+
@app.command("import")
|
|
1378
|
+
def env_import(
|
|
1379
|
+
paths: list[Path] = typer.Argument(
|
|
1380
|
+
..., help="Your data: files (JSON Lines, JSON, CSV, TSV, .xlsx, text) or folders of them."
|
|
1381
|
+
),
|
|
1382
|
+
out: Path = typer.Option(
|
|
1383
|
+
None, "--out", "-o", help="Where to write it (default: <data>-environment, made if missing)."
|
|
1384
|
+
),
|
|
1385
|
+
name: str = typer.Option(None, "--name", help="Its name (default: from the data)."),
|
|
1386
|
+
mapping_file: Path = typer.Option(
|
|
1387
|
+
None, "--mapping", help="Read the data with this mapping (a JSON file; an import writes one beside IMPORT.md)."
|
|
1388
|
+
),
|
|
1389
|
+
no_ai: bool = typer.Option(False, "--no-ai", help="Never send a sample to a model; use the CLI's own rules."),
|
|
1390
|
+
no_check: bool = typer.Option(False, "--no-check", help="Do not check the files."),
|
|
1391
|
+
force: bool = typer.Option(False, "--force", help="Overwrite files that are there."),
|
|
1392
|
+
yes: bool = YES_OPTION,
|
|
1393
|
+
) -> None:
|
|
1394
|
+
"""Turn your own data into an environment's files, to check and create.
|
|
1395
|
+
|
|
1396
|
+
Reads chat logs (OpenAI or Anthropic messages, with tool calls; request and response logs; ShareGPT), tables of tasks
|
|
1397
|
+
with a column for the right answer (CSV, TSV, .xlsx, JSON Lines or a JSON array), and folders of text files such as
|
|
1398
|
+
support tickets. It writes `usecase.json`, `scenarios.jsonl`, `traces.jsonl` (when there are conversations) and
|
|
1399
|
+
`IMPORT.md`, which says how the data was read and what to check, to `--out` (default: a folder named after the data).
|
|
1400
|
+
Conversations become tasks (the last user message, with its tool results and answer) and traces to learn from; the
|
|
1401
|
+
tools they call become the environment's tools.
|
|
1402
|
+
|
|
1403
|
+
Common shapes are read by the CLI's own rules. When the shape is not clear, a sample of at most 20 records (long
|
|
1404
|
+
text cut to 300 characters) is sent to the Workbench, where an AI model (Claude) says how to read it. You are asked
|
|
1405
|
+
first (`--yes` does not ask), and it is charged to your credit (at most $0.25). The mapping is applied here to all of
|
|
1406
|
+
your records; nothing else is sent to the model. `--no-ai` never sends a sample; `--mapping` reads the data with a
|
|
1407
|
+
mapping you give (each import saves its own as `.import-mapping.json`).
|
|
1408
|
+
|
|
1409
|
+
The files are then checked as `corethink env check` checks them (nothing is saved; `--no-check` skips it), and it
|
|
1410
|
+
exits 1 when they have problems to fix. It never creates the environment: read IMPORT.md, then
|
|
1411
|
+
`corethink env create` the folder. `--json` returns the folder, its files, the counts, the mapping and the check.
|
|
1412
|
+
|
|
1413
|
+
Examples:
|
|
1414
|
+
corethink env import chats.jsonl --name "Support chat"
|
|
1415
|
+
corethink env import tickets/ --out support-environment
|
|
1416
|
+
corethink env import tasks.csv --no-ai
|
|
1417
|
+
corethink env create support-environment
|
|
1418
|
+
"""
|
|
1419
|
+
folder = out or _import_folder(paths)
|
|
1420
|
+
if any(folder.resolve() == p.resolve() for p in paths if p.is_dir()):
|
|
1421
|
+
ui.error(f"{folder} is where your data is. Choose another folder with --out.")
|
|
1422
|
+
raise typer.Exit(2)
|
|
1423
|
+
# the sample a declined or failed import left is its own scratch file: it does not stop the next try
|
|
1424
|
+
clashes = [n for n in IMPORT_OUTPUTS if n != ".import-sample.json" and (folder / n).exists()]
|
|
1425
|
+
if clashes and not force:
|
|
1426
|
+
ui.error(
|
|
1427
|
+
f"{folder} already has {', '.join(clashes)}. Choose another folder with --out, or --force to overwrite."
|
|
1428
|
+
)
|
|
1429
|
+
raise typer.Exit(2)
|
|
1430
|
+
try:
|
|
1431
|
+
sources = importer.read_inputs(paths)
|
|
1432
|
+
except importer.ImportProblem as problem:
|
|
1433
|
+
ui.error(str(problem))
|
|
1434
|
+
raise typer.Exit(2) from None
|
|
1435
|
+
detected = importer.detect(sources)
|
|
1436
|
+
title = importer.title_of(paths[0].resolve().name if paths[0].is_dir() else paths[0].stem)
|
|
1437
|
+
draft: dict[str, Any] = {}
|
|
1438
|
+
model_notes: list[str] = []
|
|
1439
|
+
cost = 0.0
|
|
1440
|
+
summary: dict[str, Any] | None = None
|
|
1441
|
+
|
|
1442
|
+
def ask_model(previous: dict[str, Any] | None = None) -> dict[str, Any]:
|
|
1443
|
+
nonlocal cost, draft, model_notes
|
|
1444
|
+
assert summary is not None
|
|
1445
|
+
try:
|
|
1446
|
+
answer = _draft_import(summary, detected, previous)
|
|
1447
|
+
except ApiError as problem:
|
|
1448
|
+
ui.error(f"The model could not map the data: {problem.message}")
|
|
1449
|
+
if not previous and detected.mapping:
|
|
1450
|
+
ui.info("Import it with --no-ai to use the CLI's own guess, or give a mapping with --mapping.")
|
|
1451
|
+
raise typer.Exit(problem.exit_code) from None
|
|
1452
|
+
cost += float(answer.get("costUsd") or 0)
|
|
1453
|
+
draft = answer.get("usecase") or {}
|
|
1454
|
+
model_notes = [str(n) for n in answer.get("notes") or []][:10]
|
|
1455
|
+
return answer.get("mapping") or {}
|
|
1456
|
+
|
|
1457
|
+
if mapping_file is not None:
|
|
1458
|
+
mapping = _read_json(mapping_file, "The mapping")
|
|
1459
|
+
mapped_by = "the mapping you gave"
|
|
1460
|
+
elif detected.sure:
|
|
1461
|
+
mapping = detected.mapping or {}
|
|
1462
|
+
mapped_by = "the CLI's own rules"
|
|
1463
|
+
elif no_ai:
|
|
1464
|
+
if not detected.mapping:
|
|
1465
|
+
ui.error(
|
|
1466
|
+
f"The shape of the data is not clear ({detected.why}). Import it without --no-ai to have a model map it, "
|
|
1467
|
+
"or give a mapping with --mapping."
|
|
1468
|
+
)
|
|
1469
|
+
raise typer.Exit(2)
|
|
1470
|
+
mapping = detected.mapping
|
|
1471
|
+
mapped_by = "the CLI's own rules (a guess)"
|
|
1472
|
+
ui.warn(f"The shape of the data is not clear ({detected.why}); the CLI guessed. See IMPORT.md.")
|
|
1473
|
+
else:
|
|
1474
|
+
summary = importer.sample(sources)
|
|
1475
|
+
folder.mkdir(parents=True, exist_ok=True)
|
|
1476
|
+
sample_file = folder / ".import-sample.json"
|
|
1477
|
+
sample_file.write_text(json.dumps(summary, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
|
1478
|
+
ui.info(
|
|
1479
|
+
f"The shape of the data is not clear to the CLI ({detected.why or detected.label}). To map it, "
|
|
1480
|
+
f"{_plural(len(summary['sample']), 'record')} of {summary['records']} (long text cut to "
|
|
1481
|
+
f"{importer.SAMPLE_TEXT} characters), the file names and the field names are sent to the Workbench, where an "
|
|
1482
|
+
f"AI model (Claude) reads them. Nothing else is sent. It is charged to your credit (at most "
|
|
1483
|
+
f"${DRAFT_HOLD_USD:.2f}). What is sent is in {sample_file}."
|
|
1484
|
+
)
|
|
1485
|
+
ui.confirm("Send the sample?", yes=yes)
|
|
1486
|
+
mapping = ask_model()
|
|
1487
|
+
mapped_by = f"an AI model, from a sample of {_plural(len(summary['sample']), 'record')}"
|
|
1488
|
+
|
|
1489
|
+
corrected = False
|
|
1490
|
+
|
|
1491
|
+
def build(current: dict[str, Any]) -> tuple[Any, dict[str, Any]]:
|
|
1492
|
+
"""The files from a mapping; a model's mapping that cannot be used is sent back once to be corrected."""
|
|
1493
|
+
nonlocal corrected
|
|
1494
|
+
try:
|
|
1495
|
+
return importer.apply_mapping(sources, current, title=title, name=name, draft=draft), current
|
|
1496
|
+
except importer.ImportProblem as problem:
|
|
1497
|
+
if summary is None or corrected:
|
|
1498
|
+
ui.error(str(problem))
|
|
1499
|
+
raise typer.Exit(2) from None
|
|
1500
|
+
corrected = True
|
|
1501
|
+
ui.info("The model's mapping could not be used; asking it once more.")
|
|
1502
|
+
fixed = ask_model({"mapping": current, "problems": [str(problem)]})
|
|
1503
|
+
return build(fixed)
|
|
1504
|
+
|
|
1505
|
+
built, mapping = build(mapping)
|
|
1506
|
+
|
|
1507
|
+
def write() -> list[str]:
|
|
1508
|
+
notes = importer.import_notes(
|
|
1509
|
+
sources, detected, mapping, built, mapped_by=mapped_by, folder=str(folder), model_notes=model_notes
|
|
1510
|
+
)
|
|
1511
|
+
return _write_import(folder, built, notes, mapping)
|
|
1512
|
+
|
|
1513
|
+
written = write()
|
|
1514
|
+
check = None if no_check else _check_import(folder)
|
|
1515
|
+
if check is not None and not check.get("ok") and summary is not None and not corrected:
|
|
1516
|
+
corrected = True
|
|
1517
|
+
ui.info("The files do not pass the check; the model is asked once to correct its mapping.")
|
|
1518
|
+
retried, retried_mapping = build(ask_model({"mapping": mapping, "problems": _errors_of(check)[:20]}))
|
|
1519
|
+
built, mapping = retried, retried_mapping
|
|
1520
|
+
written = write()
|
|
1521
|
+
check = _check_import(folder)
|
|
1522
|
+
|
|
1523
|
+
result: dict[str, Any] = {
|
|
1524
|
+
"folder": str(folder),
|
|
1525
|
+
"files": written,
|
|
1526
|
+
"readAs": detected.label,
|
|
1527
|
+
"mappedBy": "file" if mapping_file is not None else "model" if summary is not None else "rules",
|
|
1528
|
+
"tasks": len(built.scenarios),
|
|
1529
|
+
"traces": len(built.traces),
|
|
1530
|
+
"skipped": len(built.skipped),
|
|
1531
|
+
"mapping": mapping,
|
|
1532
|
+
"check": check,
|
|
1533
|
+
}
|
|
1534
|
+
if summary is not None:
|
|
1535
|
+
result["costUsd"] = round(cost, 6)
|
|
1536
|
+
|
|
1537
|
+
def human() -> None:
|
|
1538
|
+
ui.success(f"Wrote {folder}/: {', '.join(Path(f).name for f in written)}.")
|
|
1539
|
+
counts = [_plural(len(built.scenarios), "task")]
|
|
1540
|
+
if built.traces:
|
|
1541
|
+
counts.append(_plural(len(built.traces), "conversation") + " to learn from")
|
|
1542
|
+
if built.skipped:
|
|
1543
|
+
counts.append(f"{_plural(len(built.skipped), 'record')} left out")
|
|
1544
|
+
ui.info(f"Read as {detected.label}, by {mapped_by}: {', '.join(counts)}.")
|
|
1545
|
+
if summary is not None:
|
|
1546
|
+
ui.info(f"The model's mapping cost {ui.usd(cost, 4 if cost < 0.01 else 2)}, charged to your credit.")
|
|
1547
|
+
if check is not None:
|
|
1548
|
+
print_check(check)
|
|
1549
|
+
_check_verdict(check)
|
|
1550
|
+
ui.info(f"Read {folder}/IMPORT.md for what was guessed and what to check. Then:")
|
|
1551
|
+
ui.info(f" corethink env create {folder}")
|
|
1552
|
+
ui.info(" corethink train test <environment>")
|
|
1553
|
+
|
|
1554
|
+
ui.emit(result, human)
|
|
1555
|
+
if check is not None and not check.get("ok"):
|
|
1556
|
+
raise typer.Exit(EXIT_PROBLEMS)
|
|
1557
|
+
|
|
1558
|
+
|
|
1312
1559
|
# ---- versions and files ------------------------------------------------------------------------------------------------------
|
|
1313
1560
|
|
|
1314
1561
|
|
|
@@ -105,7 +105,7 @@ def _gain(starter: dict[str, Any]) -> Text | str:
|
|
|
105
105
|
delta = _delta(starter)
|
|
106
106
|
if delta is None:
|
|
107
107
|
return "—"
|
|
108
|
-
return Text(f"{ui.points(delta)}
|
|
108
|
+
return Text(f"{ui.points(delta)} pts", style="green" if delta > 0 else "dim")
|
|
109
109
|
|
|
110
110
|
|
|
111
111
|
@app.command("list")
|
|
@@ -133,7 +133,7 @@ def lift(delta: Any) -> str:
|
|
|
133
133
|
return "—"
|
|
134
134
|
if math.isnan(value):
|
|
135
135
|
return "—"
|
|
136
|
-
return f"{ui.points(value)}
|
|
136
|
+
return f"{ui.points(value)} pts"
|
|
137
137
|
|
|
138
138
|
|
|
139
139
|
def whole(usd: float) -> float | int:
|
|
@@ -1565,7 +1565,7 @@ def estimate(
|
|
|
1565
1565
|
least, most = run_limits()
|
|
1566
1566
|
available, _ = credit_available()
|
|
1567
1567
|
budget = default_budget(likely_cost(answer), available, most, least)
|
|
1568
|
-
for line in estimate_lines(answer):
|
|
1568
|
+
for line in estimate_lines(answer, budget):
|
|
1569
1569
|
ui.out.print(line, style="dim" if line.startswith(" ") else None)
|
|
1570
1570
|
ui.out.print(
|
|
1571
1571
|
f"A run would start with a limit of {ui.usd(budget, 0)} (set it with --limit).",
|