@answerlayer/cli 0.2.0 → 0.2.1
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.
- package/README.md +23 -0
- package/package.json +1 -1
- package/src/cli.js +145 -0
package/README.md
CHANGED
|
@@ -235,6 +235,29 @@ Useful scopes:
|
|
|
235
235
|
|
|
236
236
|
## Commands
|
|
237
237
|
|
|
238
|
+
### Semantic optimization
|
|
239
|
+
|
|
240
|
+
Launch a durable, eval-driven optimization run without changing the active
|
|
241
|
+
semantic layer:
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
answerlayer optimize start \
|
|
245
|
+
--name "Exoplanet semantic optimization" \
|
|
246
|
+
--connection CONNECTION_ID \
|
|
247
|
+
--suite SUITE_ID \
|
|
248
|
+
--model openai.gpt-5.6-terra \
|
|
249
|
+
--mode recommendation
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Inspect and operate the registry with `answerlayer optimize list`,
|
|
253
|
+
`get RUN_ID`, `pause RUN_ID`, `resume RUN_ID`, `stop RUN_ID`, `clone RUN_ID`,
|
|
254
|
+
`approve RUN_ID`, and `reject RUN_ID`. Promotion is a separate, explicit atomic
|
|
255
|
+
compare-and-swap using the frozen hash shown by `get RUN_ID`:
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
answerlayer optimize promote RUN_ID --base-hash FROZEN_BASE_SHA256
|
|
259
|
+
```
|
|
260
|
+
|
|
238
261
|
```bash
|
|
239
262
|
answerlayer health
|
|
240
263
|
answerlayer openapi --output openapi.json
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -56,6 +56,9 @@ export async function main(argv, io) {
|
|
|
56
56
|
if (group === "semantic") return handleSemantic(client, command, positionals, parsed, io);
|
|
57
57
|
if (group === "inquiry") return handleInquiry(client, command, positionals, parsed, io);
|
|
58
58
|
if (group === "evals" || group === "evaluations") return handleEvals(client, command, positionals, parsed, io);
|
|
59
|
+
if (group === "optimize" || group === "optimization" || group === "semantic-optimization") {
|
|
60
|
+
return handleOptimization(client, command, positionals, parsed, io);
|
|
61
|
+
}
|
|
59
62
|
if (group === "ontologies" || group === "ontology") return handleOntologies(client, command, positionals, parsed, io);
|
|
60
63
|
if (group === "generation") return handleGeneration(client, command, positionals, parsed, io);
|
|
61
64
|
if (group === "tiles") return handleTiles(client, command, positionals, parsed, io);
|
|
@@ -737,6 +740,115 @@ async function handleEvals(client, resource, positionals, parsed, io) {
|
|
|
737
740
|
throw usage(`Expected evals resource: suites, cases, or runs`);
|
|
738
741
|
}
|
|
739
742
|
|
|
743
|
+
async function handleOptimization(client, command, positionals, parsed, io) {
|
|
744
|
+
const base = "/api/v1/semantic-optimization/runs";
|
|
745
|
+
if (command === "list" || !command) {
|
|
746
|
+
return requestAndPrint(client, "GET", base, parsed, io, {
|
|
747
|
+
query: { execution_status: firstValue(parsed.flags.status) },
|
|
748
|
+
table: [
|
|
749
|
+
{ key: "id", label: "ID" },
|
|
750
|
+
{ key: "name", label: "Name" },
|
|
751
|
+
{ key: "execution_status", label: "Status" },
|
|
752
|
+
{ key: "workflow_phase", label: "Phase" },
|
|
753
|
+
{ key: "mode", label: "Mode" },
|
|
754
|
+
{ key: "case_count", label: "Cases" },
|
|
755
|
+
{ key: "current_iteration", label: "Iteration" },
|
|
756
|
+
{ key: "max_iterations", label: "Max" },
|
|
757
|
+
{ key: "best_metric_movement", label: "Best Δ" },
|
|
758
|
+
],
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
if (command === "start" || command === "create") {
|
|
763
|
+
const sharedModel = firstValue(parsed.flags.model);
|
|
764
|
+
const selectedCaseIds = optionalCsvOrRepeated(parsed.flags.case);
|
|
765
|
+
const categories = optionalDistinctRepeated(parsed.flags.category);
|
|
766
|
+
const tags = optionalDistinctRepeated(parsed.flags.tag);
|
|
767
|
+
const selected = Boolean(selectedCaseIds?.length || categories?.length || tags?.length);
|
|
768
|
+
const payload = await readData(parsed.flags, io, {
|
|
769
|
+
name: firstValue(parsed.flags.name),
|
|
770
|
+
connection_id: firstValue(parsed.flags.connection),
|
|
771
|
+
eval_suite_id: firstValue(parsed.flags.suite),
|
|
772
|
+
cases: {
|
|
773
|
+
mode: selected ? "selected" : "all_active_authoring",
|
|
774
|
+
case_ids: selectedCaseIds || [],
|
|
775
|
+
categories: categories || [],
|
|
776
|
+
tags: tags || [],
|
|
777
|
+
},
|
|
778
|
+
eligible_component_types: optionalCsvOrRepeated(parsed.flags.component) || [
|
|
779
|
+
"entities", "relationships", "measures", "metrics", "dimensions", "filters",
|
|
780
|
+
],
|
|
781
|
+
proposal_strategy: firstValue(parsed.flags.proposalStrategy) || "coherent_patch",
|
|
782
|
+
search_strategy: "greedy_constrained_hill_climbing",
|
|
783
|
+
mode: firstValue(parsed.flags.mode) || "recommendation",
|
|
784
|
+
review_policy: firstValue(parsed.flags.reviewPolicy),
|
|
785
|
+
promotion_policy: firstValue(parsed.flags.promotionPolicy) || "manual",
|
|
786
|
+
models: {
|
|
787
|
+
eval_execution: firstValue(parsed.flags.evalModel) || sharedModel,
|
|
788
|
+
proposal: firstValue(parsed.flags.proposalModel) || sharedModel,
|
|
789
|
+
analysis: "deterministic",
|
|
790
|
+
validation: "deterministic",
|
|
791
|
+
repair: "disabled",
|
|
792
|
+
},
|
|
793
|
+
budget: {
|
|
794
|
+
max_iterations: numberFlag(parsed.flags.maxIterations, 3),
|
|
795
|
+
max_proposals: numberFlag(parsed.flags.maxProposals, 10),
|
|
796
|
+
max_input_tokens: numberFlag(parsed.flags.maxInputTokens, 250000),
|
|
797
|
+
max_output_tokens: numberFlag(parsed.flags.maxOutputTokens, 50000),
|
|
798
|
+
max_sql_queries: numberFlag(parsed.flags.maxSqlQueries, 500),
|
|
799
|
+
max_duration_seconds: numberFlag(parsed.flags.maxDuration, 7200),
|
|
800
|
+
},
|
|
801
|
+
objectives: {
|
|
802
|
+
minimum_score_improvement: numberFlag(parsed.flags.minImprovement, 0.5),
|
|
803
|
+
maximum_regressions: numberFlag(parsed.flags.maxRegressions, 0),
|
|
804
|
+
target_pass_rate: numberFlag(parsed.flags.targetPassRate, 100),
|
|
805
|
+
quality_weight: 1,
|
|
806
|
+
efficiency_weight: 0.25,
|
|
807
|
+
simplicity_weight: 0.25,
|
|
808
|
+
},
|
|
809
|
+
});
|
|
810
|
+
requirePayloadValue(payload, "name", "optimize start requires --name");
|
|
811
|
+
requirePayloadValue(payload, "connection_id", "optimize start requires --connection");
|
|
812
|
+
requirePayloadValue(payload, "eval_suite_id", "optimize start requires --suite");
|
|
813
|
+
const requiredModels = ["eval_execution", "proposal"];
|
|
814
|
+
if (requiredModels.some((key) => typeof payload.models?.[key] !== "string" || !payload.models[key].trim())) {
|
|
815
|
+
throw usage("optimize start requires --model or both --eval-model and --proposal-model");
|
|
816
|
+
}
|
|
817
|
+
return requestAndPrint(client, "POST", base, parsed, io, { body: payload });
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
const runId = requirePositional(positionals, 0, "semantic optimization run id");
|
|
821
|
+
if (command === "get" || command === "inspect") {
|
|
822
|
+
return requestAndPrint(client, "GET", `${base}/${encodeURIComponent(runId)}`, parsed, io);
|
|
823
|
+
}
|
|
824
|
+
if (["pause", "resume", "stop"].includes(command)) {
|
|
825
|
+
return requestAndPrint(client, "POST", `${base}/${encodeURIComponent(runId)}/${command}`, parsed, io, {
|
|
826
|
+
body: { reason: firstValue(parsed.flags.reason) },
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
if (command === "promote") {
|
|
830
|
+
const expectedActiveSha256 = firstValue(parsed.flags.baseHash);
|
|
831
|
+
if (!expectedActiveSha256) {
|
|
832
|
+
throw usage("optimize promote requires --base-hash from the run's frozen manifest");
|
|
833
|
+
}
|
|
834
|
+
return requestAndPrint(client, "POST", `${base}/${encodeURIComponent(runId)}/promote`, parsed, io, {
|
|
835
|
+
body: {
|
|
836
|
+
reason: firstValue(parsed.flags.reason),
|
|
837
|
+
expected_active_sha256: expectedActiveSha256,
|
|
838
|
+
},
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
if (command === "clone") {
|
|
842
|
+
return requestAndPrint(client, "POST", `${base}/${encodeURIComponent(runId)}/clone`, parsed, io);
|
|
843
|
+
}
|
|
844
|
+
if (command === "approve" || command === "reject") {
|
|
845
|
+
return requestAndPrint(client, "POST", `${base}/${encodeURIComponent(runId)}/decision`, parsed, io, {
|
|
846
|
+
body: { decision: command, reason: firstValue(parsed.flags.reason) },
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
throw usage(`Unknown optimize command: ${command}`);
|
|
850
|
+
}
|
|
851
|
+
|
|
740
852
|
async function handleOntologies(client, command, positionals, parsed, io) {
|
|
741
853
|
const base = "/api/v1/ontologies";
|
|
742
854
|
if (command === "list" || !command) {
|
|
@@ -1525,6 +1637,24 @@ function normalizeFlagName(rawName) {
|
|
|
1525
1637
|
"--h": "h",
|
|
1526
1638
|
"--prompt": "prompt",
|
|
1527
1639
|
"--model": "model",
|
|
1640
|
+
"--mode": "mode",
|
|
1641
|
+
"--reason": "reason",
|
|
1642
|
+
"--component": "component",
|
|
1643
|
+
"--proposal-strategy": "proposalStrategy",
|
|
1644
|
+
"--review-policy": "reviewPolicy",
|
|
1645
|
+
"--promotion-policy": "promotionPolicy",
|
|
1646
|
+
"--eval-model": "evalModel",
|
|
1647
|
+
"--proposal-model": "proposalModel",
|
|
1648
|
+
"--base-hash": "baseHash",
|
|
1649
|
+
"--max-iterations": "maxIterations",
|
|
1650
|
+
"--max-proposals": "maxProposals",
|
|
1651
|
+
"--max-input-tokens": "maxInputTokens",
|
|
1652
|
+
"--max-output-tokens": "maxOutputTokens",
|
|
1653
|
+
"--max-sql-queries": "maxSqlQueries",
|
|
1654
|
+
"--max-duration": "maxDuration",
|
|
1655
|
+
"--min-improvement": "minImprovement",
|
|
1656
|
+
"--max-regressions": "maxRegressions",
|
|
1657
|
+
"--target-pass-rate": "targetPassRate",
|
|
1528
1658
|
"--component-type": "componentType",
|
|
1529
1659
|
"--use-semantic-layer": "useSemanticLayer",
|
|
1530
1660
|
"--no-semantic-layer": "noSemanticLayer",
|
|
@@ -1643,6 +1773,13 @@ function requirePayloadValue(payload, key, message) {
|
|
|
1643
1773
|
if (!payload[key]) throw usage(message);
|
|
1644
1774
|
}
|
|
1645
1775
|
|
|
1776
|
+
function numberFlag(value, fallback) {
|
|
1777
|
+
if (value === undefined) return fallback;
|
|
1778
|
+
const parsed = Number(firstValue(value));
|
|
1779
|
+
if (!Number.isFinite(parsed)) throw usage(`Expected a numeric value, received ${firstValue(value)}`);
|
|
1780
|
+
return parsed;
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1646
1783
|
function requireEvalBatchSuites(suiteIds) {
|
|
1647
1784
|
if (!Array.isArray(suiteIds) || suiteIds.length < 2 || suiteIds.length > 20) {
|
|
1648
1785
|
throw usage("evals runs create-batch requires 2 to 20 suite ids");
|
|
@@ -1751,6 +1888,7 @@ Data products:
|
|
|
1751
1888
|
answerlayer evals suites list|create|get|update|delete
|
|
1752
1889
|
answerlayer evals cases create|update|reveal|delete
|
|
1753
1890
|
answerlayer evals runs list|create|create-batch|get|update|cancel|compare|analyze
|
|
1891
|
+
answerlayer optimize list|start|get|pause|resume|stop|clone|approve|reject|promote
|
|
1754
1892
|
case create/update accept --category <name>,
|
|
1755
1893
|
--partition <authoring|holdout|adversarial>, and
|
|
1756
1894
|
--oracle-sources '<JSON array>'
|
|
@@ -1761,6 +1899,13 @@ Data products:
|
|
|
1761
1899
|
create-batch accepts 2 to 20 suite ids as positionals or repeatable
|
|
1762
1900
|
--suite values, plus shared --label, --model, --concurrency <1-8>,
|
|
1763
1901
|
and --use-semantic-layer or --no-semantic-layer
|
|
1902
|
+
Optimization:
|
|
1903
|
+
answerlayer optimize start --name NAME --connection ID --suite ID --model MODEL
|
|
1904
|
+
[--mode recommendation|supervised|fully_automatic]
|
|
1905
|
+
[--component entities,relationships,measures,metrics,dimensions,filters]
|
|
1906
|
+
[--review-policy every_sweep|exceptions_only|end_of_run]
|
|
1907
|
+
[--promotion-policy manual|automatic] [--max-iterations N]
|
|
1908
|
+
answerlayer optimize promote RUN_ID --base-hash SHA256
|
|
1764
1909
|
update accepts --label <name>
|
|
1765
1910
|
answerlayer ontologies list|create|get|validate
|
|
1766
1911
|
validate accepts --file <ontology.tff>, --tff <source>, or stdin
|