-
-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
custom message renderer or wrapper #35
Comments
Thanks @Laurian for raising this, and for the well detailed suggestion. It is indeed something that I've been thinking about - as that message rendering component is quite important and responsible for a big part of the interaction with the LLM. I like your suggestion of a
With
What do you think? I'm moving this feature request into the Features Roadmap and I'll be prioritising it. |
@salmenus Were working on this feature and we need the unminified nlux-core.js To be able to interact with the message component effectively |
@TechWithTy are you using React or Vanilla JS ? It's fairly easy with core Vanilla JS. but requires more work with React. |
We are using ReactJS/Typescript And we are trying to modify this file but it is minified unfortunately |
@salmenus , since we're using ReactJS/Typescript and attempting to enhance our chat functionality, we're encountering challenges with modifying the minified nlux-core.js file. As our application primarily relies on React, we're seeking guidance on how to approach this task effectively. |
Ok. Given the numbers of requests, I'm prioritising this issue. Moving it to It's going to be similar to the JSX for user personas: You will be able to provide your own react component that can handle the rendering of the chat message. You'll have it ready in the next 48 hours. |
Awesome @salmenus |
Still WIP. I had to refactor the whole part of the library related to DOM rendering and update for a seemless support of JS and React. I'm aiming to publish a new version tomorrow with new rendering and support for custom messages. I'll keep you posted via this thread. |
Thank you, @salmenus |
Still work-in-progress. NPM not published yet. Progress Update:
I'll keep you posted via this thread once new NPM is published. |
Awesome @salmenus Thank you! |
This clearly took more than 48 hours! I had to do an entire refactoring of the view/UI layer of both React and JS ports of the library. |
Awesome can't wait! Is there any low hanging fruit we could help with? |
PR merged into main branch with new React implementation. RC following. |
Lets goo! |
Custom renderers are finally here ! 🎉 This has just been released as part of 2.1.0-beta You can give the feature a try in this code sandbox: The custom components provided as part of This major code change and React re-write will enable several other features (RSC, component streaming, etc). We're currently working on updating docs and improving theming (the last piece of this major code change). -- In action, from the code sandbox example linked above: const MyCustomResponseRenderer: ResponseRenderer<string> = (
props: FetchResponseComponentProps<string> | StreamResponseComponentProps<string>
) => {
console.log("Data fetched from LangServe!");
console.dir(props);
const propsForFetch = props as FetchResponseComponentProps<string>;
const propsForStream = props as StreamResponseComponentProps<string>;
const dataTransferMode = props.dataTransferMode as any;
return (
<>
{dataTransferMode === "fetch" && <div>{propsForFetch.content}</div>}
{dataTransferMode === "stream" && (<div ref={propsForStream.containerRef} />)}
<div>Footer Custom Response Component</div>
</>
);
}; <AiChat
adapter={adapter}
messageOptions={{
responseComponent: MyCustomResponseRenderer
}}
/> |
Reference doc on custom adapters is now available here: |
Examples on docs website with both streamed and batched custom adapters here: Also — |
Several chat UIs out there have extra widgets along a message like thumbs up / down, share, report, etc.
It would be handy to have a way to decorate the message box with interactive components.
I think there are 3 ways to approach this:
custom components to render messages
custom component to wrap the message (keep current rendering)
injecting a widget/markup in the current
nluxc-text-message-content
div
elementIn Discord @salmenus mentioned something along passing a custom rendered:
<AiChat messageRenderer={MyCustomMessageRenderer} />
type CustomMessageRenderer = (message: string, extras: OtherMessageRelatedInfo): ReactElement
But I guess this won't work in stream mode, I mean it will work as in fetch mode unless we make the component also deal with the streaming adapter.
Alternatively a wrapper would just decorate the message which is rendered by the original core component (
<AiChat />
renders<MyCustomMessageWrapper message={message} extras={extras}>{children}</My…>
) where{children}
is the original core component that does handle streaming, markdown, etc. And I guess while streaming themessage
andextras
props will get updated, maybe acomplete
prop (fed from the streaming adapter observer?) would be needed too to know that now I can interact with my decorations?Like 2, let's keep the original rendering but instead of wrapping it just add some custom component in React or markup in js:
<AiChat messageHeader={MyCustomMessageHeader} messageFooter={MyCustomMessageFooter} />
But even injecting plain markup would be enough with React, having
messageHeader={<div className="header"></div>}
would allow me to render what I need inside withcreatePortal
.It would be nice if the customisation could be done in a way to works at core component level, such that could be used in both js and react.
The text was updated successfully, but these errors were encountered: