@faces-sh/cli 1.1.0 → 1.2.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 +64 -30
- package/dist/billing.js +11 -8
- package/dist/chat-command.d.ts +31 -0
- package/dist/chat-command.js +110 -0
- package/dist/chat.d.ts +47 -0
- package/dist/chat.js +157 -0
- package/dist/choices.d.ts +2 -5
- package/dist/choices.js +9 -8
- 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/chat/chat.d.ts +31 -0
- package/dist/commands/chat/chat.js +31 -0
- package/dist/commands/chat/messages.d.ts +30 -0
- package/dist/commands/chat/messages.js +21 -0
- package/dist/commands/chat/responses.d.ts +30 -0
- package/dist/commands/chat/responses.js +22 -0
- package/dist/commands/{causes.d.ts → chat/thread.d.ts} +17 -12
- package/dist/commands/chat/thread.js +238 -0
- package/dist/commands/choices.d.ts +1 -2
- package/dist/commands/choices.js +20 -15
- package/dist/commands/conversation/compact.js +13 -16
- package/dist/commands/conversation/create.js +10 -9
- package/dist/commands/decide.d.ts +1 -4
- package/dist/commands/decide.js +53 -81
- package/dist/commands/face/get.js +1 -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/session/compact.js +5 -8
- package/dist/commands/session/create.js +9 -8
- package/dist/commands/style/make.js +1 -1
- package/dist/commands/style/upload.js +1 -1
- package/dist/decisions.d.ts +0 -5
- package/dist/decisions.js +0 -18
- package/dist/fidelity.js +3 -3
- 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/routing.d.ts +1 -4
- package/dist/routing.js +4 -40
- package/dist/utils.d.ts +1 -25
- package/dist/utils.js +10 -108
- package/oclif.manifest.json +1616 -818
- package/package.json +6 -3
- package/dist/commands/causes.js +0 -146
|
@@ -4,15 +4,15 @@ import { FacesAPIError } from '../../client.js';
|
|
|
4
4
|
import { heldDecisionError } from '../../decisions.js';
|
|
5
5
|
import { CONVERSATIONS_PATH, conversationHint } from '../../conversation.js';
|
|
6
6
|
import { retryOnceOnWarmUp, sayWarmUp, seg } from '../../utils.js';
|
|
7
|
+
import { asFace as faceAlone } from '../../model.js';
|
|
7
8
|
export default class ConversationCompact extends BaseCommand {
|
|
8
|
-
static description = 'Compact a state:
|
|
9
|
-
'
|
|
10
|
-
'
|
|
11
|
-
'
|
|
12
|
-
'not charged. A compaction expires 30 days after it is written.';
|
|
9
|
+
static description = 'Compact a state: one face\'s position over the state, kept on the server under a compaction id. ' +
|
|
10
|
+
'Pass that id with --compaction on a later request with the same face. A state that takes any face ' +
|
|
11
|
+
'needs the face named. Billed on the tokens it reads and writes; on Connect and Pro it counts against ' +
|
|
12
|
+
'the plan\'s allowance. A failed compaction is not charged. A compaction expires 30 days after it is written.';
|
|
13
13
|
static examples = [
|
|
14
14
|
'<%= config.bin %> <%= command.id %> fs_STATE_ID',
|
|
15
|
-
'<%= config.bin %> <%= command.id %> fs_STATE_ID alice --json',
|
|
15
|
+
'<%= config.bin %> <%= command.id %> fs_STATE_ID @alice --json',
|
|
16
16
|
];
|
|
17
17
|
static flags = {
|
|
18
18
|
...BaseCommand.baseFlags,
|
|
@@ -20,8 +20,8 @@ export default class ConversationCompact extends BaseCommand {
|
|
|
20
20
|
static args = {
|
|
21
21
|
conversation_id: Args.string({ description: 'State id (from state:create)', required: true }),
|
|
22
22
|
face: Args.string({
|
|
23
|
-
description: 'The face to compact,
|
|
24
|
-
'state opened with one face compacts that face.',
|
|
23
|
+
description: 'The face to compact, as @face (or @owner~face), with no model after it. Needed when the state ' +
|
|
24
|
+
'takes any face; a state opened with one face compacts that face.',
|
|
25
25
|
required: false,
|
|
26
26
|
}),
|
|
27
27
|
};
|
|
@@ -29,9 +29,9 @@ export default class ConversationCompact extends BaseCommand {
|
|
|
29
29
|
const { args, flags } = await this.parse(ConversationCompact);
|
|
30
30
|
const client = this.makeClient(flags);
|
|
31
31
|
const json = this.jsonEnabled();
|
|
32
|
-
const face = args.face
|
|
33
|
-
if (face
|
|
34
|
-
this.error(`Compact a face alone,
|
|
32
|
+
const face = args.face === undefined ? undefined : faceAlone(args.face);
|
|
33
|
+
if (face && /[:/]/.test(face))
|
|
34
|
+
this.error(`Compact a face alone, with no maestro or model: ${face.split(/[:/]/)[0]}`);
|
|
35
35
|
let data;
|
|
36
36
|
try {
|
|
37
37
|
data = (await retryOnceOnWarmUp(async () => {
|
|
@@ -45,7 +45,7 @@ export default class ConversationCompact extends BaseCommand {
|
|
|
45
45
|
catch (err) {
|
|
46
46
|
if (err instanceof FacesAPIError) {
|
|
47
47
|
if (err.statusCode === 422 && !face && /takes any face/.test(err.message)) {
|
|
48
|
-
this.error(`HTTP ${err.statusCode}: ${err.message}\nName the face: faces state:compact ${args.conversation_id}
|
|
48
|
+
this.error(`HTTP ${err.statusCode}: ${err.message}\nName the face: faces state:compact ${args.conversation_id} @<face>`);
|
|
49
49
|
}
|
|
50
50
|
const hint = conversationHint(err);
|
|
51
51
|
this.error(`HTTP ${err.statusCode}: ${err.message}${hint ? `\n${hint}` : ''}`);
|
|
@@ -53,16 +53,13 @@ export default class ConversationCompact extends BaseCommand {
|
|
|
53
53
|
throw err;
|
|
54
54
|
}
|
|
55
55
|
if (!json) {
|
|
56
|
-
if (typeof data.cause === 'string')
|
|
57
|
-
this.log(data.cause);
|
|
58
|
-
this.log('');
|
|
59
56
|
this.log(`compaction: ${data.compaction_id ?? '-'}`);
|
|
60
57
|
if (data.turns !== undefined)
|
|
61
58
|
this.log(`turns: ${data.turns}`);
|
|
62
59
|
if (data.expires_at)
|
|
63
60
|
this.log(`expires: ${data.expires_at}`);
|
|
64
61
|
if (data.compaction_id)
|
|
65
|
-
this.log(`\nUse it with: faces
|
|
62
|
+
this.log(`\nUse it with: faces chat:chat ${face ?? '@<face>'}:maestro-1/<model> --compaction ${data.compaction_id} -m "..."`);
|
|
66
63
|
}
|
|
67
64
|
return data;
|
|
68
65
|
}
|
|
@@ -2,17 +2,18 @@ import { Args, Flags } from '@oclif/core';
|
|
|
2
2
|
import { BaseCommand } from '../../base.js';
|
|
3
3
|
import { FacesAPIError } from '../../client.js';
|
|
4
4
|
import { CONVERSATIONS_PATH, MAX_CONVERSATION_ITEMS, PREMISE_DESCRIPTION_FLAG_DESCRIPTION, PREMISE_DEPENDS_ON_FLAG_DESCRIPTION, PREMISE_FLAG_DESCRIPTION, PREMISE_STATUS_FLAG_DESCRIPTION, clientItems, conversationHint, conversationLines, parsePremises, } from '../../conversation.js';
|
|
5
|
+
import { asFace as faceAlone } from '../../model.js';
|
|
5
6
|
export default class ConversationCreate extends BaseCommand {
|
|
6
7
|
static description = 'Start a state (formerly a conversation). The server keeps the situation your agent builds: premises ' +
|
|
7
8
|
'(named facts, each with a status and what it depends on), the decisions faces made, and your messages. ' +
|
|
8
|
-
'Ask a face about it with faces choices --state-id, or pass its id with --conversation on
|
|
9
|
+
'Ask a face about it with faces choices --state-id, or pass its id with --conversation on chat or decide ' +
|
|
9
10
|
'and send only what is new. Name a face and the state takes that face only; leave it out and it takes any ' +
|
|
10
11
|
'of your faces. Opening one is free. A state expires 30 days after it was last used.';
|
|
11
12
|
static examples = [
|
|
12
|
-
'<%= config.bin %> <%= command.id %> alice',
|
|
13
|
+
'<%= config.bin %> <%= command.id %> @alice',
|
|
13
14
|
'<%= config.bin %> <%= command.id %>',
|
|
14
15
|
'<%= config.bin %> <%= command.id %> --no-causes-visible --json',
|
|
15
|
-
'<%= config.bin %> <%= command.id %> alice --premise budget_usd=50000 --premise-description budget_usd="the most we can spend this year"',
|
|
16
|
+
'<%= config.bin %> <%= command.id %> @alice --premise budget_usd=50000 --premise-description budget_usd="the most we can spend this year"',
|
|
16
17
|
];
|
|
17
18
|
static flags = {
|
|
18
19
|
...BaseCommand.baseFlags,
|
|
@@ -30,17 +31,17 @@ export default class ConversationCreate extends BaseCommand {
|
|
|
30
31
|
};
|
|
31
32
|
static args = {
|
|
32
33
|
face: Args.string({
|
|
33
|
-
description: 'The face alone:
|
|
34
|
-
'for a state that takes any of your faces.',
|
|
34
|
+
description: 'The face alone: @alice, @owner~alice, or a composite such as "(@a | @b)". No maestro or model. ' +
|
|
35
|
+
'Leave it out for a state that takes any of your faces.',
|
|
35
36
|
required: false,
|
|
36
37
|
}),
|
|
37
38
|
};
|
|
38
39
|
async run() {
|
|
39
40
|
const { args, flags } = await this.parse(ConversationCreate);
|
|
40
41
|
const client = this.makeClient(flags);
|
|
41
|
-
const face = args.face
|
|
42
|
-
if (face
|
|
43
|
-
this.error(`A state is with a face alone: ${face.
|
|
42
|
+
const face = args.face === undefined ? undefined : faceAlone(args.face);
|
|
43
|
+
if (face && /[:/]/.test(face))
|
|
44
|
+
this.error(`A state is with a face alone, with no maestro or model: ${face.split(/[:/]/)[0]}`);
|
|
44
45
|
let items;
|
|
45
46
|
try {
|
|
46
47
|
items = clientItems(flags.message, parsePremises(flags.premise, flags['premise-description'], flags['premise-status'], flags['premise-depends-on']));
|
|
@@ -71,7 +72,7 @@ export default class ConversationCreate extends BaseCommand {
|
|
|
71
72
|
for (const line of conversationLines(data))
|
|
72
73
|
this.log(line);
|
|
73
74
|
if (data.id)
|
|
74
|
-
this.log(`\nAsk a face about it with: faces choices ${face ?? '
|
|
75
|
+
this.log(`\nAsk a face about it with: faces choices ${face ?? '@<face>'}:maestro-1 --state-id ${data.id} --question "..."`);
|
|
75
76
|
}
|
|
76
77
|
return data;
|
|
77
78
|
}
|
|
@@ -22,16 +22,13 @@ export default class Decide extends BaseCommand {
|
|
|
22
22
|
level: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
23
23
|
id: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
24
24
|
'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
25
|
'base-url': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
29
26
|
token: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
30
27
|
'api-key': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
31
28
|
toon: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
32
29
|
};
|
|
33
30
|
static args: {
|
|
34
|
-
|
|
31
|
+
model: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
35
32
|
};
|
|
36
33
|
run(): Promise<unknown>;
|
|
37
34
|
private ask;
|
package/dist/commands/decide.js
CHANGED
|
@@ -2,29 +2,28 @@ 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';
|
|
7
8
|
const OPENAI_FORMAT_ONLY = ['gpt-6-luna'];
|
|
8
9
|
export default class Decide extends BaseCommand {
|
|
9
10
|
static description = 'Ask what a face would decide. Describe a situation, ask typed questions about it, and get back numbers, ' +
|
|
10
11
|
'as this face: a yes-or-no (noul), a pick between options (choice), or a place on a graded scale (score). ' +
|
|
11
12
|
'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.';
|
|
13
|
+
'simulations or panels. Name the model as the upstream model over the decision model: ' +
|
|
14
|
+
'@alice:maestro-1/jev-latest. The face steers the decision model\'s answer. An answer takes about 10 to 20 ' +
|
|
15
|
+
'seconds; one that runs long is held open by the server and can take a minute or more. ' +
|
|
16
|
+
'The steering is billed per input token plus a small fee per call (see faces models:list --kind upstream), ' +
|
|
17
|
+
'and the decision model at its listed price. A face needs something compiled.';
|
|
18
18
|
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." ' +
|
|
19
|
+
'<%= 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
20
|
'--question "Does the speaker sign?" --option yes="signs it as asked" --option no="declines to sign" ' +
|
|
21
21
|
'--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 --state-file situation.json --questions-file questions.json --model clef --json',
|
|
22
|
+
'<%= config.bin %> <%= command.id %> @alice:maestro-1/jev-latest --state-file situation.txt --question "Is the speaker irritated?"',
|
|
23
|
+
'<%= config.bin %> <%= command.id %> @alice:maestro-1-flash/clef --state-file situation.txt --question "How firm is the reply?" ' +
|
|
24
|
+
'--level yields --level hedges --level firm',
|
|
25
|
+
'<%= config.bin %> <%= command.id %> "(@alice | @bob):maestro-1/jev-latest" --state-file situation.json --questions-file questions.json --json',
|
|
26
|
+
'<%= config.bin %> <%= command.id %> @alice:maestro-1/gpt-6-luna --state-file situation.txt --questions-file questions.json',
|
|
28
27
|
];
|
|
29
28
|
static flags = {
|
|
30
29
|
...BaseCommand.baseFlags,
|
|
@@ -75,31 +74,14 @@ export default class Decide extends BaseCommand {
|
|
|
75
74
|
'{"true": "...", "false": "..."}.',
|
|
76
75
|
exclusive: ['question'],
|
|
77
76
|
}),
|
|
78
|
-
|
|
79
|
-
description: 'The decision model: the model that turns the situation into probabilities, as opposed to a ' +
|
|
80
|
-
'generative model that writes text. Checked against the decision models the API lists: ' +
|
|
81
|
-
'jev-latest, clef, clef-flash and gpt-6-luna today. gpt-6-luna answers in OpenAI\'s format only, ' +
|
|
82
|
-
'so it uses --format openai.',
|
|
83
|
-
default: 'jev-latest',
|
|
84
|
-
}),
|
|
85
|
-
baseline: Flags.boolean({
|
|
86
|
-
description: 'Ask the decision model alone, with no face: the no-face baseline. Costs only the decision model.',
|
|
87
|
-
default: false,
|
|
88
|
-
}),
|
|
89
|
-
'show-cause': Flags.boolean({
|
|
90
|
-
description: 'Also show the face\'s cause, one per question when there are several. Printed to stderr ahead of ' +
|
|
91
|
-
'the answers. It is always in --json, as cause and causes.',
|
|
92
|
-
default: false,
|
|
93
|
-
}),
|
|
94
|
-
...conversationTurnFlags({ exclusive: ['baseline'] }),
|
|
77
|
+
...conversationTurnFlags(),
|
|
95
78
|
'depends-on': Flags.string({
|
|
96
79
|
description: 'In a state (--conversation), what this decision rests on, comma separated: premise keys and decision ids ' +
|
|
97
80
|
`already in the state or set with --premise, at most ${MAX_DEPENDS_ON}. The decision is shown those, and is ` +
|
|
98
81
|
'invalidated when one of them is. Left out, it rests on every premise in force.',
|
|
99
|
-
exclusive: ['baseline'],
|
|
100
82
|
}),
|
|
101
|
-
session: Flags.string({ description: SESSION_FLAG_DESCRIPTION
|
|
102
|
-
compaction: Flags.string({ description: COMPACTION_FLAG_DESCRIPTION
|
|
83
|
+
session: Flags.string({ description: SESSION_FLAG_DESCRIPTION }),
|
|
84
|
+
compaction: Flags.string({ description: COMPACTION_FLAG_DESCRIPTION }),
|
|
103
85
|
format: Flags.string({
|
|
104
86
|
description: 'The request shape: systemone (default, TypeSafe Jev\'s System One) or openai (OpenAI\'s Decisions ' +
|
|
105
87
|
'format). The answers are the same; --json returns the chosen format\'s own shape.',
|
|
@@ -114,16 +96,24 @@ export default class Decide extends BaseCommand {
|
|
|
114
96
|
}),
|
|
115
97
|
};
|
|
116
98
|
static args = {
|
|
117
|
-
|
|
99
|
+
model: Args.string({
|
|
100
|
+
description: 'The upstream model over the decision model: @<face>:<maestro>/<decision model>, e.g. ' +
|
|
101
|
+
'@alice:maestro-1/jev-latest. Another account\'s face is @owner~face; a composite is ' +
|
|
102
|
+
'"(@a | @b):maestro-1/jev-latest". The decision models are jev-latest, clef, clef-flash and gpt-6-luna ' +
|
|
103
|
+
'today (faces models:list --kind decision); gpt-6-luna answers in OpenAI\'s format only, so it uses --format openai.',
|
|
104
|
+
required: true,
|
|
105
|
+
}),
|
|
118
106
|
};
|
|
119
107
|
async run() {
|
|
120
108
|
const { args, flags } = await this.parse(Decide);
|
|
121
109
|
const client = this.makeClient(flags);
|
|
122
110
|
const json = this.jsonEnabled();
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
111
|
+
const problem = modelProblem(args.model, 'both', 'jev-latest');
|
|
112
|
+
if (problem)
|
|
113
|
+
this.error(problem);
|
|
114
|
+
const name = parseModel(args.model);
|
|
115
|
+
const face = name.faces;
|
|
116
|
+
let downstream = name.downstream;
|
|
127
117
|
let turn = {};
|
|
128
118
|
try {
|
|
129
119
|
turn = conversationFields(flags);
|
|
@@ -138,27 +128,25 @@ export default class Decide extends BaseCommand {
|
|
|
138
128
|
}
|
|
139
129
|
const state = this.readState(flags);
|
|
140
130
|
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';
|
|
131
|
+
if (!questions)
|
|
132
|
+
this.error('Ask at least one question, with --question or --questions-file.');
|
|
133
|
+
const openaiOnly = OPENAI_FORMAT_ONLY.includes(downstream.toLowerCase());
|
|
134
|
+
const problemQ = questionsProblem(questions, true, openaiOnly);
|
|
135
|
+
if (problemQ)
|
|
136
|
+
this.error(problemQ);
|
|
137
|
+
this.models = await decisionModels(client);
|
|
138
|
+
const match = this.models.find((m) => m.toLowerCase() === downstream.toLowerCase());
|
|
139
|
+
if (!match)
|
|
140
|
+
this.error(`'${downstream}' is not a decision model. The decision models are: ${this.models.join(', ')}.`);
|
|
141
|
+
downstream = match;
|
|
142
|
+
if (OPENAI_FORMAT_ONLY.includes(match)) {
|
|
143
|
+
if (this.argv.some((a) => a === '--format=systemone' || a === 'systemone')) {
|
|
144
|
+
this.error(`${match} answers in OpenAI's format only. Use --format openai, or leave --format out.`);
|
|
157
145
|
}
|
|
146
|
+
flags.format = 'openai';
|
|
158
147
|
}
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
let body = questions ? { model, state, questions } : { model, state };
|
|
148
|
+
const model = `${name.upstream}/${downstream}`;
|
|
149
|
+
let body = { model, state, questions };
|
|
162
150
|
if (flags.format === 'openai') {
|
|
163
151
|
try {
|
|
164
152
|
body = toOpenAIDecision(model, state, questions);
|
|
@@ -173,11 +161,7 @@ export default class Decide extends BaseCommand {
|
|
|
173
161
|
body.compaction = flags.compaction;
|
|
174
162
|
Object.assign(body, turn);
|
|
175
163
|
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`);
|
|
164
|
+
process.stderr.write(`Asking ${face}. Decision model: ${downstream}. This usually takes 10 to 20 seconds, sometimes a minute or more.\n`);
|
|
181
165
|
}
|
|
182
166
|
let data;
|
|
183
167
|
try {
|
|
@@ -185,24 +169,14 @@ export default class Decide extends BaseCommand {
|
|
|
185
169
|
}
|
|
186
170
|
catch (err) {
|
|
187
171
|
if (err instanceof FacesAPIError)
|
|
188
|
-
this.error(this.explain(err, face,
|
|
172
|
+
this.error(this.explain(err, face, downstream));
|
|
189
173
|
throw err;
|
|
190
174
|
}
|
|
191
|
-
const
|
|
192
|
-
const missing = missingFieldsNote(data, expected);
|
|
193
|
-
if (missing && !json && !questions)
|
|
194
|
-
this.error(missing);
|
|
175
|
+
const missing = missingFieldsNote(data, ['answers']);
|
|
195
176
|
if (missing)
|
|
196
177
|
process.stderr.write(`${missing}\n`);
|
|
197
178
|
if (json)
|
|
198
179
|
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
180
|
const answers = flags.format === 'openai' ? fromOpenAIAnswers(data.answers, questions) : (data.answers ?? {});
|
|
207
181
|
for (const line of decisionLines(answers))
|
|
208
182
|
this.log(line);
|
|
@@ -248,18 +222,16 @@ export default class Decide extends BaseCommand {
|
|
|
248
222
|
const head = `HTTP ${err.statusCode}: ${err.message}`;
|
|
249
223
|
switch (err.statusCode) {
|
|
250
224
|
case 409: {
|
|
251
|
-
|
|
252
|
-
return head;
|
|
253
|
-
return `${head}\n${compileHint(face, !/nothing compiled/i.test(err.message), 'decide')}`;
|
|
225
|
+
return `${head}\n${compileHint(face.replace(/^@/, '').replace('~', ':'), !/nothing compiled/i.test(err.message), 'decide')}`;
|
|
254
226
|
}
|
|
255
227
|
case 503: {
|
|
256
228
|
if (err.retryAfter !== undefined)
|
|
257
229
|
return `${head}\nTry again in ${err.retryAfter}s.`;
|
|
258
230
|
const others = (this.models ?? [...DECISION_MODELS]).filter((m) => m !== model).join(', ');
|
|
259
|
-
return `${head}\nTry again. If the message names the decision model, another
|
|
231
|
+
return `${head}\nTry again. If the message names the decision model, another decision model may answer (${others}).`;
|
|
260
232
|
}
|
|
261
233
|
case 504: {
|
|
262
|
-
return `${head}\
|
|
234
|
+
return `${head}\nThe face did not finish within 300 seconds. Ask again.`;
|
|
263
235
|
}
|
|
264
236
|
default: {
|
|
265
237
|
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({
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { BaseCommand } from '../../base.js';
|
|
3
|
+
import { FacesAPIError } from '../../client.js';
|
|
4
|
+
import { fidelityError, fidelityPost, nextStep } from '../../fidelity.js';
|
|
5
|
+
import { seg, usd } from '../../utils.js';
|
|
6
|
+
export default class FidelityStart extends BaseCommand {
|
|
7
|
+
static description = 'Start a fidelity run on a face you own: ten blind turns, scored out of 10. Each turn you send a ' +
|
|
8
|
+
'message, read two answers labelled a and b (one is the face, one a competitor model given the ' +
|
|
9
|
+
'face\'s own writing), and pick the one that sounds more like the person, accepting it or correcting ' +
|
|
10
|
+
'it. The picks must be the person\'s own: an agent shows both answers and passes on the choice it is ' +
|
|
11
|
+
'given, never its own. The score is saved on the face, and a new run replaces it. On Connect or Pro ' +
|
|
12
|
+
'with ChatGPT linked, answers from Codex-eligible models run on the ChatGPT plan; the rest, and grading ' +
|
|
13
|
+
'a correction, is paid from credits. To play it in the terminal, use faces fidelity:run.';
|
|
14
|
+
static examples = [
|
|
15
|
+
'<%= config.bin %> <%= command.id %> alice',
|
|
16
|
+
'<%= config.bin %> <%= command.id %> alice --competitor <model>',
|
|
17
|
+
];
|
|
18
|
+
static flags = {
|
|
19
|
+
...BaseCommand.baseFlags,
|
|
20
|
+
competitor: Flags.string({
|
|
21
|
+
description: 'The chat model the face is compared with (default: the cheapest Codex-eligible chat model)',
|
|
22
|
+
}),
|
|
23
|
+
model: Flags.string({ description: 'The model the face answers on (default: its own default model)' }),
|
|
24
|
+
};
|
|
25
|
+
static args = {
|
|
26
|
+
alias: Args.string({ description: 'Alias of a face you own', required: true }),
|
|
27
|
+
};
|
|
28
|
+
async run() {
|
|
29
|
+
const { args, flags } = await this.parse(FidelityStart);
|
|
30
|
+
const client = this.makeClient(flags);
|
|
31
|
+
const body = {};
|
|
32
|
+
if (flags.competitor)
|
|
33
|
+
body.competitor = flags.competitor;
|
|
34
|
+
if (flags.model)
|
|
35
|
+
body.model = flags.model;
|
|
36
|
+
let run;
|
|
37
|
+
try {
|
|
38
|
+
run = (await fidelityPost(client, `/v1/faces/${seg(args.alias)}/fidelity`, body));
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
if (err instanceof FacesAPIError)
|
|
42
|
+
this.error(fidelityError(err, { alias: args.alias }));
|
|
43
|
+
throw err;
|
|
44
|
+
}
|
|
45
|
+
if (this.jsonEnabled())
|
|
46
|
+
return run;
|
|
47
|
+
this.log(`run: ${run.run_id}`);
|
|
48
|
+
this.log(`face: ${run.alias ?? args.alias}`);
|
|
49
|
+
this.log(`competitor: ${run.competitor ?? '-'}`);
|
|
50
|
+
if (run.estimated_usd !== undefined)
|
|
51
|
+
this.log(`up to: ${usd(run.estimated_usd)} from credits`);
|
|
52
|
+
this.log('');
|
|
53
|
+
this.log(nextStep(run) ?? '');
|
|
54
|
+
return run;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseCommand } from '../../base.js';
|
|
2
|
+
export default class FidelityTurn extends BaseCommand {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
message: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
file: 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
|
+
run_id: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
15
|
+
};
|
|
16
|
+
run(): Promise<unknown>;
|
|
17
|
+
}
|