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
Copy file name to clipboardExpand all lines: CONTRIBUTION.md
+227Lines changed: 227 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -91,6 +91,8 @@ If you would like to add a new AI bot to ChatALL, please follow these steps:
91
91
}
92
92
```
93
93
94
+
For detailed bot development documentation, see [docs/developing_bot.md](docs/developing_bot.md).
95
+
94
96
### Basic Bot Implementation Example
95
97
96
98
This is an example of using LangChainBot. Since LangChainBot uses LangChainJS, it is easy to integrate AI bots that are already supported by LangChainJS. For detailed steps, refer to the "Step-by-Step Guide to Adding a New AI Bot" section below. If you prefer not to use LangChain, you can directly extend the Bot class.
6.**Submit a Pull Request**: Once you have tested your bot and ensured it works correctly, submit a pull request following the steps mentioned in the "How to Submit Pull Requests" section.
239
241
240
242
Thank you for your contributions! We appreciate your efforts and look forward to your involvement in our community.
243
+
244
+
### Advanced Topics on Bot Development
245
+
246
+
#### UI order configuration
247
+
248
+
In the `src/bots/index.js` file, you can find the `all` array like
249
+
250
+
```javascript
251
+
// Add to the main bot list
252
+
constall= [
253
+
ChatGPT35Bot.getInstance(),
254
+
ChatGPT4Bot.getInstance(),
255
+
OpenAIAPI35Bot.getInstance(),
256
+
OpenAIAPI4Bot.getInstance(),
257
+
BingChatCreativeBot.getInstance(),
258
+
BingChatBalancedBot.getInstance(),
259
+
BingChatPreciseBot.getInstance(),
260
+
WenxinQianfanBot.getInstance(),
261
+
SparkBot.getInstance(),
262
+
MOSSBot.getInstance(),
263
+
BardBot.getInstance(),
264
+
...existing_bots...
265
+
];
266
+
```
267
+
268
+
You can change the order of the bots in this array to control their display order in the UI.
269
+
For example, if you want to move the `BardBot` between `MOSSBot` and `WenxinQianfanBot`, you can modify the array like this:
270
+
271
+
```javascript
272
+
constall= [
273
+
ChatGPT35Bot.getInstance(),
274
+
ChatGPT4Bot.getInstance(),
275
+
OpenAIAPI35Bot.getInstance(),
276
+
OpenAIAPI4Bot.getInstance(),
277
+
BingChatCreativeBot.getInstance(),
278
+
BingChatBalancedBot.getInstance(),
279
+
BingChatPreciseBot.getInstance(),
280
+
MOSSBot.getInstance(),
281
+
BardBot.getInstance(), // Moved BardBot here
282
+
WenxinQianfanBot.getInstance(),
283
+
SparkBot.getInstance(),
284
+
...existing_bots...
285
+
];
286
+
```
287
+
288
+
#### Setting component implementation
289
+
290
+
To fulfill other core functions, you need login functionality, API key configuration, etc. If your bot does not require login, or you don't mind putting the key directly in the code (strongly not recommended), you can skip this section.
291
+
292
+
##### Create a settings component
293
+
294
+
In the `src/components/BotSettings/` directory, create a new file named `KnowNothingBotSettings.vue`.
295
+
296
+
You can use existing settings components as templates:
297
+
298
+
1. If you only need login functionality, just copy `BardBotSettings.vue` and change import Bot from `@/bots/BardBot;` to import Bot from `@/bots/KnowNothingBot;`.
299
+
- (Note: Some websites have implemented security measures to prevent ChatALL and similar clients from accessing them. If you encounter such situations, you will need to do a lot of hack work.)
300
+
2. If you only need to configure the API key, copy `WenxinQianfanBotSettings.vue` and modify it, but this will require more work.
ChatALL's settings UI is built using [Vuetify 3](https://vuetifyjs.com/).
306
+
Refer to the [Vuetify 3 official documentation](https://vuetifyjs.com/en/introduction/why-vuetify/) to see and test the rich components it supports.
307
+
308
+
By reviewing the existing implementation, you can adapt the code to suit your bot’s settings.
309
+
310
+
ChatALL's settings are stored in local storage using the [`vuex-persist`](https://github.com/championswimmer/vuex-persist). It's very handy, though the documentation is not readable enough.
311
+
Here is a brief introduction on how to use it:
312
+
313
+
First, in `src/store/index.js`, add the following code:
314
+
315
+
```javascript
316
+
exportdefaultcreateStore({
317
+
state: {
318
+
...
319
+
knowNothing: {
320
+
setting1:"",
321
+
setting2:"",
322
+
},
323
+
...
324
+
},
325
+
mutations: {
326
+
...
327
+
setKnowNothing(state, { setting1, setting2 }) {
328
+
state.knowNothing= { setting1, setting2 };
329
+
},
330
+
...
331
+
},
332
+
...
333
+
});
334
+
```
335
+
336
+
`setting1`, `setting2`, and sub-objects can be added, deleted, or modified as you like. Just make sure the top-level object is `knowNothing`, even if it only has one configuration.
337
+
338
+
Then, in `KnowNothingBotSettings.vue`, add the following code:
339
+
340
+
```javascript
341
+
exportdefault {
342
+
...
343
+
methods: {
344
+
...mapMutations(["setKnowNothing"]),
345
+
setSetting1(value){
346
+
this.setKnowNothing({
347
+
...this.knowNothing,
348
+
setting1: value
349
+
})
350
+
},
351
+
setSetting2(value){
352
+
this.setKnowNothing({
353
+
...this.knowNothing,
354
+
setting2: value
355
+
})
356
+
},
357
+
},
358
+
computed: {
359
+
...mapState(["knowNothing"])
360
+
}
361
+
}
362
+
```
363
+
364
+
Finally, bind the `v-model` of the Vuetify component to the corresponding `knowNothing.xxx`, and point the action to the corresponding `setXxx()` function. For example:
365
+
366
+
```html
367
+
<v-text-field
368
+
v-model="knowNothing.setting1"
369
+
@update:model-value="setSetting1"
370
+
></v-text-field>
371
+
```
372
+
373
+
Done! Run the program and open DevTools to check if the values are correctly stored in the "Application" tab.
374
+
375
+
In `KnowNothingBot.js`, using the parameters you set is straightforward:
This is the core function, which sends and receives messages.
390
+
391
+
Reference existing bots depending on your interface type:
392
+
393
+
1. For standard HTTP APIs: see `BardBot.js`
394
+
2. For SSE-based APIs: see `ChatGPTBot.js`
395
+
3. For WebSocket APIs: see `BingChatBot.js`
396
+
397
+
How you send and parse messages depends on the specific chatbot. Once you receive a response or hit an error, do the following:
398
+
399
+
1. If the response only contains new incremental text, and you need to assemble all the text yourself, then call `onUpdateResponse(callbackParam, { content: text, done: false });`.
400
+
2. After receiving all the text, call `onUpdateResponse(callbackParam, { content: text, done: true });` to update all the data. If the text has already been `onUpdateResponse` before, you can just call `onUpdateResponse(callbackParam, { done: true });`.
401
+
3. When ending normally, call `resolve()`.
402
+
4. If an error occurs, call `reject(error)`. The `error` can be an exception or an error message string. ChatALL will automatically handle it and display it to the user.
403
+
404
+
#### checkAvailability() implementation
405
+
406
+
ChatALL calls the `checkAvailability()` function to check if the bot is available when it starts for the first time, refreshes the page (Command+R or Ctrl+R), and completes the settings.
407
+
408
+
In general, it performs these checks:
409
+
410
+
1. Is the login valid?
411
+
2. Is the API key configured properly?
412
+
3. Are all the other necessary conditions met?
413
+
414
+
If everything is good, `checkAvailability()` should return `true`.
415
+
Else, it should return `false`.
416
+
417
+
#### Custom bot icons
418
+
419
+
Place the icon file in `public/bots/knownothing-logo.png`, and modify `KnowNothingBot.js`:
420
+
421
+
```javascript
422
+
static _logoFilename ="knownothing-logo.png";
423
+
```
424
+
425
+
#### Multi-language support in JS/HTML
426
+
427
+
Language files are located in `src/i18n/locales/`, named with language codes and in .json format.
428
+
You need to add at least the following for your bot:
429
+
430
+
`en.json`
431
+
```json
432
+
{
433
+
...
434
+
"knowNothing": {
435
+
"name": "Know Nothing"
436
+
},
437
+
...
438
+
}
439
+
```
440
+
441
+
`zh.json`
442
+
```json
443
+
{
444
+
...
445
+
"knowNothing": {
446
+
"name": "啥都不懂"
447
+
},
448
+
...
449
+
}
450
+
```
451
+
452
+
Plus any other strings your bot needs.
453
+
454
+
In JavaScript, you can use the following code to call the multi-language support:
0 commit comments