-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
546 additions
and
562 deletions.
There are no files selected for viewing
102 changes: 55 additions & 47 deletions
102
packages/plugin-nft-collections/src/actions/get-collections.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,60 @@ | ||
import { Action, IAgentRuntime, Memory } from "@elizaos/core"; | ||
import { nftCollectionProvider } from "../providers/nft-collections"; | ||
import { Action, IAgentRuntime, Memory, Provider } from "@elizaos/core"; | ||
|
||
export const getCollectionsAction: Action = { | ||
name: "GET_NFT_COLLECTIONS", | ||
similes: ["LIST_NFT_COLLECTIONS", "SHOW_NFT_COLLECTIONS"], | ||
description: | ||
"Fetches information about curated NFT collections on Ethereum", | ||
validate: async (runtime: IAgentRuntime, message: Memory) => { | ||
return message.content.text.toLowerCase().includes("nft collections"); | ||
}, | ||
handler: async (runtime: IAgentRuntime, message: Memory) => { | ||
try { | ||
const response = await nftCollectionProvider.get(runtime, message); | ||
await runtime.messageManager.createMemory({ | ||
id: message.id, | ||
content: { text: response }, | ||
roomId: message.roomId, | ||
userId: message.userId, | ||
agentId: runtime.agentId, | ||
}); | ||
return true; | ||
} catch (error) { | ||
console.error("Error fetching NFT collections:", error); | ||
await runtime.messageManager.createMemory({ | ||
id: message.id, | ||
content: { text: "Failed to fetch NFT collection data." }, | ||
roomId: message.roomId, | ||
userId: message.userId, | ||
agentId: runtime.agentId, | ||
}); | ||
return false; | ||
} | ||
}, | ||
examples: [ | ||
[ | ||
{ | ||
user: "{{user1}}", | ||
content: { | ||
text: "Can you tell me about the top NFT collections?", | ||
export const getCollectionsAction = ( | ||
nftCollectionProvider: Provider | ||
): Action => { | ||
return { | ||
name: "GET_NFT_COLLECTIONS", | ||
similes: ["LIST_NFT_COLLECTIONS", "SHOW_NFT_COLLECTIONS"], | ||
description: | ||
"Fetches information about curated NFT collections on Ethereum", | ||
validate: async (runtime: IAgentRuntime, message: Memory) => { | ||
return message.content.text | ||
.toLowerCase() | ||
.includes("nft collections"); | ||
}, | ||
handler: async (runtime: IAgentRuntime, message: Memory) => { | ||
try { | ||
const response = await nftCollectionProvider.get( | ||
runtime, | ||
message | ||
); | ||
await runtime.messageManager.createMemory({ | ||
id: message.id, | ||
content: { text: response }, | ||
roomId: message.roomId, | ||
userId: message.userId, | ||
agentId: runtime.agentId, | ||
}); | ||
return true; | ||
} catch (error) { | ||
console.error("Error fetching NFT collections:", error); | ||
await runtime.messageManager.createMemory({ | ||
id: message.id, | ||
content: { text: "Failed to fetch NFT collection data." }, | ||
roomId: message.roomId, | ||
userId: message.userId, | ||
agentId: runtime.agentId, | ||
}); | ||
return false; | ||
} | ||
}, | ||
examples: [ | ||
[ | ||
{ | ||
user: "{{user1}}", | ||
content: { | ||
text: "Can you tell me about the top NFT collections?", | ||
}, | ||
}, | ||
}, | ||
{ | ||
user: "{{user2}}", | ||
content: { | ||
text: "Certainly! Here are the top NFT collections on Ethereum:", | ||
action: "GET_NFT_COLLECTIONS", | ||
{ | ||
user: "{{user2}}", | ||
content: { | ||
text: "Certainly! Here are the top NFT collections on Ethereum:", | ||
action: "GET_NFT_COLLECTIONS", | ||
}, | ||
}, | ||
}, | ||
], | ||
], | ||
], | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.