kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
feat: format output differently depending on mechanism
rodzic
ff801f4929
commit
69efdb5085
|
@ -2,6 +2,7 @@ import checkbox from '@inquirer/checkbox'
|
|||
import editor from '@inquirer/editor'
|
||||
import input from '@inquirer/input'
|
||||
import select from '@inquirer/select'
|
||||
import { gray } from 'colorette'
|
||||
import { setTimeout } from 'timers/promises'
|
||||
|
||||
import { BaseTask } from '@/task'
|
||||
|
@ -87,17 +88,8 @@ export class HumanFeedbackMechanismCLI<
|
|||
return Promise.race([rejectError, promise])
|
||||
}
|
||||
|
||||
protected async _edit(output: string): Promise<string> {
|
||||
return this._defaultAfterTimeout(
|
||||
editor(
|
||||
{
|
||||
message: 'Edit the output:',
|
||||
default: output
|
||||
},
|
||||
INQUIRER_CONTEXT
|
||||
),
|
||||
output
|
||||
)
|
||||
protected _formatOutput(output: string): string {
|
||||
return gray(output)
|
||||
}
|
||||
|
||||
protected async _annotate(): Promise<string> {
|
||||
|
@ -113,6 +105,19 @@ export class HumanFeedbackMechanismCLI<
|
|||
)
|
||||
}
|
||||
|
||||
protected async _edit(output: string): Promise<string> {
|
||||
return this._defaultAfterTimeout(
|
||||
editor(
|
||||
{
|
||||
message: 'Edit the output:',
|
||||
default: output
|
||||
},
|
||||
INQUIRER_CONTEXT
|
||||
),
|
||||
output
|
||||
)
|
||||
}
|
||||
|
||||
protected async _select(
|
||||
response: TOutput
|
||||
): Promise<TOutput extends (infer U)[] ? U : never> {
|
||||
|
|
|
@ -14,6 +14,10 @@ export class HumanFeedbackMechanismDummy<
|
|||
return output[0] as any
|
||||
}
|
||||
|
||||
protected _formatOutput() {
|
||||
return ''
|
||||
}
|
||||
|
||||
protected async _multiselect(
|
||||
output: TOutput
|
||||
): Promise<TOutput extends any[] ? TOutput : never> {
|
||||
|
|
|
@ -178,6 +178,8 @@ export abstract class HumanFeedbackMechanism<
|
|||
return this._task.outputSchema.parse(parsedOutput)
|
||||
}
|
||||
|
||||
protected abstract _formatOutput(output: string): string
|
||||
|
||||
public async interact(output: TOutput): Promise<FeedbackTypeToMetadata<T>> {
|
||||
const stringified = JSON.stringify(output, null, 2)
|
||||
const taskDetails = `${this._task.nameForHuman} (ID: ${this._task.id})`
|
||||
|
@ -186,9 +188,7 @@ export abstract class HumanFeedbackMechanism<
|
|||
const msg = [
|
||||
taskDetails,
|
||||
outputLabel,
|
||||
'```',
|
||||
stringified,
|
||||
'```',
|
||||
this._formatOutput(stringified),
|
||||
'What would you like to do?'
|
||||
].join('\n')
|
||||
|
||||
|
@ -200,8 +200,8 @@ export abstract class HumanFeedbackMechanism<
|
|||
choices.push(HumanFeedbackUserActions.Select)
|
||||
} else {
|
||||
// Case: confirm
|
||||
choices.push(HumanFeedbackUserActions.Accept)
|
||||
choices.push(HumanFeedbackUserActions.Decline)
|
||||
choices.push(HumanFeedbackUserActions.Accept)
|
||||
}
|
||||
|
||||
if (this._options.editing) {
|
||||
|
|
|
@ -28,6 +28,10 @@ export class HumanFeedbackMechanismSlack<
|
|||
this._slackClient = slackClient
|
||||
}
|
||||
|
||||
protected _formatOutput(output: string): string {
|
||||
return ['```', output, '```'].join('\n')
|
||||
}
|
||||
|
||||
protected async _annotate(): Promise<string> {
|
||||
try {
|
||||
const annotation = await this._slackClient.sendAndWaitForReply({
|
||||
|
|
|
@ -28,6 +28,10 @@ export class HumanFeedbackMechanismTwilio<
|
|||
this._twilioClient = twilioClient
|
||||
}
|
||||
|
||||
protected _formatOutput(output: string): string {
|
||||
return output
|
||||
}
|
||||
|
||||
protected async _annotate(): Promise<string> {
|
||||
try {
|
||||
const annotation = await this._twilioClient.sendAndWaitForReply({
|
||||
|
|
Ładowanie…
Reference in New Issue