Code Monkey home page Code Monkey logo

beakjs's Introduction

๐Ÿฆ Beak.js X (formerly Twitter) Follow npm (scoped)

Beak.js contains everything you need to create custom AI-powered assistants for your React app.

Key Features:

  • Built-in UI - Comes with a beautiful, fully customizable chat window.
  • Easy to Use - Integrates with your existing React app in just a few lines of code.
  • Open Source - Beak.js is open source and free to use.

Beak.js Screenshot

Getting Started

Installation

First up, add Beak.js to your project:

npm install @beakjs/react --save

# or with yarn
yarn add @beakjs/react

Setup

Next, wrap your app in the Beak component and add the assistant window:

import { Beak } from "@beakjs/react";

const App = () => (
  <Beak
    __unsafeOpenAIApiKey__="sk-..."
    instructions="Assistant is running in a web app and helps the user with XYZ."
  >
    <MyApp />
    <AssistantWindow />
  </Beak>
);

Now, you've got a chat window ready in the bottom right corner of your website. Give it a try!

Note: Don't expose your API key in public-facing apps - this is for development only. See Deployment for information on how to securely deploy your app without compromising your API key.

Making Beak.js work with your app

You can let the assistant carry out tasks in your app by setting up functions with useBeakFunction:

import { useBeakFunction } from "@beakjs/react";

const MyApp = () => {
  const [message, setMessage] = useState("Hello World!");

  useBeakFunction({
    name: "updateMessage",
    description: "This function updates the app's display message.",
    parameters: {
      message: {
        description: "A short message to display on screen.",
      },
    },
    handler: ({ message }) => {
      setMessage(message);

      return `Updated the message to: "${message}"`;
    },
  });

  return <div>{message}</div>;
};

Note that functions become available to the assistant as soon as their respective component is mounted. This is a powerful concept, ensuring that the assistant will be able to call functions relevant to the current context of your app.

Let the Assistant Know What's Happening On Screen

You can easily let the assistant know what it currently on screen by using useBeakInfo:

import { useBeakInfo } from "@beakjs/react";

const MyApp = () => {
  const [message, setMessage] = useState("Hello World!");

  useBeakInfo("current message", message);

  // ...
};

By using useBeakFunction together with useBeakInfo, your assistant can see what's happening on the screen and take action within your app depending on the current context.

Deployment

To keep your API key safe, we use a server side handler that forwards your assistant's requests to OpenAI. Furthermore, this handler can be used to add authentication and rate limiting to your assistant.

Currently, the following frameworks are supported:

Read more about secure deployment by clicking the links above.

Run the Demo

To run the demo, build the project and start the demo app:

git clone [email protected]:mme/beakjs.git && cd beakjs
yarn && yarn build
cd demo/frontend/presentation
echo "VITE_OPENAI_API_KEY=sk-your-openai-key" > .env
yarn && yarn dev

Then go to http://localhost:5173/ to see the demo.

Issues

Feel free to submit issues and enhancement requests.

License

MIT

Copyright (c) 2023, Markus Ecker

beakjs's People

Contributors

mme avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

beakjs's Issues

Secure API keys with a backend proxy

Right now, the API key can be extracted from the frontend code. Create a proxy to secure the API key.

Frameworks:

  • express.js
  • next.js
  • remix
  • standalone

Support "freezing" instructions to prevent prompt based attacks. CORS to prevent embedding. Add rate-limiting.

Online Demo

Adapt /demo so that there is an input field for the OpenAI API key and publish on beakjs.com

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.