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
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.
16
+
`@boldare/openai-assistant` - library to kickstart your AI Assistant development under 15 minutes.
17
+
18
+
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.
19
+
20
+
**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.
17
21
18
22
## 🚀 Features
19
23
@@ -28,28 +32,34 @@ Introducing the NestJS library, designed to harness the power of OpenAI's Assist
28
32
29
33
#### Additional features in the repository
30
34
35
+
The repository not only contains a library but also provides additional features. You don't have to build everything from scratch. You can just clone the repository and run it to take advantage of the features above and below:
36
+
31
37
-**Embedded chatbot**: The library provides a way to embed the chatbot on various websites through JavaScript scripts.
32
38
-**Chatbot client application**: The repository includes an example client application (SPA) with a chatbot.
33
39
34
40
## 🏆 Getting started
35
41
36
42
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
43
38
-
### Step 0: Prerequisites
44
+
<!-- The information that after this steps we will have the endpoints ready -->
39
45
40
-
Install Node.js which includes Node Package Manager (`^20.0.0` version).
46
+
### Step 0: Prerequisites
41
47
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/).
48
+
- Node.js (`^20.0.0` version)
49
+
- npm (`^10.0.0` version)
50
+
- NestJS (`^10.0.0` version)
51
+
- OpenAI (`^4.51.0` version)
52
+
- OpenAI API key
43
53
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:
54
+
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
55
46
56
```bash
47
57
nest new project-name
48
58
```
49
59
50
60
### Step 1: Installation
51
61
52
-
Install the library using npm:
62
+
Install the library and `openai` package using npm:
53
63
54
64
```bash
55
65
npm i @boldare/openai-assistant openai --save
@@ -71,38 +81,118 @@ Add the following content to the `.env` file:
71
81
# OpenAI API Key
72
82
OPENAI_API_KEY=
73
83
74
-
# Assistant ID - leave it empty if you don't have an assistant yet
84
+
# Assistant ID - leave it empty if you don't have an assistant to reuse
75
85
ASSISTANT_ID=
76
86
```
77
87
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.
88
+
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.
79
89
80
90
### Step 3: Configuration
81
91
82
92
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
93
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).
125
+
126
+
#### What is this step for?
127
+
From now you can run your application and call the assistant.
85
128
86
129
87
130
### Step 4: Function calling
88
131
132
+
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-testing).**
133
+
89
134
Create a new service that extends the `AgentBase` class, fill the definition and implement the `output` method.
90
135
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.
136
+
- The `output` method is the main method that will be called when the function is invoked by the assistant.
137
+
- The `definition` property is an object that describes the function and its parameters so the assistant can understand how to call it.
93
138
94
139
For more information about function calling, you can refer to the [OpenAI documentation](https://platform.openai.com/docs/assistants/tools/defining-functions).
95
140
96
141
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
142
143
+
#### What is this step for?
144
+
145
+
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.
146
+
147
+
148
+
### Step 5: Running the application and testing
149
+
150
+
Run your application and this will allow you to test the assistant.
151
+
152
+
```bash
153
+
# use this if you are using the repository:
154
+
npm run start:dev
155
+
156
+
# if you are using NestJS please check the npm scripts in the package.json file
157
+
# defualt command for NestJS is:
158
+
npm run start
159
+
```
160
+
161
+
Then you can test the assistant.
162
+
1. First, you need to create a thread. You can create one
163
+
by sending a POST request to the `/assistant/threads` endpoint with the empty body:
164
+
```
165
+
{}
166
+
```
167
+
2. Then you can send a message to the assistant by sending a POST request to the `/assistant/chat` endpoint with the following body.
168
+
```json
169
+
{
170
+
"threadId": "your-thread-id",
171
+
"content": "Hello, how are you?"
172
+
}
173
+
```
174
+
98
175
---
99
176
100
-
# 👨💻 Repository
177
+
##👨💻 Repository
101
178
102
179
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
180
181
+
## Are you stuck?
182
+
183
+
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)**
184
+
185
+
You can also ask questions in the [GitHub Discussions](https://github.com/boldare/openai-assistant/discussions) section.
186
+
187
+
**Learn more how Boldare can help you with [AI development on our website](https://www.boldare.com/services/ai-software-development-consulting/).**
188
+
189
+
190
+
191
+
192
+
<!-- TODO: Use this calendly link to book a cal with one of our engineers to get help: https://calendly.com/d/4n8-4n8-4n8/30min -->
193
+
104
194
---
105
195
106
196
# License
107
197
108
-
`@boldare/openai-assistant` is MIT licensed
198
+
`@boldare/openai-assistant`and this repository is MIT licensed
0 commit comments