forked from elizaOS/eliza
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created test actions for testing integration of two plugins
- Loading branch information
1 parent
ec367bf
commit 557ac89
Showing
15 changed files
with
6,210 additions
and
2,189 deletions.
There are no files selected for viewing
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import eslintGlobalConfig from "../../eslint.config.mjs"; | ||
|
||
export default [...eslintGlobalConfig]; |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "@elizaos/test-linkedin-plugin", | ||
"version": "0.1.8+build.1", | ||
"main": "dist/index.js", | ||
"type": "module", | ||
"types": "dist/index.d.ts", | ||
"dependencies": { | ||
"axios": "^1.7.9", | ||
"tsup": "8.3.5", | ||
"zod": "3.23.8", | ||
"interchain": "^1.10.4", | ||
"@elizaos/core": "workspace:*" | ||
}, | ||
"scripts": { | ||
"build": "tsup --format esm --dts", | ||
"dev": "tsup --format esm --dts --watch", | ||
"lint": "eslint --fix --cache .", | ||
"test": "vitest run" | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/test-linkedin-plugin/src/actions/create-post/create-post-action.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
|
||
export class createPostAction { | ||
constructor() { | ||
|
||
} | ||
|
||
async execute( | ||
postText: string, | ||
imagePath: string, | ||
): Promise<boolean> { | ||
console.log(`Here shold be LinkedIn posting handled: ${postText}, with imagePath: ${imagePath}`); | ||
return true; | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
packages/test-linkedin-plugin/src/actions/create-post/index.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 |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { createPostTemplate } from "../../template/template.ts"; | ||
import { createPostAction } from "./create-post-action.ts"; | ||
import {extractedContent} from "../../types/types.ts"; | ||
import { | ||
composeContext, | ||
generateObjectDeprecated, | ||
HandlerCallback, | ||
IAgentRuntime, | ||
Memory, | ||
ModelClass, | ||
State | ||
} from "@elizaos/core"; | ||
|
||
export const createPost = ({ | ||
name: "LINKEDIN_POST", | ||
description: "Swaps tokens on cosmos chains", | ||
handler: async ( | ||
_runtime: IAgentRuntime, | ||
_message: Memory, | ||
state: State, | ||
_options: { [key: string]: unknown }, | ||
_callback?: HandlerCallback | ||
) => { | ||
const postContext = composeContext({ | ||
state: state, | ||
template: createPostTemplate, // to be aligned with logic | ||
templatingEngine: "handlebars", | ||
}); | ||
|
||
const createPostContent: extractedContent = await generateObjectDeprecated({ | ||
runtime: _runtime, | ||
context: postContext, | ||
modelClass: ModelClass.SMALL, | ||
}); | ||
|
||
try { | ||
const action = new createPostAction(); | ||
|
||
await action.execute(createPostContent.text, createPostContent.imagePath); | ||
|
||
if (_callback) { | ||
await _callback({ | ||
text: `Generation completed. Post has been published.`, | ||
content: { | ||
success:true, | ||
}, | ||
}); | ||
} | ||
return true; | ||
} catch (error) { | ||
console.error("Unhandled error:", error); | ||
|
||
if (_callback) { | ||
await _callback({ | ||
text: `Error generating image: ${error.message}`, | ||
content: { error: error.message }, | ||
}); | ||
} | ||
return false; | ||
} | ||
}, | ||
validate: async (runtime: IAgentRuntime) => { | ||
return true; | ||
}, | ||
examples: [ | ||
[ | ||
{ | ||
user: "{{user1}}", | ||
content: { | ||
text: "Generate post on LinkedIn about cats and dogs. It should contain appropriate image.", | ||
action: "GENERATE_IMAGE", | ||
}, | ||
}, | ||
{ | ||
user: "{{user2}}", | ||
content: { | ||
text: "Generated image for your post", | ||
action: "GENERATE_IMAGE", | ||
} | ||
}, | ||
{ | ||
user: "{{user2}}", | ||
content: { | ||
text: "Generated text for your post and published it.", | ||
action: "LINKEDIN_POST", | ||
} | ||
} | ||
], | ||
[ | ||
{ | ||
user: "{{user1}}", | ||
content: { | ||
text: "Create a post with image on LinkedIn about cats and dogs.", | ||
action: "GENERATE_IMAGE", | ||
}, | ||
}, | ||
{ | ||
user: "{{user2}}", | ||
content: { | ||
text: "Generated image for your post", | ||
action: "GENERATE_IMAGE", | ||
} | ||
}, | ||
{ | ||
user: "{{user2}}", | ||
content: { | ||
text: "Generated text for your post and published it.", | ||
action: "LINKEDIN_POST", | ||
} | ||
} | ||
], | ||
], | ||
similes: ["CREATE_LINKEDIN_POST", "LINKEDIN_POST"], | ||
}); |
82 changes: 82 additions & 0 deletions
82
packages/test-linkedin-plugin/src/actions/test-action/index.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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
|
||
import { | ||
HandlerCallback, | ||
IAgentRuntime, | ||
Memory, | ||
State | ||
} from "@elizaos/core"; | ||
|
||
export const testAction = ({ | ||
name: "TEST_ACTION", | ||
description: "Runs test action", | ||
handler: async ( | ||
_runtime: IAgentRuntime, | ||
_message: Memory, | ||
state: State, | ||
_options: { [key: string]: unknown }, | ||
_callback?: HandlerCallback | ||
) => { | ||
try { | ||
if (_callback) { | ||
const filepath = `../agent/generatedImages/generated_1736938600821_0.png`; | ||
const filename = `generated_1736938600821_0`; | ||
await _callback( | ||
{ | ||
text: `${filepath}`, //caption.description, | ||
attachments: [ | ||
{ | ||
id: crypto.randomUUID(), | ||
url: filepath, | ||
title: "Generated image", | ||
source: "imageGeneration", | ||
description: "...", //caption.title, | ||
text: "...", //caption.description, | ||
contentType: "image/png", | ||
}, | ||
], | ||
}, | ||
[ | ||
{ | ||
attachment: filepath, | ||
name: `${filename}.png`, | ||
}, | ||
] | ||
); | ||
} | ||
return true; | ||
} catch (error) { | ||
console.error("Unhandled error:", error); | ||
|
||
if (_callback) { | ||
await _callback({ | ||
text: `Error generating image: ${error.message}`, | ||
content: { error: error.message }, | ||
}); | ||
} | ||
return false; | ||
} | ||
}, | ||
validate: async (runtime: IAgentRuntime) => { | ||
return true; | ||
}, | ||
examples: [ | ||
[ | ||
{ | ||
user: "{{user1}}", | ||
content: { | ||
text: "Show me test action.", | ||
action: "TEST_ACTION", | ||
}, | ||
}, | ||
{ | ||
user: "{{user2}}", | ||
content: { | ||
text: "Here it is.", | ||
action: "TEST_ACTION", | ||
} | ||
}, | ||
|
||
], | ||
], | ||
similes: ["TEST-ACTION"], | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { Plugin } from "@elizaos/core"; | ||
import { createPost } from "./actions/create-post"; | ||
import {testAction} from "./actions/test-action"; | ||
|
||
export const linkedinPost: Plugin = { | ||
name: "Linkedin Plugin", | ||
description: "Linkedin integration plugin", | ||
providers: [], | ||
evaluators: [], | ||
services: [], | ||
actions: [createPost, testAction], | ||
}; | ||
|
||
export default linkedinPost; |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export const createPostTemplate = ` | ||
Given the recent messages, especially generated image, its path, and connected LinkedIn account: | ||
{{recentMessages}} | ||
{{linkedinAccount}} | ||
Prepare text for the requested LinkedIn post. Be engaging, relevant, and professional. | ||
Respond with a JSON markdown block containing only the extracted values: | ||
\`\`\`json | ||
{ | ||
"text": "Write your crafted LinkedIn post text here.", // example string | ||
"imagePath": "https://image.tmdb.org/t/p/original/original.png", //example string with url to image | ||
} | ||
\`\`\` | ||
`; | ||
|
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface extractedContent { | ||
text: string; | ||
imagePath: string; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"extends": "../core/tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"rootDir": "./src", | ||
"typeRoots": [ | ||
"./node_modules/@types", | ||
"./src/types" | ||
], | ||
"declaration": true | ||
}, | ||
"include": [ | ||
"src" | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { defineConfig } from "tsup"; | ||
|
||
export default defineConfig({ | ||
entry: ["src/index.ts"], | ||
outDir: "dist", | ||
sourcemap: true, | ||
clean: true, | ||
format: ["esm"], // Ensure you're targeting CommonJS | ||
external: [ | ||
"dotenv", // Externalize dotenv to prevent bundling | ||
"fs", // Externalize fs to use Node.js built-in module | ||
"path", // Externalize other built-ins if necessary | ||
"@reflink/reflink", | ||
"@node-llama-cpp", | ||
"https", | ||
"http", | ||
"agentkeepalive", | ||
"zod", | ||
], | ||
}); |
Oops, something went wrong.