kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
refactor: move annotate to own method
rodzic
da9adf587e
commit
7b5797e08b
|
@ -42,7 +42,21 @@ export class HumanFeedbackMechanismCLI extends HumanFeedbackMechanism {
|
|||
this._options = options
|
||||
}
|
||||
|
||||
public async confirm(
|
||||
protected async annotate(
|
||||
response: any,
|
||||
metadata: TaskResponseMetadata
|
||||
): Promise<void> {
|
||||
const annotation = await input({
|
||||
message:
|
||||
'Please leave an annotation (leave blank to skip; press enter to submit):'
|
||||
})
|
||||
|
||||
if (annotation) {
|
||||
metadata.feedback.annotation = annotation
|
||||
}
|
||||
}
|
||||
|
||||
protected async confirm(
|
||||
response: any,
|
||||
metadata: TaskResponseMetadata
|
||||
): Promise<void> {
|
||||
|
@ -90,20 +104,9 @@ export class HumanFeedbackMechanismCLI extends HumanFeedbackMechanism {
|
|||
default:
|
||||
throw new Error(`Unexpected feedback: ${feedback}`)
|
||||
}
|
||||
|
||||
if (this._options.annotations) {
|
||||
const annotation = await input({
|
||||
message:
|
||||
'Please leave an annotation (leave blank to skip; press enter to submit):'
|
||||
})
|
||||
|
||||
if (annotation) {
|
||||
metadata.feedback.annotation = annotation
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async selectOne(
|
||||
protected async selectOne(
|
||||
response: any[],
|
||||
metadata: TaskResponseMetadata
|
||||
): Promise<void> {
|
||||
|
@ -155,7 +158,7 @@ export class HumanFeedbackMechanismCLI extends HumanFeedbackMechanism {
|
|||
}
|
||||
}
|
||||
|
||||
public async selectN(
|
||||
protected async selectN(
|
||||
response: any[],
|
||||
metadata: TaskResponseMetadata
|
||||
): Promise<void> {
|
||||
|
|
|
@ -82,15 +82,20 @@ export abstract class HumanFeedbackMechanism {
|
|||
this._options = options
|
||||
}
|
||||
|
||||
public abstract confirm(
|
||||
protected abstract confirm(
|
||||
response: any,
|
||||
metadata: TaskResponseMetadata
|
||||
): Promise<void>
|
||||
public abstract selectOne(
|
||||
protected abstract selectOne(
|
||||
response: any,
|
||||
metadata: TaskResponseMetadata
|
||||
): Promise<void>
|
||||
public abstract selectN(
|
||||
protected abstract selectN(
|
||||
response: any,
|
||||
metadata: TaskResponseMetadata
|
||||
): Promise<void>
|
||||
|
||||
protected abstract annotate(
|
||||
response: any,
|
||||
metadata: TaskResponseMetadata
|
||||
): Promise<void>
|
||||
|
@ -103,6 +108,10 @@ export abstract class HumanFeedbackMechanism {
|
|||
} else if (this._options.type === 'selectOne') {
|
||||
await this.selectOne(response, metadata)
|
||||
}
|
||||
|
||||
if (this._options.annotations) {
|
||||
await this.annotate(response, metadata)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,23 @@ export class HumanFeedbackMechanismSlack extends HumanFeedbackMechanism {
|
|||
this.slackClient = new SlackClient()
|
||||
}
|
||||
|
||||
protected async annotate(
|
||||
response: any,
|
||||
metadata: TaskResponseMetadata
|
||||
): Promise<void> {
|
||||
try {
|
||||
const annotation = await this.slackClient.sendAndWaitForReply({
|
||||
text: 'Please leave an annotation (optional):'
|
||||
})
|
||||
|
||||
if (annotation) {
|
||||
metadata.feedback.annotation = annotation.text
|
||||
}
|
||||
} catch (e) {
|
||||
// Deliberately swallow the error here as the user is not required to leave an annotation
|
||||
}
|
||||
}
|
||||
|
||||
private async askUser(
|
||||
message: string,
|
||||
choices: UserActions[]
|
||||
|
@ -97,20 +114,6 @@ export class HumanFeedbackMechanismSlack extends HumanFeedbackMechanism {
|
|||
default:
|
||||
throw new Error(`Unexpected feedback: ${feedback}`)
|
||||
}
|
||||
|
||||
if (this._options.annotations) {
|
||||
try {
|
||||
const annotation = await this.slackClient.sendAndWaitForReply({
|
||||
text: 'Please leave an annotation (optional):'
|
||||
})
|
||||
|
||||
if (annotation) {
|
||||
metadata.feedback.annotation = annotation.text
|
||||
}
|
||||
} catch (e) {
|
||||
// Deliberately swallow the error here as the user is not required to leave an annotation
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async selectOne(
|
||||
|
@ -178,20 +181,6 @@ export class HumanFeedbackMechanismSlack extends HumanFeedbackMechanism {
|
|||
default:
|
||||
throw new Error(`Unexpected feedback: ${feedback}`)
|
||||
}
|
||||
|
||||
if (this._options.annotations) {
|
||||
try {
|
||||
const annotation = await this.slackClient.sendAndWaitForReply({
|
||||
text: 'Please leave an annotation (optional):'
|
||||
})
|
||||
|
||||
if (annotation) {
|
||||
metadata.feedback.annotation = annotation.text
|
||||
}
|
||||
} catch (e) {
|
||||
// Deliberately swallow the error here as the user is not required to leave an annotation
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async selectN(
|
||||
|
@ -268,19 +257,5 @@ export class HumanFeedbackMechanismSlack extends HumanFeedbackMechanism {
|
|||
default:
|
||||
throw new Error(`Unexpected feedback: ${feedback}`)
|
||||
}
|
||||
|
||||
if (this._options.annotations) {
|
||||
try {
|
||||
const annotation = await this.slackClient.sendAndWaitForReply({
|
||||
text: 'Please leave an annotation (optional):'
|
||||
})
|
||||
|
||||
if (annotation) {
|
||||
metadata.feedback.annotation = annotation.text
|
||||
}
|
||||
} catch (e) {
|
||||
// Deliberately swallow the error here as the user is not required to leave an annotation
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,24 @@ export class HumanFeedbackMechanismTwilio extends HumanFeedbackMechanism {
|
|||
this.twilioClient = new TwilioConversationClient()
|
||||
}
|
||||
|
||||
protected async annotate(
|
||||
response: any,
|
||||
metadata: TaskResponseMetadata
|
||||
): Promise<void> {
|
||||
try {
|
||||
const annotation = await this.twilioClient.sendAndWaitForReply({
|
||||
name: 'human-feedback-annotation',
|
||||
text: 'Please leave an annotation (optional):'
|
||||
})
|
||||
|
||||
if (annotation) {
|
||||
metadata.feedback.annotation = annotation.body
|
||||
}
|
||||
} catch (e) {
|
||||
// Deliberately swallow the error here as the user is not required to leave an annotation
|
||||
}
|
||||
}
|
||||
|
||||
private async askUser(
|
||||
message: string,
|
||||
choices: UserActions[]
|
||||
|
@ -98,21 +116,6 @@ export class HumanFeedbackMechanismTwilio extends HumanFeedbackMechanism {
|
|||
default:
|
||||
throw new Error(`Unexpected feedback: ${feedback}`)
|
||||
}
|
||||
|
||||
if (this._options.annotations) {
|
||||
try {
|
||||
const annotation = await this.twilioClient.sendAndWaitForReply({
|
||||
name: 'human-feedback-annotation',
|
||||
text: 'Please leave an annotation (optional):'
|
||||
})
|
||||
|
||||
if (annotation) {
|
||||
metadata.feedback.annotation = annotation.body
|
||||
}
|
||||
} catch (e) {
|
||||
// Deliberately swallow the error here as the user is not required to leave an annotation
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async selectOne(
|
||||
|
@ -181,21 +184,6 @@ export class HumanFeedbackMechanismTwilio extends HumanFeedbackMechanism {
|
|||
default:
|
||||
throw new Error(`Unexpected feedback: ${feedback}`)
|
||||
}
|
||||
|
||||
if (this._options.annotations) {
|
||||
try {
|
||||
const annotation = await this.twilioClient.sendAndWaitForReply({
|
||||
text: 'Please leave an annotation (optional):',
|
||||
name: 'human-feedback-annotation'
|
||||
})
|
||||
|
||||
if (annotation) {
|
||||
metadata.feedback.annotation = annotation.body
|
||||
}
|
||||
} catch (e) {
|
||||
// Deliberately swallow the error here as the user is not required to leave an annotation
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async selectN(
|
||||
|
@ -275,20 +263,5 @@ export class HumanFeedbackMechanismTwilio extends HumanFeedbackMechanism {
|
|||
default:
|
||||
throw new Error(`Unexpected feedback: ${feedback}`)
|
||||
}
|
||||
|
||||
if (this._options.annotations) {
|
||||
try {
|
||||
const annotation = await this.twilioClient.sendAndWaitForReply({
|
||||
text: 'Please leave an annotation (optional):',
|
||||
name: 'human-feedback-annotation'
|
||||
})
|
||||
|
||||
if (annotation) {
|
||||
metadata.feedback.annotation = annotation.body
|
||||
}
|
||||
} catch (e) {
|
||||
// Deliberately swallow the error here as the user is not required to leave an annotation
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue