Skip to content

Commit 8578e5e

Browse files
chore: adjust readme.md for beginners
Signed-off-by: Olivier Halupczok <[email protected]>
1 parent a19973b commit 8578e5e

File tree

1 file changed

+103
-13
lines changed

1 file changed

+103
-13
lines changed

README.md

Lines changed: 103 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313

1414
# 🤖 AI Assistant
1515

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

1822
## 🚀 Features
1923

@@ -28,28 +32,34 @@ Introducing the NestJS library, designed to harness the power of OpenAI's Assist
2832

2933
#### Additional features in the repository
3034

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+
3137
- **Embedded chatbot**: The library provides a way to embed the chatbot on various websites through JavaScript scripts.
3238
- **Chatbot client application**: The repository includes an example client application (SPA) with a chatbot.
3339

3440
## 🏆 Getting started
3541

3642
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.
3743

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

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

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
4353

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

4656
```bash
4757
nest new project-name
4858
```
4959

5060
### Step 1: Installation
5161

52-
Install the library using npm:
62+
Install the library and `openai` package using npm:
5363

5464
```bash
5565
npm i @boldare/openai-assistant openai --save
@@ -71,38 +81,118 @@ Add the following content to the `.env` file:
7181
# OpenAI API Key
7282
OPENAI_API_KEY=
7383
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
7585
ASSISTANT_ID=
7686
```
7787

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

8090
### Step 3: Configuration
8191

8292
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.
8393

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).
94+
```typescript
95+
// chat.config.ts file
96+
import { AssistantConfigParams } from '@boldare/openai-assistant';
97+
import { AssistantCreateParams } from 'openai/resources/beta';
98+
99+
// Default OpenAI configuration
100+
export const assistantParams: AssistantCreateParams = {
101+
name: 'Your assistant name',
102+
instructions: `You are a chatbot assistant. Speak briefly and clearly.`,
103+
tools: [
104+
{ type: 'code_interpreter' },
105+
],
106+
model: 'gpt-4-turbo',
107+
temperature: 0.05,
108+
};
109+
110+
// Additional configuration for our assistant
111+
export const assistantConfig: AssistantConfigParams = {
112+
id: process.env['ASSISTANT_ID'],
113+
params: assistantParams,
114+
filesDir: './apps/api/src/app/knowledge',
115+
toolResources: {
116+
codeInterpreter: {
117+
fileNames: [],
118+
},
119+
},
120+
};
121+
```
122+
123+
124+
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.
85128

86129

87130
### Step 4: Function calling
88131

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

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

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

96141
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.
97142

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+
98175
---
99176

100-
# 👨‍💻 Repository
177+
## 👨‍💻 Repository
101178

102179
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).
103180

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+
104194
---
105195

106196
# License
107197

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

0 commit comments

Comments
 (0)