Skip to content

Commit f43d0a2

Browse files
authored
Merge branch 'develop' into images-in-chat-client
2 parents 9432bf8 + 8eefb03 commit f43d0a2

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

client/src/Chat.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { useRef, useState } from "react";
22
import { useParams } from "react-router-dom";
33
import { useMutation } from "@tanstack/react-query";
4-
import { Input } from "@/components/ui/input";
54
import { Button } from "@/components/ui/button";
65
import { ImageIcon } from "lucide-react";
6+
import { Input } from "@/components/ui/input";
77
import "./App.css";
88
import path from "path";
99

@@ -78,7 +78,7 @@ export default function Chat() {
7878
messages.map((message, index) => (
7979
<div
8080
key={index}
81-
className={`flex ${
81+
className={`text-left flex ${
8282
message.user === "user"
8383
? "justify-end"
8484
: "justify-start"
@@ -107,6 +107,9 @@ export default function Chat() {
107107
/>
108108
)
109109
))}
110+
<pre className="whitespace-pre-wrap break-words font-sans m-0">
111+
{message.text}
112+
</pre>
110113
</div>
111114
</div>
112115
))

packages/client-direct/src/index.ts

+28-20
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import bodyParser from "body-parser";
22
import cors from "cors";
33
import express, { Request as ExpressRequest } from "express";
4-
import multer from "multer";
4+
import multer, { File } from "multer";
55
import {
66
elizaLogger,
77
generateCaption,
88
generateImage,
99
Media,
10+
getEmbeddingZeroVector
1011
} from "@elizaos/core";
1112
import { composeContext } from "@elizaos/core";
1213
import { generateMessageResponse } from "@elizaos/core";
@@ -229,17 +230,19 @@ export class DirectClient {
229230
};
230231

231232
const memory: Memory = {
232-
id: messageId,
233+
id: stringToUuid(messageId + "-" + userId),
234+
...userMessage,
233235
agentId: runtime.agentId,
234236
userId,
235237
roomId,
236238
content,
237239
createdAt: Date.now(),
238240
};
239241

242+
await runtime.messageManager.addEmbeddingToMemory(memory);
240243
await runtime.messageManager.createMemory(memory);
241244

242-
const state = await runtime.composeState(userMessage, {
245+
let state = await runtime.composeState(userMessage, {
243246
agentName: runtime.character.name,
244247
});
245248

@@ -254,34 +257,30 @@ export class DirectClient {
254257
modelClass: ModelClass.LARGE,
255258
});
256259

260+
if (!response) {
261+
res.status(500).send(
262+
"No response from generateMessageResponse"
263+
);
264+
return;
265+
}
266+
257267
// save response to memory
258-
const responseMessage = {
268+
const responseMessage: Memory = {
269+
id: stringToUuid(messageId + "-" + runtime.agentId),
259270
...userMessage,
260271
userId: runtime.agentId,
261272
content: response,
273+
embedding: getEmbeddingZeroVector(),
274+
createdAt: Date.now(),
262275
};
263276

264277
await runtime.messageManager.createMemory(responseMessage);
265278

266-
if (!response) {
267-
res.status(500).send(
268-
"No response from generateMessageResponse"
269-
);
270-
return;
271-
}
279+
state = await runtime.updateRecentMessageState(state);
272280

273281
let message = null as Content | null;
274282

275-
await runtime.evaluate(memory, state);
276-
277-
// Check if we should suppress the initial message
278-
const action = runtime.actions.find(
279-
(a) => a.name === response.action
280-
);
281-
const shouldSuppressInitialMessage =
282-
action?.suppressInitialMessage;
283-
284-
const _result = await runtime.processActions(
283+
await runtime.processActions(
285284
memory,
286285
[responseMessage],
287286
state,
@@ -291,6 +290,15 @@ export class DirectClient {
291290
}
292291
);
293292

293+
await runtime.evaluate(memory, state);
294+
295+
// Check if we should suppress the initial message
296+
const action = runtime.actions.find(
297+
(a) => a.name === response.action
298+
);
299+
const shouldSuppressInitialMessage =
300+
action?.suppressInitialMessage;
301+
294302
if (!shouldSuppressInitialMessage) {
295303
if (message) {
296304
res.json([response, message]);

0 commit comments

Comments
 (0)