Skip to content

Commit

Permalink
rename storage to upload, update env
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Nov 19, 2024
1 parent c95c2d3 commit b32a546
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 27 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,9 @@ SERVER_PORT=3000
# Starknet
STARKNET_ADDRESS=
STARKNET_PRIVATE_KEY=

#ZeroG
ZEROG_INDEXER_RPC=
ZEROG_EVM_RPC=
ZEROG_PRIVATE_KEY=
ZEROG_FLOW_ADDRESS=
43 changes: 22 additions & 21 deletions packages/plugin-zerog/src/actions/uoload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { composeContext } from "@ai16z/eliza";
import { generateObject } from "@ai16z/eliza";


const storageTemplate = `Respond with a JSON markdown block containing only the extracted values. Use null for any values that cannot be determined.
const uploadTemplate = `Respond with a JSON markdown block containing only the extracted values. Use null for any values that cannot be determined.
Example response:
\`\`\`json
Expand All @@ -38,22 +38,22 @@ If the user provides any specific description of the file, include that as well.
Respond with a JSON markdown block containing only the extracted values.`;

export interface StorageContent extends Content {
export interface UploadContent extends Content {
filePath: string;
}

function isStorageContent(
function isUploadContent(
_runtime: IAgentRuntime,
content: any
): content is StorageContent {
console.log("Content for storage", content);
): content is UploadContent {
console.log("Content for upload", content);
return (
typeof content.filePath === "string"
);
}

export const zgStorage: Action = {
name: "ZG_STORAGE",
export const zgUpload: Action = {
name: "ZG_UPLOAD",
similes: [
"UPLOAD_FILE_TO_ZG",
"STORE_FILE_ON_ZG",
Expand All @@ -78,32 +78,33 @@ export const zgStorage: Action = {
options: any,
callback: HandlerCallback
) => {
console.log("ZG_UPLOAD action called");
if (!state) {
state = (await runtime.composeState(message)) as State;
} else {
state = await runtime.updateRecentMessageState(state);
}

// Compose storage context
const storageContext = composeContext({
// Compose upload context
const uploadContext = composeContext({
state,
template: storageTemplate,
template: uploadTemplate,
});

// Generate storage content
// Generate upload content
const content = await generateObject({
runtime,
context: storageContext,
context: uploadContext,
modelClass: ModelClass.SMALL,
});

// Validate storage content
if (!isStorageContent(runtime, content)) {
console.error("Invalid content for STORAGE action.");
// Validate upload content
if (!isUploadContent(runtime, content)) {
console.error("Invalid content for UPLOAD action.");
if (callback) {
callback({
text: "Unable to process zg storage request. Invalid content provided.",
content: { error: "Invalid storage content" },
text: "Unable to process zg upload request. Invalid content provided.",
content: { error: "Invalid upload content" },
});
}
return false;
Expand Down Expand Up @@ -140,31 +141,31 @@ export const zgStorage: Action = {
}

} catch (error) {
console.error("Error getting settings for ZG storage:", error);
console.error("Error getting settings for zg upload:", error);
}
},
examples: [[
{
user: "{{user1}}",
content: {
text: "upload my resume.pdf file",
action: "ZG_STORAGE"
action: "ZG_UPLOAD"
}
}
], [
{
user: "{{user1}}",
content: {
text: "can you help me upload this document.docx?",
action: "ZG_STORAGE"
action: "ZG_UPLOAD"
}
}
], [
{
user: "{{user1}}",
content: {
text: "I need to upload an image file image.png",
action: "ZG_STORAGE"
action: "ZG_UPLOAD"
}
}
]] as ActionExample[][],
Expand Down
10 changes: 5 additions & 5 deletions packages/plugin-zerog/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Plugin } from "@ai16z/eliza";
import { zgStorage } from "./actions/uoload";
import { zgUpload } from "./actions/uoload";

export const zgStoragePlugin: Plugin = {
name: "zgStorage",
description: "Store data using 0G protocol",
actions: [zgStorage],
export const zgUploadPlugin: Plugin = {
name: "zgUpload",
description: "Upload data using 0G protocol",
actions: [zgUpload],
evaluators: [],
providers: [],
};
11 changes: 10 additions & 1 deletion pnpm-lock.yaml

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

0 comments on commit b32a546

Please sign in to comment.