Skip to content

Commit

Permalink
doc: readme update (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianmusial committed Mar 13, 2024
1 parent 7b2414c commit af6ad6f
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 20 deletions.
70 changes: 56 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,53 @@
<p align="center">
<a href="https://boldare.com/" target="blank">
<img src="https://szukampracy.pl/uploads/download_5baaafea22d41.png" width="160" alt="Boldare" />
<img src="https://assistant.ai.boldare.dev/assets/boldare-circle.png" width="160" alt="Boldare" />
</a>
</p>

<p align="center">
<a href="https://www.npmjs.com/package/@boldare/assistant-ai" target="_blank">
NPM
</a>
</p>

# 馃 AI Assistant

Introducing the NestJS library, designed to harness the power of OpenAI's Assistant, enabling developers to create highly efficient, scalable, and rapid AI assistants and chatbots. This library is tailored for seamless integration into the NestJS ecosystem, offering an intuitive API, WebSockets, and tools that streamline the development of AI-driven interactions. Whether you're building a customer service bot, a virtual assistant, or an interactive chatbot for engaging user experiences, our library empowers you to leverage cutting-edge AI capabilities with minimal effort.

## 馃殌 Features

#### AI Assistant library features
- **WebSockets**: The library provides a WebSocket server for real-time communication between the client and the assistant.
- **REST API**: The library provides a REST API for communication with the assistant.
- **Function calling**: The library provides a way to create functions, which allows you to extend the assistant's capabilities with custom logic.
- **File support**: The library provides a way to add files to the assistant, which allows you to extend the assistant's knowledge base with custom data.
- **TTS (Text-to-Speech)**: The library provides a way to convert text to speech, which allows you to create voice-based interactions with the assistant.
- **STT (Speech-to-Text)**: The library provides a way to convert speech to text, which allows you to create voice-based interactions with the assistant.

#### Additional features in the repository
- **Embedded chatbot**: The library provides a way to embed the chatbot on various websites through JavaScript scripts.
- **Chatbot client application**: The repository includes an example client application (SPA) with a chatbot.

## Getting started

In this section, you will learn how to integrate the AI Assistant library into your NestJS application. The following steps will guide you through the process of setting up the library and creating simple functionalities.

### Step 0: Prerequiring

Before you start, you will need to have an account on the OpenAI platform and an API key. You can create an account [here](https://platform.openai.com/).

Open or create your NestJS application where you would like to integrate the AI Assistant. If you don't have a NestJS application yet, you can create one using the following command:

```bash
$ nest new project-name
nest new project-name
```

### Step 1: Installation

Install the library using npm:

```bash
$ npm i @boldare/ai-assistant --save
npm i @boldare/ai-assistant --save
```

### Step 2: Env variables
Expand All @@ -33,7 +57,7 @@ Set up your environment variables, create environment variables in the `.env` fi
Create a `.env` file in the root directory of your project and populate it with the necessary secrets:

```bash
$ touch .env
touch .env
```

Add the following content to the `.env` file:
Expand Down Expand Up @@ -84,6 +108,18 @@ Import the AI Assistant module with your configuration into the module file wher
export class ChatbotModule {}
```

Automatically, the library will add WebSockets ([chat.gateway.ts](libs/ai-assistant/src/lib/chat/chat.gateway.ts)) and a [REST API](https://assistant.ai.boldare.dev/api/docs) for the assistant. The WebSocket server will be available at the `/` endpoint, and the [REST API](https://assistant.ai.boldare.dev/api/docs) will be available at the `/api` endpoint (depending on the API prefix).

#### Websockets events

Currently, the library provides the following WebSocket events:

| Event name | Description |
|--------------------|----------------------------------------------------------|
| `send_message` | The event is emitted when the user sends a message. |
| `message_received` | The event is emitted when the assistant sends a message. |


### Step 4: Function calling

Create a new service that extends the `AgentBase` class, fill the definition and implement the `output` method.
Expand Down Expand Up @@ -124,6 +160,8 @@ export class GetNicknameAgent extends AgentBase {
}
```

More examples can be found in the [agents](apps/api/src/app/chat/agents) directory.

Import the service into the module file where you intend to use it:

```js
Expand Down Expand Up @@ -168,36 +206,40 @@ The repository includes a library with an AI assistant as well as other useful p
### Step 1: Install dependencies

```bash
$ npm install
npm install
```

### Step 2: Env variables

Set up your environment variables, copy the `.env.dist` file to `.env` file in the root directory of the project, and populate it with the necessary secrets.

```bash
$ cp .env.dist .env
cp .env.dist .env
```

### Step 3: Run applications

```bash
# Start the app (api and spa)
$ npm run start:dev
npm run start:dev

# Start the api
$ npm run start:api
npm run start:api

# Start the spa
$ npm run start:spa
npm run start:spa
```

Now you can open your browser and navigate to:

| URL | Description |
| ------------------------------ | --------------------------- |
| http://localhost:4200/ | Client application (SPA) |
| http://localhost:3000/api/ | API application |
| http://localhost:3000/api/docs | API documentation (swagger) |
| URL | Description |
|--------------------------------|-----------------------------------------|
| http://localhost:4200/ | Client application (Angular) |
| http://localhost:3000/ | API application, WebSockets (socket.io) |
| http://localhost:3000/api/ | API endpoints |
| http://localhost:3000/api/docs | API documentation (swagger) |

### 馃帀 Happy coding 馃帀

# License
`@boldare/ai-assistant` is MIT licensed
2 changes: 1 addition & 1 deletion apps/api/src/app/chat/chat.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import { assistantConfig } from './chat.config';
import { AgentsModule } from './agents/agents.module';

@Module({
imports: [AssistantModule.forRoot(assistantConfig), AgentsModule],
imports: [AgentsModule, AssistantModule.forRoot(assistantConfig)],
})
export class ChatModule {}
2 changes: 1 addition & 1 deletion apps/spa/src/app/modules/+chat/shared/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class ChatService {
}

isTextMessage(message: ThreadMessage): boolean {
return message.content[0].type === 'text';
return message.content?.[0]?.type === 'text';
}

parseMessages(thread: GetThreadResponseDto): Message[] {
Expand Down
Binary file added apps/spa/src/assets/boldare-circle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions apps/spa/src/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export const environment = {
env: 'prod',
appUrl: 'https://ai-assistant-c8b469d88808.herokuapp.com',
apiUrl: 'https://ai-assistant-c8b469d88808.herokuapp.com/api',
websocketUrl: 'https://ai-assistant-c8b469d88808.herokuapp.com',
appUrl: 'https://assistant.ai.boldare.dev',
apiUrl: 'https://assistant.ai.boldare.dev/api',
websocketUrl: 'https://assistant.ai.boldare.dev',
isThreadMemorized: true,
isAudioEnabled: true,
isTranscriptionEnabled: true,
Expand Down
2 changes: 1 addition & 1 deletion libs/ai-embedded/src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const environment = {
env: 'prod',
appUrl: 'https://ai-assistant-c8b469d88808.herokuapp.com',
appUrl: 'https://assistant.ai.boldare.dev',
};

0 comments on commit af6ad6f

Please sign in to comment.