Skip to content

Commit

Permalink
build is building
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Feb 8, 2025
1 parent 10ce8f1 commit f379568
Show file tree
Hide file tree
Showing 30 changed files with 273 additions and 1,042 deletions.
41 changes: 12 additions & 29 deletions packages/agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import {
type Character,
type ClientInstance,
DbCacheAdapter,
logger,
FsCacheAdapter,
type IAgentRuntime,
type IDatabaseAdapter,
type IDatabaseCacheAdapter,
logger,
ModelType,
parseBooleanFromText,
settings,
stringToUuid,
validateCharacterConfig,
validateCharacterConfig
} from "@elizaos/core";
import { bootstrapPlugin } from "@elizaos/plugin-bootstrap";
import fs from "node:fs";
Expand Down Expand Up @@ -349,10 +349,17 @@ export async function initializeClients(
clients.push(startedClient);
}
}
if (plugin.handlers) {
for (const [modelType, handler] of Object.entries(plugin.handlers)) {
runtime.registerHandler(modelType as ModelType, handler);
}
}
}
}

return clients;
runtime.clients = clients;


}

export async function createAgent(
Expand All @@ -374,18 +381,6 @@ export async function createAgent(
});
}

function initializeFsCache(baseDir: string, character: Character) {
if (!character?.id) {
throw new Error(
"initializeFsCache requires id to be set in character definition"
);
}
const cacheDir = path.resolve(baseDir, character.id, "cache");

const cache = new CacheManager(new FsCacheAdapter(cacheDir));
return cache;
}

function initializeDbCache(character: Character, db: IDatabaseCacheAdapter) {
if (!character?.id) {
throw new Error(
Expand All @@ -412,23 +407,13 @@ function initializeCache(
"Database adapter is not provided for CacheStore.Database."
);

case CacheStore.FILESYSTEM:
logger.info("Using File System Cache...");
if (!baseDir) {
throw new Error(
"baseDir must be provided for CacheStore.FILESYSTEM."
);
}
return initializeFsCache(baseDir, character);

default:
throw new Error(
`Invalid cache store: ${cacheStore} or required configuration missing.`
);
}
}


async function findDatabaseAdapter(runtime: AgentRuntime) {
const { adapters } = runtime;
let adapter: Adapter | undefined;
Expand All @@ -449,8 +434,6 @@ async function findDatabaseAdapter(runtime: AgentRuntime) {
return adapterInterface;
}



async function startAgent(
character: Character,
characterServer: CharacterServer
Expand Down Expand Up @@ -482,7 +465,7 @@ async function startAgent(
await runtime.initialize();

// start assigned clients
runtime.clients = await initializeClients(character, runtime);
await initializeClients(character, runtime);

// add to container
characterServer.registerAgent(runtime);
Expand Down
22 changes: 13 additions & 9 deletions packages/agent/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import {
generateImage,
generateMessageResponse,
generateObject,
getEmbeddingZeroVector,
messageCompletionFooter,
ModelClass,
ModelType,
stringToUuid,
type Content,
type Media,
type Memory
type Memory,
type IAgentRuntime
} from "@elizaos/core";
import bodyParser from "body-parser";
import cors from "cors";
Expand Down Expand Up @@ -166,7 +166,7 @@ export class CharacterServer {
return;
}

const transcription = await runtime.getModelProviderManager().call(ModelClass.AUDIO_TRANSCRIPTION, {
const transcription = await runtime.getModelProviderManager().call(ModelType.AUDIO_TRANSCRIPTION, {
file: fs.createReadStream(audioFile.path),

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
model: "whisper-1",
});
Expand Down Expand Up @@ -276,7 +276,7 @@ export class CharacterServer {
const response = await generateMessageResponse({
runtime: runtime,
context,
modelClass: ModelClass.TEXT_LARGE,
modelType: ModelType.TEXT_LARGE,
});

if (!response) {
Expand All @@ -286,13 +286,17 @@ export class CharacterServer {
return;
}

const zeroVector = runtime.getModelProviderManager().call(ModelType.EMBEDDING, {
text: null,
});

// save response to memory
const responseMessage: Memory = {
id: stringToUuid(`${messageId}-${runtime.agentId}`),
...userMessage,
userId: runtime.agentId,
content: response,
embedding: getEmbeddingZeroVector(),
embedding: zeroVector,
createdAt: Date.now(),
};

Expand Down Expand Up @@ -488,7 +492,7 @@ export class CharacterServer {
const response = await generateObject({
runtime,
context,
modelClass: ModelClass.TEXT_SMALL,
modelType: ModelType.TEXT_SMALL,
schema: hyperfiOutSchema,
});

Expand Down Expand Up @@ -791,7 +795,7 @@ export class CharacterServer {
const response = await generateMessageResponse({
runtime: runtime,
context,
modelClass: ModelClass.TEXT_LARGE,
modelType: ModelType.TEXT_LARGE,
});

// save response to memory
Expand Down Expand Up @@ -824,7 +828,7 @@ export class CharacterServer {
// Get the text to convert to speech
const textToSpeak = response.text;

const speechResponse = await runtime.getModelProviderManager().call(ModelClass.AUDIO_TRANSCRIPTION, {
const speechResponse = await runtime.getModelProviderManager().call(ModelType.AUDIO_TRANSCRIPTION, {
text: textToSpeak,
runtime,
});
Expand Down
1 change: 0 additions & 1 deletion packages/client/src/components/overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export default function Overview({ character }: { character: Character }) {
<InputCopy title="Name" value={character?.name} />
<InputCopy title="Username" value={character?.username} />
<InputCopy title="System" value={character?.system} />
<InputCopy title="Model" value={character?.modelProvider} />
<InputCopy
title="Voice Model"
value={character?.settings?.voice?.model}
Expand Down
Loading

0 comments on commit f379568

Please sign in to comment.