diff --git a/api/app/clients/BaseClient.js b/api/app/clients/BaseClient.js index 05ea5c0149..a57e424889 100644 --- a/api/app/clients/BaseClient.js +++ b/api/app/clients/BaseClient.js @@ -2,6 +2,7 @@ const crypto = require('crypto'); const fetch = require('node-fetch'); const { supportsBalanceCheck, + isAgentsEndpoint, ErrorTypes, Constants, CacheKeys, @@ -66,6 +67,17 @@ class BaseClient { 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. * @param {TMessage} responseMessage @@ -558,7 +570,7 @@ class BaseClient { parentMessageId: userMessage.messageId, isCreatedByUser: false, isEdited, - model: this.modelOptions.model, + model: this.getResponseModel(), sender: this.sender, promptTokens, iconURL: this.options.iconURL, diff --git a/client/src/components/Messages/ContentRender.tsx b/client/src/components/Messages/ContentRender.tsx index d3f58942b5..9039a0d6c2 100644 --- a/client/src/components/Messages/ContentRender.tsx +++ b/client/src/components/Messages/ContentRender.tsx @@ -35,9 +35,10 @@ const ContentRender = memo( isSubmittingFamily, }: ContentRenderProps) => { const { - ask, + // ask, edit, index, + agent, assistant, enterEdit, conversation, @@ -55,6 +56,8 @@ const ContentRender = memo( setCurrentEditId, }); + console.log('ContentRender', { agent, conversation, msg }); + const fontSize = useRecoilValue(store.fontSize); const handleRegenerateMessage = useCallback(() => regenerateMessage(), [regenerateMessage]); // const { isCreatedByUser, error, unfinished } = msg ?? {}; @@ -108,7 +111,12 @@ const ContentRender = memo(
- +
diff --git a/client/src/hooks/Messages/useMessageActions.tsx b/client/src/hooks/Messages/useMessageActions.tsx index 3c481476df..3a7e1d59d3 100644 --- a/client/src/hooks/Messages/useMessageActions.tsx +++ b/client/src/hooks/Messages/useMessageActions.tsx @@ -1,8 +1,13 @@ import { useRecoilValue } from 'recoil'; import { useCallback, useMemo } from 'react'; -import { isAssistantsEndpoint } from 'librechat-data-provider'; +import { isAssistantsEndpoint, isAgentsEndpoint } from 'librechat-data-provider'; import type { TMessageProps } from '~/common'; -import { useChatContext, useAddedChatContext, useAssistantsMapContext } from '~/Providers'; +import { + useChatContext, + useAddedChatContext, + useAssistantsMapContext, + useAgentsMapContext, +} from '~/Providers'; import useCopyToClipboard from './useCopyToClipboard'; import { useAuthContext } from '~/hooks/AuthContext'; import useLocalize from '~/hooks/useLocalize'; @@ -35,6 +40,8 @@ export default function useMessageActions(props: TMessageActions) { () => (isMultiMessage === true ? addedConvo : rootConvo), [isMultiMessage, addedConvo, rootConvo], ); + + const agentMap = useAgentsMapContext(); const assistantMap = useAssistantsMapContext(); const { text, content, messageId = null, isCreatedByUser } = message ?? {}; @@ -56,6 +63,26 @@ export default function useMessageActions(props: TMessageActions) { return assistantMap?.[endpointKey] ? assistantMap[endpointKey][modelKey] : undefined; }, [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( () => (isMultiMessage === true ? isSubmittingAdditional : isSubmittingRoot), [isMultiMessage, isSubmittingAdditional, isSubmittingRoot], @@ -74,17 +101,20 @@ export default function useMessageActions(props: TMessageActions) { const messageLabel = useMemo(() => { if (message?.isCreatedByUser === true) { return UsernameDisplay ? (user?.name ?? '') || user?.username : localize('com_user_message'); + } else if (agent) { + return agent.name ?? 'Assistant'; } else if (assistant) { return assistant.name ?? 'Assistant'; } else { return message?.sender; } - }, [message, assistant, UsernameDisplay, user, localize]); + }, [message, agent, assistant, UsernameDisplay, user, localize]); return { ask, edit, index, + agent, assistant, enterEdit, conversation, diff --git a/client/src/hooks/Messages/useMessageHelpers.tsx b/client/src/hooks/Messages/useMessageHelpers.tsx index 873dae9b33..2db72031e4 100644 --- a/client/src/hooks/Messages/useMessageHelpers.tsx +++ b/client/src/hooks/Messages/useMessageHelpers.tsx @@ -103,7 +103,7 @@ export default function useMessageHelpers(props: TMessageProps) { const modelKey = message?.model ?? ''; return agentMap ? agentMap[modelKey] : undefined; - }, [agentMap, conversation?.endpoint]); + }, [agentMap, conversation?.endpoint, message?.model]); const regenerateMessage = () => { if ((isSubmitting && isCreatedByUser === true) || !message) {