Skip to content

Commit

Permalink
feat: nvidia-nim-plugin (elizaOS#2599)
Browse files Browse the repository at this point in the history
* Commit for the preparation of the PR

* Fix conflicts in .env.example and package.json

* fix node version

* Update pnpm-lock.yaml

* Fixed 2 issues from Coderabbit check

* fixes build

* fix coinbase agent kit loading

* fix initialization issues

---------

Co-authored-by: Sayo <[email protected]>
  • Loading branch information
AIFlowML and wtfsayo authored Jan 21, 2025
1 parent e80c2e6 commit 4c8a60a
Show file tree
Hide file tree
Showing 59 changed files with 4,661 additions and 581 deletions.
24 changes: 24 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -718,3 +718,27 @@ ROUTER_NITRO_EVM_PRIVATE_KEY=
INITIA_PRIVATE_KEY= # Your Initia wallet private key
INITIA_NODE_URL= # Initia node URL (default: testnet)
INITIA_CHAIN_ID=initia-test # Chain ID (default: testnet)

# ####################################
# #### NVIDIA Configuration ##########
# ####################################
NVIDIA_NIM_ENV=production
NVIDIA_NIM_SPASH=false
# Api Keys
NVIDIA_NIM_API_KEY=
NVIDIA_NGC_API_KEY=
NVIDIA_NIM_MAX_RETRIES=3
NVIDIA_NIM_RETRY_DELAY=1000
NVIDIA_NIM_TIMEOUT=5000
# Logging Configuration
NVIDIA_GRANULAR_LOG=true
NVIDIA_LOG_LEVEL=debug
# NVIDIA Off-topic system and user configuration
NVIDIA_OFFTOPIC_SYSTEM=
NVIDIA_OFFTOPIC_USER=
# NVIDIA Cosmos Model Configuration
NVIDIA_NIM_BASE_VISION_URL=https://ai.api.nvidia.com/v1/vlm
NVIDIA_COSMOS_MODEL=nvidia/cosmos-nemotron-34b
NVIDIA_COSMOS_INVOKE_URL=https://ai.api.nvidia.com/v1/vlm/nvidia/cosmos-nemotron-34b
NVIDIA_COSMOS_ASSET_URL=https://api.nvcf.nvidia.com/v2/nvcf/assets
NVIDIA_COSMOS_MAX_TOKENS=1000
2 changes: 1 addition & 1 deletion .github/workflows/integrationTests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version: "23"
node-version: "23.3"
cache: "pnpm"

- name: Clean up
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/smoke-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

- uses: actions/setup-node@v4
with:
node-version: "23"
node-version: "23.3"
cache: "pnpm"

- name: Run smoke tests
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@ agent/content
eliza.manifest
eliza.manifest.sgx
eliza.sig
packages/plugin-nvidia-nim/extra
packages/plugin-nvidia-nim/old_code
packages/plugin-nvidia-nim/docs
5 changes: 4 additions & 1 deletion agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"@elizaos/plugin-goat": "workspace:*",
"@elizaos/plugin-lensNetwork": "workspace:*",
"@elizaos/plugin-icp": "workspace:*",
"@elizaos/plugin-initia": "workspace:*",
"@elizaos/plugin-initia": "workspace:*",
"@elizaos/plugin-image-generation": "workspace:*",
"@elizaos/plugin-movement": "workspace:*",
"@elizaos/plugin-massa": "workspace:*",
Expand All @@ -84,6 +84,7 @@
"@elizaos/plugin-twitter": "workspace:*",
"@elizaos/plugin-primus": "workspace:*",
"@elizaos/plugin-cronoszkevm": "workspace:*",
"@elizaos/plugin-cronos": "workspace:*",
"@elizaos/plugin-3d-generation": "workspace:*",
"@elizaos/plugin-fuel": "workspace:*",
"@elizaos/plugin-avalanche": "workspace:*",
Expand Down Expand Up @@ -111,6 +112,8 @@
"@elizaos/plugin-devin": "workspace:*",
"@elizaos/plugin-holdstation": "workspace:*",
"@elizaos/plugin-router-nitro": "workspace:*",
"@elizaos/plugin-nvidia-nim": "workspace:*",

"readline": "1.3.0",
"ws": "8.18.0",
"yargs": "17.7.2"
Expand Down
12 changes: 10 additions & 2 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ import { devinPlugin } from '@elizaos/plugin-devin';


import { zksyncEraPlugin } from "@elizaos/plugin-zksync-era";

import { nvidiaNimPlugin } from "@elizaos/plugin-nvidia-nim";

import Database from "better-sqlite3";
import fs from "fs";
import net from "net";
Expand Down Expand Up @@ -902,8 +905,7 @@ export async function createAgent(
? elizaCodeinPlugin
: null,
bootstrapPlugin,
getSecret(character, "CDP_API_KEY_NAME") &&
getSecret(character, "CDP_API_KEY_PRIVATE_KEY")
getSecret(character, "CDP_API_KEY_NAME") && getSecret(character, "CDP_API_KEY_PRIVATE_KEY") && getSecret(character, "CDP_AGENT_KIT_NETWORK")
? agentKitPlugin
: null,
getSecret(character, "DEXSCREENER_API_KEY")
Expand Down Expand Up @@ -1099,6 +1101,12 @@ export async function createAgent(
? holdstationPlugin
: null,
getSecret(character, "INITIA_PRIVATE_KEY") ? initiaPlugin : null,

getSecret(character, "NVIDIA_NIM_API_KEY") ||
getSecret(character, "NVIDIA_NGC_API_KEY")
? nvidiaNimPlugin
: null,
getSecret(character, "INITIA_PRIVATE_KEY") && getSecret(character, "INITIA_NODE_URL") ? initiaPlugin : null
].filter(Boolean),
providers: [],
actions: [],
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@
"optional": "0.1.4",
"pnpm": "9.14.4",
"sharp": "0.33.5",
"tslog": "4.9.3"
"tslog": "4.9.3",
"bs58": "4.0.0"
},
"packageManager": "[email protected]+sha512.cce0f9de9c5a7c95bef944169cc5dfe8741abfb145078c0d508b868056848a87c81e626246cb60967cbd7fd29a6c062ef73ff840d96b3c86c40ac92cf4a813ee",
"workspaces": [
"packages/*"
]
}
}
11 changes: 10 additions & 1 deletion packages/plugin-agentkit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,23 @@ console.log("└═════════════════════

const initializeActions = async () => {
try {
// Validate environment variables
const apiKeyName = process.env.CDP_API_KEY_NAME;
const apiKeyPrivateKey = process.env.CDP_API_KEY_PRIVATE_KEY;

if (!apiKeyName || !apiKeyPrivateKey) {
console.warn("⚠️ Missing CDP API credentials - AgentKit actions will not be available");
return [];
}

const actions = await getAgentKitActions({
getClient,
});
console.log("✔ AgentKit actions initialized successfully.");
return actions;
} catch (error) {
console.error("❌ Failed to initialize AgentKit actions:", error);
return null;
return []; // Return empty array instead of failing
}
};

Expand Down
28 changes: 21 additions & 7 deletions packages/plugin-agentkit/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import * as fs from "fs";
const WALLET_DATA_FILE = "wallet_data.txt";

export async function getClient(): Promise<CdpAgentkit> {
// Validate required environment variables first
const apiKeyName = process.env.CDP_API_KEY_NAME;
const apiKeyPrivateKey = process.env.CDP_API_KEY_PRIVATE_KEY;

if (!apiKeyName || !apiKeyPrivateKey) {
throw new Error("Missing required CDP API credentials. Please set CDP_API_KEY_NAME and CDP_API_KEY_PRIVATE_KEY environment variables.");
}

let walletDataStr: string | null = null;

// Read existing wallet data if available
Expand All @@ -21,14 +29,20 @@ export async function getClient(): Promise<CdpAgentkit> {
const config = {
cdpWalletData: walletDataStr || undefined,
networkId: process.env.CDP_AGENT_KIT_NETWORK || "base-sepolia",
apiKeyName: apiKeyName,
apiKeyPrivateKey: apiKeyPrivateKey
};

const agentkit = await CdpAgentkit.configureWithWallet(config);
// Save wallet data
const exportedWallet = await agentkit.exportWallet();
fs.writeFileSync(WALLET_DATA_FILE, exportedWallet);

return agentkit;
try {
const agentkit = await CdpAgentkit.configureWithWallet(config);
// Save wallet data
const exportedWallet = await agentkit.exportWallet();
fs.writeFileSync(WALLET_DATA_FILE, exportedWallet);
return agentkit;
} catch (error) {
console.error("Failed to initialize CDP AgentKit:", error);
throw new Error(`Failed to initialize CDP AgentKit: ${error.message || 'Unknown error'}`);
}
}

export const walletProvider: Provider = {
Expand All @@ -39,7 +53,7 @@ export const walletProvider: Provider = {
return `AgentKit Wallet Address: ${address}`;
} catch (error) {
console.error("Error in AgentKit provider:", error);
return null;
return `Error initializing AgentKit wallet: ${error.message}`;
}
},
};
19 changes: 9 additions & 10 deletions packages/plugin-cronos/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@elizaos/plugin-cronos",
"version": "0.0.1",
"version": "0.1.9-alpha.1",
"type": "module",
"main": "dist/index.js",
"module": "dist/index.js",
Expand All @@ -18,16 +18,15 @@
"files": [
"dist"
],
"scripts": {
"build": "tsup --format esm --dts"
},
"dependencies": {
"@elizaos/core": "workspace:*",
"node-cache": "^5.1.2",
"viem": "^2.0.0"
"tsup": "^8.3.5",
"viem": "2.22.2"
},
"scripts": {
"build": "tsup --format esm --dts"
},
"devDependencies": {
"tsup": "^8.0.1",
"typescript": "^5.3.3"
"peerDependencies": {
"whatwg-url": "7.1.0"
}
}
}
21 changes: 7 additions & 14 deletions packages/plugin-cronos/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
{
"extends": "../core/tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"moduleResolution": "Bundler",
"module": "ESNext",
"target": "ESNext",
"declaration": true,
"emitDeclarationOnly": true
},
"include": [
"src/**/*.ts"
]
}
"extends": "../core/tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
},
"include": ["src/**/*.ts"]
}
18 changes: 9 additions & 9 deletions packages/plugin-holdstation/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@elizaos/plugin-holdstation",
"version": "0.1.1",
"version": "0.1.9-alpha.1",
"type": "module",
"main": "dist/index.js",
"module": "dist/index.js",
Expand All @@ -15,18 +15,18 @@
}
}
},
"files": [
"dist"
],
"dependencies": {
"@elizaos/core": "workspace:*",
"node-cache": "5.1.2",
"tsup": "^8.3.5",
"viem": "2.22.2"
},
"devDependencies": {
"tsup": "8.3.5",
"@types/node": "^20.0.0"
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch",
"lint": "eslint --fix --cache ."
"build": "tsup --format esm --dts"
},
"peerDependencies": {
"whatwg-url": "7.1.0"
}
}
34 changes: 31 additions & 3 deletions packages/plugin-holdstation/src/providers/walletProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,38 @@ import { PrivateKeyAccount } from "viem/accounts";
import { useGetAccount, useGetWalletClient } from "../hooks";
import { Item, SendTransactionParams, WalletPortfolio } from "../types";

import NodeCache from "node-cache";
// Add this simple cache class
class SimpleCache {
private cache: Map<string, { value: any; expiry: number }>;
private defaultTTL: number;

constructor(defaultTTL: number = 300) { // 300 seconds = 5 minutes
this.cache = new Map();
this.defaultTTL = defaultTTL;
}

set(key: string, value: any): void {
this.cache.set(key, {
value,
expiry: Date.now() + (this.defaultTTL * 1000)
});
}

get<T>(key: string): T | undefined {
const item = this.cache.get(key);
if (!item) return undefined;

if (Date.now() > item.expiry) {
this.cache.delete(key);
return undefined;
}

return item.value as T;
}
}

export class WalletProvider {
private cache: NodeCache;
private cache: SimpleCache;
account: PrivateKeyAccount;
walletClient: WalletClient;
publicClient: PublicClient<HttpTransport, Chain, Account | undefined>;
Expand All @@ -39,7 +67,7 @@ export class WalletProvider {
chain: zksync,
transport: http(),
}) as PublicClient<HttpTransport, Chain, Account | undefined>;
this.cache = new NodeCache({ stdTTL: 300 });
this.cache = new SimpleCache(300); // 5 minutes TTL
}

getAddress() {
Expand Down
19 changes: 7 additions & 12 deletions packages/plugin-holdstation/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
{
"extends": "../core/tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"types": [
"node"
]
},
"include": [
"src/**/*.ts"
]
}
"extends": "../core/tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
},
"include": ["src/**/*.ts"]
}
Loading

0 comments on commit 4c8a60a

Please sign in to comment.