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: Image descriptions into interaction.ts #1775

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions packages/client-twitter/src/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
stringToUuid,
elizaLogger,
getEmbeddingZeroVector,
IImageDescriptionService,
ServiceType
} from "@elizaos/core";
import { ClientBase } from "./base";
import { buildConversationThread, sendTweet, wait } from "./utils.ts";
Expand Down Expand Up @@ -43,6 +45,8 @@ Recent interactions between {{agentName}} and other users:

Current Post:
{{currentPost}}
Here is the descriptions of images in the Current post.
{{imageDescriptions}}

Thread of Tweets You Are Replying To:
{{formattedConversation}}
Expand All @@ -53,6 +57,8 @@ Thread of Tweets You Are Replying To:

Here is the current post text again. Remember to include an action if the current post text includes a prompt that asks for one of the available actions mentioned above (does not need to be exact)
{{currentPost}}
Here is the descriptions of images in the Current post.
{{imageDescriptions}}
` + messageCompletionFooter;

export const twitterShouldRespondTemplate = (targetUsersStr: string) =>
Expand Down Expand Up @@ -342,11 +348,36 @@ export class TwitterInteractionClient {

elizaLogger.debug("formattedConversation: ", formattedConversation);

//Get image description for the provided iamges.
//console.log(tweet);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can remove this

let imageDescriptionsArray = [];
try{
elizaLogger.debug('Getting images');
for (const photo of tweet.photos) {
elizaLogger.debug(photo.url);
const description = await this.runtime
.getService<IImageDescriptionService>(
ServiceType.IMAGE_DESCRIPTION
)
.describeImage(photo.url);
imageDescriptionsArray.push(description);
}
} catch (error) {
// Handle the error
elizaLogger.error("Error Occured during describing image: ", error);
}




let state = await this.runtime.composeState(message, {
twitterClient: this.client.twitterClient,
twitterUserName: this.client.twitterConfig.TWITTER_USERNAME,
currentPost,
formattedConversation,
imageDescriptions: imageDescriptionsArray.length > 0
? `\nImages in Tweet:\n${imageDescriptionsArray.map((desc, i) =>
`Image ${i + 1}: Title: ${desc.title}\nDescription: ${desc.description}`).join("\n\n")}`:""
});

// check if the tweet exists, save if it doesn't
Expand Down Expand Up @@ -413,7 +444,6 @@ export class TwitterInteractionClient {
this.runtime.character?.templates?.messageHandlerTemplate ||
twitterMessageHandlerTemplate,
});

elizaLogger.debug("Interactions prompt:\n" + context);

const response = await generateMessageResponse({
Expand Down Expand Up @@ -624,4 +654,4 @@ export class TwitterInteractionClient {

return thread;
}
}
}
Loading