-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[feature] Embed assistants #1489
base: main
Are you sure you want to change the base?
Conversation
3194ba5
to
54f1570
Compare
|
||
document.addEventListener('DOMContentLoaded', function() { | ||
const button = document.createElement('button'); | ||
button.className = 'fixed bottom-5 right-5 z-50 px-1.5 py-1 bg-blue-500 text-white rounded cursor-pointer hover:bg-blue-600 transition-colors flex items-center focus:outline-none'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how is it going to work with tailwindcss?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will convert it back to regular css once we agree on the design
ed116a5
to
8749982
Compare
b19cc4b
to
fb52674
Compare
<!-- TODO: remove --> | ||
{#if !$page.data.embeddedAssistantId} | ||
<script | ||
src="http://localhost:5173/chat/api/assistant/{$page.data.assistants.at(-1) | ||
._id}/embed-snippet" | ||
defer | ||
></script> | ||
{/if} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to make testing the embedded assistants easier, I'm embedding hf assistant inside the chat-ui. These lines would be removed before merging to main
.
you can change {$page.data.assistants.at(-1)._id}
this part that grabs the last assistant id to any specific local assistant id if you want
this is really cool! will do a deeper review but loving this already 🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
works great ! found one bug and the rest are more open ended comments, let me know what you think!
src/routes/settings/(nav)/assistants/[assistantId]/+page.svelte
Outdated
Show resolved
Hide resolved
@@ -194,6 +199,26 @@ | |||
</div> | |||
</div> | |||
|
|||
<div> | |||
<h2 class="b-2 inline font-semibold">Embed this assistant</h2> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just my opinion but I think this is kind of an advanced feature and it's very visible in the UI of assistants atm
Maybe a button that copies the code to clipboard with an explainer text would be enough and take less space ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it can grow the usage of HuggingChat I think it's fine if it's stays well visible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes same
const script = `(function() { | ||
function resizeIframeToContentSize(iframe) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, i'm curious if there's a way to do this that's more maintainable ? it works great but i can imagine it would be very difficult to modify in the future
i know there's a render()
method from svelte you can use to get the HTML for a component, we use something similar in thumbnails (
chat-ui/src/routes/assistant/[assistantId]/thumbnail.png/+server.ts
Lines 44 to 55 in c544c28
const renderedComponent = (ChatThumbnail as unknown as SvelteComponent).render({ | |
name: assistant.name, | |
description: assistant.description, | |
createdByName: assistant.createdByName, | |
avatar, | |
}); | |
const reactLike = html( | |
"<style>" + renderedComponent.css.code + "</style>" + renderedComponent.html | |
); | |
const svg = await satori(reactLike, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or simpler, make the JS snippet completely static (a static file) that gets the assistant's id from a property in a <a>
link inside the embedding webpage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<script src="https://link/to/static.js"></script>
<a huggingchat-assistant="66017fca" href="https://hf.co/chat/assistant/66017fca">Chat with {Assistant}</a>
export async function GET({ params }) { | ||
const { id } = params; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nit: should the route be called embed-snippet.js ?
Co-authored-by: Nathan Sarrazin <[email protected]>
const iframe = document.createElement('iframe'); | ||
iframe.className = 'w-full'; | ||
iframe.style.height = '400px'; // Set an initial height | ||
iframe.src = \`http://localhost:5173/chat/?embeddedAssistantId=${id}\`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will have to be configurable using the base path I guess in order to work on self-hosted versions
just thinking out loud, would it be interesting to have the script try to find an existing button in the dom? for example if there's already a button with id This would let people integrate the button where they want on the page with their own styling, with fallback on the absolutely positioned button |
Description
Users can now create tools and connect their tools to their assistants (read here), making for use cases such as: create an assistant that queries your websites and chats about your website.
This PR adds an ability where users can embed their assistants on their websites.
Step1: under assistants settings, there will be
script
tag that can be put on a website's html head section.Step2:
HF Chat
button will appear on the bottom right section of your website.Step3: When you click on
HF Chat
button, a chat window modal with minimal hf/hf-chat chrome will appearTesting locally
Reviewing
when reviewing make sure to click
Hide whitespace
to see the actual diffScreen recording
Screen.Recording.2024-09-28.at.11.00.44.mov
it may look bit confusing in the video because I'm embedding hf-chat inside hf-chat locally for testing purposes. but you can imagine the hf-chat modal being embedded on any arbitrary website