Skip to content

Commit ce2de2d

Browse files
committed
update convert message content
1 parent b3f3ce4 commit ce2de2d

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

templates/types/streaming/express/src/controllers/llamaindex-stream.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,21 @@ export const convertMessageContent = (
3434
textMessage: string,
3535
additionalData?: DataParserOptions,
3636
): MessageContent => {
37+
if (!additionalData) return textMessage;
38+
const content: MessageContent = [
39+
{
40+
type: "text",
41+
text: textMessage,
42+
}
43+
];
3744
if (additionalData?.imageUrl) {
38-
return [
39-
{
40-
type: "text",
41-
text: textMessage,
42-
},
45+
content.push(
4346
{
4447
type: "image_url",
4548
image_url: {
4649
url: additionalData?.imageUrl,
4750
},
48-
},
49-
];
51+
});
5052
}
5153

5254
if (additionalData?.uploadedCsv) {
@@ -55,10 +57,13 @@ export const convertMessageContent = (
5557
"```csv\n" +
5658
additionalData.uploadedCsv.content +
5759
"\n```";
58-
return `${csvContent}\n\n${textMessage}`;
60+
content.push({
61+
type: "text",
62+
text: `${csvContent}\n\n${textMessage}`
63+
});
5964
}
6065

61-
return textMessage;
66+
return content;
6267
};
6368

6469
function createParser(

templates/types/streaming/nextjs/app/api/chat/llamaindex-stream.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,21 @@ export const convertMessageContent = (
3434
textMessage: string,
3535
additionalData?: DataParserOptions,
3636
): MessageContent => {
37+
if (!additionalData) return textMessage;
38+
const content: MessageContent = [
39+
{
40+
type: "text",
41+
text: textMessage,
42+
}
43+
];
3744
if (additionalData?.imageUrl) {
38-
return [
39-
{
40-
type: "text",
41-
text: textMessage,
42-
},
45+
content.push(
4346
{
4447
type: "image_url",
4548
image_url: {
4649
url: additionalData?.imageUrl,
4750
},
48-
},
49-
];
51+
});
5052
}
5153

5254
if (additionalData?.uploadedCsv) {
@@ -55,10 +57,13 @@ export const convertMessageContent = (
5557
"```csv\n" +
5658
additionalData.uploadedCsv.content +
5759
"\n```";
58-
return `${csvContent}\n\n${textMessage}`;
60+
content.push({
61+
type: "text",
62+
text: `${csvContent}\n\n${textMessage}`
63+
});
5964
}
6065

61-
return textMessage;
66+
return content;
6267
};
6368

6469
function createParser(

templates/types/streaming/nextjs/app/components/ui/chat/chat-resources.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface ChatResourcesProps {
1010
}
1111

1212
export default function ChatResources(props: ChatResourcesProps) {
13+
if (!props.resources.length) return null;
1314
return (
1415
<div className="flex gap-4 text-sm">
1516
{props.resources.map((data, index) => {

0 commit comments

Comments
 (0)