Skip to content

Commit 8ee6058

Browse files
Merge pull request #71 from boldare/chore/adjust-readme-for-easier-understanding
chore: adjust readme.md for beginners
2 parents a19973b + c9270f4 commit 8ee6058

File tree

1 file changed

+135
-26
lines changed

1 file changed

+135
-26
lines changed

README.md

Lines changed: 135 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,77 @@
55
</p>
66

77
<p align="center">
8-
<a href="https://assistant.ai.boldare.dev/" target="_blank">demo</a> 🔹
9-
<a href="https://assistant.ai.boldare.dev/api/docs" target="_blank">api docs</a> 🔹
8+
<a href="https://assistant.ai.boldare.dev/" target="_blank">Demo</a> 🔹
9+
<a href="https://assistant.ai.boldare.dev/api/docs" target="_blank">API docs</a> 🔹
1010
<a href="https://www.npmjs.com/package/@boldare/openai-assistant" target="_blank">npm</a> 🔹
11-
<a href="https://github.com/boldare/openai-assistant" target="_blank">github</a>
11+
<a href="https://github.com/boldare/openai-assistant" target="_blank">Github</a> 🔹
12+
<a href="https://www.boldare.com/services/ai-software-development-consulting/" target="_blank">How we can help you</a>
1213
</p>
1314

15+
1416
# 🤖 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.
1522

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+
[![Watch the tutorial](https://img.youtube.com/vi/rxPdFat90qY/0.jpg)](https://www.youtube.com/watch?v=rxPdFat90qY)
1726

1827
## 🚀 Features
1928

20-
#### AI Assistant library features
29+
### AI Assistant library features
2130

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!
2838

2939
#### Additional features in the repository
3040

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!
3345

3446
## 🏆 Getting started
3547

3648
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.
3749

38-
### Step 0: Prerequisites
50+
<!-- The information that after this steps we will have the endpoints ready -->
3951

40-
Install Node.js which includes Node Package Manager (`^20.0.0` version).
52+
### Step 0: Prerequisites
4153

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
4359

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:
4561

4662
```bash
4763
nest new project-name
4864
```
4965

66+
Now you have to install the packages. Go to the next step.
67+
5068
### Step 1: Installation
5169

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:
5372

5473
```bash
5574
npm i @boldare/openai-assistant openai --save
5675
```
5776

77+
The library is installed but we have to configure it. Go to the next step.
78+
5879
### Step 2: Env variables
5980

6081
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:
7192
# OpenAI API Key
7293
OPENAI_API_KEY=
7394
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
7596
ASSISTANT_ID=
7697
```
7798

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.
79102

80103
### Step 3: Configuration
81104

82105
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.
83106

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).
107+
```typescript
108+
// chat.config.ts file
109+
import { AssistantConfigParams } from '@boldare/openai-assistant';
110+
import { AssistantCreateParams } from 'openai/resources/beta';
111+
112+
// Default OpenAI configuration
113+
export const assistantParams: AssistantCreateParams = {
114+
name: 'Your assistant name',
115+
instructions: `You are a chatbot assistant. Speak briefly and clearly.`,
116+
tools: [{ type: 'file_search'}],
117+
model: 'gpt-4-turbo',
118+
temperature: 0.05,
119+
};
120+
121+
// Additional configuration for our assistant
122+
export const assistantConfig: AssistantConfigParams = {
123+
id: process.env['ASSISTANT_ID'],
124+
params: assistantParams,
125+
filesDir: './apps/api/src/app/knowledge',
126+
toolResources: {
127+
file_search: {
128+
// Provide files if you use file_search tool
129+
fileNames: ['example1.txt', 'example2.txt'],
130+
},
131+
},
132+
};
133+
```
134+
135+
136+
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.
85140

86141

87142
### Step 4: Function calling
88143

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+
89146
Create a new service that extends the `AgentBase` class, fill the definition and implement the `output` method.
90147

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.
93150

94151
For more information about function calling, you can refer to the [OpenAI documentation](https://platform.openai.com/docs/assistants/tools/defining-functions).
95152

96153
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.
97154

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+
98187
---
99188

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
101201

102202
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).
103203

104204
---
105205

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
107216

108-
`@boldare/openai-assistant` is MIT licensed
217+
`@boldare/openai-assistant` and this repository is MIT licensed

0 commit comments

Comments
 (0)