@answerlayer/cli 0.2.0 → 0.2.2
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 +26 -0
- package/package.json +1 -1
- package/src/cli.js +149 -0
package/README.md
CHANGED
|
@@ -235,6 +235,32 @@ 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
|
+
By default the proposal model also reviews bounded failed-case traces during
|
|
253
|
+
failure analysis. Use `--analysis-model MODEL` to select a dedicated reviewer.
|
|
254
|
+
|
|
255
|
+
Inspect and operate the registry with `answerlayer optimize list`,
|
|
256
|
+
`get RUN_ID`, `pause RUN_ID`, `resume RUN_ID`, `stop RUN_ID`, `clone RUN_ID`,
|
|
257
|
+
`approve RUN_ID`, and `reject RUN_ID`. Promotion is a separate, explicit atomic
|
|
258
|
+
compare-and-swap using the frozen hash shown by `get RUN_ID`:
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
answerlayer optimize promote RUN_ID --base-hash FROZEN_BASE_SHA256
|
|
262
|
+
```
|
|
263
|
+
|
|
238
264
|
```bash
|
|
239
265
|
answerlayer health
|
|
240
266
|
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,117 @@ 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: firstValue(parsed.flags.analysisModel)
|
|
790
|
+
|| firstValue(parsed.flags.proposalModel)
|
|
791
|
+
|| sharedModel,
|
|
792
|
+
validation: "deterministic",
|
|
793
|
+
repair: "disabled",
|
|
794
|
+
},
|
|
795
|
+
budget: {
|
|
796
|
+
max_iterations: numberFlag(parsed.flags.maxIterations, 3),
|
|
797
|
+
max_proposals: numberFlag(parsed.flags.maxProposals, 10),
|
|
798
|
+
max_input_tokens: numberFlag(parsed.flags.maxInputTokens, 250000),
|
|
799
|
+
max_output_tokens: numberFlag(parsed.flags.maxOutputTokens, 50000),
|
|
800
|
+
max_sql_queries: numberFlag(parsed.flags.maxSqlQueries, 500),
|
|
801
|
+
max_duration_seconds: numberFlag(parsed.flags.maxDuration, 7200),
|
|
802
|
+
},
|
|
803
|
+
objectives: {
|
|
804
|
+
minimum_score_improvement: numberFlag(parsed.flags.minImprovement, 0.5),
|
|
805
|
+
maximum_regressions: numberFlag(parsed.flags.maxRegressions, 0),
|
|
806
|
+
target_pass_rate: numberFlag(parsed.flags.targetPassRate, 100),
|
|
807
|
+
quality_weight: 1,
|
|
808
|
+
efficiency_weight: 0.25,
|
|
809
|
+
simplicity_weight: 0.25,
|
|
810
|
+
},
|
|
811
|
+
});
|
|
812
|
+
requirePayloadValue(payload, "name", "optimize start requires --name");
|
|
813
|
+
requirePayloadValue(payload, "connection_id", "optimize start requires --connection");
|
|
814
|
+
requirePayloadValue(payload, "eval_suite_id", "optimize start requires --suite");
|
|
815
|
+
const requiredModels = ["eval_execution", "proposal"];
|
|
816
|
+
if (requiredModels.some((key) => typeof payload.models?.[key] !== "string" || !payload.models[key].trim())) {
|
|
817
|
+
throw usage("optimize start requires --model or both --eval-model and --proposal-model");
|
|
818
|
+
}
|
|
819
|
+
return requestAndPrint(client, "POST", base, parsed, io, { body: payload });
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
const runId = requirePositional(positionals, 0, "semantic optimization run id");
|
|
823
|
+
if (command === "get" || command === "inspect") {
|
|
824
|
+
return requestAndPrint(client, "GET", `${base}/${encodeURIComponent(runId)}`, parsed, io);
|
|
825
|
+
}
|
|
826
|
+
if (["pause", "resume", "stop"].includes(command)) {
|
|
827
|
+
return requestAndPrint(client, "POST", `${base}/${encodeURIComponent(runId)}/${command}`, parsed, io, {
|
|
828
|
+
body: { reason: firstValue(parsed.flags.reason) },
|
|
829
|
+
});
|
|
830
|
+
}
|
|
831
|
+
if (command === "promote") {
|
|
832
|
+
const expectedActiveSha256 = firstValue(parsed.flags.baseHash);
|
|
833
|
+
if (!expectedActiveSha256) {
|
|
834
|
+
throw usage("optimize promote requires --base-hash from the run's frozen manifest");
|
|
835
|
+
}
|
|
836
|
+
return requestAndPrint(client, "POST", `${base}/${encodeURIComponent(runId)}/promote`, parsed, io, {
|
|
837
|
+
body: {
|
|
838
|
+
reason: firstValue(parsed.flags.reason),
|
|
839
|
+
expected_active_sha256: expectedActiveSha256,
|
|
840
|
+
},
|
|
841
|
+
});
|
|
842
|
+
}
|
|
843
|
+
if (command === "clone") {
|
|
844
|
+
return requestAndPrint(client, "POST", `${base}/${encodeURIComponent(runId)}/clone`, parsed, io);
|
|
845
|
+
}
|
|
846
|
+
if (command === "approve" || command === "reject") {
|
|
847
|
+
return requestAndPrint(client, "POST", `${base}/${encodeURIComponent(runId)}/decision`, parsed, io, {
|
|
848
|
+
body: { decision: command, reason: firstValue(parsed.flags.reason) },
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
throw usage(`Unknown optimize command: ${command}`);
|
|
852
|
+
}
|
|
853
|
+
|
|
740
854
|
async function handleOntologies(client, command, positionals, parsed, io) {
|
|
741
855
|
const base = "/api/v1/ontologies";
|
|
742
856
|
if (command === "list" || !command) {
|
|
@@ -1525,6 +1639,25 @@ function normalizeFlagName(rawName) {
|
|
|
1525
1639
|
"--h": "h",
|
|
1526
1640
|
"--prompt": "prompt",
|
|
1527
1641
|
"--model": "model",
|
|
1642
|
+
"--mode": "mode",
|
|
1643
|
+
"--reason": "reason",
|
|
1644
|
+
"--component": "component",
|
|
1645
|
+
"--proposal-strategy": "proposalStrategy",
|
|
1646
|
+
"--review-policy": "reviewPolicy",
|
|
1647
|
+
"--promotion-policy": "promotionPolicy",
|
|
1648
|
+
"--eval-model": "evalModel",
|
|
1649
|
+
"--analysis-model": "analysisModel",
|
|
1650
|
+
"--proposal-model": "proposalModel",
|
|
1651
|
+
"--base-hash": "baseHash",
|
|
1652
|
+
"--max-iterations": "maxIterations",
|
|
1653
|
+
"--max-proposals": "maxProposals",
|
|
1654
|
+
"--max-input-tokens": "maxInputTokens",
|
|
1655
|
+
"--max-output-tokens": "maxOutputTokens",
|
|
1656
|
+
"--max-sql-queries": "maxSqlQueries",
|
|
1657
|
+
"--max-duration": "maxDuration",
|
|
1658
|
+
"--min-improvement": "minImprovement",
|
|
1659
|
+
"--max-regressions": "maxRegressions",
|
|
1660
|
+
"--target-pass-rate": "targetPassRate",
|
|
1528
1661
|
"--component-type": "componentType",
|
|
1529
1662
|
"--use-semantic-layer": "useSemanticLayer",
|
|
1530
1663
|
"--no-semantic-layer": "noSemanticLayer",
|
|
@@ -1643,6 +1776,13 @@ function requirePayloadValue(payload, key, message) {
|
|
|
1643
1776
|
if (!payload[key]) throw usage(message);
|
|
1644
1777
|
}
|
|
1645
1778
|
|
|
1779
|
+
function numberFlag(value, fallback) {
|
|
1780
|
+
if (value === undefined) return fallback;
|
|
1781
|
+
const parsed = Number(firstValue(value));
|
|
1782
|
+
if (!Number.isFinite(parsed)) throw usage(`Expected a numeric value, received ${firstValue(value)}`);
|
|
1783
|
+
return parsed;
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1646
1786
|
function requireEvalBatchSuites(suiteIds) {
|
|
1647
1787
|
if (!Array.isArray(suiteIds) || suiteIds.length < 2 || suiteIds.length > 20) {
|
|
1648
1788
|
throw usage("evals runs create-batch requires 2 to 20 suite ids");
|
|
@@ -1751,6 +1891,7 @@ Data products:
|
|
|
1751
1891
|
answerlayer evals suites list|create|get|update|delete
|
|
1752
1892
|
answerlayer evals cases create|update|reveal|delete
|
|
1753
1893
|
answerlayer evals runs list|create|create-batch|get|update|cancel|compare|analyze
|
|
1894
|
+
answerlayer optimize list|start|get|pause|resume|stop|clone|approve|reject|promote
|
|
1754
1895
|
case create/update accept --category <name>,
|
|
1755
1896
|
--partition <authoring|holdout|adversarial>, and
|
|
1756
1897
|
--oracle-sources '<JSON array>'
|
|
@@ -1761,6 +1902,14 @@ Data products:
|
|
|
1761
1902
|
create-batch accepts 2 to 20 suite ids as positionals or repeatable
|
|
1762
1903
|
--suite values, plus shared --label, --model, --concurrency <1-8>,
|
|
1763
1904
|
and --use-semantic-layer or --no-semantic-layer
|
|
1905
|
+
Optimization:
|
|
1906
|
+
answerlayer optimize start --name NAME --connection ID --suite ID --model MODEL
|
|
1907
|
+
[--eval-model MODEL] [--proposal-model MODEL] [--analysis-model MODEL]
|
|
1908
|
+
[--mode recommendation|supervised|fully_automatic]
|
|
1909
|
+
[--component entities,relationships,measures,metrics,dimensions,filters]
|
|
1910
|
+
[--review-policy every_sweep|exceptions_only|end_of_run]
|
|
1911
|
+
[--promotion-policy manual|automatic] [--max-iterations N]
|
|
1912
|
+
answerlayer optimize promote RUN_ID --base-hash SHA256
|
|
1764
1913
|
update accepts --label <name>
|
|
1765
1914
|
answerlayer ontologies list|create|get|validate
|
|
1766
1915
|
validate accepts --file <ontology.tff>, --tff <source>, or stdin
|