feat: rename selectN to multiselect and selectOne to select

Travis Fischer 2023-06-23 15:19:36 -07:00
rodzic 1c318654f9
commit d2504aa6e2
9 zmienionych plików z 34 dodań i 35 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -41,7 +41,7 @@ async function main() {
})
)
.output(z.array(z.string()).describe('question'))
.withHumanFeedback({ type: 'selectN' })
.withHumanFeedback({ type: 'multiselect' })
.callWithMetadata({ topic })
console.log()

Wyświetl plik

@ -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

Wyświetl plik

@ -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,

Wyświetl plik

@ -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,

Wyświetl plik

@ -82,11 +82,11 @@ export class HumanFeedbackMechanismCLI<
)
}
protected async _selectOne(
protected async _select(
response: TOutput
): Promise<TOutput extends (infer U)[] ? U : never> {
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<TOutput extends any[] ? TOutput : never> {
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) => ({

Wyświetl plik

@ -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 HumanFeedbackType> =
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<TOutput extends any[] ? TOutput[0] : never>
protected abstract _selectN(
protected abstract _multiselect(
response: TOutput
): Promise<TOutput extends any[] ? TOutput : never>
@ -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

Wyświetl plik

@ -74,11 +74,11 @@ export class HumanFeedbackMechanismSlack<
return choices[parseInt(response.text)]
}
protected async _selectOne(
protected async _select(
response: TOutput
): Promise<TOutput extends (infer U)[] ? U : never> {
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<TOutput extends any[] ? TOutput : never> {
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 } =

Wyświetl plik

@ -78,11 +78,11 @@ export class HumanFeedbackMechanismTwilio<
return choices[parseInt(response.body)]
}
protected async _selectOne(
protected async _select(
response: TOutput
): Promise<TOutput extends (infer U)[] ? U : never> {
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<TOutput extends any[] ? TOutput : never> {
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 } =