I have a problem, i need to be able to send annotations from my message rows to the…
- User
I have a problem, i need to be able to send annotations from my message rows to the composer, how can i handle this without passing the annotations as an arguement? The annotaitons are stored in a usestate. I want to access the annotAddedDict (usestate) from the last 2 message rows then assemble it into a prompt. import { ChangeEvent, useEffect, useRef } from ‘react’;
import { Tool } from ‘@/cohere-client’; import { ComposerFiles } from ‘@/components/Conversation/ComposerFiles’; import { ComposerMenu } from ‘@/components/Conversation/ComposerMenu’; import { Icon, STYLE_LEVEL_TO_CLASSES } from ‘@/components/Shared’; import { CHAT_COMPOSER_TEXTAREA_ID } from ‘@/constants’; import { useIsDesktop } from ‘@/hooks/breakpoint’; import { useFileActions } from ‘@/hooks/files’; import { useSettingsStore } from ‘@/stores’; import { ChatMessage } from ‘@/types/message’; import { cn } from ‘@/utils’;
type Props = { isStreaming: boolean; value: string; messages: ChatMessage[]; streamingMessage: ChatMessage | null; onStop: VoidFunction; onSend: (message?: string, tools?: Tool[]) => void; onChange: (e: ChangeEvent) => void; onUploadFile: (e: React.ChangeEvent) => void; };
const Composer: React.FC = ({ value, isStreaming, onSend, onChange, onStop, onUploadFile, }) => { const isReadyToReceiveMessage = !isStreaming; const canSend = isReadyToReceiveMessage && value.trim().length > 0; const { settings: { isMobileConvListPanelOpen }, } = useSettingsStore(); const { uploadingFiles, composerFiles, deleteComposerFile, deleteUploadingFile } = useFileActions(); const isDesktop = useIsDesktop(); const textareaRef = useRef(null);
const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === ‘Enter’) { // Do expected default behaviour (add a newline inside of the textarea) if (e.shiftKey) return;
e.preventDefault(); if (canSend) { onSend(undefined); } } };
useEffect(() => { const textarea = textareaRef.current; if (textarea) { textarea.style.height = ‘auto’; textarea.style.height = ${textarea.scrollHeight}px;
// if the content overflows the max height, show the scrollbar if (textarea.scrollHeight > textarea.clientHeight + 2) { textarea.style.overflowY = ‘scroll’; } else { textarea.style.overflowY = ‘hidden’; } } }, [value]);
useEffect(() => { if (!textareaRef.current) return; let timer: NodeJS.Timeout; if (!isMobileConvListPanelOpen || isDesktop) { /**
- The textarea focus state is delayed so that the slide in transition can finish on smaller screens
- See chat/src/components/Layout.tsx for the transition duration and details */ timer = setTimeout(() => { textareaRef.current?.focus(); }, 500); } else { textareaRef.current?.blur(); } return () => clearTimeout(timer); }, [isMobileConvListPanelOpen, isDesktop, textareaRef.current]);
return (
const Square = () => ( <svg xmlns=“http://www.w3.org/2000/svg” width=“1em” height=“1em” fill=“currentColor” stroke=“currentColor” strokeWidth=“0” viewBox=“0 0 448 512”
- Assistant
- User
keep in mind, this needs to grab annotDicts from multiple messageRows that exist in the component.
- Assistant
- User
- Assistant
- User
i need a context that allows me to grab an array of all the dictionaries from the messageRows in here: const Messages = React.memo(forwardRef<HTMLDivElement, MessagesProps>(function MessagesInternal( { startOptionsEnabled, onRetry, messages, streamingMessage, onPromptSelected }, ref ) { const isConversationEmpty = messages.length === 0; //console.log("THE MSGS") //console.log(messages) //console.log(streamingMessage) return ( {startOptionsEnabled && ( )}
<div className="mt-auto flex flex-col gap-y-4 md:gap-y-6"> {messages.map((m, i) => { const isLastInList = i === messages.length - 1; m.annotations = {} //Initialize the annotations here! return ( <MessageRow key={i} message={m} isLast={isLastInList && !streamingMessage} order={i + 1} className={cn({ // Hide the last message if it is the same as the separate streamed message // to avoid a flash of duplicate messages. hidden: isLastInList && streamingMessage && isFulfilledMessage(streamingMessage) && isFulfilledMessage(m) && streamingMessage.generationId === m.generationId, })} onRetry={onRetry} /> ); })} {/** DO NOT REMOVE key this fixes the annotaiton from jumping.*/} {streamingMessage && ( <MessageRow key={messages.length} order={messages.length} message={streamingMessage} isLast={true} onRetry={onRetry} /> )} </div> </div> - Assistant
- User
I am confused, why do i have annotationContext? Cant i just use the dictionary annotDict present in every messageRow instance, have all of them passed to messageContainer via contextAPI?
- Assistant
- User
will context from messagerows present on other user screens be passed? or only those within messages?
- Assistant
- User
can you wrap this as an annotation Provider? const MessagingContainer: React.FC = (props) => { const { scrollViewClassName = '', ...rest } = props; return ( <ScrollToBottom initialScrollBehavior="auto" className={cn(ReservedClasses.MESSAGES, 'relative flex h-0 flex-grow flex-col')} scrollViewClassName={cn( 'md:!h-full !h-fit', 'flex relative mt-auto overflow-x-hidden', scrollViewClassName )} followButtonClassName="hidden" debounce={100} > <Content {...rest} /> ); }; export default memo(MessagingContainer);
- Assistant
- User
can i add a setter method of some sort instead of a updater method here? class Message(MessageBase): id: str created_at: datetime.datetime updated_at: datetime.datetime
generation_id: Union[str, None] position: int is_active: bool documents: List[Document] citations: List[Citation] files: List[File] annotations: List[Annotation] #added annotaitons agent: MessageAgent class Config: from_attributes = Trueclass UpdateMessage(BaseModel): annotations: Optional[List[Annotation]] = None description: Optional[str] = None
class Config: from_attributes = True - Assistant