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