@faces-sh/cli 1.1.0 → 1.3.0
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 +106 -54
- package/dist/billing.js +11 -8
- package/dist/chat-command.d.ts +33 -0
- package/dist/chat-command.js +110 -0
- package/dist/chat.d.ts +49 -0
- package/dist/chat.js +157 -0
- package/dist/choices.d.ts +11 -5
- package/dist/choices.js +26 -9
- package/dist/client.d.ts +8 -0
- package/dist/client.js +37 -0
- package/dist/commands/billing/llm-costs.js +9 -5
- package/dist/commands/billing/subscription/index.js +1 -1
- package/dist/commands/catalog/doctor.js +2 -2
- package/dist/commands/{causes.d.ts → chat/chat.d.ts} +14 -14
- package/dist/commands/chat/chat.js +31 -0
- package/dist/commands/chat/messages.d.ts +32 -0
- package/dist/commands/chat/messages.js +21 -0
- package/dist/commands/chat/responses.d.ts +32 -0
- package/dist/commands/chat/responses.js +22 -0
- package/dist/commands/chat/thread.d.ts +40 -0
- package/dist/commands/chat/thread.js +238 -0
- package/dist/commands/choices.d.ts +4 -2
- package/dist/commands/choices.js +56 -15
- package/dist/commands/conversation/add.d.ts +2 -0
- package/dist/commands/conversation/add.js +5 -2
- package/dist/commands/conversation/compact.js +13 -16
- package/dist/commands/conversation/create.d.ts +2 -0
- package/dist/commands/conversation/create.js +14 -11
- package/dist/commands/decide.d.ts +32 -4
- package/dist/commands/decide.js +135 -83
- package/dist/commands/face/get.js +1 -1
- package/dist/commands/face/list.d.ts +2 -0
- package/dist/commands/face/list.js +23 -1
- package/dist/commands/fidelity/pick.js +2 -2
- package/dist/commands/fidelity/run.d.ts +20 -0
- package/dist/commands/fidelity/run.js +99 -0
- package/dist/commands/fidelity/start.d.ts +17 -0
- package/dist/commands/fidelity/start.js +56 -0
- package/dist/commands/fidelity/turn.d.ts +17 -0
- package/dist/commands/fidelity/turn.js +48 -0
- package/dist/commands/group/add.js +1 -1
- package/dist/commands/media/list.d.ts +12 -0
- package/dist/commands/media/list.js +35 -0
- package/dist/commands/models/list.js +13 -6
- package/dist/commands/premise/add.d.ts +30 -0
- package/dist/commands/premise/add.js +86 -0
- package/dist/commands/premise/choices.d.ts +21 -0
- package/dist/commands/premise/choices.js +68 -0
- package/dist/commands/premise/claim.d.ts +20 -0
- package/dist/commands/premise/claim.js +38 -0
- package/dist/commands/premise/decide.d.ts +18 -0
- package/dist/commands/premise/decide.js +36 -0
- package/dist/commands/premise/delete.d.ts +17 -0
- package/dist/commands/premise/delete.js +17 -0
- package/dist/commands/premise/edit.d.ts +28 -0
- package/dist/commands/premise/edit.js +51 -0
- package/dist/commands/premise/get.d.ts +22 -0
- package/dist/commands/premise/get.js +37 -0
- package/dist/commands/premise/refine.d.ts +20 -0
- package/dist/commands/premise/refine.js +80 -0
- package/dist/commands/session/compact.js +5 -8
- package/dist/commands/session/create.js +9 -8
- package/dist/commands/state/create.d.ts +13 -2
- package/dist/commands/state/create.js +55 -2
- package/dist/commands/state/get.d.ts +19 -2
- package/dist/commands/state/get.js +30 -2
- package/dist/commands/state/use.d.ts +16 -0
- package/dist/commands/state/use.js +25 -0
- package/dist/commands/style/make.js +1 -1
- package/dist/commands/style/upload.js +1 -1
- package/dist/conversation.d.ts +30 -3
- package/dist/conversation.js +202 -18
- package/dist/decisions.d.ts +0 -5
- package/dist/decisions.js +0 -18
- package/dist/fidelity.js +3 -3
- package/dist/foreman.d.ts +47 -0
- package/dist/foreman.js +115 -0
- package/dist/media.d.ts +8 -0
- package/dist/media.js +12 -0
- package/dist/model.d.ts +11 -0
- package/dist/model.js +53 -0
- package/dist/refine.d.ts +106 -0
- package/dist/refine.js +601 -0
- package/dist/routing.d.ts +1 -4
- package/dist/routing.js +4 -40
- package/dist/synopsis.d.ts +49 -0
- package/dist/synopsis.js +43 -0
- package/dist/utils.d.ts +1 -25
- package/dist/utils.js +10 -108
- package/oclif.manifest.json +3939 -1835
- package/package.json +10 -4
- package/dist/commands/causes.js +0 -146
|
@@ -1,9 +1,37 @@
|
|
|
1
1
|
import { BaseCommand } from '../base.js';
|
|
2
|
+
export interface WeighResponse {
|
|
3
|
+
answers?: Array<{
|
|
4
|
+
probabilities?: Array<{
|
|
5
|
+
value?: string;
|
|
6
|
+
probability?: number;
|
|
7
|
+
}>;
|
|
8
|
+
choice?: string;
|
|
9
|
+
}>;
|
|
10
|
+
decision_ids?: Record<string, string>;
|
|
11
|
+
weigh?: {
|
|
12
|
+
premise?: string;
|
|
13
|
+
kind?: string;
|
|
14
|
+
cutoff?: number;
|
|
15
|
+
edges?: Array<{
|
|
16
|
+
id?: string;
|
|
17
|
+
p?: number;
|
|
18
|
+
}>;
|
|
19
|
+
pruned?: string[];
|
|
20
|
+
side_node?: string;
|
|
21
|
+
written?: boolean;
|
|
22
|
+
decision?: string;
|
|
23
|
+
reason?: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export declare function weighLines(data: WeighResponse): string[];
|
|
2
27
|
export default class Decide extends BaseCommand {
|
|
3
28
|
static description: string;
|
|
4
29
|
static examples: string[];
|
|
5
30
|
static flags: {
|
|
6
31
|
'depends-on': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
32
|
+
weigh: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
33
|
+
'weigh-kind': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
34
|
+
cutoff: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
35
|
session: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
36
|
compaction: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
37
|
format: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
@@ -13,6 +41,8 @@ export default class Decide extends BaseCommand {
|
|
|
13
41
|
'premise-description': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
42
|
'premise-status': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
43
|
'premise-depends-on': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
44
|
+
'premise-role': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
45
|
+
'premise-origin': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
46
|
'causes-visible': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
17
47
|
state: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
18
48
|
'state-file': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
@@ -22,19 +52,17 @@ export default class Decide extends BaseCommand {
|
|
|
22
52
|
level: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
23
53
|
id: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
24
54
|
'questions-file': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
25
|
-
model: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
26
|
-
baseline: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
27
|
-
'show-cause': import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
28
55
|
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
29
56
|
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
30
57
|
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
31
58
|
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
32
59
|
};
|
|
33
60
|
static args: {
|
|
34
|
-
|
|
61
|
+
model: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
35
62
|
};
|
|
36
63
|
run(): Promise<unknown>;
|
|
37
64
|
private ask;
|
|
65
|
+
private weigh;
|
|
38
66
|
private readState;
|
|
39
67
|
private readQuestions;
|
|
40
68
|
private models?;
|
package/dist/commands/decide.js
CHANGED
|
@@ -2,29 +2,45 @@ import { Args, Flags } from '@oclif/core';
|
|
|
2
2
|
import { BaseCommand } from '../base.js';
|
|
3
3
|
import { FacesAPIError, missingFieldsNote } from '../client.js';
|
|
4
4
|
import { conversationFields, conversationTurnFlags, MAX_DEPENDS_ON, parseDependsOn } from '../conversation.js';
|
|
5
|
-
import { DECISION_MODELS, decisionModels, DECISION_FORMATS, fromOpenAIAnswers, toOpenAIDecision, questionsProblem, MAX_WARM_UP_WAIT_S, QUESTION_TYPES,
|
|
6
|
-
import { compileHint,
|
|
5
|
+
import { DECISION_MODELS, decisionModels, DECISION_FORMATS, fromOpenAIAnswers, toOpenAIDecision, questionsProblem, MAX_WARM_UP_WAIT_S, QUESTION_TYPES, decisionLines, heldDecisionError, readStateFlags, readQuestionFlags, warmUpWait, } from '../decisions.js';
|
|
6
|
+
import { compileHint, sayWarmUp, SESSION_FLAG_DESCRIPTION, COMPACTION_FLAG_DESCRIPTION } from '../utils.js';
|
|
7
|
+
import { modelProblem, parseModel } from '../model.js';
|
|
8
|
+
export function weighLines(data) {
|
|
9
|
+
const w = data.weigh ?? {};
|
|
10
|
+
if (!w.written)
|
|
11
|
+
return [`Nothing was written: ${w.reason ?? 'the decision gave no weights'}.`];
|
|
12
|
+
const lines = [`${w.premise ?? '?'}: its ${w.kind ?? '?'} edges, weighed by ${w.decision ?? 'the decision'}`];
|
|
13
|
+
for (const e of w.edges ?? []) {
|
|
14
|
+
const p = typeof e.p === 'number' ? e.p : 0;
|
|
15
|
+
const pruned = (w.pruned ?? []).includes(e.id ?? '') ? ' pruned' : '';
|
|
16
|
+
lines.push(` ${String(Math.round(p * 100) / 100).padEnd(5)} ${e.id ?? '?'}${pruned}`);
|
|
17
|
+
}
|
|
18
|
+
if ((w.pruned ?? []).length > 0) {
|
|
19
|
+
lines.push('', `Pruned (set invalidated): the alternatives outside ${w.cutoff ?? 0.85} of the probability.`);
|
|
20
|
+
}
|
|
21
|
+
lines.push(`side node: ${w.side_node ?? '-'}`);
|
|
22
|
+
return lines;
|
|
23
|
+
}
|
|
7
24
|
const OPENAI_FORMAT_ONLY = ['gpt-6-luna'];
|
|
8
25
|
export default class Decide extends BaseCommand {
|
|
9
26
|
static description = 'Ask what a face would decide. Describe a situation, ask typed questions about it, and get back numbers, ' +
|
|
10
27
|
'as this face: a yes-or-no (noul), a pick between options (choice), or a place on a graded scale (score). ' +
|
|
11
28
|
'faces choices gives you the options a face would weigh; this gives you what it would decide, for routing, ' +
|
|
12
|
-
'simulations or panels.
|
|
13
|
-
'
|
|
14
|
-
'
|
|
15
|
-
'
|
|
16
|
-
'
|
|
17
|
-
'credits; on Free both bill per token. A face needs something compiled.';
|
|
29
|
+
'simulations or panels. Name the model as the upstream model over the decision model: ' +
|
|
30
|
+
'@alice:maestro-1/jev-latest. The face steers the decision model\'s answer. An answer takes about 10 to 20 ' +
|
|
31
|
+
'seconds; one that runs long is held open by the server and can take a minute or more. ' +
|
|
32
|
+
'The steering is billed per input token plus a small fee per call (see faces models:list --kind upstream), ' +
|
|
33
|
+
'and the decision model at its listed price. A face needs something compiled.';
|
|
18
34
|
static examples = [
|
|
19
|
-
'<%= config.bin %> <%= command.id %> alice --state "A colleague asks you to sign a grant proposal you have not read, due in an hour." ' +
|
|
35
|
+
'<%= config.bin %> <%= command.id %> @alice:maestro-1/jev-latest --state "A colleague asks you to sign a grant proposal you have not read, due in an hour." ' +
|
|
20
36
|
'--question "Does the speaker sign?" --option yes="signs it as asked" --option no="declines to sign" ' +
|
|
21
37
|
'--option later="asks for time to read it first"',
|
|
22
|
-
'<%= config.bin %> <%= command.id %> alice --state-file situation.txt --question "Is the speaker irritated?"',
|
|
23
|
-
'<%= config.bin %> <%= command.id %> alice --state-file situation.txt --question "How firm is the reply?" ' +
|
|
24
|
-
'--level yields --level hedges --level firm
|
|
25
|
-
'<%= config.bin %> <%= command.id %>
|
|
26
|
-
'<%= config.bin %> <%= command.id %> alice --state-file situation.txt',
|
|
27
|
-
'<%= config.bin %> <%= command.id %> alice --
|
|
38
|
+
'<%= config.bin %> <%= command.id %> @alice:maestro-1/jev-latest --state-file situation.txt --question "Is the speaker irritated?"',
|
|
39
|
+
'<%= config.bin %> <%= command.id %> @alice:maestro-1-flash/clef --state-file situation.txt --question "How firm is the reply?" ' +
|
|
40
|
+
'--level yields --level hedges --level firm',
|
|
41
|
+
'<%= config.bin %> <%= command.id %> "(@alice | @bob):maestro-1/jev-latest" --state-file situation.json --questions-file questions.json --json',
|
|
42
|
+
'<%= config.bin %> <%= command.id %> @alice:maestro-1/gpt-6-luna --state-file situation.txt --questions-file questions.json',
|
|
43
|
+
'<%= config.bin %> <%= command.id %> @alice:maestro-1/jev-latest --conversation fs_STATE_ID --weigh "handle bad input"',
|
|
28
44
|
];
|
|
29
45
|
static flags = {
|
|
30
46
|
...BaseCommand.baseFlags,
|
|
@@ -75,31 +91,33 @@ export default class Decide extends BaseCommand {
|
|
|
75
91
|
'{"true": "...", "false": "..."}.',
|
|
76
92
|
exclusive: ['question'],
|
|
77
93
|
}),
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
'
|
|
82
|
-
|
|
83
|
-
|
|
94
|
+
...conversationTurnFlags(),
|
|
95
|
+
'depends-on': Flags.string({
|
|
96
|
+
description: 'In a state (--conversation), what this decision rests on, comma separated: premise keys, decision ids and ' +
|
|
97
|
+
'option ids (opt_..., or cho_... for all of a choices list, from faces choices --state-id) ' +
|
|
98
|
+
`already in the state or set with --premise, at most ${MAX_DEPENDS_ON} (a key that holds a comma goes in ` +
|
|
99
|
+
'double quotes: \'"x, y",dec_1\'). The decision is shown those, and is ' +
|
|
100
|
+
'invalidated when one of them is. Left out, it rests on every premise in force.',
|
|
84
101
|
}),
|
|
85
|
-
|
|
86
|
-
description: '
|
|
87
|
-
|
|
102
|
+
weigh: Flags.string({
|
|
103
|
+
description: 'In a state (--conversation): weigh the edges of this premise. The face decides between the premises it rests ' +
|
|
104
|
+
'on (one kind at a time, --weigh-kind), and each probability is written onto its edge with the decision that ' +
|
|
105
|
+
'set it. For or edges, the alternatives outside --cutoff are set invalidated, with the reason. No --question: ' +
|
|
106
|
+
'the question is the premise and its children. Sent in OpenAI\'s format.',
|
|
107
|
+
exclusive: ['question', 'questions-file', 'depends-on'],
|
|
88
108
|
}),
|
|
89
|
-
'
|
|
90
|
-
description: '
|
|
91
|
-
|
|
92
|
-
|
|
109
|
+
'weigh-kind': Flags.string({
|
|
110
|
+
description: 'With --weigh, when the premise rests on both kinds: which edges to weigh, or or and.',
|
|
111
|
+
options: ['or', 'and'],
|
|
112
|
+
dependsOn: ['weigh'],
|
|
93
113
|
}),
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
'invalidated when one of them is. Left out, it rests on every premise in force.',
|
|
99
|
-
exclusive: ['baseline'],
|
|
114
|
+
cutoff: Flags.string({
|
|
115
|
+
description: 'With --weigh: the probability mass to keep, above 0 and at most 1 (default 0.85). The likeliest or ' +
|
|
116
|
+
'alternatives are kept until they reach it; the rest are pruned. and children are never pruned.',
|
|
117
|
+
dependsOn: ['weigh'],
|
|
100
118
|
}),
|
|
101
|
-
session: Flags.string({ description: SESSION_FLAG_DESCRIPTION
|
|
102
|
-
compaction: Flags.string({ description: COMPACTION_FLAG_DESCRIPTION
|
|
119
|
+
session: Flags.string({ description: SESSION_FLAG_DESCRIPTION }),
|
|
120
|
+
compaction: Flags.string({ description: COMPACTION_FLAG_DESCRIPTION }),
|
|
103
121
|
format: Flags.string({
|
|
104
122
|
description: 'The request shape: systemone (default, TypeSafe Jev\'s System One) or openai (OpenAI\'s Decisions ' +
|
|
105
123
|
'format). The answers are the same; --json returns the chosen format\'s own shape.',
|
|
@@ -114,16 +132,24 @@ export default class Decide extends BaseCommand {
|
|
|
114
132
|
}),
|
|
115
133
|
};
|
|
116
134
|
static args = {
|
|
117
|
-
|
|
135
|
+
model: Args.string({
|
|
136
|
+
description: 'The upstream model over the decision model: @<face>:<maestro>/<decision model>, e.g. ' +
|
|
137
|
+
'@alice:maestro-1/jev-latest. Another account\'s face is @owner~face; a composite is ' +
|
|
138
|
+
'"(@a | @b):maestro-1/jev-latest". The decision models are jev-latest, clef, clef-flash and gpt-6-luna ' +
|
|
139
|
+
'today (faces models:list --kind decision); gpt-6-luna answers in OpenAI\'s format only, so it uses --format openai.',
|
|
140
|
+
required: true,
|
|
141
|
+
}),
|
|
118
142
|
};
|
|
119
143
|
async run() {
|
|
120
144
|
const { args, flags } = await this.parse(Decide);
|
|
121
145
|
const client = this.makeClient(flags);
|
|
122
146
|
const json = this.jsonEnabled();
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
147
|
+
const problem = modelProblem(args.model, 'both', 'jev-latest');
|
|
148
|
+
if (problem)
|
|
149
|
+
this.error(problem);
|
|
150
|
+
const name = parseModel(args.model);
|
|
151
|
+
const face = name.faces;
|
|
152
|
+
let downstream = name.downstream;
|
|
127
153
|
let turn = {};
|
|
128
154
|
try {
|
|
129
155
|
turn = conversationFields(flags);
|
|
@@ -136,29 +162,29 @@ export default class Decide extends BaseCommand {
|
|
|
136
162
|
catch (err) {
|
|
137
163
|
this.error(err instanceof Error ? err.message : String(err));
|
|
138
164
|
}
|
|
139
|
-
|
|
165
|
+
if (flags.weigh !== undefined)
|
|
166
|
+
return this.weigh(client, flags, name, downstream, json, turn);
|
|
167
|
+
const state = flags.conversation && !flags.state && !flags['state-file'] ? undefined : this.readState(flags);
|
|
140
168
|
const questions = this.readQuestions(flags);
|
|
141
|
-
if (!questions
|
|
142
|
-
this.error('
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
flags.format = 'openai';
|
|
169
|
+
if (!questions)
|
|
170
|
+
this.error('Ask at least one question, with --question or --questions-file.');
|
|
171
|
+
const openaiOnly = OPENAI_FORMAT_ONLY.includes(downstream.toLowerCase());
|
|
172
|
+
const problemQ = questionsProblem(questions, true, openaiOnly);
|
|
173
|
+
if (problemQ)
|
|
174
|
+
this.error(problemQ);
|
|
175
|
+
this.models = await decisionModels(client);
|
|
176
|
+
const match = this.models.find((m) => m.toLowerCase() === downstream.toLowerCase());
|
|
177
|
+
if (!match)
|
|
178
|
+
this.error(`'${downstream}' is not a decision model. The decision models are: ${this.models.join(', ')}.`);
|
|
179
|
+
downstream = match;
|
|
180
|
+
if (OPENAI_FORMAT_ONLY.includes(match)) {
|
|
181
|
+
if (this.argv.some((a) => a === '--format=systemone' || a === 'systemone')) {
|
|
182
|
+
this.error(`${match} answers in OpenAI's format only. Use --format openai, or leave --format out.`);
|
|
157
183
|
}
|
|
184
|
+
flags.format = 'openai';
|
|
158
185
|
}
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
let body = questions ? { model, state, questions } : { model, state };
|
|
186
|
+
const model = `${name.upstream}/${downstream}`;
|
|
187
|
+
let body = state === undefined ? { model, questions } : { model, state, questions };
|
|
162
188
|
if (flags.format === 'openai') {
|
|
163
189
|
try {
|
|
164
190
|
body = toOpenAIDecision(model, state, questions);
|
|
@@ -173,11 +199,7 @@ export default class Decide extends BaseCommand {
|
|
|
173
199
|
body.compaction = flags.compaction;
|
|
174
200
|
Object.assign(body, turn);
|
|
175
201
|
if (!json) {
|
|
176
|
-
process.stderr.write(
|
|
177
|
-
? `Asking ${face} for its cause alone, with no questions.\n`
|
|
178
|
-
: face
|
|
179
|
-
? `Asking ${face}. Decision model: ${flags.model}. This usually takes 10 to 20 seconds, sometimes a minute or more.\n`
|
|
180
|
-
: `Asking the decision model alone (no-face baseline). Decision model: ${flags.model}.\n`);
|
|
202
|
+
process.stderr.write(`Asking ${face}. Decision model: ${downstream}. This usually takes 10 to 20 seconds, sometimes a minute or more.\n`);
|
|
181
203
|
}
|
|
182
204
|
let data;
|
|
183
205
|
try {
|
|
@@ -185,24 +207,14 @@ export default class Decide extends BaseCommand {
|
|
|
185
207
|
}
|
|
186
208
|
catch (err) {
|
|
187
209
|
if (err instanceof FacesAPIError)
|
|
188
|
-
this.error(this.explain(err, face,
|
|
210
|
+
this.error(this.explain(err, face, downstream));
|
|
189
211
|
throw err;
|
|
190
212
|
}
|
|
191
|
-
const
|
|
192
|
-
const missing = missingFieldsNote(data, expected);
|
|
193
|
-
if (missing && !json && !questions)
|
|
194
|
-
this.error(missing);
|
|
213
|
+
const missing = missingFieldsNote(data, ['answers']);
|
|
195
214
|
if (missing)
|
|
196
215
|
process.stderr.write(`${missing}\n`);
|
|
197
216
|
if (json)
|
|
198
217
|
return data;
|
|
199
|
-
if (!questions) {
|
|
200
|
-
this.log(data.cause ?? '');
|
|
201
|
-
return data;
|
|
202
|
-
}
|
|
203
|
-
const cause = causeLines(data, Object.keys(questions));
|
|
204
|
-
if (flags['show-cause'] && cause.length > 0 && face)
|
|
205
|
-
process.stderr.write(`${reasoningHeading(face)}\n${cause.join('\n')}\n\n`);
|
|
206
218
|
const answers = flags.format === 'openai' ? fromOpenAIAnswers(data.answers, questions) : (data.answers ?? {});
|
|
207
219
|
for (const line of decisionLines(answers))
|
|
208
220
|
this.log(line);
|
|
@@ -237,6 +249,48 @@ export default class Decide extends BaseCommand {
|
|
|
237
249
|
}
|
|
238
250
|
}
|
|
239
251
|
}
|
|
252
|
+
async weigh(client, flags, name, downstream, json, turn) {
|
|
253
|
+
const sid = flags.conversation ?? flags.session;
|
|
254
|
+
if (!sid)
|
|
255
|
+
this.error('--weigh weighs a premise of a state: add --conversation <id> (from faces state:create).');
|
|
256
|
+
const premise = (flags.weigh ?? '').trim();
|
|
257
|
+
if (!premise)
|
|
258
|
+
this.error('--weigh is empty: name the premise whose edges to weigh.');
|
|
259
|
+
const weigh = { premise };
|
|
260
|
+
if (flags['weigh-kind'])
|
|
261
|
+
weigh.kind = flags['weigh-kind'];
|
|
262
|
+
if (flags.cutoff !== undefined) {
|
|
263
|
+
const c = Number(flags.cutoff);
|
|
264
|
+
if (!Number.isFinite(c) || c <= 0 || c > 1)
|
|
265
|
+
this.error(`--cutoff is a number above 0 and at most 1 (got '${flags.cutoff}').`);
|
|
266
|
+
weigh.cutoff = c;
|
|
267
|
+
}
|
|
268
|
+
this.models = await decisionModels(client);
|
|
269
|
+
const match = this.models.find((m) => m.toLowerCase() === downstream.toLowerCase());
|
|
270
|
+
if (!match)
|
|
271
|
+
this.error(`'${downstream}' is not a decision model. The decision models are: ${this.models.join(', ')}.`);
|
|
272
|
+
const body = { model: `${name.upstream}/${match}`, conversation: sid, weigh, ...turn };
|
|
273
|
+
if (flags.state !== undefined || flags['state-file'] !== undefined) {
|
|
274
|
+
const st = this.readState(flags);
|
|
275
|
+
body.input = typeof st === 'string' ? st : JSON.stringify(st);
|
|
276
|
+
}
|
|
277
|
+
if (!json)
|
|
278
|
+
process.stderr.write(`Weighing ${premise} with ${name.faces}. Decision model: ${match}. This usually takes 10 to 20 seconds.\n`);
|
|
279
|
+
let data;
|
|
280
|
+
try {
|
|
281
|
+
data = (await this.ask(client, body, flags.retry, json, '/v1/decisions'));
|
|
282
|
+
}
|
|
283
|
+
catch (err) {
|
|
284
|
+
if (err instanceof FacesAPIError)
|
|
285
|
+
this.error(this.explain(err, name.faces, match));
|
|
286
|
+
throw err;
|
|
287
|
+
}
|
|
288
|
+
if (json)
|
|
289
|
+
return data;
|
|
290
|
+
for (const line of weighLines(data))
|
|
291
|
+
this.log(line);
|
|
292
|
+
return data;
|
|
293
|
+
}
|
|
240
294
|
readState(flags) {
|
|
241
295
|
return readStateFlags(flags, (m) => this.error(m));
|
|
242
296
|
}
|
|
@@ -248,18 +302,16 @@ export default class Decide extends BaseCommand {
|
|
|
248
302
|
const head = `HTTP ${err.statusCode}: ${err.message}`;
|
|
249
303
|
switch (err.statusCode) {
|
|
250
304
|
case 409: {
|
|
251
|
-
|
|
252
|
-
return head;
|
|
253
|
-
return `${head}\n${compileHint(face, !/nothing compiled/i.test(err.message), 'decide')}`;
|
|
305
|
+
return `${head}\n${compileHint(face.replace(/^@/, '').replace('~', ':'), !/nothing compiled/i.test(err.message), 'decide')}`;
|
|
254
306
|
}
|
|
255
307
|
case 503: {
|
|
256
308
|
if (err.retryAfter !== undefined)
|
|
257
309
|
return `${head}\nTry again in ${err.retryAfter}s.`;
|
|
258
310
|
const others = (this.models ?? [...DECISION_MODELS]).filter((m) => m !== model).join(', ');
|
|
259
|
-
return `${head}\nTry again. If the message names the decision model, another
|
|
311
|
+
return `${head}\nTry again. If the message names the decision model, another decision model may answer (${others}).`;
|
|
260
312
|
}
|
|
261
313
|
case 504: {
|
|
262
|
-
return `${head}\
|
|
314
|
+
return `${head}\nThe face did not finish within 300 seconds. Ask again.`;
|
|
263
315
|
}
|
|
264
316
|
default: {
|
|
265
317
|
return head;
|
|
@@ -6,7 +6,7 @@ import { score10 } from '../../fidelity.js';
|
|
|
6
6
|
import { faceStyles, renameFaceFields, resolveFace, isMeAlias, ME_MISSING, seg } from '../../utils.js';
|
|
7
7
|
export default class FaceGet extends BaseCommand {
|
|
8
8
|
static description = 'Get details for a face, by alias or owner:alias. A published or shared face is reachable under the ' +
|
|
9
|
-
'
|
|
9
|
+
'owner:alias address (in a model it is written @owner~alias); it is shown with a note that you do not own it.';
|
|
10
10
|
static flags = {
|
|
11
11
|
...BaseCommand.baseFlags,
|
|
12
12
|
include: Flags.string({
|
|
@@ -14,6 +14,8 @@ export default class FaceList extends BaseCommand {
|
|
|
14
14
|
sort: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
15
15
|
order: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
16
16
|
search: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
17
|
+
for: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
18
|
+
limit: import("@oclif/core/interfaces").OptionFlag<number | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
17
19
|
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
18
20
|
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
19
21
|
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
@@ -2,6 +2,7 @@ import { Flags } from '@oclif/core';
|
|
|
2
2
|
import { BaseCommand } from '../../base.js';
|
|
3
3
|
import { FacesAPIError } from '../../client.js';
|
|
4
4
|
import { renameFaceFields, faceStyles, readablePatternError } from '../../utils.js';
|
|
5
|
+
const FOR_LIMIT = 10;
|
|
5
6
|
const SYSTEM_OWNER = 'head';
|
|
6
7
|
export default class FaceList extends BaseCommand {
|
|
7
8
|
static description = 'List faces. By default lists owned faces, newest first; use --public to include published faces ' +
|
|
@@ -38,6 +39,14 @@ export default class FaceList extends BaseCommand {
|
|
|
38
39
|
search: Flags.string({
|
|
39
40
|
description: 'Only faces whose alias, name or description matches this text',
|
|
40
41
|
}),
|
|
42
|
+
for: Flags.string({
|
|
43
|
+
description: 'A task, in plain words: ranks the faces by how well their "use me for" line fits it, best first, each with ' +
|
|
44
|
+
'its fit from 0 to 1. It ranks and never filters. Shows the best 10 unless --limit says otherwise.',
|
|
45
|
+
}),
|
|
46
|
+
limit: Flags.integer({
|
|
47
|
+
description: `The most faces to show, best first with --for; 0 shows all. Default: ${FOR_LIMIT} with --for, all without.`,
|
|
48
|
+
min: 0,
|
|
49
|
+
}),
|
|
41
50
|
};
|
|
42
51
|
async run() {
|
|
43
52
|
const { flags } = await this.parse(FaceList);
|
|
@@ -76,6 +85,8 @@ export default class FaceList extends BaseCommand {
|
|
|
76
85
|
parts.push(`order=${encodeURIComponent(flags.order)}`);
|
|
77
86
|
if (flags.search)
|
|
78
87
|
parts.push(`q=${encodeURIComponent(flags.search)}`);
|
|
88
|
+
if (flags.for)
|
|
89
|
+
parts.push(`for=${encodeURIComponent(flags.for)}`);
|
|
79
90
|
if (includePublished)
|
|
80
91
|
parts.push('include_published=true');
|
|
81
92
|
if (flags.shared)
|
|
@@ -115,6 +126,12 @@ export default class FaceList extends BaseCommand {
|
|
|
115
126
|
const block = new Set(notFromUsers);
|
|
116
127
|
faces = faces.filter(f => f.owned_by == null || !block.has(f.owned_by));
|
|
117
128
|
}
|
|
129
|
+
const limit = flags.limit ?? (flags.for ? FOR_LIMIT : 0);
|
|
130
|
+
const more = limit > 0 ? Math.max(0, faces.length - limit) : 0;
|
|
131
|
+
if (more > 0)
|
|
132
|
+
faces = faces.slice(0, limit);
|
|
133
|
+
if (more > 0 && data && typeof data === 'object' && !Array.isArray(data))
|
|
134
|
+
data.more = more;
|
|
118
135
|
if (data.data !== undefined)
|
|
119
136
|
data.data = faces;
|
|
120
137
|
else
|
|
@@ -155,9 +172,14 @@ export default class FaceList extends BaseCommand {
|
|
|
155
172
|
if (f.read_only)
|
|
156
173
|
suffix += ' [read only]';
|
|
157
174
|
const spec = f.specialty ? ` (${f.specialty})` : '';
|
|
158
|
-
|
|
175
|
+
const fit = typeof f.fit === 'number' ? `${f.fit.toFixed(2)} ` : '';
|
|
176
|
+
this.log(`${fit}${handle(f).padEnd(handleWidth)} ${f.name.padEnd(nameWidth)}${spec}${suffix}`.trimEnd());
|
|
159
177
|
}
|
|
160
178
|
}
|
|
179
|
+
if (more > 0) {
|
|
180
|
+
this.log('');
|
|
181
|
+
this.log(`${more} more face${more === 1 ? '' : 's'} ${flags.for ? 'fit less well' : 'not shown'}. --limit N shows the first N; --limit 0 shows all.`);
|
|
182
|
+
}
|
|
161
183
|
if (truncated) {
|
|
162
184
|
this.log('');
|
|
163
185
|
this.log('This list is incomplete: the server had more faces than could be read in one go.');
|
|
@@ -40,7 +40,7 @@ export default class FidelityPick extends BaseCommand {
|
|
|
40
40
|
if (!run.next)
|
|
41
41
|
this.error(`This run is finished. Read it with: faces fidelity:get ${args.run_id}`);
|
|
42
42
|
if (run.next.awaiting !== 'choice') {
|
|
43
|
-
this.error(`Turn ${run.next.turn} has no answers to pick from
|
|
43
|
+
this.error(`Turn ${run.next.turn} has no answers to pick from yet. Send its message: faces fidelity:turn ${args.run_id} -m "..."`);
|
|
44
44
|
}
|
|
45
45
|
turn = run.next.turn;
|
|
46
46
|
}
|
|
@@ -63,7 +63,7 @@ export default class FidelityPick extends BaseCommand {
|
|
|
63
63
|
this.log(`Keep the conversation as a thread, to compile: faces fidelity:save-thread ${args.run_id}`);
|
|
64
64
|
}
|
|
65
65
|
else {
|
|
66
|
-
this.log(
|
|
66
|
+
this.log(`Next turn: faces fidelity:turn ${args.run_id} -m "..."`);
|
|
67
67
|
}
|
|
68
68
|
return data;
|
|
69
69
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class FidelityRunCommand extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
competitor: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
model: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
run: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
13
|
+
};
|
|
14
|
+
static args: {
|
|
15
|
+
alias: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
16
|
+
};
|
|
17
|
+
private rl?;
|
|
18
|
+
run(): Promise<unknown>;
|
|
19
|
+
private ask;
|
|
20
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { createInterface } from 'node:readline';
|
|
3
|
+
import { BaseCommand } from '../../base.js';
|
|
4
|
+
import { FacesAPIError } from '../../client.js';
|
|
5
|
+
import { FIDELITY_TURNS, answerLines, fidelityError, fidelityPost, getRun, runLines, score10, turnLines } from '../../fidelity.js';
|
|
6
|
+
import { seg, usd } from '../../utils.js';
|
|
7
|
+
export default class FidelityRunCommand extends BaseCommand {
|
|
8
|
+
static description = 'Play a fidelity run in the terminal: ten turns of writing a message, reading answers a and b, and ' +
|
|
9
|
+
'picking the one that sounds more like the person, with an optional correction. Needs a person at ' +
|
|
10
|
+
'the keyboard; without a terminal, use fidelity:start, fidelity:turn and fidelity:pick. Resume a run ' +
|
|
11
|
+
'with --run.';
|
|
12
|
+
static examples = [
|
|
13
|
+
'<%= config.bin %> <%= command.id %> alice',
|
|
14
|
+
'<%= config.bin %> <%= command.id %> alice --run <run>',
|
|
15
|
+
];
|
|
16
|
+
static flags = {
|
|
17
|
+
...BaseCommand.baseFlags,
|
|
18
|
+
competitor: Flags.string({ description: 'The chat model the face is compared with (default: the cheapest Codex-eligible chat model)' }),
|
|
19
|
+
model: Flags.string({ description: 'The model the face answers on (default: its own default model)' }),
|
|
20
|
+
run: Flags.string({ description: 'Resume this run instead of starting one', exclusive: ['competitor', 'model'] }),
|
|
21
|
+
};
|
|
22
|
+
static args = {
|
|
23
|
+
alias: Args.string({ description: 'Alias of a face you own', required: true }),
|
|
24
|
+
};
|
|
25
|
+
rl;
|
|
26
|
+
async run() {
|
|
27
|
+
const { args, flags } = await this.parse(FidelityRunCommand);
|
|
28
|
+
if (this.jsonEnabled() || !process.stdin.isTTY) {
|
|
29
|
+
this.error('fidelity:run needs a person at a terminal. Without one, use fidelity:start, fidelity:turn and fidelity:pick.');
|
|
30
|
+
}
|
|
31
|
+
const client = this.makeClient(flags);
|
|
32
|
+
this.rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
33
|
+
try {
|
|
34
|
+
let run;
|
|
35
|
+
if (flags.run) {
|
|
36
|
+
run = await getRun(client, flags.run);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const body = {};
|
|
40
|
+
if (flags.competitor)
|
|
41
|
+
body.competitor = flags.competitor;
|
|
42
|
+
if (flags.model)
|
|
43
|
+
body.model = flags.model;
|
|
44
|
+
run = (await fidelityPost(client, `/v1/faces/${seg(args.alias)}/fidelity`, body));
|
|
45
|
+
this.log(`Run ${run.run_id} against ${run.competitor ?? 'the competitor'}, up to ${usd(run.estimated_usd)} from credits.`);
|
|
46
|
+
}
|
|
47
|
+
const id = run.run_id;
|
|
48
|
+
this.log('Each turn, pick the answer that sounds more like the person. Ctrl-C stops; --run resumes.\n');
|
|
49
|
+
while (run.next) {
|
|
50
|
+
const n = run.next.turn;
|
|
51
|
+
if (run.next.awaiting === 'message') {
|
|
52
|
+
const message = await this.ask(`Turn ${n} of ${FIDELITY_TURNS}, your message: `);
|
|
53
|
+
if (!message.trim())
|
|
54
|
+
continue;
|
|
55
|
+
process.stderr.write('Waiting for both answers...\n');
|
|
56
|
+
const t = await fidelityPost(client, `/v1/fidelity/${seg(id)}/turns`, { message });
|
|
57
|
+
this.log('');
|
|
58
|
+
for (const line of answerLines(n, (t.answers ?? {})))
|
|
59
|
+
this.log(line);
|
|
60
|
+
this.log('');
|
|
61
|
+
}
|
|
62
|
+
let pick = '';
|
|
63
|
+
while (pick !== 'a' && pick !== 'b')
|
|
64
|
+
pick = (await this.ask('Which sounds more like them, a or b? ')).trim().toLowerCase();
|
|
65
|
+
const correction = await this.ask('What would they actually have said? (Enter to accept it as it is) ');
|
|
66
|
+
const body = { pick };
|
|
67
|
+
if (correction.trim())
|
|
68
|
+
body.correction = correction;
|
|
69
|
+
const c = await fidelityPost(client, `/v1/fidelity/${seg(id)}/turns/${n}/choice`, body);
|
|
70
|
+
this.log(`Turn ${n} scored ${score10(c.score)}, ${score10(c.score_so_far)} so far.\n`);
|
|
71
|
+
run = await getRun(client, id);
|
|
72
|
+
}
|
|
73
|
+
for (const line of runLines(run))
|
|
74
|
+
this.log(line);
|
|
75
|
+
this.log('');
|
|
76
|
+
for (const line of turnLines(run))
|
|
77
|
+
this.log(line);
|
|
78
|
+
if (!run.thread_id) {
|
|
79
|
+
const save = await this.ask('\nSave the conversation as a thread on the face, to compile? [y/N] ');
|
|
80
|
+
if (save.trim().toLowerCase() === 'y') {
|
|
81
|
+
const s = await fidelityPost(client, `/v1/fidelity/${seg(id)}/save-thread`, {});
|
|
82
|
+
this.log(`Saved as thread ${s.thread_id}. Compile it: faces compile:thread:make ${s.thread_id}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return run;
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
if (err instanceof FacesAPIError)
|
|
89
|
+
this.error(fidelityError(err, { run: flags.run, alias: args.alias }));
|
|
90
|
+
throw err;
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
this.rl.close();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
ask(question) {
|
|
97
|
+
return new Promise((resolve) => this.rl.question(question, resolve));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class FidelityStart extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
competitor: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
model: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
12
|
+
};
|
|
13
|
+
static args: {
|
|
14
|
+
alias: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
15
|
+
};
|
|
16
|
+
run(): Promise<unknown>;
|
|
17
|
+
}
|