Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make express payload limit configurable #1245

Merged
merged 5 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
monilpat marked this conversation as resolved.
Show resolved Hide resolved
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
Loading