An open API service indexing awesome lists of open source software.

https://github.com/michaelsolati/tldr-wikipedia

Talk to any Wikipedia article! - A LiveKit tech demo.
https://github.com/michaelsolati/tldr-wikipedia

Last synced: 12 months ago
JSON representation

Talk to any Wikipedia article! - A LiveKit tech demo.

Awesome Lists containing this project

README

          

# tldr Wikipedia

This is a demo project to show how to use LiveKit with the `livekit-client` and `@livekit/agents` JS libraries.

This demo is broken into two parts:

- A Chrome extension that adds a button to any Wikipedia page that allows you to start a LiveKit room to ask questions about the page.
- An express server that generates tokens and initializes an agent and a room with the information from the Wikipedia page to answer questions about.

## Running the demo

### Chrome extension

Build the Chrome extension by running:

```bash
cd extension
npm install
npm run build
```

Then load the unpacked extension in Chrome by going to `chrome://extensions`, enabling developer mode, and selecting the `dist` folder.

By default the extension will use the `localhost` server. To use a different server, set the `tokenUrl` param in `extension/src/environment.ts` to the URL of the server you want to use.

### Server

First copy `server/.env.example` to `server/.env.local` and update the values to match your LiveKit project, add your OpenAI API key to the `OPENAI_API_KEY`, and set `MODE` to `dev`.

Then run the server:

```bash
cd server
npm install
npm run build
npm run start
```

The server will be running on `http://localhost:8080`.

### Wikipedia

Go to any Wikipedia article and click the button in the bottom right corner to start a LiveKit room and ask any questions about the page.

## How does it work?

The Chrome extension uses the `livekit-client` library to connect to the LiveKit room created by the express server. That process begins by sending the URL of the Wikipedia page to the server, which then uses the `livekit-server-sdk` library to generate an access token a user can use to connect to a room as well as creating a room with the URL of the Wikipedia page sent by the extension. (See `server/src/api/token.ts`)

The server also runs the `@livekit/agents` CLI which is where we define the agent that will answer questions about the Wikipedia page. The agent is defined in `server/src/agents.ts` and basically does two things:

1. It takes the Wikipedia URL that `server/src/api/token.ts` used to create the room and uses scrapes all the content from the page, filtering out superflous content on the page in order to minimize how much data we send to OpenAI. This is done in the `getContentFromUrl` function.
2. We start a session with our agent and a specific prompt that asks the agent to answer questions about the Wikipedia page.

And that's it! The agent will now be able to answer questions about the Wikipedia page in the LiveKit room created by the extension.