@cobrowser/chatgpt 0.6.1 → 0.6.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/dist/services/BaseService/BaseService.d.ts +0 -6
- package/dist/services/BaseService/BaseService.js +0 -13
- package/dist/services/CopilotService/CopilotService.d.ts +1 -2
- package/dist/services/CopilotService/CopilotService.js +1 -4
- package/dist/services/TranslationService/TranslationService.d.ts +1 -2
- package/dist/services/TranslationService/TranslationService.js +3 -49
- package/package.json +4 -4
- package/dist/models/ChatGptUsageTokens.d.ts +0 -6
- package/dist/models/ChatGptUsageTokens.js +0 -3
- package/dist/models/CopilotSuggestion.d.ts +0 -6
- package/dist/models/CopilotSuggestion.js +0 -2
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AxiosError, AxiosInstance, AxiosResponse } from 'axios';
|
|
2
|
-
import ChatGptUsageTokens from '../../models/ChatGptUsageTokens';
|
|
3
2
|
declare class BaseService {
|
|
4
3
|
request: AxiosInstance;
|
|
5
4
|
readonly BASE_CHAT_COMPLETION_URL = "https://api.openai.com/v1/chat/completions";
|
|
@@ -17,11 +16,6 @@ declare class BaseService {
|
|
|
17
16
|
* @param response
|
|
18
17
|
*/
|
|
19
18
|
getResponseFirstChoice(response: AxiosResponse): string | undefined;
|
|
20
|
-
/**
|
|
21
|
-
* Filter the response from chatGpt API and only get the first choice
|
|
22
|
-
* @param response
|
|
23
|
-
*/
|
|
24
|
-
getResponseUsageTokens(response: AxiosResponse): ChatGptUsageTokens | undefined;
|
|
25
19
|
/**
|
|
26
20
|
* function to handle requests errors
|
|
27
21
|
* @param error
|
|
@@ -60,19 +60,6 @@ class BaseService {
|
|
|
60
60
|
}
|
|
61
61
|
return undefined;
|
|
62
62
|
}
|
|
63
|
-
/**
|
|
64
|
-
* Filter the response from chatGpt API and only get the first choice
|
|
65
|
-
* @param response
|
|
66
|
-
*/
|
|
67
|
-
getResponseUsageTokens(response) {
|
|
68
|
-
var _a;
|
|
69
|
-
if ((_a = response.data) === null || _a === void 0 ? void 0 : _a.usage) {
|
|
70
|
-
const usage = response.data.usage;
|
|
71
|
-
logger_1.default.info(`ChatGpt response usage tokens: ${JSON.stringify(usage)}`);
|
|
72
|
-
return usage;
|
|
73
|
-
}
|
|
74
|
-
return undefined;
|
|
75
|
-
}
|
|
76
63
|
/**
|
|
77
64
|
* function to handle requests errors
|
|
78
65
|
* @param error
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import BaseService from '../BaseService/BaseService';
|
|
2
2
|
import ChatGptMessage from '../../models/ChatGptMessage';
|
|
3
|
-
import CopilotSuggestion from '../../models/CopilotSuggestion';
|
|
4
3
|
import Item from '../../models/Item';
|
|
5
4
|
export declare class CopilotService extends BaseService {
|
|
6
5
|
constructor(apiUrl?: string, model?: string, maxNumberOfChoices?: number);
|
|
@@ -16,7 +15,7 @@ export declare class CopilotService extends BaseService {
|
|
|
16
15
|
* this will make it easy to ask chatGpt for quick replies
|
|
17
16
|
* @param conversation
|
|
18
17
|
*/
|
|
19
|
-
suggest(conversation: string): Promise<
|
|
18
|
+
suggest(conversation: string): Promise<string | undefined>;
|
|
20
19
|
/**
|
|
21
20
|
* this will request chatGPT to recommend product or item based on the whole conversation
|
|
22
21
|
* @param conversation the whole chat conversation
|
|
@@ -53,10 +53,7 @@ class CopilotService extends BaseService_1.default {
|
|
|
53
53
|
messages: [mainPromptMessage],
|
|
54
54
|
};
|
|
55
55
|
const response = yield this.request.post('', requestBody);
|
|
56
|
-
return
|
|
57
|
-
firstChoice: this.getResponseFirstChoice(response),
|
|
58
|
-
usageTokens: this.getResponseUsageTokens(response),
|
|
59
|
-
};
|
|
56
|
+
return this.getResponseFirstChoice(response);
|
|
60
57
|
}
|
|
61
58
|
catch (e) {
|
|
62
59
|
this.handleErrors(e);
|
|
@@ -8,6 +8,5 @@ export declare class TranslationService extends BaseService {
|
|
|
8
8
|
* @param toLanguage the desired language to translate to ( English is the default )
|
|
9
9
|
* @param fromLanguage if we want to specify the language of the text, we can use this ( optional)
|
|
10
10
|
*/
|
|
11
|
-
translate(text: string, toLanguage?: string, fromLanguage?: string): Promise<
|
|
12
|
-
findTextLanguage(text: string): Promise<any | undefined>;
|
|
11
|
+
translate(text: string, toLanguage?: string, fromLanguage?: string): Promise<string | undefined>;
|
|
13
12
|
}
|
|
@@ -44,60 +44,14 @@ class TranslationService extends BaseService_1.default {
|
|
|
44
44
|
// the body we need to send to the request
|
|
45
45
|
requestBody = {
|
|
46
46
|
model: this.chatGptModel,
|
|
47
|
-
messages: [
|
|
48
|
-
{
|
|
49
|
-
role: ChatGptMessage_1.ChatGptRole.SYSTEM,
|
|
50
|
-
content: 'Your a translator that providees a response in JSON format only, the response should be a json having a boolean called error and data which is array of objects, the array of objects will contain objects, each object will have translation property which will hold the translation of the message and the translated_message property will contain the the original message before being translated',
|
|
51
|
-
},
|
|
52
|
-
{
|
|
47
|
+
messages: [{
|
|
53
48
|
role: ChatGptMessage_1.ChatGptRole.USER,
|
|
54
49
|
content: translateText,
|
|
55
|
-
}
|
|
56
|
-
],
|
|
50
|
+
}],
|
|
57
51
|
};
|
|
58
52
|
try {
|
|
59
53
|
const response = yield this.request.post('', requestBody);
|
|
60
|
-
return
|
|
61
|
-
firstChoice: this.getResponseFirstChoice(response),
|
|
62
|
-
usageTokens: this.getResponseUsageTokens(response),
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
catch (e) {
|
|
66
|
-
this.handleErrors(e);
|
|
67
|
-
return Promise.reject(e);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
findTextLanguage(text) {
|
|
72
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
if (!text) {
|
|
74
|
-
logger_1.default.error('translation text should be provided');
|
|
75
|
-
return Promise.reject(new Error('text must be provided'));
|
|
76
|
-
}
|
|
77
|
-
// instruction on what to do with the text
|
|
78
|
-
const translateText = `In which language is this text in '${text}', The response should be
|
|
79
|
-
{"languageCode": "Code_here", "isError": 'true or false based on if you did fine the language code or not'}
|
|
80
|
-
other responses or explanation are not allowed `,
|
|
81
|
-
// the body we need to send to the request
|
|
82
|
-
requestBody = {
|
|
83
|
-
model: this.chatGptModel,
|
|
84
|
-
messages: [
|
|
85
|
-
{
|
|
86
|
-
role: ChatGptMessage_1.ChatGptRole.SYSTEM,
|
|
87
|
-
content: 'Your a translator that providees a response in JSON format only, a JSON that contains languageCode and isError if you cannot detect the language',
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
role: ChatGptMessage_1.ChatGptRole.USER,
|
|
91
|
-
content: translateText,
|
|
92
|
-
}
|
|
93
|
-
],
|
|
94
|
-
};
|
|
95
|
-
try {
|
|
96
|
-
const response = yield this.request.post('', requestBody);
|
|
97
|
-
return {
|
|
98
|
-
firstChoice: this.getResponseFirstChoice(response),
|
|
99
|
-
usageTokens: this.getResponseUsageTokens(response),
|
|
100
|
-
};
|
|
54
|
+
return this.getResponseFirstChoice(response);
|
|
101
55
|
}
|
|
102
56
|
catch (e) {
|
|
103
57
|
this.handleErrors(e);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cobrowser/chatgpt",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "chatgpt services to connect our projects with chatgpt api",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chatgpt",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@cobrowser/logger": "^1.0.0",
|
|
25
|
-
"axios": "^1.
|
|
26
|
-
"axios-mock-adapter": "^1.
|
|
25
|
+
"axios": "^1.6.1",
|
|
26
|
+
"axios-mock-adapter": "^1.22.0"
|
|
27
27
|
},
|
|
28
28
|
"directories": {
|
|
29
29
|
"dist": "dist"
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"bugs": {
|
|
39
39
|
"url": "https://bitbucket.org/cobrowser/cb_utils/issues"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "776fc3a9a455791a81880f83df04eb178aff5760"
|
|
42
42
|
}
|