Skip to content

Commit

Permalink
Update environment variable naming from POSTGRES_URL to DATABASE_URL,…
Browse files Browse the repository at this point in the history
… remove bun.lockb file, update pnpm-lock.yaml for @types/bun and bun-types versions, and add GitHub Actions workflow for Fly deployment. Refactor database initialization to use DATABASE_URL.
  • Loading branch information
tinypell3ts committed Jan 16, 2025
1 parent fa6e907 commit 89c1347
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 30 deletions.
7 changes: 5 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Database
POSTGRES_URL=your-postgres-url
DATABASE_URL=your-postgres-url
POSTGRES_POOL_MIN=2
POSTGRES_POOL_MAX=10


# Model Provider (choose one)
# Model Provider (OPENAI used for embedding, ANTHROPIC used for chat)
OPENAI_API_KEY=sk-*
ANTHROPIC_API_KEY=your-anthropic-api-key

# Discord (if using)
DISCORD_APPLICATION_ID=your-application-id
DISCORD_API_TOKEN=your-bot-token

# Use OpenAI embedding model
USE_OPENAI_EMBEDDING=true

18 changes: 18 additions & 0 deletions .github/workflows/fly-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/

name: Fly Deploy
on:
push:
branches:
- main
jobs:
deploy:
name: Deploy app
runs-on: ubuntu-latest
concurrency: deploy-group # optional: ensure only one action runs at a time
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ bun run dev

| Variable | Required | Description |
| ------------------------ | -------- | ------------------------------------------------------------------------------ |
| `POSTGRES_URL` || Connection URL for your PostgreSQL database |
| `DATABASE_URL` || Connection URL for your PostgreSQL database |
| `POSTGRES_POOL_MIN` || Minimum number of connections in the database pool (recommended: 2) |
| `POSTGRES_POOL_MAX` || Maximum number of connections in the database pool (recommended: 10) |
| `OPENAI_API_KEY` || OpenAI API key starting with 'sk-'. Required if using OpenAI as model provider |
Expand Down Expand Up @@ -249,7 +249,7 @@ This will:
fly secrets set DISCORD_API_TOKEN="your-token"
fly secrets set DISCORD_APPLICATION_ID="your-app-id"
fly secrets set OPENAI_API_KEY="your-key"
fly secrets set POSTGRES_URL="your-postgres-url"
fly secrets set DATABASE_URL="your-postgres-url"
# Set any other required environment variables
```

Expand Down
Binary file removed bun.lockb
Binary file not shown.
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/agent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ export function getTokenForProvider(provider: ModelProviderName, character: Char
}

function initializeDatabase() {
if (process.env.POSTGRES_URL) {
if (process.env.DATABASE_URL) {
elizaLogger.info("Initializing PostgreSQL connection...");
const db = new PostgresDatabaseAdapter({
connectionString: process.env.POSTGRES_URL,
connectionString: process.env.DATABASE_URL,
parseInputs: true,
});

Expand Down
32 changes: 17 additions & 15 deletions src/clients/discord/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,21 +246,23 @@ export class MessageManager {
await this.runtime.messageManager.addEmbeddingToMemory(memory);
await this.runtime.messageManager.createMemory(memory);

if (this.interestChannels[message.channelId]) {
// Add new message
this.interestChannels[message.channelId].messages.push({
userId: userIdUUID,
userName: userName,
content: content,
});

// Trim to keep only recent messages
if (this.interestChannels[message.channelId].messages.length > MESSAGE_CONSTANTS.MAX_MESSAGES) {
this.interestChannels[message.channelId].messages = this.interestChannels[message.channelId].messages.slice(
-MESSAGE_CONSTANTS.MAX_MESSAGES
);
}
}
return;

// if (this.interestChannels[message.channelId]) {
// // Add new message
// this.interestChannels[message.channelId].messages.push({
// userId: userIdUUID,
// userName: userName,
// content: content,
// });

// // Trim to keep only recent messages
// if (this.interestChannels[message.channelId].messages.length > MESSAGE_CONSTANTS.MAX_MESSAGES) {
// this.interestChannels[message.channelId].messages = this.interestChannels[message.channelId].messages.slice(
// -MESSAGE_CONSTANTS.MAX_MESSAGES
// );
// }
// }
}

let state = await this.runtime.composeState(userMessage, {
Expand Down
6 changes: 3 additions & 3 deletions src/config/database.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { PostgresDatabaseAdapter } from "@elizaos/adapter-postgres";

export function initializeDatabase() {
if (!process.env.POSTGRES_URL) {
throw new Error("POSTGRES_URL is required");
if (!process.env.DATABASE_URL) {
throw new Error("DATABASE_URL is required");
}

const db = new PostgresDatabaseAdapter({
connectionString: process.env.POSTGRES_URL,
connectionString: process.env.DATABASE_URL,
parseInputs: true,
pool: {
min: Number(process.env.POSTGRES_POOL_MIN || 2),
Expand Down

0 comments on commit 89c1347

Please sign in to comment.