Skip to content

Commit 96e8d4a

Browse files
danny-avilaolivierhub
authored andcommitted
šŸ› fix: Artifacts Type Error, Tool Token Counts, and Agent Chat Import (danny-avila#5142)
* fix: message import functionality to support content field * fix: handle tool calls token counts in context window management * fix: handle potential undefined size in FilePreview component
1 parent ceb38c0 commit 96e8d4a

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

ā€Žapi/app/clients/BaseClient.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,24 @@ class BaseClient {
931931
continue;
932932
}
933933

934+
if (item.type === 'tool_call' && item.tool_call != null) {
935+
const toolName = item.tool_call?.name || '';
936+
if (toolName != null && toolName && typeof toolName === 'string') {
937+
numTokens += this.getTokenCount(toolName);
938+
}
939+
940+
const args = item.tool_call?.args || '';
941+
if (args != null && args && typeof args === 'string') {
942+
numTokens += this.getTokenCount(args);
943+
}
944+
945+
const output = item.tool_call?.output || '';
946+
if (output != null && output && typeof output === 'string') {
947+
numTokens += this.getTokenCount(output);
948+
}
949+
continue;
950+
}
951+
934952
const nestedValue = item[item.type];
935953

936954
if (!nestedValue) {

ā€Žapi/server/utils/import/importers.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,23 @@ async function importLibreChatConvo(
113113
*/
114114
const traverseMessages = async (messages, parentMessageId = null) => {
115115
for (const message of messages) {
116-
if (!message.text) {
116+
if (!message.text && !message.content) {
117117
continue;
118118
}
119119

120120
let savedMessage;
121121
if (message.sender?.toLowerCase() === 'user' || message.isCreatedByUser) {
122122
savedMessage = await importBatchBuilder.saveMessage({
123123
text: message.text,
124+
content: message.content,
124125
sender: 'user',
125126
isCreatedByUser: true,
126127
parentMessageId: parentMessageId,
127128
});
128129
} else {
129130
savedMessage = await importBatchBuilder.saveMessage({
130131
text: message.text,
132+
content: message.content,
131133
sender: message.sender,
132134
isCreatedByUser: false,
133135
model: options.model,

ā€Žclient/src/components/Chat/Input/Files/FilePreview.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ const FilePreview = ({
2121
}) => {
2222
const radius = 55; // Radius of the SVG circle
2323
const circumference = 2 * Math.PI * radius;
24-
const progress = useProgress(file?.['progress'] ?? 1, 0.001, (file as ExtendedFile).size ?? 1);
24+
const progress = useProgress(
25+
file?.['progress'] ?? 1,
26+
0.001,
27+
(file as ExtendedFile | undefined)?.size ?? 1,
28+
);
2529

2630
// Calculate the offset based on the loading progress
2731
const offset = circumference - progress * circumference;

0 commit comments

Comments
Ā (0)