DEV Community

victor forissier
victor forissier

Posted on

🔥 8 React components with LLMs 🤖

We’re 3 devs who started an open-source library of React components with integrated LLM calls. It would mean the world if you gave us a star on GitHub!

  • Use directly in React client-side code
  • Just wrap a provider & calls work through our API (also open-source.)

Probably half of those 8 components are useless. But tell us on our Discord or in the comments! We'll improve those you like, and make those you want.

⚠️ To test the components in your app, first create a Polyfire project and wrap your app with the <PolyfireProvider /> passing your project ID as a prop → Here is how to set it up.


1. <TextSummary />

Displays a summary of a long text you pass in as a prop. It also caches the summary on our API after generation so you only pay LLM cost once.

Code

<TextSummary 
    prompt="Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, `and what is the use of a book,' thought Alice `without pictures or conversation?'
        So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her.
        There was nothing so very remarkable in that; nor did Alice think it so very much out of the way to hear the Rabbit say to itself, `Oh dear! Oh dear! I shall be late!' (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually took a watch out of its waistcoat-pocket, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and fortunately was just in time to see it pop down a large rabbit-hole under the hedge." 
    stream={false} 
/>
Enter fullscreen mode Exit fullscreen mode

Result

Text summary result


2. <AutoCompleteTextArea />

Turns a regular Textarea element into a Copilot-like with autocomplete.

Code

<AutoCompleteTextArea />
Enter fullscreen mode Exit fullscreen mode

Result

AutoCompleteTextArea Result


3. <AutoCompleteInput />

Like but extends an Input instead of a Textarea.

Code

<AutoCompleteInput />
Enter fullscreen mode Exit fullscreen mode

Result

AutoCompleteInput Result


4. <TextTranslated />

Translates, caches and displays the text you pass in, in the language of your choice.

Code

<TextTranslated 
    text="Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, `and what is the use of a book,' thought Alice `without pictures or conversation?'
        So she was considering in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her.
        There was nothing so very remarkable in that; nor did Alice think it so very much out of the way to hear the Rabbit say to itself, `Oh dear! Oh dear! I shall be late!' (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural); but when the Rabbit actually took a watch out of its waistcoat-pocket, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to take out of it, and burning with curiosity, she ran across the field after it, and fortunately was just in time to see it pop down a large rabbit-hole under the hedge."
    language="french" 
/>
Enter fullscreen mode Exit fullscreen mode

Result

TextTranslated Result


5. <ImageGenerated />

Generates, caches and displays an AI generated image based on your prompt.

Code

<ImageGenerated prompt={"funny smiley with beautiful teeth"} model={dall-e-3} />
Enter fullscreen mode Exit fullscreen mode

Result

ImageGenerated Result


6. <TextGenerated />

Generates, caches and displays an LLM answer based on the prompt passed as a prop.

Code

<TextGenerated prompt={"Make a funny pun"} stream={false} />
Enter fullscreen mode Exit fullscreen mode

Result

TextGenerated Result


7. <Chat />

Set of components that reproduce a basic ChatGPT interface, you can customize it to make your chatbot or app.

Code

<Chat.Sidebar>
  <Chat.SidebarHeader />
  <Chat.NewChatButton />
  <Chat.ChatList />
  <Chat.SidebarButtonGroup>
    <Chat.LogoutButton onClick={() => auth.logout()} />
  </Chat.SidebarButtonGroup>
</Chat.Sidebar>
<Chat.View>
  <Chat.History
    HistoryItemComponent={Chat.RoundedChatListItem}
    HistoryLoadingComponent={Chat.RoundedHistoryLoadingComponent}
    HistoryEmptyComponent={Chat.HistoryEmptyComponent}
  />
  <Chat.ScrollToBottomButton
    disabled={chat.isAtBottom}
    onClick={utils.onScrollToBottom}
  />
  <Chat.Prompt>
    <Chat.Input autoFocus />
    <Chat.SendButton />
  </Chat.Prompt>
</Chat.View>
Enter fullscreen mode Exit fullscreen mode

Result

Chat Result


8. <Login />

To use all the previous components, you need to connect to Polyfire Auth in someway (otherwise our API can’t distinguish expensive bots). If you have already auth setup, you can authenticate you Auth Token. But otherwise, you can log users in with Polyfire Auth using the usePolyfire() hook, but this component does it all for you.

Code

<Login
  termsOfService="https://example.com/tos"
  privacyPolicy="https://example.com/privacy"
>
  /*
        What to display when the user is logged in.
    */
</Login>
Enter fullscreen mode Exit fullscreen mode

Result

Login Result


Let's connect on X? :)
I'm here

Have you seen other cool AI React components?

Let me know about them in the comments :)

Top comments (1)

Collapse
 
blandine profile image
Blandine

Fireeee 🔥🔥🔥