Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@
"langdetect": "^0.2.1",
"ollama-ai-provider": "0.16.1",
"optional": "0.1.4",
"pnpm": "9.15.0",
"pnpm": "10.4.1",
"sharp": "0.33.5"
},
"packageManager": "pnpm@9.15.0",
"packageManager": "pnpm@10.4.1",
"workspaces": [
"packages/*"
]
Expand Down
14 changes: 14 additions & 0 deletions packages/client-twitter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TwitterInteractionClient } from "./interactions.ts";
import { TwitterPostClient } from "./post.ts";
import { TwitterSearchClient } from "./search.ts";
import { TwitterSpaceClient } from "./spaces.ts";
import { getTemplateByService } from "./templates/index.ts";

/**
* A manager that orchestrates all specialized Twitter logic:
Expand Down Expand Up @@ -46,6 +47,19 @@ class TwitterManager {
this.space = new TwitterSpaceClient(this.client, runtime);
}
}

setTemplateByService(serviceName: string, template: string, topic: string) {
// const template = getTemplateByService(serviceName);
console.log(`Setting template for ${serviceName}`);
if (this.post.runtime.character.templates) {
this.post.runtime.character.templates.twitterPostTemplate = template;
} else {
this.post.runtime.character.templates = {
twitterPostTemplate: template,
};
}
// this.post.runtime.character.topics = [topic];
}
}

export const TwitterClientInterface: Client = {
Expand Down
21 changes: 14 additions & 7 deletions packages/client-twitter/src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import {
} from "discord.js";
import type { State } from "@elizaos/core";
import type { ActionResponse } from "@elizaos/core";
import { MediaData } from "./types.ts";
import { MediaData, TaskData } from "./types.ts";
import { getTemplateByService } from "./templates/index.ts";

const MAX_TIMELINES_TO_FETCH = 15;

Expand Down Expand Up @@ -132,7 +133,7 @@ export class TwitterPostClient {
`- Action Interval: ${this.client.twitterConfig.ACTION_INTERVAL} minutes`
);
elizaLogger.log(
`- Post Immediately: ${
`- Post Immediately: ${
this.client.twitterConfig.POST_IMMEDIATELY
? "enabled"
: "disabled"
Expand Down Expand Up @@ -447,7 +448,7 @@ export class TwitterPostClient {
rawTweetContent: string,
twitterUsername: string,
mediaData?: MediaData[]
) {
): Promise<Tweet> {
try {
elizaLogger.log(`Posting new tweet:\n`);

Expand Down Expand Up @@ -482,6 +483,8 @@ export class TwitterPostClient {
roomId,
rawTweetContent
);

return tweet;
} catch (error) {
elizaLogger.error("Error sending tweet:", error);
}
Expand All @@ -490,9 +493,11 @@ export class TwitterPostClient {
/**
* Generates and posts a new tweet. If isDryRun is true, only logs what would have been posted.
*/
async generateNewTweet() {
async generateNewTweet(additionalKeys?: { [key: string]: unknown }): Promise<Tweet | string> {
elizaLogger.log("Generating new tweet");

// const { service } = task
// const serviceTemplate = getTemplate(service)
try {
const roomId = stringToUuid(
"twitter_generate_room-" + this.client.profile.username
Expand All @@ -518,7 +523,8 @@ export class TwitterPostClient {
},
{
twitterUserName: this.client.profile.username,
maxTweetLength,
maxTweetLength,
...additionalKeys,
}
);

Expand Down Expand Up @@ -596,7 +602,7 @@ export class TwitterPostClient {
elizaLogger.info(
`Dry run: would have posted tweet: ${tweetTextForPosting}`
);
return;
return tweetTextForPosting;
}

try {
Expand All @@ -615,7 +621,7 @@ export class TwitterPostClient {
elizaLogger.log(
`Posting new tweet:\n ${tweetTextForPosting}`
);
this.postTweet(
const tweet = await this.postTweet(
this.runtime,
this.client,
tweetTextForPosting,
Expand All @@ -624,6 +630,7 @@ export class TwitterPostClient {
this.twitterUsername,
mediaData
);
return tweet;
}
} catch (error) {
elizaLogger.error("Error sending tweet:", error);
Expand Down
21 changes: 21 additions & 0 deletions packages/client-twitter/src/templates/bull-post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const kolTemplate = `
# Areas of Expertise
{{knowledge}}

# About {{agentName}} (@{{twitterUserName}}):
{{bio}}
{{lore}}
{{topics}}

{{providers}}

{{characterPostExamples}}

{{postDirections}}

# Task: Generate a post in the voice and style and perspective of {{agentName}} @{{twitterUserName}}.
Write a post that is {{adjective}} about {{topic}}, from the perspective of {{agentName}}. Do not add commentary or acknowledge this request, just write the post.
Your response should be 1, 2, or 3 sentences (choose the length at random).
Your response should not contain any questions. Brief, concise statements only. The total character count MUST be less than {{maxTweetLength}}. No emojis. Use \\n\\n (double spaces) between statements if there are multiple statements in your response.`;

export default kolTemplate
12 changes: 12 additions & 0 deletions packages/client-twitter/src/templates/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@


const templates = {
'bull-post': require('./bull-post.ts'),
}
export const getTemplateByService = (serviceName: string) => {
if (templates[serviceName]) {
return templates[serviceName];
} else {
console.error(`Template ${serviceName} not found`);
}
}
18 changes: 18 additions & 0 deletions packages/client-twitter/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,21 @@ export type MediaData = {
data: Buffer;
mediaType: string;
};

export enum TaskStatus {
CREATED,
ASSIGNED,
COMPLETED,
FAILED
}

export interface TaskData {
id: string;
prompt: string;
params: Object;
service: string;
assignee?: string;
status: TaskStatus;
issuer: string;
proposalId: string;
}
Loading