Skip to content

Commit ab6e5dc

Browse files
committed
improve code
1 parent 8dd5dfd commit ab6e5dc

File tree

7 files changed

+23
-27
lines changed

7 files changed

+23
-27
lines changed

templates/components/agents/typescript/blog/workflow/agents.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ If you use the tools but don't find any related information, please return "I di
3636
If the request doesn't need any new information because it was in the conversation history, please return "The task doesn't need any new information. Please reuse the existing content in the conversation history.
3737
`,
3838
chatHistory,
39-
writeEvents: true,
4039
});
4140
};
4241

@@ -57,7 +56,6 @@ Example:
5756
-> This is not your task: Create a PDF
5857
Please note that a localhost link is acceptable, but dummy links like "example.com" or "your-website.com" are not valid.`,
5958
chatHistory,
60-
writeEvents: true,
6159
});
6260
};
6361

@@ -76,7 +74,6 @@ Example:
7674
-> Your task: Review whether the main content of the post is about the history of the internet and if it is written in English.
7775
-> This is not your task: Create blog post, create PDF, write in English.`,
7876
chatHistory,
79-
writeEvents: true,
8077
});
8178
};
8279

@@ -94,6 +91,5 @@ Otherwise, simply return the content of the post.`;
9491
tools: tools,
9592
systemPrompt: systemPrompt,
9693
chatHistory,
97-
writeEvents: true,
9894
});
9995
};

templates/components/agents/typescript/financial_report/workflow/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ChatMessage, ToolCallLLM } from "llamaindex";
2-
import { FinancialReportWorkflow } from "./finReport";
2+
import { FinancialReportWorkflow } from "./fin-report";
33
import { getAvailableTools } from "./tools";
44

55
const TIMEOUT = 360 * 1000;

templates/components/agents/typescript/form_filling/workflow/factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ChatMessage, ToolCallLLM } from "llamaindex";
2-
import { FormFillingWorkflow } from "./formFilling";
2+
import { FormFillingWorkflow } from "./form-filling";
33
import { getAvailableTools } from "./tools";
44

55
const TIMEOUT = 360 * 1000;

templates/components/llamaindex/typescript/streaming/annotations.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,25 @@ export function retrieveMessageContent(messages: Message[]): MessageContent {
6464
];
6565
}
6666

67-
export function retrieveAgentHistoryMessage(
67+
export function convertToChatHistory(messages: Message[]): ChatMessage[] {
68+
if (!messages || !Array.isArray(messages)) {
69+
return [];
70+
}
71+
const agentHistory = retrieveAgentHistoryMessage(messages);
72+
if (agentHistory) {
73+
const previousMessages = messages.slice(0, -1);
74+
return [...previousMessages, agentHistory].map((msg) => ({
75+
role: msg.role as MessageType,
76+
content: msg.content,
77+
}));
78+
}
79+
return messages.map((msg) => ({
80+
role: msg.role as MessageType,
81+
content: msg.content,
82+
}));
83+
}
84+
85+
function retrieveAgentHistoryMessage(
6886
messages: Message[],
6987
maxAgentMessages = 10,
7088
): ChatMessage | null {
@@ -85,24 +103,6 @@ export function retrieveAgentHistoryMessage(
85103
return null;
86104
}
87105

88-
export function convertToChatHistory(messages: Message[]): ChatMessage[] {
89-
if (!messages || !Array.isArray(messages)) {
90-
return [];
91-
}
92-
const agentHistory = retrieveAgentHistoryMessage(messages);
93-
if (agentHistory) {
94-
const previousMessages = messages.slice(0, -1);
95-
return [...previousMessages, agentHistory].map((msg) => ({
96-
role: msg.role as MessageType,
97-
content: msg.content,
98-
}));
99-
}
100-
return messages.map((msg) => ({
101-
role: msg.role as MessageType,
102-
content: msg.content,
103-
}));
104-
}
105-
106106
function getFileContent(file: DocumentFile): string {
107107
let defaultContent = `=====File: ${file.name}=====\n`;
108108
// Include file URL if it's available

templates/components/multiagent/typescript/express/chat.controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Message, StreamingTextResponse } from "ai";
1+
import { Message, streamToResponse } from "ai";
22
import { Request, Response } from "express";
33
import {
44
convertToChatHistory,
@@ -28,7 +28,7 @@ export const chat = async (req: Request, res: Response) => {
2828
const { stream, dataStream } =
2929
await createStreamFromWorkflowContext(context);
3030

31-
return new StreamingTextResponse(stream, {}, dataStream);
31+
return streamToResponse(stream, res, {}, dataStream);
3232
} catch (error) {
3333
console.error("[LlamaIndex]", error);
3434
return res.status(500).json({

0 commit comments

Comments
 (0)