You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<ahref="https://www.boldare.com/services/ai-software-development-consulting/"target="_blank">How we can help you</a>
12
13
</p>
13
14
15
+
14
16
# 🤖 AI Assistant
17
+
`@boldare/openai-assistant` - library to kickstart your AI Assistant development under 15 minutes.
18
+
19
+
Introducing the NestJS library. Whether you're building a virtual assistant, or an interactive chatbot for engaging user experiences, our library empowers you to leverage cutting-edge AI capabilities with minimal effort.
20
+
21
+
**The library provides ready-to-use API endpoints** handling your assistant and WebSocket server for real-time communication between the client and the assistant. Install the library and paste the config to get it running.
15
22
16
-
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.
23
+
## 📚 Watch the tutorial
24
+
25
+
[](https://www.youtube.com/watch?v=rxPdFat90qY)
17
26
18
27
## 🚀 Features
19
28
20
-
####AI Assistant library features
29
+
### AI Assistant library features
21
30
22
-
-**Function calling**: The library provides a way to create functions, which allows you to extend the assistant's capabilities with custom logic.
23
-
-**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.
24
-
-**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.
25
-
-**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.
26
-
-**WebSockets**: The library provides a WebSocket server for real-time communication between the client and the assistant.
27
-
-**REST API**: The library provides a REST API for communication with the assistant.
31
+
-**Function calling**: create functions, so assistant can execute your custom logic!
32
+
-**TTS (Text-to-Speech)**: convert text to speech, so you can hear your assistant!
33
+
-**STT (Speech-to-Text)**: convert speech to text, so you can make conversation easier!
34
+
-**File support**: add files to the assistant, so you can extend assistant's knowledge base with custom data!
35
+
-**WebSockets**: establish WebSocket server for real-time communication between the client and the assistant!
36
+
-**REST API**: Just use ready REST API for communication with the assistant!
37
+
-**Vision with GPT-4o** - use the GPT-4o and make your assistant understand images and generate text based on them!
28
38
29
39
#### Additional features in the repository
30
40
31
-
-**Embedded chatbot**: The library provides a way to embed the chatbot on various websites through JavaScript scripts.
32
-
-**Chatbot client application**: The repository includes an example client application (SPA) with a chatbot.
41
+
The repository contains a library but also provides additional features. You can just clone the repository and use it instantly to gain from all features:
42
+
43
+
-**Embedded chatbot**: embed the chatbot on various websites through JavaScript scripts!
44
+
-**Chatbot client application**: use ready client application (SPA) with a chatbot!
33
45
34
46
## 🏆 Getting started
35
47
36
48
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.
37
49
38
-
### Step 0: Prerequisites
50
+
<!-- The information that after this steps we will have the endpoints ready -->
39
51
40
-
Install Node.js which includes Node Package Manager (`^20.0.0` version).
52
+
### Step 0: Prerequisites
41
53
42
-
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/).
54
+
- Node.js (`^20.0.0` version)
55
+
- npm (`^10.0.0` version)
56
+
- NestJS (`^10.0.0` version)
57
+
- OpenAI (`^4.51.0` version)
58
+
- OpenAI API key
43
59
44
-
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:
60
+
Open or create your NestJS application where you would like to integrate the AI Assistant. To create a new NestJS application, use the following command:
45
61
46
62
```bash
47
63
nest new project-name
48
64
```
49
65
66
+
Now you have to install the packages. Go to the next step.
67
+
50
68
### Step 1: Installation
51
69
52
-
Install the library using npm:
70
+
Make sure you are in the root directory of your project.
71
+
Install the library and `openai` package using npm:
53
72
54
73
```bash
55
74
npm i @boldare/openai-assistant openai --save
56
75
```
57
76
77
+
The library is installed but we have to configure it. Go to the next step.
78
+
58
79
### Step 2: Env variables
59
80
60
81
Set up your environment variables, create environment variables in the `.env` file in the root directory of the project, and populate it with the necessary secrets. The assistant ID is optional and serves as a unique identifier for your assistant. When the environment variable is not set, the assistant will be created automatically. You can use the assistant ID to connect to an existing assistant, which can be found in the OpenAI platform after creating an assistant.
@@ -71,38 +92,126 @@ Add the following content to the `.env` file:
71
92
# OpenAI API Key
72
93
OPENAI_API_KEY=
73
94
74
-
# Assistant ID - leave it empty if you don't have an assistant yet
95
+
# Assistant ID - leave it empty if you don't have an assistant to reuse
75
96
ASSISTANT_ID=
76
97
```
77
98
78
-
Please note that the `.env` file should not be committed to the repository. Add it to the `.gitignore` file to prevent it from being committed.
99
+
Please note that the `.env` file should not be committed to the repository. *Add the `.env` file to the `.gitignore`* file to prevent it from being committed.
100
+
101
+
This was the first step needed to run the library. The next step is to configure the assistant.
79
102
80
103
### Step 3: Configuration
81
104
82
105
The library provides a way to configure the assistant with the `AssistantModule.forRoot` method. The method takes a configuration object as an argument. Create a new configuration file like in a [sample configuration file (chat.config.ts)](apps%2Fapi%2Fsrc%2Fapp%2Fchat%2Fchat.config.ts) and fill it with the necessary configuration.
83
106
84
-
More details about the configuration with code examples can be found in the [wiki](https://github.com/boldare/openai-assistant/wiki/%F0%9F%A4%96-AI-Assistant#step-3-configuration).
More details about the configuration can be found in the [wiki](https://github.com/boldare/openai-assistant/wiki/%F0%9F%A4%96-AI-Assistant#step-3-configuration).
137
+
138
+
#### What is this step for?
139
+
From now you can run your application and call the assistant.
85
140
86
141
87
142
### Step 4: Function calling
88
143
144
+
Function calling allows you to extend the assistant's capabilities with custom logic. **If you are not going to use function calling you can jump to: [Step 5: Testing](#step-5-running-the-application-and-testing).**
145
+
89
146
Create a new service that extends the `AgentBase` class, fill the definition and implement the `output` method.
90
147
91
-
- The `output` method is the main method that will be called when the function is invoked.
92
-
- The `definition` property is an object that describes the function and its parameters.
148
+
- The `output` method is the main method that will be called when the function is invoked by the assistant.
149
+
- The `definition` property is an object that describes the function and its parameters so the assistant can understand how to call it.
93
150
94
151
For more information about function calling, you can refer to the [OpenAI documentation](https://platform.openai.com/docs/assistants/tools/defining-functions).
95
152
96
153
The instructions for creating a function can be found in the [wiki](https://github.com/boldare/openai-assistant/wiki/%F0%9F%A4%96-AI-Assistant#step-4-function-calling), while examples can be found in the [agents](apps/api/src/app/chat/agents) directory.
97
154
155
+
#### What is this step for?
156
+
157
+
If you've defined a function and the output method, you can now call it from the assistant just by asking him to do the action described in the function definition.
158
+
159
+
160
+
### Step 5: Running the application and testing
161
+
162
+
Run your application and this will allow you to test the assistant.
163
+
164
+
```bash
165
+
# use this if you are using the repository:
166
+
npm run start:dev
167
+
168
+
# if you are using your own NestJS application, please check the npm scripts in the package.json file
169
+
# defualt command for NestJS is:
170
+
npm run start
171
+
```
172
+
173
+
Then you can test the assistant.
174
+
1. First, you need to create a thread. You can create one
175
+
by sending a POST request to the `/assistant/threads` endpoint with the **empty object in the body**.
176
+
2. Then you can send a message to the assistant by sending a POST request to the `/assistant/chat` endpoint with the following body:
177
+
```json
178
+
{
179
+
"threadId": "your-thread-id",
180
+
"content": "Hello, how are you?"
181
+
}
182
+
```
183
+
3. The assistant will respond with a message. You can send more messages to the assistant by sending a POST request to the `/assistant/chat` endpoint with the same body as in step 2.
184
+
185
+
Congrats! You have successfully integrated the AI Assistant library into your NestJS application. 🎉
186
+
98
187
---
99
188
100
-
# 👨💻 Repository
189
+
190
+
## 🤔 Are you stuck?
191
+
192
+
Boldare's engineers are here to help you. If you have any questions or need help with the implementation, feel free to **[click here to book a call with one of our engineers.](https://calendly.com/olivier-halupczok/30min)**
193
+
194
+
**Learn more how [Boldare can help you with AI development on our website](https://www.boldare.com/services/ai-software-development-consulting/).**
195
+
196
+
You can also ask questions in the [GitHub Discussions](https://github.com/boldare/openai-assistant/discussions) section.
197
+
198
+
---
199
+
200
+
## 👨💻 Repository
101
201
102
202
The complete documentation on how to run the demo with all applications and libraries from the repository can be found in the [wiki](https://github.com/boldare/openai-assistant/wiki/%F0%9F%91%A8%E2%80%8D%F0%9F%92%BB-Repository).
103
203
104
204
---
105
205
106
-
# License
206
+
## Contributions
207
+
208
+
Would you like to see new features in the library?
209
+
- You can freely contribute to the project! Just create a pull request with your changes.
210
+
-[Talk your idea over with one of our engineers.](https://calendly.com/olivier-halupczok/30min)
211
+
- You can also [post your idea here](https://github.com/boldare/openai-assistant/discussions).
212
+
213
+
---
214
+
215
+
## License
107
216
108
-
`@boldare/openai-assistant` is MIT licensed
217
+
`@boldare/openai-assistant`and this repository is MIT licensed
0 commit comments