Skip to content

Commit

Permalink
Merge branch 'v2-develop' into hash/fix-plugins-install
Browse files Browse the repository at this point in the history
  • Loading branch information
HashWarlock authored Feb 12, 2025
2 parents e773f44 + 97ca4ef commit 4116739
Show file tree
Hide file tree
Showing 43 changed files with 1,782 additions and 357 deletions.
25 changes: 25 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
# OpenAI Configuration
OPENAI_API_KEY=

# Anthropic Configuration
ANTHROPIC_API_KEY=

# Fill these out if you want to use Discord
DISCORD_APPLICATION_ID=
DISCORD_API_TOKEN=

# Fill these out if you want to use Telegram
TELEGRAM_BOT_TOKEN=

# Fill these out if you want to use Twitter
TWITTER_USERNAME=
TWITTER_PASSWORD=
TWITTER_EMAIL=

# Fill these out if you want to use EVM
EVM_PRIVATE_KEY=
EVM_CHAINS=mainnet,sepolia,base,arbitrum,polygon
EVM_PROVIDER_URL=

# Fill these out if you want to use Solana
SOLANA_PUBLIC_KEY=
SOLANA_PRIVATE_KEY=
BIRDEYE_API_KEY=
8 changes: 0 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ node_modules
.env_main
concatenated-output.ts
embedding-cache.json
packages/plugin-buttplug/intiface-engine

node-compile-cache

Expand Down Expand Up @@ -50,10 +49,7 @@ characters/**/*.env
characters/**/*.key
characters/**/private/

