-
Notifications
You must be signed in to change notification settings - Fork 323
/
base.ts
46 lines (37 loc) · 1.1 KB
/
base.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { PromptMixin } from "../prompts/Mixin.js";
import type { QueryBundle, ToolMetadataOnlyDescription } from "../types.js";
export interface SingleSelection {
index: number;
reason: string;
}
export type SelectorResult = {
selections: SingleSelection[];
};
type QueryType = string | QueryBundle;
function wrapChoice(
choice: string | ToolMetadataOnlyDescription,
): ToolMetadataOnlyDescription {
if (typeof choice === "string") {
return { description: choice };
} else {
return choice;
}
}
function wrapQuery(query: QueryType): QueryBundle {
if (typeof query === "string") {
return { queryStr: query };
}
return query;
}
type MetadataType = string | ToolMetadataOnlyDescription;
export abstract class BaseSelector extends PromptMixin {
async select(choices: MetadataType[], query: QueryType) {
const metadatas = choices.map((choice) => wrapChoice(choice));
const queryBundle = wrapQuery(query);
return await this._select(metadatas, queryBundle);
}
abstract _select(
choices: ToolMetadataOnlyDescription[],
query: QueryBundle,
): Promise<SelectorResult>;
}