Skip to content

Commit

Permalink
Merge pull request elizaOS#1245 from renlulu/feat/express-payload-config
Browse files Browse the repository at this point in the history
feat: make express payload limit configurable
  • Loading branch information
monilpat authored Dec 19, 2024
2 parents da405cd + 31b336f commit 800cd0d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ LARGE_HYPERBOLIC_MODEL= # Default: meta-llama/Meta-Llama-3.1-405-Instruc
# Speech Synthesis
ELEVENLABS_XI_API_KEY= # API key from elevenlabs

# Direct Client Setting
EXPRESS_MAX_PAYLOAD= # Default: 100kb

# ElevenLabs Settings
ELEVENLABS_MODEL_ID=eleven_multilingual_v2
ELEVENLABS_VOICE_ID=21m00Tcm4TlvDq8ikWAM
Expand Down
43 changes: 26 additions & 17 deletions packages/client-direct/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,27 @@ import cors from "cors";
import {
AgentRuntime,
elizaLogger,
getEnvVariable,
validateCharacterConfig,
} from "@ai16z/eliza";

import { REST, Routes } from "discord.js";
import { DirectClient } from ".";

export function createApiRouter(agents: Map<string, AgentRuntime>, directClient) {
export function createApiRouter(
agents: Map<string, AgentRuntime>,
directClient: DirectClient
) {
const router = express.Router();

router.use(cors());
router.use(bodyParser.json());
router.use(bodyParser.urlencoded({ extended: true }));
router.use(
express.json({
limit: getEnvVariable("EXPRESS_MAX_PAYLOAD") || "100kb",
})
);

router.get("/", (req, res) => {
res.send("Welcome, this is the REST API!");
Expand Down Expand Up @@ -51,41 +61,40 @@ export function createApiRouter(agents: Map<string, AgentRuntime>, directClient)

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

// update character
if (agent) {
// stop agent
agent.stop()
directClient.unregisterAgent(agent)
agent.stop();
directClient.unregisterAgent(agent);
// if it has a different name, the agentId will change
}

// load character from body
const character = req.body
const character = req.body;
try {
validateCharacterConfig(character)
} catch(e) {
elizaLogger.error(`Error parsing character: ${e}`);
res.status(400).json({
success: false,
message: e.message,
});
return;
validateCharacterConfig(character);
} catch (e) {
elizaLogger.error(`Error parsing character: ${e}`);
res.status(400).json({
success: false,
message: e.message,
});
return;
}

// start it up (and register it)
agent = await directClient.startAgent(character)
elizaLogger.log(`${character.name} started`)
agent = await directClient.startAgent(character);
elizaLogger.log(`${character.name} started`);

res.json({
id: character.id,
character: character,
});
});


router.get("/agents/:agentId/channels", async (req, res) => {
const agentId = req.params.agentId;
const runtime = agents.get(agentId);
Expand Down

0 comments on commit 800cd0d

Please sign in to comment.