@cobrowser/chatgpt 0.5.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/services/CopilotService/CopilotService.d.ts +25 -0
- package/dist/services/{CoPilotService/CoPilotService.js → CopilotService/CopilotService.js} +49 -3
- package/package.json +2 -2
- package/dist/services/CoPilotService/CoPilotService.d.ts +0 -7
package/README.md
CHANGED
|
@@ -13,6 +13,29 @@ the API key will be used to make authorization with the openAI APIs
|
|
|
13
13
|
|
|
14
14
|
we will have a list of services to use for different purposes
|
|
15
15
|
|
|
16
|
+
### CoPilotService
|
|
17
|
+
a service that can be used to make products recommendation and quick replies suggestion
|
|
18
|
+
|
|
19
|
+
**Usage**
|
|
20
|
+
|
|
21
|
+
to suggest some quick replies for a conversation
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
const { CopilotService } = require('@cobrowser/chatgpt');
|
|
25
|
+
const copilotService = new CopilotService();
|
|
26
|
+
const conversation = `
|
|
27
|
+
Customer: Hello
|
|
28
|
+
Agent: Hello
|
|
29
|
+
Customer: Need some help
|
|
30
|
+
`;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* return a promise that will resolve a string ( a list of suggestions ) or an undefined or an error
|
|
34
|
+
*/
|
|
35
|
+
copilotService.suggest(conversation);
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
|
|
16
39
|
### Translation Service
|
|
17
40
|
can be used to translate a text from one language to another
|
|
18
41
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './services/TranslationService/TranslationService';
|
|
2
|
-
export * from './services/
|
|
2
|
+
export * from './services/CopilotService/CopilotService';
|
package/dist/index.js
CHANGED
|
@@ -15,4 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./services/TranslationService/TranslationService"), exports);
|
|
18
|
-
__exportStar(require("./services/
|
|
18
|
+
__exportStar(require("./services/CopilotService/CopilotService"), exports);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import BaseService from '../BaseService/BaseService';
|
|
2
|
+
import ChatGptMessage from '../../models/ChatGptMessage';
|
|
3
|
+
import Item from '../../models/Item';
|
|
4
|
+
export declare class CopilotService extends BaseService {
|
|
5
|
+
constructor(apiUrl?: string, model?: string, maxNumberOfChoices?: number);
|
|
6
|
+
/**
|
|
7
|
+
* a method to be used to suggest some quick replies for the agent based on the conversation
|
|
8
|
+
* will be added as a single string in the format
|
|
9
|
+
* ```
|
|
10
|
+
* customer: hi
|
|
11
|
+
* agent: hi
|
|
12
|
+
* customer: I need some help
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* this will make it easy to ask chatGpt for quick replies
|
|
16
|
+
* @param conversation
|
|
17
|
+
*/
|
|
18
|
+
suggest(conversation: string): Promise<string | undefined>;
|
|
19
|
+
/**
|
|
20
|
+
* this will request chatGPT to recommend product or item based on the whole conversation
|
|
21
|
+
* @param conversation the whole chat conversation
|
|
22
|
+
* @param items the items to recommend from
|
|
23
|
+
*/
|
|
24
|
+
recommend(conversation: ChatGptMessage[], items: Item[]): Promise<string | undefined>;
|
|
25
|
+
}
|
|
@@ -12,14 +12,60 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.CopilotService = void 0;
|
|
16
16
|
const BaseService_1 = __importDefault(require("../BaseService/BaseService"));
|
|
17
17
|
const logger_1 = __importDefault(require("../logger"));
|
|
18
18
|
const ChatGptMessage_1 = require("../../models/ChatGptMessage");
|
|
19
|
-
class
|
|
19
|
+
class CopilotService extends BaseService_1.default {
|
|
20
20
|
constructor(apiUrl, model, maxNumberOfChoices) {
|
|
21
21
|
super(apiUrl, model, maxNumberOfChoices);
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* a method to be used to suggest some quick replies for the agent based on the conversation
|
|
25
|
+
* will be added as a single string in the format
|
|
26
|
+
* ```
|
|
27
|
+
* customer: hi
|
|
28
|
+
* agent: hi
|
|
29
|
+
* customer: I need some help
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* this will make it easy to ask chatGpt for quick replies
|
|
33
|
+
* @param conversation
|
|
34
|
+
*/
|
|
35
|
+
suggest(conversation) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
if (!(conversation === null || conversation === void 0 ? void 0 : conversation.length)) {
|
|
38
|
+
logger_1.default.error('conversation must be provided');
|
|
39
|
+
return Promise.reject(new Error('conversation must be provided'));
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
// main prompt used to instruct chatGPT to suggest some quick replies
|
|
43
|
+
const mainPrompt = `Propose some quick replies for the agent to be used on the following conversation
|
|
44
|
+
display your response as unordered list:-\n${conversation}`;
|
|
45
|
+
// main prompt will be the whole conversation as string
|
|
46
|
+
const mainPromptMessage = {
|
|
47
|
+
role: ChatGptMessage_1.ChatGptRole.USER,
|
|
48
|
+
content: mainPrompt,
|
|
49
|
+
};
|
|
50
|
+
// the body we need to send to the request
|
|
51
|
+
const requestBody = {
|
|
52
|
+
model: this.chatGptModel,
|
|
53
|
+
messages: [mainPromptMessage],
|
|
54
|
+
};
|
|
55
|
+
const response = yield this.request.post('', requestBody);
|
|
56
|
+
return this.getResponseFirstChoice(response);
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
this.handleErrors(e);
|
|
60
|
+
return Promise.reject(e);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* this will request chatGPT to recommend product or item based on the whole conversation
|
|
66
|
+
* @param conversation the whole chat conversation
|
|
67
|
+
* @param items the items to recommend from
|
|
68
|
+
*/
|
|
23
69
|
recommend(conversation, items) {
|
|
24
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
71
|
if (!(items === null || items === void 0 ? void 0 : items.length) || !(conversation === null || conversation === void 0 ? void 0 : conversation.length)) {
|
|
@@ -49,4 +95,4 @@ class CoPilotService extends BaseService_1.default {
|
|
|
49
95
|
});
|
|
50
96
|
}
|
|
51
97
|
}
|
|
52
|
-
exports.
|
|
98
|
+
exports.CopilotService = CopilotService;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobrowser/chatgpt",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "chatgpt services to connect our projects with chatgpt api",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chatgpt",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"bugs": {
|
|
39
39
|
"url": "https://bitbucket.org/cobrowser/cb_utils/issues"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "e68ebdaa78a548e653392a939a508d3e55e47494"
|
|
42
42
|
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import BaseService from '../BaseService/BaseService';
|
|
2
|
-
import ChatGptMessage from '../../models/ChatGptMessage';
|
|
3
|
-
import Item from '../../models/Item';
|
|
4
|
-
export declare class CoPilotService extends BaseService {
|
|
5
|
-
constructor(apiUrl?: string, model?: string, maxNumberOfChoices?: number);
|
|
6
|
-
recommend(conversation: ChatGptMessage[], items: Item[]): Promise<string | undefined>;
|
|
7
|
-
}
|