Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
0x330a authored Dec 21, 2024
2 parents d3030f0 + e15dd54 commit 86194df
Show file tree
Hide file tree
Showing 34 changed files with 148 additions and 168 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_2FA_SECRET=

TWITTER_COOKIES= # Account cookies
TWITTER_POLL_INTERVAL=120 # How often (in seconds) the bot should check for interactions
TWITTER_SEARCH_ENABLE=FALSE # Enable timeline search, WARNING this greatly increases your chance of getting banned
TWITTER_TARGET_USERS= # Comma separated list of Twitter user names to interact with
Expand Down
1 change: 0 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion README_ES.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Nombre de usuario de la cuenta
TWITTER_PASSWORD= # Contraseña de la cuenta
TWITTER_EMAIL= # Correo electrónico de la cuenta
TWITTER_COOKIES= # Cookies de la cuenta
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion README_JA.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # アカウントのユーザー名
TWITTER_PASSWORD= # アカウントのパスワード
TWITTER_EMAIL= # アカウントのメール
TWITTER_COOKIES= # アカウントのクッキー
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion README_PTBR.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Nome de usuário da conta
TWITTER_PASSWORD= # Senha da conta
TWITTER_EMAIL= # Email da conta
TWITTER_COOKIES= # Cookies da conta
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion README_RU.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Имя пользователя аккаунта
TWITTER_PASSWORD= # Пароль аккаунта
TWITTER_EMAIL= # Email аккаунта
TWITTER_COOKIES= # Cookies аккаунта
X_SERVER_URL=
XAI_API_KEY=
Expand Down
13 changes: 11 additions & 2 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,13 @@ export function getTokenForProvider(
character: Character
): string {
switch (provider) {
// no key needed for llama_local
// no key needed for llama_local or gaianet
case ModelProviderName.LLAMALOCAL:
return "";
case ModelProviderName.OLLAMA:
return "";
case ModelProviderName.GAIANET:
return "";
case ModelProviderName.OPENAI:
return (
character.settings?.secrets?.OPENAI_API_KEY ||
Expand Down Expand Up @@ -311,6 +315,11 @@ export function getTokenForProvider(
character.settings?.secrets?.AKASH_CHAT_API_KEY ||
settings.AKASH_CHAT_API_KEY
);
case ModelProviderName.GOOGLE:
return (
character.settings?.secrets?.GOOGLE_GENERATIVE_AI_API_KEY ||
settings.GOOGLE_GENERATIVE_AI_API_KEY
);
default:
const errorMessage = `Failed to get token - unsupported model provider: ${provider}`;
elizaLogger.error(errorMessage);
Expand Down Expand Up @@ -645,7 +654,7 @@ async function startAgent(
await db.init();

const cache = initializeCache(
process.env.CACHE_STORE,
process.env.CACHE_STORE ?? CacheStore.DATABASE,
character,
"",
db
Expand Down
1 change: 0 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/README_FR.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/README_TH.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # ชื่อผู้ใช้บัญชี
TWITTER_PASSWORD= # รหัสผ่าน
TWITTER_EMAIL= # อีเมล
TWITTER_COOKIES= # คุกกี้
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/docs/api/_media/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/docs/api/_media/README_FR.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/docs/api/_media/README_JA.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # アカウントのユーザー名
TWITTER_PASSWORD= # アカウントのパスワード
TWITTER_EMAIL= # アカウントのメール
TWITTER_COOKIES= # アカウントのクッキー
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/docs/api/_media/README_KOR.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ TWITTER_DRY_RUN=false
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies
X_SERVER_URL=
XAI_API_KEY=
Expand Down
1 change: 0 additions & 1 deletion docs/docs/guides/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ DISCORD_API_TOKEN= # Discord bot token
TWITTER_USERNAME= # Bot Twitter username
TWITTER_PASSWORD= # Bot Twitter password
TWITTER_EMAIL= # Twitter account email
TWITTER_COOKIES= # Twitter auth cookies
TWITTER_DRY_RUN=false # Test mode without posting
```

Expand Down
1 change: 0 additions & 1 deletion docs/docs/packages/clients.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ const client = await TwitterClientInterface.start(runtime);
TWITTER_USERNAME = your_username;
TWITTER_PASSWORD = your_password;
TWITTER_EMAIL = your_email;
TWITTER_COOKIES = your_cookies;
```

### Components
Expand Down
11 changes: 0 additions & 11 deletions docs/docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,10 @@ Add to your `.env`:
TWITTER_USERNAME= # Account username
TWITTER_PASSWORD= # Account password
TWITTER_EMAIL= # Account email
TWITTER_COOKIES= # Account cookies (auth_token and CT0)
```

**Important:** Log in to the [Twitter Developer Portal](https://developer.twitter.com) and enable the "Automated" label for your account to avoid being flagged as inauthentic.

Example for TWITTER_COOKIES

The TWITTER_COOKIES variable should be a JSON string containing the necessary cookies. You can find these cookies in your web browser's developer tools. Here is an example format:

```bash
TWITTER_COOKIES='[{"key":"auth_token","value":"your token","domain":".twitter.com"},
{"key":"ct0","value":"your ct0","domain":".twitter.com"},
{"key":"guest_id","value":"your guest_id","domain":".twitter.com"}]'
```

### Telegram Bot

1. Create a bot
Expand Down
38 changes: 23 additions & 15 deletions packages/adapter-postgres/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,28 @@ CREATE TABLE IF NOT EXISTS rooms (
"createdAt" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS memories (
"id" UUID PRIMARY KEY,
"type" TEXT NOT NULL,
"createdAt" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
"content" JSONB NOT NULL,
"embedding" vector(get_embedding_dimension()), -- Dynamic vector size
"userId" UUID REFERENCES accounts("id"),
"agentId" UUID REFERENCES accounts("id"),
"roomId" UUID REFERENCES rooms("id"),
"unique" BOOLEAN DEFAULT true NOT NULL,
CONSTRAINT fk_room FOREIGN KEY ("roomId") REFERENCES rooms("id") ON DELETE CASCADE,
CONSTRAINT fk_user FOREIGN KEY ("userId") REFERENCES accounts("id") ON DELETE CASCADE,
CONSTRAINT fk_agent FOREIGN KEY ("agentId") REFERENCES accounts("id") ON DELETE CASCADE
);
DO $$
DECLARE
vector_dim INTEGER;
BEGIN
vector_dim := get_embedding_dimension();

EXECUTE format('
CREATE TABLE IF NOT EXISTS memories (
"id" UUID PRIMARY KEY,
"type" TEXT NOT NULL,
"createdAt" TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP,
"content" JSONB NOT NULL,
"embedding" vector(%s),
"userId" UUID REFERENCES accounts("id"),
"agentId" UUID REFERENCES accounts("id"),
"roomId" UUID REFERENCES rooms("id"),
"unique" BOOLEAN DEFAULT true NOT NULL,
CONSTRAINT fk_room FOREIGN KEY ("roomId") REFERENCES rooms("id") ON DELETE CASCADE,
CONSTRAINT fk_user FOREIGN KEY ("userId") REFERENCES accounts("id") ON DELETE CASCADE,
CONSTRAINT fk_agent FOREIGN KEY ("agentId") REFERENCES accounts("id") ON DELETE CASCADE
)', vector_dim);
END $$;

CREATE TABLE IF NOT EXISTS goals (
"id" UUID PRIMARY KEY,
Expand Down Expand Up @@ -126,4 +134,4 @@ CREATE INDEX IF NOT EXISTS idx_participants_user ON participants("userId");
CREATE INDEX IF NOT EXISTS idx_participants_room ON participants("roomId");
CREATE INDEX IF NOT EXISTS idx_relationships_users ON relationships("userA", "userB");

COMMIT;
COMMIT;
44 changes: 22 additions & 22 deletions packages/client-twitter/package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"name": "@ai16z/client-twitter",
"version": "0.1.6",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",
"dependencies": {
"@ai16z/eliza": "workspace:*",
"agent-twitter-client": "0.0.16",
"glob": "11.0.0",
"zod": "3.23.8"
},
"devDependencies": {
"tsup": "8.3.5"
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch",
"lint": "eslint --fix --cache ."
},
"peerDependencies": {
"whatwg-url": "7.1.0"
}
"name": "@ai16z/client-twitter",
"version": "0.1.6",
"main": "dist/index.js",
"type": "module",
"types": "dist/index.d.ts",
"dependencies": {
"@ai16z/eliza": "workspace:*",
"agent-twitter-client": "0.0.17",
"glob": "11.0.0",
"zod": "3.23.8"
},
"devDependencies": {
"tsup": "8.3.5"
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch",
"lint": "eslint --fix --cache ."
},
"peerDependencies": {
"whatwg-url": "7.1.0"
}
}
38 changes: 16 additions & 22 deletions packages/client-twitter/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ export class ClientBase extends EventEmitter {
}

async init() {
//test
const username = this.runtime.getSetting("TWITTER_USERNAME");
const password = this.runtime.getSetting("TWITTER_PASSWORD");
const email = this.runtime.getSetting("TWITTER_EMAIL");
Expand All @@ -163,43 +162,38 @@ export class ClientBase extends EventEmitter {
);
const twitter2faSecret =
this.runtime.getSetting("TWITTER_2FA_SECRET") || undefined;
const cookies = this.runtime.getSetting("TWITTER_COOKIES");

if (!username) {
throw new Error("Twitter username not configured");
}
// Check for Twitter cookies
if (cookies) {
elizaLogger.debug("Using cookies from settings");
const cookiesArray = JSON.parse(cookies);

await this.setCookiesFromArray(cookiesArray);
} else {
elizaLogger.debug("No cookies found in settings");
elizaLogger.debug("Checking for cached cookies");
const cachedCookies = await this.getCachedCookies(username);
if (cachedCookies) {
await this.setCookiesFromArray(cachedCookies);
}
const cachedCookies = await this.getCachedCookies(username);

if (cachedCookies) {
elizaLogger.info("Using cached cookies");
await this.setCookiesFromArray(cachedCookies);
}

elizaLogger.log("Waiting for Twitter login");
while (retries > 0) {
const cookies = await this.twitterClient.getCookies();
if ((await this.twitterClient.isLoggedIn()) && !!cookies) {
elizaLogger.info("Already logged in.");
await this.cacheCookies(username, cookies);
elizaLogger.info("Successfully logged in and cookies cached.");
break;
}

try {
await this.twitterClient.login(
username,
password,
email,
twitter2faSecret
);
if (await this.twitterClient.isLoggedIn()) {
elizaLogger.info("Successfully logged in.");
if (!cachedCookies) {
elizaLogger.info("Caching cookies");
await this.cacheCookies(
username,
await this.twitterClient.getCookies()
);
}
break;
}
} catch (error) {
elizaLogger.error(`Login attempt failed: ${error.message}`);
}
Expand Down
4 changes: 0 additions & 4 deletions packages/client-twitter/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const twitterEnvSchema = z.object({
TWITTER_USERNAME: z.string().min(1, "Twitter username is required"),
TWITTER_PASSWORD: z.string().min(1, "Twitter password is required"),
TWITTER_EMAIL: z.string().email("Valid Twitter email is required"),
TWITTER_COOKIES: z.string().optional(),
MAX_TWEET_LENGTH: z
.string()
.pipe(z.coerce.number().min(0).int())
Expand All @@ -37,9 +36,6 @@ export async function validateTwitterConfig(
TWITTER_EMAIL:
runtime.getSetting("TWITTER_EMAIL") ||
process.env.TWITTER_EMAIL,
TWITTER_COOKIES:
runtime.getSetting("TWITTER_COOKIES") ||
process.env.TWITTER_COOKIES,
MAX_TWEET_LENGTH:
runtime.getSetting("MAX_TWEET_LENGTH") ||
process.env.MAX_TWEET_LENGTH ||
Expand Down
Loading

0 comments on commit 86194df

Please sign in to comment.