packages/core/src/providers/cache
packages/core/src/providers/cache/*
cache/*
packages/plugin-coinbase/src/plugins/transactions.csv

tsup.config.bundled_*.mjs

Expand All @@ -71,10 +67,6 @@ eliza.manifest
eliza.manifest.sgx
eliza.sig

packages/plugin-nvidia-nim/extra
packages/plugin-nvidia-nim/old_code
packages/plugin-nvidia-nim/docs

# Edriziai specific ignores
characters/edriziai-info/secrets.json

Expand Down
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build:cli": "turbo run build --filter=./packages/cli && cd packages/cli && bun link",
"start": "turbo run start --filter=!./packages/docs",
"agent": "turbo run start --filter=@elizaos/agent",
"dev": "turbo run build --filter=./packages/core && turbo run dev --filter=!./packages/core --concurrency=20",
"dev": "turbo run build --filter=./packages/core && turbo run dev --filter=!./packages/core --filter=!./packages/docs --concurrency=20",
"release": "bun run build && bun format && npx lerna publish --no-private --force-publish",
"docker:build": "bash ./scripts/docker.sh build",
"docker:run": "bash ./scripts/docker.sh run",
Expand Down
3 changes: 0 additions & 3 deletions packages/agent/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,6 @@ export function createApiRouter(

router.post("/agent/start", async (req, res) => {
const { characterPath, characterJson } = req.body;
console.log("characterPath:", characterPath);
console.log("characterJson:", characterJson);
try {
let character: Character;
if (characterJson) {
Expand Down Expand Up @@ -340,7 +338,6 @@ export function createApiRouter(

router.post("/agents/:agentId/stop", async (req, res) => {
const agentId = req.params.agentId;
console.log("agentId", agentId);
const agent: IAgentRuntime = agents.get(agentId);

// update character
Expand Down
12 changes: 7 additions & 5 deletions packages/agent/src/defaultCharacter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ export const defaultCharacter: Character = {
name: "Eliza",
username: "eliza",
plugins: [
"@elizaos/plugin-anthropic",
// "@elizaos/plugin-anthropic",
"@elizaos/plugin-openai",
"@elizaos/plugin-local-ai",
"@elizaos/plugin-discord",
// "@elizaos/plugin-local-ai",
// "@elizaos/plugin-discord",
"@elizaos/plugin-node",
"@elizaos/plugin-telegram",
"@elizaos/plugin-twitter",
// "@elizaos/plugin-telegram",
// "@elizaos/plugin-twitter",
"@elizaos/plugin-evm",
"@elizaos/plugin-solana",
],
settings: {
secrets: {},
Expand Down
2 changes: 1 addition & 1 deletion packages/agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ async function findDatabaseAdapter(runtime: IAgentRuntime) {
let adapter: Adapter | undefined;
// if not found, default to sqlite
if (adapters.length === 0) {
const sqliteAdapterPlugin = await import('@elizaos-plugins/sqlite');
const sqliteAdapterPlugin = await import('@elizaos/plugin-sqlite');
const sqliteAdapterPluginDefault = sqliteAdapterPlugin.default;
adapter = sqliteAdapterPluginDefault.adapters[0];
if (!adapter) {
Expand Down
2 changes: 1 addition & 1 deletion packages/agent/src/plugins.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function findDatabaseAdapter(runtime: IAgentRuntime) {

// Default to sqlite if no adapter found
if (adapters.length === 0) {
const sqliteAdapter = await import('@elizaos-plugins/sqlite');
const sqliteAdapter = await import('@elizaos/plugin-sqlite');
adapter = sqliteAdapter.default.adapters[0];
if (!adapter) {
throw new Error("No database adapter found in default sqlite plugin");
Expand Down
21 changes: 10 additions & 11 deletions packages/agent/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import {
composeContext,
logger,
generateMessageResponse,
generateObject,
messageCompletionFooter,
logger,
ModelClass,
stringToUuid,
type Character,
type Content,
type Media,
type Memory,
type IAgentRuntime,
type Character
type Media,
type Memory
} from "@elizaos/core";
import bodyParser from "body-parser";
import cors from "cors";
Expand All @@ -20,9 +19,8 @@ import * as fs from "node:fs";
import * as path from "node:path";
import { z } from "zod";
import { createApiRouter } from "./api.ts";
import { hyperfiHandlerTemplate, messageHandlerTemplate, upload } from "./helper.ts";
import replyAction from "./reply.ts";
import { messageHandlerTemplate } from "./helper.ts";
import { upload } from "./helper.ts";



Expand All @@ -31,7 +29,7 @@ export class CharacterServer {
public app: express.Application;
private agents: Map<string, IAgentRuntime>; // container management
private server: any; // Store server instance
public startAgent: () => Promise<void>; // Store startAgent function
public startAgent: (character: Character) => Promise<IAgentRuntime>; // Store startAgent function
public loadCharacterTryPath: (characterPath: string) => Promise<Character>; // Store loadCharacterTryPath function
public jsonToCharacter: (filePath: string, character: string | never) => Promise<Character>; // Store jsonToCharacter function

Expand Down Expand Up @@ -91,9 +89,10 @@ export class CharacterServer {
return;
}

const transcription = await runtime.useModel(ModelClass.TRANSCRIPTION, fs.createReadStream(audioFile.path));

res.json(transcription);
const audioBuffer = fs.readFileSync(audioFile.path);
const transcription = await runtime.useModel(ModelClass.TRANSCRIPTION, audioBuffer);

res.json({text: transcription});
}
);

Expand Down
16 changes: 11 additions & 5 deletions packages/cli/src/commands/character.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// src/commands/agent.ts
import { Database, SqliteDatabaseAdapter } from "@elizaos-plugins/sqlite";
import { Database, SqliteDatabaseAdapter } from "@elizaos/plugin-sqlite";
import type { MessageExample, UUID } from "@elizaos/core";
import { MessageExampleSchema } from "@elizaos/core";
import { Command } from "commander";
Expand Down Expand Up @@ -116,10 +116,16 @@ async function collectCharacterData(
const examples = response.value
.split('\\n')
.map(line => line.trim())
.filter(Boolean);
formData.messageExamples = examples.length > 0
? examples
: [`{{user1}}: hey how are you?\n${formData.name}`];
.filter(Boolean)
.map(line => ({
user: line.split(':')[0].trim(),
content: {
text: line.split(':').slice(1).join(':').trim()
}
}));
formData.messageExamples = examples.length > 0
? [examples]
: [];
break;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/database.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Database from "better-sqlite3"
import { SqliteDatabaseAdapter } from "@elizaos-plugins/sqlite"
import { SqliteDatabaseAdapter } from "@elizaos/plugin-sqlite"

// Initialize database
export const adapter = new SqliteDatabaseAdapter(new Database("./eliza.db"))
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/templates/database/sqlite.ts.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SqliteDatabaseAdapter } from '@elizaos-plugins/sqlite';
import { SqliteDatabaseAdapter } from '@elizaos/plugin-sqlite';
import Database from 'better-sqlite3';
import path from 'path';

Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/utils/registry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const agent = process.env.https_proxy

export async function getRegistryIndex(): Promise<Registry> {
try {
console.log("REGISTRY_URL", REGISTRY_URL)
const response = await fetch(REGISTRY_URL, { agent })
// Get the response body as text first
const text = await response.text()
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/utils/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
export function createDatabaseTemplate(database: string) {
if (database === "sqlite") {
return `import { Database } from "better-sqlite3"
import { SqliteDatabaseAdapter } from "@elizaos-plugins/sqlite"
import { SqliteDatabaseAdapter } from "@elizaos/plugin-sqlite"
// Initialize database
export const db = new Database("./eliza.db")
Expand Down
36 changes: 32 additions & 4 deletions packages/core/src/generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,19 @@ export async function generateText({
stopSequences?: string[];
customSystemPrompt?: string;
}): Promise<string> {

logger.debug("Generating text")
logger.debug(context)

const text = await runtime.useModel(modelClass, {
runtime,
context,
stopSequences,
});

logger.debug("Generated text")
logger.debug(text)

return text;
}

Expand Down Expand Up @@ -257,7 +264,7 @@ export async function generateTrueOrFalse({
export const generateObject = async ({
runtime,
context,
modelClass = ModelClass.TEXT_SMALL,
modelClass = ModelClass.TEXT_LARGE,
stopSequences,
}: GenerateObjectOptions): Promise<any> => {
if (!context) {
Expand All @@ -266,16 +273,37 @@ export const generateObject = async ({
throw new Error(errorMessage);
}

const { object } = await runtime.useModel(modelClass, {
const obj = await runtime.useModel(modelClass, {
runtime,
context,
modelClass,
stopSequences,
object: true,
});

logger.debug(`Received Object response from ${modelClass} model.`);
return object;
let jsonString = obj;

// try to find a first and last bracket
const firstBracket = obj.indexOf("{");
const lastBracket = obj.lastIndexOf("}");
if (firstBracket !== -1 && lastBracket !== -1 && firstBracket < lastBracket) {
jsonString = obj.slice(firstBracket, lastBracket + 1);
}

if (jsonString.length === 0) {
logger.error("Failed to extract JSON string from model response");
return null;
}

// parse the json string
try {
const json = JSON.parse(jsonString);
return json;
} catch (error) {
logger.error("Failed to parse JSON string");
logger.error(jsonString);
return null;
}
};

export async function generateObjectArray({
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/knowledge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ async function get(
runtime: AgentRuntime,
message: Memory
): Promise<KnowledgeItem[]> {
console.log("get", message);
// Add validation for message
if (!message?.content?.text) {
logger.warn("Invalid message for knowledge query:", {
Expand Down Expand Up @@ -70,7 +69,6 @@ async function set(
chunkSize = 512,
bleed = 20
) {
console.log("set", item);
const embedding = await runtime.useModel(ModelClass.TEXT_EMBEDDING, null);
await runtime.documentsManager.createMemory({
id: item.id,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const createStream = () => {
});
};

const defaultLevel = process?.env?.DEFAULT_LOG_LEVEL || "info";
const defaultLevel = process?.env?.DEFAULT_LOG_LEVEL || process?.env?.LOG_LEVEL || "info";

const options = {
level: defaultLevel,
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export class MemoryManager implements IMemoryManager {
* @throws Error if the memory content is empty
*/
async addEmbeddingToMemory(memory: Memory): Promise<Memory> {
console.log("addEmbeddingToMemory", memory);
// Return early if embedding already exists
if (memory.embedding) {
return memory;
Expand Down Expand Up @@ -174,7 +173,6 @@ export class MemoryManager implements IMemoryManager {
*/
async createMemory(memory: Memory, unique = false): Promise<void> {
// TODO: check memory.agentId == this.runtime.agentId
console.log("createMemory", memory);

const existingMessage =
await this.runtime.databaseAdapter.getMemoryById(memory.id);
Expand Down
30 changes: 28 additions & 2 deletions packages/core/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,15 @@ export class AgentRuntime implements IAgentRuntime {
for(const route of plugin.routes){
this.routes.push(route);
}

for(const client of plugin.clients){
client.start(this).then((startedClient) => {
logger.debug(
`Initializing client: ${client.name}`
);
this.clients.push(startedClient);
});
}
}

this.plugins = plugins;
Expand All @@ -353,6 +362,25 @@ export class AgentRuntime implements IAgentRuntime {
this.clients.push(startedClient);
}
}

if (plugin.actions) {
for (const action of plugin.actions) {
this.registerAction(action);
}
}

if (plugin.evaluators) {
for (const evaluator of plugin.evaluators) {
this.registerEvaluator(evaluator);
}
}

if (plugin.providers) {
for (const provider of plugin.providers) {
this.registerContextProvider(provider);
}
}

if (plugin.models) {
for (const [modelClass, handler] of Object.entries(plugin.models)) {
this.registerModel(modelClass as ModelClass, handler as (params: any) => Promise<any>);
Expand Down Expand Up @@ -602,8 +630,6 @@ export class AgentRuntime implements IAgentRuntime {
modelClass: ModelClass.TEXT_SMALL,
});

console.log("***** result", result);

const evaluators = parseJsonArrayFromText(
result,
) as unknown as string[];
Expand Down
Loading

0 comments on commit 4116739

Please sign in to comment.