diff --git a/examples/expert-qa.ts b/examples/expert-qa.ts index 0c73fb35..0d31f348 100644 --- a/examples/expert-qa.ts +++ b/examples/expert-qa.ts @@ -30,7 +30,7 @@ async function main() { }) ) .withHumanFeedback({ - type: 'selectN' + type: 'multiselect' }) .callWithMetadata({ question @@ -38,7 +38,7 @@ async function main() { if ( metadata.feedback && - metadata.feedback.type === 'selectN' && + metadata.feedback.type === 'multiselect' && metadata.feedback.selected ) { const answer = await agentic diff --git a/examples/hf0-demo.ts b/examples/hf0-demo.ts index 6d440e46..a48a4928 100644 --- a/examples/hf0-demo.ts +++ b/examples/hf0-demo.ts @@ -41,7 +41,7 @@ async function main() { }) ) .output(z.array(z.string()).describe('question')) - .withHumanFeedback({ type: 'selectN' }) + .withHumanFeedback({ type: 'multiselect' }) .callWithMetadata({ topic }) console.log() diff --git a/scratch/examples/human-feedback-cli.ts b/scratch/examples/human-feedback-cli.ts index 96bbee3d..8c5a9b6c 100644 --- a/scratch/examples/human-feedback-cli.ts +++ b/scratch/examples/human-feedback-cli.ts @@ -19,7 +19,7 @@ async function main() { .output(z.array(z.string())) .modelParams({ temperature: 0.9 }) .withHumanFeedback({ - type: 'selectN', + type: 'multiselect', annotations: false, abort: false, editing: true diff --git a/scratch/examples/human-feedback-slack.ts b/scratch/examples/human-feedback-slack.ts index 50b8ac7b..42c9a4ef 100644 --- a/scratch/examples/human-feedback-slack.ts +++ b/scratch/examples/human-feedback-slack.ts @@ -19,7 +19,7 @@ async function main() { .output(z.array(z.string())) .modelParams({ temperature: 0.9 }) .withHumanFeedback({ - type: 'selectN', + type: 'multiselect', annotations: false, abort: false, editing: true, diff --git a/scratch/examples/human-feedback-twilio.ts b/scratch/examples/human-feedback-twilio.ts index 527f4d39..cc02d034 100644 --- a/scratch/examples/human-feedback-twilio.ts +++ b/scratch/examples/human-feedback-twilio.ts @@ -19,7 +19,7 @@ async function main() { .output(z.array(z.string())) .modelParams({ temperature: 0.9 }) .withHumanFeedback({ - type: 'selectN', + type: 'multiselect', annotations: false, abort: false, editing: true, diff --git a/src/human-feedback/cli.ts b/src/human-feedback/cli.ts index aa00ece4..da2259ca 100644 --- a/src/human-feedback/cli.ts +++ b/src/human-feedback/cli.ts @@ -82,11 +82,11 @@ export class HumanFeedbackMechanismCLI< ) } - protected async _selectOne( + protected async _select( response: TOutput ): Promise { if (!Array.isArray(response)) { - throw new Error('selectOne called on non-array response') + throw new Error('select called on non-array response') } const choices = response.map((option) => ({ @@ -98,11 +98,11 @@ export class HumanFeedbackMechanismCLI< ) } - protected async _selectN( + protected async _multiselect( response: TOutput ): Promise { if (!Array.isArray(response)) { - throw new Error('selectN called on non-array response') + throw new Error('multiselect called on non-array response') } const choices = response.map((option) => ({ diff --git a/src/human-feedback/feedback.ts b/src/human-feedback/feedback.ts index 4e8f5dab..849dffbf 100644 --- a/src/human-feedback/feedback.ts +++ b/src/human-feedback/feedback.ts @@ -30,7 +30,7 @@ export const HumanFeedbackUserActionMessages: Record< /** * Available types of human feedback. */ -export type HumanFeedbackType = 'confirm' | 'selectOne' | 'selectN' +export type HumanFeedbackType = 'confirm' | 'select' | 'multiselect' type HumanFeedbackMechanismConstructor< T extends HumanFeedbackType, @@ -102,12 +102,11 @@ export interface HumanFeedbackConfirmMetadata accepted: boolean } -export interface HumanFeedbackSelectOneMetadata - extends BaseHumanFeedbackMetadata { +export interface HumanFeedbackSelectMetadata extends BaseHumanFeedbackMetadata { /** * The type of feedback requested. */ - type: 'selectOne' + type: 'select' /** * The selected output. @@ -115,12 +114,12 @@ export interface HumanFeedbackSelectOneMetadata chosen: any } -export interface HumanFeedbackSelectNMetadata +export interface HumanFeedbackMultiselectMetadata extends BaseHumanFeedbackMetadata { /** * The type of feedback requested. */ - type: 'selectN' + type: 'multiselect' /** * The selected outputs. @@ -131,9 +130,9 @@ export interface HumanFeedbackSelectNMetadata export type FeedbackTypeToMetadata = T extends 'confirm' ? HumanFeedbackConfirmMetadata - : T extends 'selectOne' - ? HumanFeedbackSelectOneMetadata - : HumanFeedbackSelectNMetadata + : T extends 'select' + ? HumanFeedbackSelectMetadata + : HumanFeedbackMultiselectMetadata export abstract class HumanFeedbackMechanism< T extends HumanFeedbackType, @@ -157,11 +156,11 @@ export abstract class HumanFeedbackMechanism< this._options = options } - protected abstract _selectOne( + protected abstract _select( output: TOutput ): Promise - protected abstract _selectN( + protected abstract _multiselect( response: TOutput ): Promise @@ -195,8 +194,8 @@ export abstract class HumanFeedbackMechanism< const choices: HumanFeedbackUserActions[] = [] if ( - this._options.type === 'selectN' || - this._options.type === 'selectOne' + this._options.type === 'multiselect' || + this._options.type === 'select' ) { choices.push(HumanFeedbackUserActions.Select) } else { @@ -243,18 +242,18 @@ export abstract class HumanFeedbackMechanism< break case HumanFeedbackUserActions.Select: - if (this._options.type === 'selectN') { + if (this._options.type === 'multiselect') { if (!Array.isArray(output)) { throw new Error('Expected output to be an array') } - feedback.selected = await this._selectN(output) - } else if (this._options.type === 'selectOne') { + feedback.selected = await this._multiselect(output) + } else if (this._options.type === 'select') { if (!Array.isArray(output)) { throw new Error('Expected output to be an array') } - feedback.chosen = await this._selectOne(output) + feedback.chosen = await this._select(output) } break diff --git a/src/human-feedback/slack.ts b/src/human-feedback/slack.ts index 10ee38a6..b4ba4110 100644 --- a/src/human-feedback/slack.ts +++ b/src/human-feedback/slack.ts @@ -74,11 +74,11 @@ export class HumanFeedbackMechanismSlack< return choices[parseInt(response.text)] } - protected async _selectOne( + protected async _select( response: TOutput ): Promise { if (!Array.isArray(response)) { - throw new Error('selectOne called on non-array response') + throw new Error('select called on non-array response') } const { text: selectedOutput } = @@ -98,11 +98,11 @@ export class HumanFeedbackMechanismSlack< return response[parseInt(selectedOutput)] } - protected async _selectN( + protected async _multiselect( response: TOutput ): Promise { if (!Array.isArray(response)) { - throw new Error('selectN called on non-array response') + throw new Error('multiselect called on non-array response') } const { text: selectedOutput } = diff --git a/src/human-feedback/twilio.ts b/src/human-feedback/twilio.ts index 3801db84..9e8dc104 100644 --- a/src/human-feedback/twilio.ts +++ b/src/human-feedback/twilio.ts @@ -78,11 +78,11 @@ export class HumanFeedbackMechanismTwilio< return choices[parseInt(response.body)] } - protected async _selectOne( + protected async _select( response: TOutput ): Promise { if (!Array.isArray(response)) { - throw new Error('selectOne called on non-array response') + throw new Error('select called on non-array response') } const { body: selectedOutput } = @@ -102,11 +102,11 @@ export class HumanFeedbackMechanismTwilio< return response[parseInt(selectedOutput)] } - protected async _selectN( + protected async _multiselect( response: TOutput ): Promise { if (!Array.isArray(response)) { - throw new Error('selectN called on non-array response') + throw new Error('multiselect called on non-array response') } const { body: selectedOutput } =