Skip to content

Commit

Permalink
update; test enum stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfsayo committed Feb 7, 2025
1 parent b39d2aa commit ab00b65
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 42 deletions.
28 changes: 13 additions & 15 deletions packages/core/src/generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ async function generateEnum<T extends string>({
runtime: IAgentRuntime;
context: string;
modelClass: ModelClass;
enumValues: readonly T[];
enumValues: Array<T>;
functionName: string;
}): Promise<JSONValue> {
logFunctionCall(functionName, runtime);
Expand All @@ -303,7 +303,7 @@ async function generateEnum<T extends string>({
context,
modelClass,
output: 'enum',
enum: enumValues as unknown as string[],
enum: enumValues,
});

elizaLogger.debug("Received enum response:", result);
Expand All @@ -322,18 +322,17 @@ export async function generateShouldRespond({
context: string;
modelClass: ModelClass;
}): Promise<"RESPOND" | "IGNORE" | "STOP" | null> {
const RESPONSE_VALUES = ['RESPOND', 'IGNORE', 'STOP'] as const;
type ResponseType = typeof RESPONSE_VALUES[number];
const RESPONSE_VALUES = ['RESPOND', 'IGNORE', 'STOP'];

const result = await generateEnum<ResponseType>({
const result = await generateEnum({
runtime,
context,
modelClass,
enumValues: RESPONSE_VALUES,
functionName: 'generateShouldRespond',
});

return result as ResponseType;
return result as "RESPOND" | "IGNORE" | "STOP";
}

export async function generateTrueOrFalse({
Expand All @@ -347,10 +346,10 @@ export async function generateTrueOrFalse({
}): Promise<boolean> {
logFunctionCall('generateTrueOrFalse', runtime);

const BOOL_VALUES = ['true', 'false'] as const;
type BoolString = typeof BOOL_VALUES[number];
const BOOL_VALUES = ['true', 'false'];

const result = await generateEnum<BoolString>({

const result = await generateEnum({
runtime,
context,
modelClass,
Expand Down Expand Up @@ -591,35 +590,34 @@ export async function generateTweetActions({
modelClass: ModelClass;
}): Promise<ActionResponse | null> {
try {
const BOOL_VALUES = ['true', 'false'] as const;
type BoolString = typeof BOOL_VALUES[number];
const BOOL_VALUES = ['true', 'false'];

// Generate each action using generateEnum
const like = await generateEnum<BoolString>({
const like = await generateEnum({
runtime,
context: `${context}\nShould I like this tweet?`,
modelClass,
enumValues: BOOL_VALUES,
functionName: 'generateTweetActions_like'
});

const retweet = await generateEnum<BoolString>({
const retweet = await generateEnum({
runtime,
context: `${context}\nShould I retweet this tweet?`,
modelClass,
enumValues: BOOL_VALUES,
functionName: 'generateTweetActions_retweet'
});

const quote = await generateEnum<BoolString>({
const quote = await generateEnum({
runtime,
context: `${context}\nShould I quote this tweet?`,
modelClass,
enumValues: BOOL_VALUES,
functionName: 'generateTweetActions_quote'
});

const reply = await generateEnum<BoolString>({
const reply = await generateEnum({
runtime,
context: `${context}\nShould I reply to this tweet?`,
modelClass,
Expand Down
54 changes: 27 additions & 27 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ab00b65

Please sign in to comment.