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

Update environment, add twitter quality of life updates #765

Merged
merged 9 commits into from
Dec 1, 2024
Merged
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: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ cache/*
packages/plugin-coinbase/src/plugins/transactions.csv
packages/plugin-coinbase/package-lock.json

.turbo
tsup.config.bundled_*.mjs

.turbo
2 changes: 1 addition & 1 deletion docs/api/variables/messageCompletionFooter.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Variable: messageCompletionFooter

> `const` **messageCompletionFooter**: "\nResponse format should be formatted in a JSON block like this:\n\`\`\`json\n\{ \"user\": \"\{\{agentName\}\}\", \"text\": string, \"action\": \"string\" \}\n\`\`\`"
> `const` **messageCompletionFooter**: "\nResponse format should be formatted in a JSON block like this:\n\`\`\`json\n\{ \"user\": \"\{\{agentName\}\}\", \"text\": \"string\", \"action\": \"string\" \}\n\`\`\`"

## Defined in

Expand Down
3 changes: 2 additions & 1 deletion packages/client-twitter/src/enviroment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export async function validateTwitterConfig(
const config = {
TWITTER_DRY_RUN:
runtime.getSetting("TWITTER_DRY_RUN") ||
process.env.TWITTER_DRY_RUN,
process.env.TWITTER_DRY_RUN ||
"false",
TWITTER_USERNAME:
runtime.getSetting("TWITTER_USERNAME") ||
process.env.TWITTER_USERNAME,
Expand Down
28 changes: 3 additions & 25 deletions packages/client-twitter/src/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ import { ClientBase } from "./base";
import { buildConversationThread, sendTweet, wait } from "./utils.ts";

export const twitterMessageHandlerTemplate =
`{{timeline}}

# Knowledge
`
# Areas of Expertise
{{knowledge}}

# Task: Generate a post for the character {{agentName}}.
About {{agentName}} (@{{twitterUserName}}):
# About {{agentName}} (@{{twitterUserName}}):
{{bio}}
{{lore}}
{{topics}}
Expand Down Expand Up @@ -226,17 +224,6 @@ export class TwitterInteractionClient {
};
const currentPost = formatTweet(tweet);

let homeTimeline: Tweet[] = [];
// read the file if it exists

const cachedTimeline = await this.client.getCachedTimeline();
if (cachedTimeline) {
homeTimeline = cachedTimeline;
} else {
homeTimeline = await this.client.fetchHomeTimeline(50);
await this.client.cacheTimeline(homeTimeline);
}

elizaLogger.debug("Thread: ", thread);
const formattedConversation = thread
.map(
Expand All @@ -254,20 +241,11 @@ export class TwitterInteractionClient {

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

const formattedHomeTimeline =
`# ${this.runtime.character.name}'s Home Timeline\n\n` +
homeTimeline
.map((tweet) => {
return `ID: ${tweet.id}\nFrom: ${tweet.name} (@${tweet.username})${tweet.inReplyToStatusId ? ` In reply to: ${tweet.inReplyToStatusId}` : ""}\nText: ${tweet.text}\n---\n`;
})
.join("\n");

let state = await this.runtime.composeState(message, {
twitterClient: this.client.twitterClient,
twitterUserName: this.runtime.getSetting("TWITTER_USERNAME"),
currentPost,
formattedConversation,
timeline: formattedHomeTimeline,
});

// check if the tweet exists, save if it doesn't
Expand Down
43 changes: 9 additions & 34 deletions packages/client-twitter/src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,24 @@ import {
import { elizaLogger } from "@ai16z/eliza";
import { ClientBase } from "./base.ts";

const twitterPostTemplate = `{{timeline}}

# Knowledge
const twitterPostTemplate = `
# Areas of Expertise
{{knowledge}}

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

{{providers}}

{{recentPosts}}

{{characterPostExamples}}

# Task: Generate a post in the voice and style of {{agentName}}, aka @{{twitterUserName}}
Write a single sentence post that is {{adjective}} about {{topic}} (without mentioning {{topic}} directly), from the perspective of {{agentName}}. Try to write something totally different than previous posts. Do not add commentary or acknowledge this request, just write the post.
Your response should not contain any questions. Brief, concise statements only. No emojis. Use \\n\\n (double spaces) between statements.`;
{{postDirections}}

# Task: Generate a post in the voice and style and perspective of {{agentName}} @{{twitterUserName}}.
Write a 1-3 sentence post that is {{adjective}} about {{topic}} (without mentioning {{topic}} directly), from the perspective of {{agentName}}. Do not add commentary or acknowledge this request, just write the post.
Your response should not contain any questions. Brief, concise statements only. The total character count MUST be less than 280. No emojis. Use \\n\\n (double spaces) between statements.`;

const MAX_TWEET_LENGTH = 280;

Expand Down Expand Up @@ -132,28 +131,7 @@ export class TwitterPostClient {
"twitter"
);

let homeTimeline: Tweet[] = [];

const cachedTimeline = await this.client.getCachedTimeline();

// console.log({ cachedTimeline });

if (cachedTimeline) {
homeTimeline = cachedTimeline;
} else {
homeTimeline = await this.client.fetchHomeTimeline(10);
await this.client.cacheTimeline(homeTimeline);
}
const formattedHomeTimeline =
`# ${this.runtime.character.name}'s Home Timeline\n\n` +
homeTimeline
.map((tweet) => {
return `#${tweet.id}\n${tweet.name} (@${tweet.username})${tweet.inReplyToStatusId ? `\nIn reply to: ${tweet.inReplyToStatusId}` : ""}\n${new Date(tweet.timestamp).toDateString()}\n\n${tweet.text}\n---\n`;
})
.join("\n");

const topics = this.runtime.character.topics.join(", ");

const state = await this.runtime.composeState(
{
userId: this.runtime.agentId,
Expand All @@ -166,7 +144,6 @@ export class TwitterPostClient {
},
{
twitterUserName: this.client.profile.username,
timeline: formattedHomeTimeline,
}
);

Expand Down Expand Up @@ -243,8 +220,6 @@ export class TwitterPostClient {

await this.client.cacheTweet(tweet);

homeTimeline.push(tweet);
await this.client.cacheTimeline(homeTimeline);
elizaLogger.log(`Tweet posted:\n ${tweet.permanentUrl}`);

const roomId = stringToUuid(
Expand Down
12 changes: 7 additions & 5 deletions packages/core/src/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ export async function getProviders(
message: Memory,
state?: State
) {
const providerResults = await Promise.all(
runtime.providers.map(async (provider) => {
return await provider.get(runtime, message, state);
})
);
const providerResults = (
await Promise.all(
runtime.providers.map(async (provider) => {
return await provider.get(runtime, message, state);
})
)
).filter((result) => result != null && result !== "");

return providerResults.join("\n");
}
5 changes: 4 additions & 1 deletion packages/plugin-solana/src/providers/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,10 @@ const walletProvider: Provider = {
try {
const publicKey = runtime.getSetting("SOLANA_PUBLIC_KEY");
if (!publicKey) {
throw new Error("SOLANA_PUBLIC_KEY not configured");
console.error(
"SOLANA_PUBLIC_KEY not configured, skipping wallet injection"
);
return "";
}

const connection = new Connection(
Expand Down
Loading
Loading