2023-06-13 15:21:31 +00:00
|
|
|
import checkbox from '@inquirer/checkbox'
|
|
|
|
import editor from '@inquirer/editor'
|
|
|
|
import input from '@inquirer/input'
|
|
|
|
import select from '@inquirer/select'
|
|
|
|
|
|
|
|
import { Agentic } from '@/agentic'
|
|
|
|
|
2023-06-13 16:36:45 +00:00
|
|
|
import {
|
|
|
|
HumanFeedbackMechanism,
|
|
|
|
HumanFeedbackOptions,
|
|
|
|
UserActionMessages,
|
|
|
|
UserActions
|
|
|
|
} from './feedback'
|
2023-06-13 15:21:31 +00:00
|
|
|
|
|
|
|
export class HumanFeedbackMechanismCLI extends HumanFeedbackMechanism {
|
|
|
|
constructor({
|
|
|
|
agentic,
|
|
|
|
options
|
|
|
|
}: {
|
|
|
|
agentic: Agentic
|
|
|
|
options: HumanFeedbackOptions
|
|
|
|
}) {
|
|
|
|
super({ agentic, options })
|
|
|
|
this._agentic = agentic
|
|
|
|
this._options = options
|
|
|
|
}
|
|
|
|
|
2023-06-13 20:32:58 +00:00
|
|
|
/**
|
|
|
|
* Prompt the user to select one of a list of options.
|
|
|
|
*/
|
|
|
|
protected async askUser(
|
|
|
|
message: string,
|
|
|
|
choices: UserActions[]
|
|
|
|
): Promise<UserActions> {
|
|
|
|
return select({
|
|
|
|
message,
|
|
|
|
choices: choices.map((choice) => ({
|
|
|
|
name: UserActionMessages[choice],
|
|
|
|
value: choice
|
|
|
|
}))
|
2023-06-13 19:52:45 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-06-13 20:32:58 +00:00
|
|
|
protected async edit(output: string): Promise<string> {
|
|
|
|
return editor({
|
|
|
|
message: 'Edit the output:',
|
|
|
|
default: output
|
|
|
|
})
|
2023-06-13 15:21:31 +00:00
|
|
|
}
|
|
|
|
|
2023-06-13 20:32:58 +00:00
|
|
|
protected async annotate(): Promise<string> {
|
|
|
|
return input({
|
|
|
|
message:
|
|
|
|
'Please leave an annotation (leave blank to skip; press enter to submit):'
|
|
|
|
})
|
2023-06-13 15:21:31 +00:00
|
|
|
}
|
|
|
|
|
2023-06-13 20:32:58 +00:00
|
|
|
protected async selectOne(response: any[]): Promise<void> {
|
|
|
|
const choices = response.map((option) => ({
|
|
|
|
name: option,
|
|
|
|
value: option
|
|
|
|
}))
|
|
|
|
return select({ message: 'Pick one output:', choices })
|
|
|
|
}
|
2023-06-13 15:21:31 +00:00
|
|
|
|
2023-06-13 20:32:58 +00:00
|
|
|
protected async selectN(response: any[]): Promise<any[]> {
|
|
|
|
const choices = response.map((option) => ({
|
|
|
|
name: option,
|
|
|
|
value: option
|
|
|
|
}))
|
|
|
|
return checkbox({ message: 'Select outputs:', choices })
|
2023-06-13 15:21:31 +00:00
|
|
|
}
|
|
|
|
}
|