Skip to content

Commit 7af10f1

Browse files
committed
rename generateObjectV2 to generateObject
1 parent 2cdbc67 commit 7af10f1

File tree

27 files changed

+457
-339
lines changed

27 files changed

+457
-339
lines changed

packages/_examples/plugin/src/actions/sampleAction.ts

+64-70
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,20 @@ import {
55
HandlerCallback,
66
State,
77
composeContext,
8-
generateObjectV2,
8+
generateObject,
99
ModelClass,
1010
elizaLogger,
1111
} from "@ai16z/eliza";
1212

13-
import {
14-
CreateResourceSchema,
15-
isCreateResourceContent,
16-
} from "../types";
13+
import { CreateResourceSchema, isCreateResourceContent } from "../types";
1714

1815
import { createResourceTemplate } from "../templates";
1916

2017
export const createResourceAction: Action = {
2118
name: "CREATE_RESOURCE",
2219
description: "Create a new resource with the specified details",
2320
validate: async (runtime: IAgentRuntime, _message: Memory) => {
24-
return !!(runtime.character.settings.secrets?.API_KEY);
21+
return !!runtime.character.settings.secrets?.API_KEY;
2522
},
2623
handler: async (
2724
runtime: IAgentRuntime,
@@ -30,88 +27,85 @@ export const createResourceAction: Action = {
3027
_options: any,
3128
callback: HandlerCallback
3229
) => {
33-
try {
34-
const context = composeContext({
35-
state,
36-
template: createResourceTemplate,
37-
});
30+
try {
31+
const context = composeContext({
32+
state,
33+
template: createResourceTemplate,
34+
});
3835

39-
const resourceDetails = await generateObjectV2({
40-
runtime,
41-
context,
42-
modelClass: ModelClass.SMALL,
43-
schema: CreateResourceSchema,
44-
});
36+
const resourceDetails = await generateObject({
37+
runtime,
38+
context,
39+
modelClass: ModelClass.SMALL,
40+
schema: CreateResourceSchema,
41+
});
4542

46-
if (!isCreateResourceContent(resourceDetails.object)) {
47-
callback(
48-
{ text: "Invalid resource details provided." },
49-
[]
50-
);
51-
return;
52-
}
43+
if (!isCreateResourceContent(resourceDetails.object)) {
44+
callback({ text: "Invalid resource details provided." }, []);
45+
return;
46+
}
5347

54-
// persist relevant data if needed to memory/knowledge
55-
// const memory = {
56-
// type: "resource",
57-
// content: resourceDetails.object,
58-
// timestamp: new Date().toISOString()
59-
// };
48+
// persist relevant data if needed to memory/knowledge
49+
// const memory = {
50+
// type: "resource",
51+
// content: resourceDetails.object,
52+
// timestamp: new Date().toISOString()
53+
// };
6054

61-
// await runtime.storeMemory(memory);
55+
// await runtime.storeMemory(memory);
6256

63-
callback(
64-
{
65-
text: `Resource created successfully:
57+
callback(
58+
{
59+
text: `Resource created successfully:
6660
- Name: ${resourceDetails.object.name}
6761
- Type: ${resourceDetails.object.type}
6862
- Description: ${resourceDetails.object.description}
6963
- Tags: ${resourceDetails.object.tags.join(", ")}
7064
71-
Resource has been stored in memory.`
72-
},
73-
[]
74-
);
75-
} catch (error) {
76-
elizaLogger.error("Error creating resource:", error);
77-
callback(
78-
{ text: "Failed to create resource. Please check the logs." },
79-
[]
80-
);
81-
}
65+
Resource has been stored in memory.`,
66+
},
67+
[]
68+
);
69+
} catch (error) {
70+
elizaLogger.error("Error creating resource:", error);
71+
callback(
72+
{ text: "Failed to create resource. Please check the logs." },
73+
[]
74+
);
75+
}
8276
},
8377
examples: [
84-
[
85-
{
86-
user: "{{user1}}",
87-
content: {
88-
text: "Create a new resource with the name 'Resource1' and type 'TypeA'",
78+
[
79+
{
80+
user: "{{user1}}",
81+
content: {
82+
text: "Create a new resource with the name 'Resource1' and type 'TypeA'",
83+
},
8984
},
90-
},
91-
{
92-
user: "{{agentName}}",
93-
content: {
94-
text: `Resource created successfully:
85+
{
86+
user: "{{agentName}}",
87+
content: {
88+
text: `Resource created successfully:
9589
- Name: Resource1
9690
- Type: TypeA`,
91+
},
9792
},
98-
},
99-
],
100-
[
101-
{
102-
user: "{{user1}}",
103-
content: {
104-
text: "Create a new resource with the name 'Resource2' and type 'TypeB'",
93+
],
94+
[
95+
{
96+
user: "{{user1}}",
97+
content: {
98+
text: "Create a new resource with the name 'Resource2' and type 'TypeB'",
99+
},
105100
},
106-
},
107-
{
108-
user: "{{agentName}}",
109-
content: {
110-
text: `Resource created successfully:
101+
{
102+
user: "{{agentName}}",
103+
content: {
104+
text: `Resource created successfully:
111105
- Name: Resource2
112106
- Type: TypeB`,
107+
},
113108
},
114-
},
115-
],
109+
],
116110
],
117-
};
111+
};

packages/core/src/generation.ts

+16-11
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
parseJsonArrayFromText,
2222
parseJSONObjectFromText,
2323
parseShouldRespondFromText,
24-
parseActionResponseFromText
24+
parseActionResponseFromText,
2525
} from "./parsing.ts";
2626
import settings from "./settings.ts";
2727
import {
@@ -33,7 +33,7 @@ import {
3333
ModelProviderName,
3434
ServiceType,
3535
SearchResponse,
36-
ActionResponse
36+
ActionResponse,
3737
} from "./types.ts";
3838
import { fal } from "@fal-ai/client";
3939

@@ -537,7 +537,7 @@ export async function generateText({
537537
elizaLogger.debug("Initializing Venice model.");
538538
const venice = createOpenAI({
539539
apiKey: apiKey,
540-
baseURL: endpoint
540+
baseURL: endpoint,
541541
});
542542

543543
const { text: veniceResponse } = await aiGenerateText({
@@ -797,7 +797,7 @@ export async function generateTextArray({
797797
}
798798
}
799799

800-
export async function generateObjectDEPRECATED({
800+
export async function generateObjectDeprecated({
801801
runtime,
802802
context,
803803
modelClass,
@@ -807,7 +807,7 @@ export async function generateObjectDEPRECATED({
807807
modelClass: string;
808808
}): Promise<any> {
809809
if (!context) {
810-
elizaLogger.error("generateObjectDEPRECATED context is empty");
810+
elizaLogger.error("generateObjectDeprecated context is empty");
811811
return null;
812812
}
813813
let retryDelay = 1000;
@@ -1130,7 +1130,9 @@ export const generateImage = async (
11301130

11311131
const base64s = result.images.map((base64String) => {
11321132
if (!base64String) {
1133-
throw new Error("Empty base64 string in Venice AI response");
1133+
throw new Error(
1134+
"Empty base64 string in Venice AI response"
1135+
);
11341136
}
11351137
return `data:image/png;base64,${base64String}`;
11361138
});
@@ -1260,7 +1262,7 @@ interface ModelSettings {
12601262
* @returns {Promise<any[]>} - A promise that resolves to an array of generated objects.
12611263
* @throws {Error} - Throws an error if the provider is unsupported or if generation fails.
12621264
*/
1263-
export const generateObjectV2 = async ({
1265+
export const generateObject = async ({
12641266
runtime,
12651267
context,
12661268
modelClass,
@@ -1271,7 +1273,7 @@ export const generateObjectV2 = async ({
12711273
mode = "json",
12721274
}: GenerationOptions): Promise<GenerateObjectResult<unknown>> => {
12731275
if (!context) {
1274-
const errorMessage = "generateObjectV2 context is empty";
1276+
const errorMessage = "generateObject context is empty";
12751277
console.error(errorMessage);
12761278
throw new Error(errorMessage);
12771279
}
@@ -1365,7 +1367,7 @@ export async function handleProvider(
13651367
case ModelProviderName.GROQ:
13661368
return await handleGroq(options);
13671369
case ModelProviderName.LLAMALOCAL:
1368-
return await generateObjectDEPRECATED({
1370+
return await generateObjectDeprecated({
13691371
runtime,
13701372
context,
13711373
modelClass,
@@ -1626,7 +1628,10 @@ export async function generateTweetActions({
16261628
context,
16271629
modelClass,
16281630
});
1629-
console.debug("Received response from generateText for tweet actions:", response);
1631+
console.debug(
1632+
"Received response from generateText for tweet actions:",
1633+
response
1634+
);
16301635
const { actions } = parseActionResponseFromText(response.trim());
16311636
if (actions) {
16321637
console.debug("Parsed tweet actions:", actions);
@@ -1649,4 +1654,4 @@ export async function generateTweetActions({
16491654
await new Promise((resolve) => setTimeout(resolve, retryDelay));
16501655
retryDelay *= 2;
16511656
}
1652-
}
1657+
}

packages/plugin-0g/src/actions/upload.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
ModelClass,
88
Content,
99
ActionExample,
10-
generateObjectV2,
10+
generateObject,
1111
} from "@ai16z/eliza";
1212
import { Indexer, ZgFile, getFlowContract } from "@0glabs/0g-ts-sdk";
1313
import { ethers } from "ethers";
@@ -68,7 +68,7 @@ export const zgUpload: Action = {
6868
});
6969

7070
// Generate upload content
71-
const content = await generateObjectV2({
71+
const content = await generateObject({
7272
runtime,
7373
context: uploadContext,
7474
modelClass: ModelClass.LARGE,

packages/plugin-aptos/src/actions/transfer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
type Action,
1111
} from "@ai16z/eliza";
1212
import { composeContext } from "@ai16z/eliza";
13-
import { generateObjectDEPRECATED } from "@ai16z/eliza";
13+
import { generateObjectDeprecated } from "@ai16z/eliza";
1414
import {
1515
Account,
1616
Aptos,
@@ -111,7 +111,7 @@ export default {
111111
});
112112

113113
// Generate transfer content
114-
const content = await generateObjectDEPRECATED({
114+
const content = await generateObjectDeprecated({
115115
runtime,
116116
context: transferContext,
117117
modelClass: ModelClass.SMALL,

0 commit comments

Comments
 (0)