Skip to content

Commit

Permalink
Merge pull request elizaOS#313 from o-on-x/main
Browse files Browse the repository at this point in the history
added working pumpfun.ts
  • Loading branch information
o-on-x authored Nov 14, 2024
2 parents a22e07f + 79637da commit 8805eb4
Show file tree
Hide file tree
Showing 4 changed files with 358 additions and 107 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ X_SERVER_URL=
XAI_API_KEY=
XAI_MODEL=

#USE IMAGE GEN
IMAGE_GEN= #TRUE

#Leave blank to use local embeddings
USE_OPENAI_EMBEDDING= #TRUE

Expand Down
1 change: 1 addition & 0 deletions packages/client-discord/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class DiscordClient extends EventEmitter {
this.runtime.registerAction(transcribe_media);
this.runtime.registerAction(download_media);


this.runtime.providers.push(channelStateProvider);
this.runtime.providers.push(voiceStateProvider);
}
Expand Down
73 changes: 62 additions & 11 deletions packages/plugin-image-generation/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,34 @@ import {
} from "@ai16z/eliza/src/types.ts";
import { generateCaption, generateImage } from "@ai16z/eliza/src/generation.ts";

import fs from 'fs';
import path from 'path';

export function saveBase64Image(base64Data: string, filename: string): string {
// Create generatedImages directory if it doesn't exist
const imageDir = path.join(process.cwd(), 'generatedImages');
if (!fs.existsSync(imageDir)) {
fs.mkdirSync(imageDir, { recursive: true });
}

// Remove the data:image/png;base64 prefix if it exists
const base64Image = base64Data.replace(/^data:image\/\w+;base64,/, '');

// Create a buffer from the base64 string
const imageBuffer = Buffer.from(base64Image, 'base64');

// Create full file path
const filepath = path.join(imageDir, `${filename}.png`);

// Save the file
fs.writeFileSync(filepath, imageBuffer);

return filepath;
}

const imageGeneration: Action = {
name: "GENERATE_IMAGE",
similes: ["IMAGE_GENERATION", "IMAGE_GEN", "CREATE_IMAGE", "MAKE_PICTURE"],
similes: ["IMAGE_GENERATION", "IMAGE_GEN", "CREATE_IMAGE", "MAKE_PICTURE",],
description: "Generate an image to go along with the message.",
validate: async (runtime: IAgentRuntime, message: Memory) => {
const anthropicApiKeyOk = !!runtime.getSetting("ANTHROPIC_API_KEY");
Expand Down Expand Up @@ -58,36 +83,62 @@ const imageGeneration: Action = {
);
for (let i = 0; i < images.data.length; i++) {
const image = images.data[i];
elizaLogger.log(`Processing image ${i + 1}:`, image);

const base64Image = images.data[i];
// Save the image and get filepath
const filename = `generated_${Date.now()}_${i}`;
const filepath = saveBase64Image(base64Image, filename);
elizaLogger.log(`Processing image ${i + 1}:`, filename);

const caption = await generateCaption(
//just dont even add a caption or a description just have it generate & send
/*
try {
const imageService = runtime.getService(ServiceType.IMAGE_DESCRIPTION);
if (imageService && typeof imageService.describeImage === 'function') {
const caption = await imageService.describeImage({ imageUrl: filepath });
captionText = caption.description;
captionTitle = caption.title;
}
} catch (error) {
elizaLogger.error("Caption generation failed, using default caption:", error);
}*/

const caption = "...";
/*= await generateCaption(
{
imageUrl: image,
},
runtime
);
);*/

res.push({ image: filepath, caption: "..."});//caption.title });

elizaLogger.log(
`Generated caption for image ${i + 1}:`,
caption.title
"..."//caption.title
);
res.push({ image: image, caption: caption.title });
//res.push({ image: image, caption: caption.title });

callback(
{
text: caption.description,
text: "...",//caption.description,
attachments: [
{
id: crypto.randomUUID(),
url: image,
url: filepath,
title: "Generated image",
source: "imageGeneration",
description: caption.title,
text: caption.description,
description: "...",//caption.title,
text: "...",//caption.description,
},
],
},
[]
[
{
attachment: filepath,
name: `${filename}.png`
}
]
);
}
} else {
Expand Down
Loading

0 comments on commit 8805eb4

Please sign in to comment.