kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
feat: rename selectN to multiselect and selectOne to select
rodzic
1c318654f9
commit
d2504aa6e2
|
@ -30,7 +30,7 @@ async function main() {
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.withHumanFeedback({
|
.withHumanFeedback({
|
||||||
type: 'selectN'
|
type: 'multiselect'
|
||||||
})
|
})
|
||||||
.callWithMetadata({
|
.callWithMetadata({
|
||||||
question
|
question
|
||||||
|
@ -38,7 +38,7 @@ async function main() {
|
||||||
|
|
||||||
if (
|
if (
|
||||||
metadata.feedback &&
|
metadata.feedback &&
|
||||||
metadata.feedback.type === 'selectN' &&
|
metadata.feedback.type === 'multiselect' &&
|
||||||
metadata.feedback.selected
|
metadata.feedback.selected
|
||||||
) {
|
) {
|
||||||
const answer = await agentic
|
const answer = await agentic
|
||||||
|
|
|
@ -41,7 +41,7 @@ async function main() {
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.output(z.array(z.string()).describe('question'))
|
.output(z.array(z.string()).describe('question'))
|
||||||
.withHumanFeedback({ type: 'selectN' })
|
.withHumanFeedback({ type: 'multiselect' })
|
||||||
.callWithMetadata({ topic })
|
.callWithMetadata({ topic })
|
||||||
|
|
||||||
console.log()
|
console.log()
|
||||||
|
|
|
@ -19,7 +19,7 @@ async function main() {
|
||||||
.output(z.array(z.string()))
|
.output(z.array(z.string()))
|
||||||
.modelParams({ temperature: 0.9 })
|
.modelParams({ temperature: 0.9 })
|
||||||
.withHumanFeedback({
|
.withHumanFeedback({
|
||||||
type: 'selectN',
|
type: 'multiselect',
|
||||||
annotations: false,
|
annotations: false,
|
||||||
abort: false,
|
abort: false,
|
||||||
editing: true
|
editing: true
|
||||||
|
|
|
@ -19,7 +19,7 @@ async function main() {
|
||||||
.output(z.array(z.string()))
|
.output(z.array(z.string()))
|
||||||
.modelParams({ temperature: 0.9 })
|
.modelParams({ temperature: 0.9 })
|
||||||
.withHumanFeedback({
|
.withHumanFeedback({
|
||||||
type: 'selectN',
|
type: 'multiselect',
|
||||||
annotations: false,
|
annotations: false,
|
||||||
abort: false,
|
abort: false,
|
||||||
editing: true,
|
editing: true,
|
||||||
|
|
|
@ -19,7 +19,7 @@ async function main() {
|
||||||
.output(z.array(z.string()))
|
.output(z.array(z.string()))
|
||||||
.modelParams({ temperature: 0.9 })
|
.modelParams({ temperature: 0.9 })
|
||||||
.withHumanFeedback({
|
.withHumanFeedback({
|
||||||
type: 'selectN',
|
type: 'multiselect',
|
||||||
annotations: false,
|
annotations: false,
|
||||||
abort: false,
|
abort: false,
|
||||||
editing: true,
|
editing: true,
|
||||||
|
|
|
@ -82,11 +82,11 @@ export class HumanFeedbackMechanismCLI<
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async _selectOne(
|
protected async _select(
|
||||||
response: TOutput
|
response: TOutput
|
||||||
): Promise<TOutput extends (infer U)[] ? U : never> {
|
): Promise<TOutput extends (infer U)[] ? U : never> {
|
||||||
if (!Array.isArray(response)) {
|
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) => ({
|
const choices = response.map((option) => ({
|
||||||
|
@ -98,11 +98,11 @@ export class HumanFeedbackMechanismCLI<
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async _selectN(
|
protected async _multiselect(
|
||||||
response: TOutput
|
response: TOutput
|
||||||
): Promise<TOutput extends any[] ? TOutput : never> {
|
): Promise<TOutput extends any[] ? TOutput : never> {
|
||||||
if (!Array.isArray(response)) {
|
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) => ({
|
const choices = response.map((option) => ({
|
||||||
|
|
|
@ -30,7 +30,7 @@ export const HumanFeedbackUserActionMessages: Record<
|
||||||
/**
|
/**
|
||||||
* Available types of human feedback.
|
* Available types of human feedback.
|
||||||
*/
|
*/
|
||||||
export type HumanFeedbackType = 'confirm' | 'selectOne' | 'selectN'
|
export type HumanFeedbackType = 'confirm' | 'select' | 'multiselect'
|
||||||
|
|
||||||
type HumanFeedbackMechanismConstructor<
|
type HumanFeedbackMechanismConstructor<
|
||||||
T extends HumanFeedbackType,
|
T extends HumanFeedbackType,
|
||||||
|
@ -102,12 +102,11 @@ export interface HumanFeedbackConfirmMetadata
|
||||||
accepted: boolean
|
accepted: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HumanFeedbackSelectOneMetadata
|
export interface HumanFeedbackSelectMetadata extends BaseHumanFeedbackMetadata {
|
||||||
extends BaseHumanFeedbackMetadata {
|
|
||||||
/**
|
/**
|
||||||
* The type of feedback requested.
|
* The type of feedback requested.
|
||||||
*/
|
*/
|
||||||
type: 'selectOne'
|
type: 'select'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The selected output.
|
* The selected output.
|
||||||
|
@ -115,12 +114,12 @@ export interface HumanFeedbackSelectOneMetadata
|
||||||
chosen: any
|
chosen: any
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HumanFeedbackSelectNMetadata
|
export interface HumanFeedbackMultiselectMetadata
|
||||||
extends BaseHumanFeedbackMetadata {
|
extends BaseHumanFeedbackMetadata {
|
||||||
/**
|
/**
|
||||||
* The type of feedback requested.
|
* The type of feedback requested.
|
||||||
*/
|
*/
|
||||||
type: 'selectN'
|
type: 'multiselect'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The selected outputs.
|
* The selected outputs.
|
||||||
|
@ -131,9 +130,9 @@ export interface HumanFeedbackSelectNMetadata
|
||||||
export type FeedbackTypeToMetadata<T extends HumanFeedbackType> =
|
export type FeedbackTypeToMetadata<T extends HumanFeedbackType> =
|
||||||
T extends 'confirm'
|
T extends 'confirm'
|
||||||
? HumanFeedbackConfirmMetadata
|
? HumanFeedbackConfirmMetadata
|
||||||
: T extends 'selectOne'
|
: T extends 'select'
|
||||||
? HumanFeedbackSelectOneMetadata
|
? HumanFeedbackSelectMetadata
|
||||||
: HumanFeedbackSelectNMetadata
|
: HumanFeedbackMultiselectMetadata
|
||||||
|
|
||||||
export abstract class HumanFeedbackMechanism<
|
export abstract class HumanFeedbackMechanism<
|
||||||
T extends HumanFeedbackType,
|
T extends HumanFeedbackType,
|
||||||
|
@ -157,11 +156,11 @@ export abstract class HumanFeedbackMechanism<
|
||||||
this._options = options
|
this._options = options
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract _selectOne(
|
protected abstract _select(
|
||||||
output: TOutput
|
output: TOutput
|
||||||
): Promise<TOutput extends any[] ? TOutput[0] : never>
|
): Promise<TOutput extends any[] ? TOutput[0] : never>
|
||||||
|
|
||||||
protected abstract _selectN(
|
protected abstract _multiselect(
|
||||||
response: TOutput
|
response: TOutput
|
||||||
): Promise<TOutput extends any[] ? TOutput : never>
|
): Promise<TOutput extends any[] ? TOutput : never>
|
||||||
|
|
||||||
|
@ -195,8 +194,8 @@ export abstract class HumanFeedbackMechanism<
|
||||||
|
|
||||||
const choices: HumanFeedbackUserActions[] = []
|
const choices: HumanFeedbackUserActions[] = []
|
||||||
if (
|
if (
|
||||||
this._options.type === 'selectN' ||
|
this._options.type === 'multiselect' ||
|
||||||
this._options.type === 'selectOne'
|
this._options.type === 'select'
|
||||||
) {
|
) {
|
||||||
choices.push(HumanFeedbackUserActions.Select)
|
choices.push(HumanFeedbackUserActions.Select)
|
||||||
} else {
|
} else {
|
||||||
|
@ -243,18 +242,18 @@ export abstract class HumanFeedbackMechanism<
|
||||||
break
|
break
|
||||||
|
|
||||||
case HumanFeedbackUserActions.Select:
|
case HumanFeedbackUserActions.Select:
|
||||||
if (this._options.type === 'selectN') {
|
if (this._options.type === 'multiselect') {
|
||||||
if (!Array.isArray(output)) {
|
if (!Array.isArray(output)) {
|
||||||
throw new Error('Expected output to be an array')
|
throw new Error('Expected output to be an array')
|
||||||
}
|
}
|
||||||
|
|
||||||
feedback.selected = await this._selectN(output)
|
feedback.selected = await this._multiselect(output)
|
||||||
} else if (this._options.type === 'selectOne') {
|
} else if (this._options.type === 'select') {
|
||||||
if (!Array.isArray(output)) {
|
if (!Array.isArray(output)) {
|
||||||
throw new Error('Expected output to be an array')
|
throw new Error('Expected output to be an array')
|
||||||
}
|
}
|
||||||
|
|
||||||
feedback.chosen = await this._selectOne(output)
|
feedback.chosen = await this._select(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
|
@ -74,11 +74,11 @@ export class HumanFeedbackMechanismSlack<
|
||||||
return choices[parseInt(response.text)]
|
return choices[parseInt(response.text)]
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async _selectOne(
|
protected async _select(
|
||||||
response: TOutput
|
response: TOutput
|
||||||
): Promise<TOutput extends (infer U)[] ? U : never> {
|
): Promise<TOutput extends (infer U)[] ? U : never> {
|
||||||
if (!Array.isArray(response)) {
|
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 } =
|
const { text: selectedOutput } =
|
||||||
|
@ -98,11 +98,11 @@ export class HumanFeedbackMechanismSlack<
|
||||||
return response[parseInt(selectedOutput)]
|
return response[parseInt(selectedOutput)]
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async _selectN(
|
protected async _multiselect(
|
||||||
response: TOutput
|
response: TOutput
|
||||||
): Promise<TOutput extends any[] ? TOutput : never> {
|
): Promise<TOutput extends any[] ? TOutput : never> {
|
||||||
if (!Array.isArray(response)) {
|
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 } =
|
const { text: selectedOutput } =
|
||||||
|
|
|
@ -78,11 +78,11 @@ export class HumanFeedbackMechanismTwilio<
|
||||||
return choices[parseInt(response.body)]
|
return choices[parseInt(response.body)]
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async _selectOne(
|
protected async _select(
|
||||||
response: TOutput
|
response: TOutput
|
||||||
): Promise<TOutput extends (infer U)[] ? U : never> {
|
): Promise<TOutput extends (infer U)[] ? U : never> {
|
||||||
if (!Array.isArray(response)) {
|
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 } =
|
const { body: selectedOutput } =
|
||||||
|
@ -102,11 +102,11 @@ export class HumanFeedbackMechanismTwilio<
|
||||||
return response[parseInt(selectedOutput)]
|
return response[parseInt(selectedOutput)]
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async _selectN(
|
protected async _multiselect(
|
||||||
response: TOutput
|
response: TOutput
|
||||||
): Promise<TOutput extends any[] ? TOutput : never> {
|
): Promise<TOutput extends any[] ? TOutput : never> {
|
||||||
if (!Array.isArray(response)) {
|
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 } =
|
const { body: selectedOutput } =
|
||||||
|
|
Ładowanie…
Reference in New Issue