Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add 0G plugin for file storage #416

Merged
merged 15 commits into from
Nov 25, 2024
Merged

Conversation

Wilbert957
Copy link
Contributor

@Wilbert957 Wilbert957 commented Nov 19, 2024

This PR adds a new plugin for 0G.

Risks

Low. This change involves adding a new plugin, which is isolated and should not affect existing functionality.

Background

What does this PR do?

This PR adds a new plugin for 0G, which includes an action that allows users to upload local files to 0G Storage.
Future work will include extending 0G support for model serving, state persistence via KV store, and enhanced file management capabilities.

What kind of change is this?

Features (non-breaking change which adds functionality).

Why are we doing this? Any context or related work?

To extend the functionality of Eliza.

Documentation changes needed?

Require a change to the project documentation.

Testing

Where should a reviewer start?

The review can start with the new 0G plugin code, focusing on the action that uploads files to ensure it handles files correctly and integrates well with 0G Storage.

Detailed testing steps

  1. Set Environment Variables
Screenshot 2024-11-20 at 09 34 49 Configure the following variables: - `ZEROG_INDEXER_RPC` - `ZEROG_EVM_RPC` - `ZEROG_PRIVATE_KEY` - `ZEROG_FLOW_ADDRESS` [More details](https://github.com/0glabs/0g-ts-sdk)
  1. Add 0g-plugin into character file
    Ensure the @ai16z/plugin-0g is properly added and configured in the character file.
Screenshot 2024-11-20 at 09 34 10
  1. Interact with the Agent
    Send a message to the agent: Upload the file at /path/to/your/file.txt to zg storage.
Screenshot 2024-11-20 at 08 47 05 Screenshot 2024-11-20 at 08 47 58

Screenshots

Before

After

Database changes

Deployment instructions

@Wilbert957 Wilbert957 changed the title 415 add 0g plugin 415 add 0G plugin Nov 19, 2024
@Wilbert957 Wilbert957 changed the title 415 add 0G plugin feat: add 0G plugin Nov 19, 2024
@Wilbert957 Wilbert957 changed the title feat: add 0G plugin feat(plugin): Add 0G plugin for file storage Nov 19, 2024
@Wilbert957 Wilbert957 changed the title feat(plugin): Add 0G plugin for file storage feat: Add 0G plugin for file storage Nov 19, 2024
@shakkernerd
Copy link
Member

shakkernerd commented Nov 19, 2024

Hey @Wilbert957 Great work!

There are conflicts that needs to be resolved before a merge could happen, could you fix that?

In the package.json for 0g-plugin, kind add dev command ("dev": "tsup --watch").

@Wilbert957
Copy link
Contributor Author

Wilbert957 commented Nov 19, 2024 via email

@Wilbert957
Copy link
Contributor Author

Hey @Wilbert957 Great work!

There are conflicts that needs to be resolved before a merge could happen, could you fix that?

In the package.json for 0g-plugin, kind add dev command ("dev": "tsup --watch").

I've fixed it. Could you please check?

@shakkernerd
Copy link
Member

shakkernerd commented Nov 19, 2024

Kindly attach a screengrab of the upload/file storage interaction.

@Wilbert957 This has been updated.

import { promises as fs } from 'fs';


const uploadTemplate = `Respond with a JSON markdown block containing only the extracted values. Use null for any values that cannot be determined.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this to a templates file for maintainability

Copy link
Contributor Author

@Wilbert957 Wilbert957 Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, thanks, I've fixed.

});

// Generate upload content
const content = await generateObject({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we consider using generateObjectV2 which actually uses z objects to be more type safe.

Copy link
Contributor Author

@Wilbert957 Wilbert957 Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, thanks, I've fixed.

const zgPrivateKey = runtime.getSetting("ZEROG_PRIVATE_KEY");
const flowAddr = runtime.getSetting("ZEROG_FLOW_ADDRESS");
const filePath = content.filePath;
if (!filePath) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add escape clauses if those settings aren't there? Or will validate ensure this cannot happen

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, maybe I didn't get you, but I checked settings-exsitance using the validator of the action.

@monilpat
Copy link
Collaborator

Please resolve conflicts and add a test and / or screen grab of working plugin functionality thanks so much! Amazing work with this plugin you are the GOAT!

if (err === null) {
console.log("File uploaded successfully, tx: ", tx);
} else {
console.log("Error uploading file: ", err);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.error please thanks

Copy link
Contributor Author

@Wilbert957 Wilbert957 Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, thanks, I've fixed.

@Wilbert957
Copy link
Contributor Author

Kindly attach a screengrab of the upload/file storage interaction.

@Wilbert957 This has been updated.

Sure, thanks. I've attached a screengrab.

@Wilbert957
Copy link
Contributor Author

Please resolve conflicts and add a test and / or screen grab of working plugin functionality thanks so much! Amazing work with this plugin you are the GOAT!

Sure, thanks. I've attached a screengrab.

@Wilbert957
Copy link
Contributor Author

Please resolve conflicts and add a test and / or screen grab of working plugin functionality thanks so much! Amazing work with this plugin you are the GOAT!

I've resolved conflicts~

@Wilbert957
Copy link
Contributor Author

Hey @Wilbert957 Great work!

There are conflicts that needs to be resolved before a merge could happen, could you fix that?

In the package.json for 0g-plugin, kind add dev command ("dev": "tsup --watch").

I've resolved conflicts~

@Wilbert957
Copy link
Contributor Author

Hey @Wilbert957 Great work!

There are conflicts that needs to be resolved before a merge could happen, could you fix that?

In the package.json for 0g-plugin, kind add dev command ("dev": "tsup --watch").

Hi @shakkernerd

I hope you're doing well! I wanted to kindly remind you that my pull request (#PR-416) is awaiting your review and approval. Your feedback would be greatly appreciated.

@Wilbert957 Wilbert957 requested a review from monilpat November 25, 2024 05:48
@Wilbert957
Copy link
Contributor Author

Hi, @monilpat. Conflicts resolved. Would know if can merge? Your feedback would be greatly appreciated.

@lalalune lalalune merged commit 8442d09 into elizaOS:main Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants