mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-22 11:20:15 +01:00
fix: agent icons/labels for messages
This commit is contained in:
parent
2150c4815d
commit
9a9f993f32
4 changed files with 57 additions and 7 deletions
|
|
@ -2,6 +2,7 @@ const crypto = require('crypto');
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const {
|
const {
|
||||||
supportsBalanceCheck,
|
supportsBalanceCheck,
|
||||||
|
isAgentsEndpoint,
|
||||||
ErrorTypes,
|
ErrorTypes,
|
||||||
Constants,
|
Constants,
|
||||||
CacheKeys,
|
CacheKeys,
|
||||||
|
|
@ -66,6 +67,17 @@ class BaseClient {
|
||||||
throw new Error('Subclasses attempted to call summarizeMessages without implementing it');
|
throw new Error('Subclasses attempted to call summarizeMessages without implementing it');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
getResponseModel() {
|
||||||
|
if (this.options.agent.id && isAgentsEndpoint(this.options.endpoint)) {
|
||||||
|
return this.options.agent.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.modelOptions.model;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract method to get the token count for a message. Subclasses must implement this method.
|
* Abstract method to get the token count for a message. Subclasses must implement this method.
|
||||||
* @param {TMessage} responseMessage
|
* @param {TMessage} responseMessage
|
||||||
|
|
@ -558,7 +570,7 @@ class BaseClient {
|
||||||
parentMessageId: userMessage.messageId,
|
parentMessageId: userMessage.messageId,
|
||||||
isCreatedByUser: false,
|
isCreatedByUser: false,
|
||||||
isEdited,
|
isEdited,
|
||||||
model: this.modelOptions.model,
|
model: this.getResponseModel(),
|
||||||
sender: this.sender,
|
sender: this.sender,
|
||||||
promptTokens,
|
promptTokens,
|
||||||
iconURL: this.options.iconURL,
|
iconURL: this.options.iconURL,
|
||||||
|
|
|
||||||
|
|
@ -35,9 +35,10 @@ const ContentRender = memo(
|
||||||
isSubmittingFamily,
|
isSubmittingFamily,
|
||||||
}: ContentRenderProps) => {
|
}: ContentRenderProps) => {
|
||||||
const {
|
const {
|
||||||
ask,
|
// ask,
|
||||||
edit,
|
edit,
|
||||||
index,
|
index,
|
||||||
|
agent,
|
||||||
assistant,
|
assistant,
|
||||||
enterEdit,
|
enterEdit,
|
||||||
conversation,
|
conversation,
|
||||||
|
|
@ -55,6 +56,8 @@ const ContentRender = memo(
|
||||||
setCurrentEditId,
|
setCurrentEditId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log('ContentRender', { agent, conversation, msg });
|
||||||
|
|
||||||
const fontSize = useRecoilValue(store.fontSize);
|
const fontSize = useRecoilValue(store.fontSize);
|
||||||
const handleRegenerateMessage = useCallback(() => regenerateMessage(), [regenerateMessage]);
|
const handleRegenerateMessage = useCallback(() => regenerateMessage(), [regenerateMessage]);
|
||||||
// const { isCreatedByUser, error, unfinished } = msg ?? {};
|
// const { isCreatedByUser, error, unfinished } = msg ?? {};
|
||||||
|
|
@ -108,7 +111,12 @@ const ContentRender = memo(
|
||||||
<div>
|
<div>
|
||||||
<div className="pt-0.5">
|
<div className="pt-0.5">
|
||||||
<div className="flex h-6 w-6 items-center justify-center overflow-hidden rounded-full">
|
<div className="flex h-6 w-6 items-center justify-center overflow-hidden rounded-full">
|
||||||
<Icon message={msg} conversation={conversation} assistant={assistant} />
|
<Icon
|
||||||
|
message={msg}
|
||||||
|
conversation={conversation}
|
||||||
|
assistant={assistant}
|
||||||
|
agent={agent}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,13 @@
|
||||||
import { useRecoilValue } from 'recoil';
|
import { useRecoilValue } from 'recoil';
|
||||||
import { useCallback, useMemo } from 'react';
|
import { useCallback, useMemo } from 'react';
|
||||||
import { isAssistantsEndpoint } from 'librechat-data-provider';
|
import { isAssistantsEndpoint, isAgentsEndpoint } from 'librechat-data-provider';
|
||||||
import type { TMessageProps } from '~/common';
|
import type { TMessageProps } from '~/common';
|
||||||
import { useChatContext, useAddedChatContext, useAssistantsMapContext } from '~/Providers';
|
import {
|
||||||
|
useChatContext,
|
||||||
|
useAddedChatContext,
|
||||||
|
useAssistantsMapContext,
|
||||||
|
useAgentsMapContext,
|
||||||
|
} from '~/Providers';
|
||||||
import useCopyToClipboard from './useCopyToClipboard';
|
import useCopyToClipboard from './useCopyToClipboard';
|
||||||
import { useAuthContext } from '~/hooks/AuthContext';
|
import { useAuthContext } from '~/hooks/AuthContext';
|
||||||
import useLocalize from '~/hooks/useLocalize';
|
import useLocalize from '~/hooks/useLocalize';
|
||||||
|
|
@ -35,6 +40,8 @@ export default function useMessageActions(props: TMessageActions) {
|
||||||
() => (isMultiMessage === true ? addedConvo : rootConvo),
|
() => (isMultiMessage === true ? addedConvo : rootConvo),
|
||||||
[isMultiMessage, addedConvo, rootConvo],
|
[isMultiMessage, addedConvo, rootConvo],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const agentMap = useAgentsMapContext();
|
||||||
const assistantMap = useAssistantsMapContext();
|
const assistantMap = useAssistantsMapContext();
|
||||||
|
|
||||||
const { text, content, messageId = null, isCreatedByUser } = message ?? {};
|
const { text, content, messageId = null, isCreatedByUser } = message ?? {};
|
||||||
|
|
@ -56,6 +63,26 @@ export default function useMessageActions(props: TMessageActions) {
|
||||||
return assistantMap?.[endpointKey] ? assistantMap[endpointKey][modelKey] : undefined;
|
return assistantMap?.[endpointKey] ? assistantMap[endpointKey][modelKey] : undefined;
|
||||||
}, [conversation?.endpoint, message?.model, assistantMap]);
|
}, [conversation?.endpoint, message?.model, assistantMap]);
|
||||||
|
|
||||||
|
const agent = useMemo(() => {
|
||||||
|
if (!isAgentsEndpoint(conversation?.endpoint)) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!agentMap) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const modelKey = message?.model ?? '';
|
||||||
|
if (modelKey) {
|
||||||
|
return agentMap[modelKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
const agentId = conversation?.agent_id ?? '';
|
||||||
|
if (agentId) {
|
||||||
|
return agentMap[agentId];
|
||||||
|
}
|
||||||
|
}, [agentMap, conversation?.agent_id, conversation?.endpoint, message?.model]);
|
||||||
|
|
||||||
const isSubmitting = useMemo(
|
const isSubmitting = useMemo(
|
||||||
() => (isMultiMessage === true ? isSubmittingAdditional : isSubmittingRoot),
|
() => (isMultiMessage === true ? isSubmittingAdditional : isSubmittingRoot),
|
||||||
[isMultiMessage, isSubmittingAdditional, isSubmittingRoot],
|
[isMultiMessage, isSubmittingAdditional, isSubmittingRoot],
|
||||||
|
|
@ -74,17 +101,20 @@ export default function useMessageActions(props: TMessageActions) {
|
||||||
const messageLabel = useMemo(() => {
|
const messageLabel = useMemo(() => {
|
||||||
if (message?.isCreatedByUser === true) {
|
if (message?.isCreatedByUser === true) {
|
||||||
return UsernameDisplay ? (user?.name ?? '') || user?.username : localize('com_user_message');
|
return UsernameDisplay ? (user?.name ?? '') || user?.username : localize('com_user_message');
|
||||||
|
} else if (agent) {
|
||||||
|
return agent.name ?? 'Assistant';
|
||||||
} else if (assistant) {
|
} else if (assistant) {
|
||||||
return assistant.name ?? 'Assistant';
|
return assistant.name ?? 'Assistant';
|
||||||
} else {
|
} else {
|
||||||
return message?.sender;
|
return message?.sender;
|
||||||
}
|
}
|
||||||
}, [message, assistant, UsernameDisplay, user, localize]);
|
}, [message, agent, assistant, UsernameDisplay, user, localize]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ask,
|
ask,
|
||||||
edit,
|
edit,
|
||||||
index,
|
index,
|
||||||
|
agent,
|
||||||
assistant,
|
assistant,
|
||||||
enterEdit,
|
enterEdit,
|
||||||
conversation,
|
conversation,
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ export default function useMessageHelpers(props: TMessageProps) {
|
||||||
const modelKey = message?.model ?? '';
|
const modelKey = message?.model ?? '';
|
||||||
|
|
||||||
return agentMap ? agentMap[modelKey] : undefined;
|
return agentMap ? agentMap[modelKey] : undefined;
|
||||||
}, [agentMap, conversation?.endpoint]);
|
}, [agentMap, conversation?.endpoint, message?.model]);
|
||||||
|
|
||||||
const regenerateMessage = () => {
|
const regenerateMessage = () => {
|
||||||
if ((isSubmitting && isCreatedByUser === true) || !message) {
|
if ((isSubmitting && isCreatedByUser === true) || !message) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue