@cobrowser/chatgpt 0.4.1 → 0.5.1
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/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -11,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
11
15
|
};
|
|
12
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
17
|
__exportStar(require("./services/TranslationService/TranslationService"), exports);
|
|
18
|
+
__exportStar(require("./services/CoPilotService/CoPilotService"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.CoPilotService = void 0;
|
|
16
|
+
const BaseService_1 = __importDefault(require("../BaseService/BaseService"));
|
|
17
|
+
const logger_1 = __importDefault(require("../logger"));
|
|
18
|
+
const ChatGptMessage_1 = require("../../models/ChatGptMessage");
|
|
19
|
+
class CoPilotService extends BaseService_1.default {
|
|
20
|
+
constructor(apiUrl, model, maxNumberOfChoices) {
|
|
21
|
+
super(apiUrl, model, maxNumberOfChoices);
|
|
22
|
+
}
|
|
23
|
+
recommend(conversation, items) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
if (!(items === null || items === void 0 ? void 0 : items.length) || !(conversation === null || conversation === void 0 ? void 0 : conversation.length)) {
|
|
26
|
+
logger_1.default.error('conversation or items not found');
|
|
27
|
+
return Promise.reject(new Error('conversation and items must be provided'));
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
// main prompt used to instruct chatGPT to recommend products
|
|
31
|
+
const mainPrompt = `we have this list of Items: ${JSON.stringify(items)}, what to recommend for you`;
|
|
32
|
+
// main prompt will be the first message of the whole conversation
|
|
33
|
+
const firstMessage = {
|
|
34
|
+
role: ChatGptMessage_1.ChatGptRole.ASSISTANT,
|
|
35
|
+
content: mainPrompt,
|
|
36
|
+
};
|
|
37
|
+
// the body we need to send to the request
|
|
38
|
+
const requestBody = {
|
|
39
|
+
model: this.chatGptModel,
|
|
40
|
+
messages: [firstMessage, ...conversation],
|
|
41
|
+
};
|
|
42
|
+
const response = yield this.request.post('', requestBody);
|
|
43
|
+
return this.getResponseFirstChoice(response);
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
this.handleErrors(e);
|
|
47
|
+
return Promise.reject(e);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.CoPilotService = CoPilotService;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobrowser/chatgpt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
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": "b54444fc2f1ef834b588602204fc5208b39f995d"
|
|
42
42
|
}
|