kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
feat: parse output after manual editing
rodzic
feb95a2665
commit
bbf3f25d9d
|
@ -71,7 +71,7 @@ export interface BaseHumanFeedbackMetadata {
|
||||||
/**
|
/**
|
||||||
* Edited output by the user (if applicable).
|
* Edited output by the user (if applicable).
|
||||||
*/
|
*/
|
||||||
editedOutput?: string
|
editedOutput?: any
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Annotation left by the user (if applicable).
|
* Annotation left by the user (if applicable).
|
||||||
|
@ -128,16 +128,19 @@ export type FeedbackTypeToMetadata<T extends HumanFeedbackType> =
|
||||||
export abstract class HumanFeedbackMechanism<T extends HumanFeedbackType> {
|
export abstract class HumanFeedbackMechanism<T extends HumanFeedbackType> {
|
||||||
protected _agentic: Agentic
|
protected _agentic: Agentic
|
||||||
|
|
||||||
|
protected _task: BaseTask
|
||||||
|
|
||||||
protected _options: Required<HumanFeedbackOptions<T>>
|
protected _options: Required<HumanFeedbackOptions<T>>
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
agentic,
|
task,
|
||||||
options
|
options
|
||||||
}: {
|
}: {
|
||||||
agentic: Agentic
|
task: BaseTask
|
||||||
options: Required<HumanFeedbackOptions<T>>
|
options: Required<HumanFeedbackOptions<T>>
|
||||||
}) {
|
}) {
|
||||||
this._agentic = agentic
|
this._agentic = task.agentic
|
||||||
|
this._task = task
|
||||||
this._options = options
|
this._options = options
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,6 +157,11 @@ export abstract class HumanFeedbackMechanism<T extends HumanFeedbackType> {
|
||||||
choices: HumanFeedbackUserActions[]
|
choices: HumanFeedbackUserActions[]
|
||||||
): Promise<HumanFeedbackUserActions>
|
): Promise<HumanFeedbackUserActions>
|
||||||
|
|
||||||
|
protected parseEditedOutput(editedOutput: string): any {
|
||||||
|
const parsedOutput = JSON.parse(editedOutput)
|
||||||
|
return this._task.outputSchema.parse(parsedOutput)
|
||||||
|
}
|
||||||
|
|
||||||
public async interact(response: any): Promise<FeedbackTypeToMetadata<T>> {
|
public async interact(response: any): Promise<FeedbackTypeToMetadata<T>> {
|
||||||
const stringified = JSON.stringify(response, null, 2)
|
const stringified = JSON.stringify(response, null, 2)
|
||||||
const msg = [
|
const msg = [
|
||||||
|
@ -198,7 +206,7 @@ export abstract class HumanFeedbackMechanism<T extends HumanFeedbackType> {
|
||||||
|
|
||||||
case HumanFeedbackUserActions.Edit: {
|
case HumanFeedbackUserActions.Edit: {
|
||||||
const editedOutput = await this.edit(stringified)
|
const editedOutput = await this.edit(stringified)
|
||||||
feedback.editedOutput = editedOutput
|
feedback.editedOutput = await this.parseEditedOutput(editedOutput)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,7 +272,7 @@ export function withHumanFeedback<T, U, V extends HumanFeedbackType>(
|
||||||
}
|
}
|
||||||
|
|
||||||
const feedbackMechanism = new finalOptions.mechanism({
|
const feedbackMechanism = new finalOptions.mechanism({
|
||||||
agentic: task.agentic,
|
task: task,
|
||||||
options: finalOptions
|
options: finalOptions
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Agentic } from '@/agentic'
|
|
||||||
import { SlackClient } from '@/services/slack'
|
import { SlackClient } from '@/services/slack'
|
||||||
|
import { BaseTask } from '@/task'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
HumanFeedbackMechanism,
|
HumanFeedbackMechanism,
|
||||||
|
@ -15,13 +15,13 @@ export class HumanFeedbackMechanismSlack<
|
||||||
private slackClient: SlackClient
|
private slackClient: SlackClient
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
agentic,
|
task,
|
||||||
options
|
options
|
||||||
}: {
|
}: {
|
||||||
agentic: Agentic
|
task: BaseTask
|
||||||
options: Required<HumanFeedbackOptions<T>>
|
options: Required<HumanFeedbackOptions<T>>
|
||||||
}) {
|
}) {
|
||||||
super({ agentic, options })
|
super({ task, options })
|
||||||
this.slackClient = new SlackClient()
|
this.slackClient = new SlackClient()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Agentic } from '@/agentic'
|
|
||||||
import { TwilioConversationClient } from '@/services/twilio-conversation'
|
import { TwilioConversationClient } from '@/services/twilio-conversation'
|
||||||
|
import { BaseTask } from '@/task'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
HumanFeedbackMechanism,
|
HumanFeedbackMechanism,
|
||||||
|
@ -15,13 +15,13 @@ export class HumanFeedbackMechanismTwilio<
|
||||||
private twilioClient: TwilioConversationClient
|
private twilioClient: TwilioConversationClient
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
agentic,
|
task,
|
||||||
options
|
options
|
||||||
}: {
|
}: {
|
||||||
agentic: Agentic
|
task: BaseTask
|
||||||
options: Required<HumanFeedbackOptions<T>>
|
options: Required<HumanFeedbackOptions<T>>
|
||||||
}) {
|
}) {
|
||||||
super({ agentic, options })
|
super({ task, options })
|
||||||
this.twilioClient = new TwilioConversationClient()
|
this.twilioClient = new TwilioConversationClient()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue