Skip to content

Commit

Permalink
šŸ› fix: Artifacts Type Error, Tool Token Counts, and Agent Chat Import (ā€¦
Browse files Browse the repository at this point in the history
ā€¦#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
  • Loading branch information
danny-avila authored Dec 30, 2024
1 parent cb19216 commit 6c9a468
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
18 changes: 18 additions & 0 deletions api/app/clients/BaseClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,24 @@ class BaseClient {
continue;
}

if (item.type === 'tool_call' && item.tool_call != null) {
const toolName = item.tool_call?.name || '';
if (toolName != null && toolName && typeof toolName === 'string') {
numTokens += this.getTokenCount(toolName);
}

const args = item.tool_call?.args || '';
if (args != null && args && typeof args === 'string') {
numTokens += this.getTokenCount(args);
}

const output = item.tool_call?.output || '';
if (output != null && output && typeof output === 'string') {
numTokens += this.getTokenCount(output);
}
continue;
}

const nestedValue = item[item.type];

if (!nestedValue) {
Expand Down
4 changes: 3 additions & 1 deletion api/server/utils/import/importers.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,23 @@ async function importLibreChatConvo(
*/
const traverseMessages = async (messages, parentMessageId = null) => {
for (const message of messages) {
if (!message.text) {
if (!message.text && !message.content) {
continue;
}

let savedMessage;
if (message.sender?.toLowerCase() === 'user' || message.isCreatedByUser) {
savedMessage = await importBatchBuilder.saveMessage({
text: message.text,
content: message.content,
sender: 'user',
isCreatedByUser: true,
parentMessageId: parentMessageId,
});
} else {
savedMessage = await importBatchBuilder.saveMessage({
text: message.text,
content: message.content,
sender: message.sender,
isCreatedByUser: false,
model: options.model,
Expand Down
6 changes: 5 additions & 1 deletion client/src/components/Chat/Input/Files/FilePreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ const FilePreview = ({
}) => {
const radius = 55; // Radius of the SVG circle
const circumference = 2 * Math.PI * radius;
const progress = useProgress(file?.['progress'] ?? 1, 0.001, (file as ExtendedFile).size ?? 1);
const progress = useProgress(
file?.['progress'] ?? 1,
0.001,
(file as ExtendedFile | undefined)?.size ?? 1,
);

// Calculate the offset based on the loading progress
const offset = circumference - progress * circumference;
Expand Down

0 comments on commit 6c9a468

Please sign in to comment.