mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-05 01:01:51 +01:00
fix: handle text parts with tool_call_ids and empty text
This commit is contained in:
parent
0c04018bb3
commit
350d709763
4 changed files with 17 additions and 5 deletions
|
|
@ -31,10 +31,14 @@ const Part = memo(({ part, isSubmitting, showCursor, messageId, isCreatedByUser
|
|||
if (part.type === ContentTypes.ERROR) {
|
||||
return <ErrorMessage text={part[ContentTypes.TEXT].value} className="my-2" />;
|
||||
} else if (part.type === ContentTypes.TEXT) {
|
||||
const text = typeof part.text === 'string' ? part.text : part.text.value;
|
||||
const text = typeof part.text === 'string' ? part.text : (part.text as { value: string }).value;
|
||||
|
||||
if (typeof text !== 'string') {
|
||||
return null;
|
||||
}
|
||||
if (part.tool_call_ids != null && !text) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<Container>
|
||||
<Text
|
||||
|
|
@ -55,7 +59,7 @@ const Part = memo(({ part, isSubmitting, showCursor, messageId, isCreatedByUser
|
|||
if ('args' in toolCall && (!toolCall.type || toolCall.type === ToolCallTypes.TOOL_CALL)) {
|
||||
return (
|
||||
<ToolCall
|
||||
args={toolCall.args}
|
||||
args={toolCall.args ?? ''}
|
||||
name={toolCall.name ?? ''}
|
||||
output={toolCall.output ?? ''}
|
||||
initialProgress={toolCall.progress ?? 0.1}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ type TStepEvent = {
|
|||
data: Agents.MessageDeltaEvent | Agents.RunStep | Agents.ToolEndEvent;
|
||||
};
|
||||
|
||||
type MessageDeltaUpdate = { type: ContentTypes.TEXT; text: string; tool_call_ids?: string[] };
|
||||
|
||||
type AllContentTypes =
|
||||
| ContentTypes.TEXT
|
||||
| ContentTypes.TOOL_CALL
|
||||
|
|
@ -55,11 +57,16 @@ export default function useStepHandler({ setMessages, getMessages }: TUseStepHan
|
|||
ContentTypes.TEXT in contentPart &&
|
||||
typeof contentPart.text === 'string'
|
||||
) {
|
||||
const currentContent = updatedContent[index] as { type: ContentTypes.TEXT; text: string };
|
||||
updatedContent[index] = {
|
||||
const currentContent = updatedContent[index] as MessageDeltaUpdate;
|
||||
const update: MessageDeltaUpdate = {
|
||||
type: ContentTypes.TEXT,
|
||||
text: (currentContent.text || '') + contentPart.text,
|
||||
};
|
||||
|
||||
if (contentPart.tool_call_ids != null) {
|
||||
update.tool_call_ids = contentPart.tool_call_ids;
|
||||
}
|
||||
updatedContent[index] = update;
|
||||
} else if (contentType === ContentTypes.IMAGE_URL && 'image_url' in contentPart) {
|
||||
const currentContent = updatedContent[index] as {
|
||||
type: ContentTypes.IMAGE_URL;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ export namespace Agents {
|
|||
export type MessageContentText = {
|
||||
type: ContentTypes.TEXT;
|
||||
text: string;
|
||||
tool_call_ids?: string[];
|
||||
};
|
||||
|
||||
export type MessageContentImageUrl = {
|
||||
|
|
|
|||
|
|
@ -381,7 +381,7 @@ export type ContentPart = (
|
|||
|
||||
export type TMessageContentParts =
|
||||
| { type: ContentTypes.ERROR; text: Text & PartMetadata }
|
||||
| { type: ContentTypes.TEXT; text: string | (Text & PartMetadata) }
|
||||
| { type: ContentTypes.TEXT; text: string; tool_call_ids?: string[] | (Text & PartMetadata) }
|
||||
| {
|
||||
type: ContentTypes.TOOL_CALL;
|
||||
tool_call: (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue