🔥 8 React components with LLMs 🤖
Published: 2024-01-10 15:59:52

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](https://github.com/polyfire-ai/polyfire-js)!

* Use directly in **React client-side code**
* Just **wrap a provider** & calls work through our API ([also open-source](https://github.com/polyfire-ai/polyfire-api).)

Probably half of those 8 components are useless. But [tell us on our Discord](https://discord.polyfire.com/) 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.](https://docs.polyfire.com/docs/basic-usage)**

---

## 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

```jsx
<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} 
/>
```

### Result

![Text summary result](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/awsd5cf0p3jy9xnc15ns.png)

---

## 2. \<AutoCompleteTextArea /\>

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

### Code

```jsx
<AutoCompleteTextArea />
```

### Result

![AutoCompleteTextArea Result](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5fxm1vqpokepuyebzju2.png)

---

## 3. \<AutoCompleteInput /\>

Like <AutoCompleteTextArea /> but extends an Input instead of a Textarea.

### Code

```jsx
<AutoCompleteInput />
```

### Result

![AutoCompleteInput Result](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ljmu82wxeigd1ay1lraw.png)

---

## 4. \<TextTranslated /\>

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

### Code

```jsx
<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" 
/>
```

### Result

![TextTranslated Result](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8j50ezqlkhdtpxrxcau3.png)

---

## 5. \<ImageGenerated /\>

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

### Code

```jsx
<ImageGenerated prompt={"funny smiley with beautiful teeth"} model={dall-e-3} />
```

### Result


![ImageGenerated Result](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5vshsl3hi49fufxit4mg.png)

---

## 6. \<TextGenerated /\>

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

### Code

```jsx
<TextGenerated prompt={"Make a funny pun"} stream={false} />
```

### Result


![TextGenerated Result](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vlzhs5irtyeyfdg649vx.png)

---

## 7. \<Chat /\>

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

### Code

```jsx
<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>
```

### Result


![Chat Result](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/slpv7ydkl5gfzbj37bzb.png)

---

## 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

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

### Result

![Login Result](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r54ofi0vfwoh7fixmdix.png)

---

Let's connect on X? :)
[I'm here](x.com/victorforissier)

Have you seen other cool AI React components? 

Let me know about them in the comments :)