@cobrowser/chatgpt 0.4.0 → 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
@@ -1 +1,2 @@
1
1
  export * from './services/TranslationService/TranslationService';
2
+ export * from './services/CoPilotService/CoPilotService';
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.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
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,10 @@
1
+ interface Item {
2
+ id?: string;
3
+ name?: string;
4
+ description?: string;
5
+ link?: string;
6
+ price: number;
7
+ category?: string;
8
+ rating?: string;
9
+ }
10
+ export default Item;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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;
@@ -32,13 +32,13 @@ class TranslationService extends BaseService_1.default {
32
32
  * @param toLanguage the desired language to translate to ( English is the default )
33
33
  * @param fromLanguage if we want to specify the language of the text, we can use this ( optional)
34
34
  */
35
- translate(text, toLanguage = 'English', fromLanguage) {
35
+ translate(text, toLanguage = this.DESTINATION_LANGUAGE, fromLanguage) {
36
36
  return __awaiter(this, void 0, void 0, function* () {
37
37
  if (!text) {
38
38
  logger_1.default.error('translation text should be provided');
39
39
  return Promise.reject(new Error('test must be provided'));
40
40
  }
41
- const desiredLanguage = toLanguage || this.DESTINATION_LANGUAGE,
41
+ const desiredLanguage = toLanguage,
42
42
  // instruction on what to do with the text
43
43
  translateText = `Translate the following ${fromLanguage} text to ${desiredLanguage}: ${text}`,
44
44
  // the body we need to send to the request
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cobrowser/chatgpt",
3
- "version": "0.4.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": "c3e9dd6ac0f9796698aa88ce1f2c2cc4fbc1a2c2"
41
+ "gitHead": "b54444fc2f1ef834b588602204fc5208b39f995d"
42
42
  }